Skip to content
Edit this page

ictdesigntools.cabling.splices

Fiber splices: which strand meets which, in which tray, and the splice diagram.

A FiberCable has its fibers in buffer tubes, numbered and coloured by the TIA-598 code (strand gives a fiber's tube, colours and stripe). A SplicePlan joins fibers of cables on the A side to fibers of cables on the B side, in splice trays; check finds fibers used twice, fibers a cable doesn't have and trays over capacity; schedule lists every splice as a row for a table or CSV; and splice_diagram draws a sheet to the Splice.me proposal for a splice diagram standard: a title block, A cables in a column on the left and B cables on the right (splitters too, as Splitter), and nothing between them but the splices, computed from the plan instead of placed by hand; bedsheet puts a network's sheets on a grid of pages. Each splice is a group with a Meta (kind splice) for to_svg(interactive=True), so hovering one lights up the whole path from fiber to fiber.

>>> a, b = FiberCable("F1", 24), FiberCable("D1", 12)
>>> plan = SplicePlan([a], [b], tray_capacity=12)
>>> plan.join(a, 1, b, 1, count=12)
>>> [row[0] for row in schedule(plan)][:2], check(plan)
([1, 1], [])
>>> strand(a, 14)
Strand(fiber=14, tube=2, tube_color='Orange', color='Orange', stripe='', port='')

Splitter dataclass

Splitter(name: str, outputs: int, inputs: int = 1)

A passive optical splitter as equipment on a splice sheet: inputs and outputs pigtails, numbered as ports with the inputs first (input(k) and output(k) give a port's number for SplicePlan.join). Pigtails take the colour code in each group.

loss_db property

loss_db: float | None

Typical maximum insertion loss for a 1×N PLC splitter (optical.budget).

SplicePlan dataclass

SplicePlan(
    a: list[Item],
    b: list[Item],
    splices: list[Splice] = list(),
    tray_capacity: int = 12,
    name: str = "",
)

Cables and equipment (splitters) in a closure or panel on the A and B sides, and the splices between them. Every splice joins an A-side fiber to a B-side fiber, so a splitter goes on the side opposite both its feeder and the cables its outputs serve.

join

join(
    a: Item | str,
    a_fiber: int,
    b: Item | str,
    b_fiber: int,
    count: int = 1,
    tray: int | None = None,
    kind: str = "fusion",
) -> None

Splice count fibers in order, from a_fiber of a to b_fiber of b, into the next free slots (filling each tray before the next unless tray is given).

Source code in src/ictdesigntools/cabling/splices.py
def join(self, a: Item | str, a_fiber: int, b: Item | str, b_fiber: int,
         count: int = 1, tray: int | None = None, kind: str = "fusion") -> None:  # fmt: skip
    """Splice ``count`` fibers in order, from ``a_fiber`` of ``a`` to ``b_fiber`` of ``b``,
    into the next free slots (filling each tray before the next unless ``tray`` is given)."""
    a_name = a if isinstance(a, str) else a.name
    b_name = b if isinstance(b, str) else b.name
    for k in range(count):
        t, slot = self._next_slot(tray)
        self.splices.append(Splice(a_name, a_fiber + k, b_name, b_fiber + k, t, slot, kind))

colors cached

colors() -> tuple[tuple[str, str, str], ...]

The twelve colours as (name, abbreviation, hex), in TIA-598 order.

Source code in src/ictdesigntools/cabling/splices.py
@cache
def colors() -> tuple[tuple[str, str, str], ...]:
    """The twelve colours as (name, abbreviation, hex), in TIA-598 order."""
    found = sorted(rows("fiber_colors", "color"), key=lambda r: r["position"])
    return tuple((r["name"], r["abbr"], r["hex"]) for r in found)

color_of

color_of(position: int) -> tuple[str, str]

(colour, stripe) for a position in the sequence, from 1: 14 is ("Orange", "Black").

Source code in src/ictdesigntools/cabling/splices.py
def color_of(position: int) -> tuple[str, str]:
    """(colour, stripe) for a position in the sequence, from 1: 14 is ("Orange", "Black")."""
    if position < 1:
        raise ValueError("Positions count from 1.")
    names = [c[0] for c in colors()]
    base = names[(position - 1) % 12]
    group = (position - 1) // 12 + 1
    if group == 1:
        return base, ""
    if group not in _stripes():
        raise ValueError(f"Position {position} is past the colour code (48).")
    stripe, except_black = _stripes()[group]
    if base == stripe:
        stripe = except_black or stripe
    return base, stripe

strand

strand(cable: Item, fiber: int) -> Strand

Fiber fiber of cable: its tube and colours (for a splitter, its port: tube 1 holds the inputs and tube 2 the outputs).

Source code in src/ictdesigntools/cabling/splices.py
def strand(cable: Item, fiber: int) -> Strand:
    """Fiber ``fiber`` of ``cable``: its tube and colours (for a splitter, its port: tube 1
    holds the inputs and tube 2 the outputs)."""
    if not 1 <= fiber <= cable.fibers:
        raise ValueError(f"{cable.name} has fibers 1–{cable.fibers}, not {fiber}.")
    if isinstance(cable, Splitter):
        if fiber <= cable.inputs:
            port = "IN" if cable.inputs == 1 else f"IN {fiber}"
            color, stripe = color_of(fiber)
            return Strand(fiber, 1, "", color, stripe, port)
        k = fiber - cable.inputs
        color, stripe = color_of(k)
        return Strand(fiber, 2, "", color, stripe, f"OUT {k}")
    tube = (fiber - 1) // cable.fibers_per_tube + 1
    color, stripe = color_of((fiber - 1) % cable.fibers_per_tube + 1)
    tube_color, _ = color_of(tube)
    return Strand(fiber, tube, tube_color, color, stripe)

check

check(plan: SplicePlan) -> list[str]

Problems with a plan: unknown cables, fibers out of range or used twice, trays and slots over capacity or used twice.

Source code in src/ictdesigntools/cabling/splices.py
def check(plan: SplicePlan) -> list[str]:
    """Problems with a plan: unknown cables, fibers out of range or used twice, trays and
    slots over capacity or used twice."""
    problems = []
    seen: dict[tuple[str, int], Splice] = {}
    slots: dict[tuple[int, int], Splice] = {}
    a_side, b_side = {c.name for c in plan.a}, {c.name for c in plan.b}
    for s in plan.splices:
        if s.a_cable in b_side and s.a_cable not in a_side:
            problems.append(f"{s.a_cable} is on the B side but spliced as an A-side fiber.")
        if s.b_cable in a_side and s.b_cable not in b_side:
            problems.append(f"{s.b_cable} is on the A side but spliced as a B-side fiber.")
        for name, fiber in ((s.a_cable, s.a_fiber), (s.b_cable, s.b_fiber)):
            try:
                cable = plan.cable(name)
            except ValueError as exc:
                problems.append(str(exc))
                continue
            if not 1 <= fiber <= cable.fibers:
                problems.append(f"{name} has no fiber {fiber}.")
            elif (name, fiber) in seen:
                trays = f"trays {seen[name, fiber].tray} and {s.tray}"
                problems.append(f"{name} fiber {fiber} is spliced twice ({trays}).")
            seen[name, fiber] = s
        if s.slot > plan.tray_capacity:
            problems.append(f"Tray {s.tray} slot {s.slot} is past its {plan.tray_capacity} slots.")
        if (s.tray, s.slot) in slots:
            problems.append(f"Tray {s.tray} slot {s.slot} holds two splices.")
        slots[s.tray, s.slot] = s
    return list(dict.fromkeys(problems))

schedule

schedule(plan: SplicePlan) -> list[tuple]

One row per splice, by tray and slot (see SCHEDULE_HEADER).

Source code in src/ictdesigntools/cabling/splices.py
def schedule(plan: SplicePlan) -> list[tuple]:
    """One row per splice, by tray and slot (see ``SCHEDULE_HEADER``)."""
    out = []
    for s in sorted(plan.splices, key=lambda s: (s.tray, s.slot)):
        a = strand(plan.cable(s.a_cable), s.a_fiber)
        b = strand(plan.cable(s.b_cable), s.b_fiber)
        out.append((s.tray, s.slot, s.a_cable, _tube(a), a.port or a.fiber, _colour(a),
                    s.b_cable, _tube(b), b.port or b.fiber, _colour(b), s.kind))  # fmt: skip
    return out

splice_diagram

splice_diagram(
    plan: SplicePlan,
    all_fibers: bool = False,
    id_prefix: str = "",
) -> Drawing

The plan as a splice diagram sheet, in mm. Only spliced fibers are listed unless all_fibers; spare fibers are then listed on their face with no splice. Splitters are drawn in their column like cables (rule 4.4), their inputs and outputs in place of tubes. id_prefix goes before each splice's Meta id, to keep ids apart on a bedsheet.

Source code in src/ictdesigntools/cabling/splices.py
def splice_diagram(plan: SplicePlan, all_fibers: bool = False, id_prefix: str = "") -> Drawing:
    """The plan as a splice diagram sheet, in mm. Only spliced fibers are listed unless
    ``all_fibers``; spare fibers are then listed on their face with no splice. Splitters are
    drawn in their column like cables (rule 4.4), their inputs and outputs in place of tubes.
    ``id_prefix`` goes before each splice's ``Meta`` id, to keep ids apart on a bedsheet."""
    used = {(s.a_cable, s.a_fiber) for s in plan.splices} | {
        (s.b_cable, s.b_fiber) for s in plan.splices}  # fmt: skip
    top = PITCH * 2  # under the title block and one gap
    a_rows, a_heads, a_end = _face(plan.a, used, all_fibers, top)
    b_rows, b_heads, b_end = _face(plan.b, used, all_fibers, top)
    a_y = {(c.name, st.fiber): y for c, st, y in a_rows}
    b_y = {(c.name, st.fiber): y for c, st, y in b_rows}

    face_a = TUBE_W + FIBER_W + TRAY_COL_W
    face_b = TUBE_W + FIBER_W
    xa = face_a  # inner edge of the A column
    xb = xa + SPAN  # inner edge of the B column
    width = xb + face_b
    height = max(a_end, b_end)
    trays = sorted({s.tray for s in plan.splices})
    styles = {
        "title": Style(color=INK),
        "face": Style(fill="#ffffff", stroke=INK, width=0.3),
        "header": Style(fill="#f1f0ec", stroke=INK, width=0.3),
        "label": Style(color=INK),
        "spare": Style(color=MUTED),
        "tube": Style(fill="#ffffff", stroke=INK, width=0.3),
    }
    # Colour by where a splice goes: one colour for each pair of cables or equipment joined.
    targets = list(dict.fromkeys((s.a_cable, s.b_cable) for s in sorted(plan.splices, key=_order)))
    for i in range(len(targets)):
        styles[f"splice-{i}"] = Style(stroke=SPLICE_COLORS[i % len(SPLICE_COLORS)], width=0.45)
    title = plan.name or "Splice diagram"
    count = f"{len(plan.splices)} splices in {len(trays)} tray{'' if len(trays) == 1 else 's'}"
    d = Drawing(view=(-4, -4, width + 8, height + 8), units="mm", stroke=0.3, font=2.4,
                title=title, desc=f"{count}.", styles=styles)  # fmt: skip

    # 4.1: the title block, centred on top, one pitch high.
    d.add(Rect(0, 0, width, PITCH, style="header"))
    d.add(Text(width / 2, PITCH / 2, truncate(f"{title} · {count}", 2.6, width - 4), 2.6,
               style="title"))  # fmt: skip

    tray_of = {(s.a_cable, s.a_fiber): s for s in plan.splices}

    def face(rows_, heads, x0, w, mirror):
        """One column: a header per cable, then a row per fiber with its tube and colour in
        black and white (4.7)."""
        for cable, hy in heads:
            d.add(Rect(x0, hy, w, PITCH, style="header"))
            d.add(Text(x0 + (w - 1.5 if mirror else 1.5), hy + PITCH / 2,
                       truncate(cable.heading, 2.6, w - 3), 2.6,
                       anchor="end" if mirror else "start", style="label"))  # fmt: skip
            if not mirror:
                d.add(Text(x0 + w - 1.5, hy + PITCH / 2, "tray·slot", 2.0, anchor="end",
                           style="spare"))  # fmt: skip
        tubes: dict[tuple[str, int], list[float]] = {}
        items = {}
        for cable, st, y in rows_:
            tubes.setdefault((cable.name, st.tube), []).append(y)
            items[cable.name] = cable
        tube_x = x0 + w - TUBE_W if mirror else x0
        for (name, tube), ys in tubes.items():
            text = _group_text(items[name], tube)
            d.add(Rect(tube_x, ys[0], TUBE_W, ys[-1] + PITCH - ys[0], style="tube",
                       title=f"{name} {text}"))  # fmt: skip
            d.add(Text(tube_x + TUBE_W / 2, (ys[0] + ys[-1] + PITCH) / 2,
                       truncate(text, 2.2, TUBE_W - 2), 2.2, style="label"))  # fmt: skip
        fiber_x = x0 + TUBE_W if not mirror else x0
        for cable, st, y in rows_:
            spliced = (cable.name, st.fiber) in used
            d.add(Rect(fiber_x, y, FIBER_W + (0 if mirror else TRAY_COL_W), PITCH, style="face"))
            label = st.label if spliced else f"{st.label} · spare"
            d.add(Text(fiber_x + (FIBER_W - 1.5 if mirror else 1.5), y + PITCH / 2,
                       truncate(label, 2.2, FIBER_W - 3), 2.2,
                       anchor="end" if mirror else "start",
                       style="label" if spliced else "spare"))  # fmt: skip
            s = tray_of.get((cable.name, st.fiber)) if not mirror else None
            if s is not None:
                d.add(Text(x0 + face_a - 1.5, y + PITCH / 2, f"{s.tray}·{s.slot:02d}", 2.2,
                           anchor="end", style="label"))  # fmt: skip

    face(a_rows, a_heads, 0.0, face_a, False)
    face(b_rows, b_heads, xb, face_b, True)

    # 4.4 and 4.5: only splices between the columns, level at both faces, two bends at most.
    for s in sorted(plan.splices, key=_order):
        a = strand(plan.cable(s.a_cable), s.a_fiber)
        b = strand(plan.cable(s.b_cable), s.b_fiber)
        ya = a_y[s.a_cable, s.a_fiber] + PITCH / 2
        yb = b_y[s.b_cable, s.b_fiber] + PITCH / 2
        pts = ((xa, ya), (xa + LEAD, ya), (xb - LEAD, yb), (xb, yb))
        if ya == yb:
            pts = ((xa, ya), (xb, yb))
        tip = f"Tray {s.tray} slot {s.slot}: {s.a_cable} {a.label} ↔ {s.b_cable} {b.label}"
        ends = {"a": f"{s.a_cable}:{s.a_fiber}", "b": f"{s.b_cable}:{s.b_fiber}"}
        meta = Meta.of(id=f"{id_prefix}splice-{s.tray}-{s.slot}", kind="splice", tray=s.tray,
                       slot=s.slot, **ends)  # fmt: skip
        line = Polyline(pts, style=f"splice-{targets.index((s.a_cable, s.b_cable))}")
        d.add(Group((line,), title=tip, meta=meta))
    return d

bedsheet

bedsheet(
    sheets: list[SplicePlan | Drawing],
    columns: int | None = None,
    page: str = "A4",
    margin: float = 10.0,
    gap: float = 10.0,
    title: str = "",
) -> Drawing

Every sheet of a network on one drawing (rules 5.1 to 5.4): each sheet on a portrait page (A4 or Letter, or larger where a sheet doesn't fit, the same for every cell), pages on a grid read left to right and top to bottom from the top-left, so the network's central unit goes first, with gap between pages for room to breathe. Plans are drawn with splice_diagram and their splice ids prefixed with the sheet number.

Source code in src/ictdesigntools/cabling/splices.py
def bedsheet(sheets: list[SplicePlan | Drawing], columns: int | None = None, page: str = "A4",
             margin: float = 10.0, gap: float = 10.0, title: str = "") -> Drawing:  # fmt: skip
    """Every sheet of a network on one drawing (rules 5.1 to 5.4): each sheet on a portrait
    page (``A4`` or ``Letter``, or larger where a sheet doesn't fit, the same for every cell),
    pages on a grid read left to right and top to bottom from the top-left, so the network's
    central unit goes first, with ``gap`` between pages for room to breathe. Plans are drawn
    with ``splice_diagram`` and their splice ids prefixed with the sheet number."""
    if not sheets:
        raise ValueError("A bedsheet needs at least one sheet.")
    drawings = [splice_diagram(x, id_prefix=f"{i}-") if isinstance(x, SplicePlan) else x
                for i, x in enumerate(sheets, 1)]  # fmt: skip
    pw, ph = PAGES[page]
    cw = max(pw, *(d.view[2] + 2 * margin for d in drawings))
    ch = max(ph, *(d.view[3] + 2 * margin for d in drawings))
    cols = columns or math.ceil(math.sqrt(len(drawings)))
    rows_ = math.ceil(len(drawings) / cols)
    top = PITCH * 3 if title else 0.0
    width, height = cols * cw + (cols - 1) * gap, top + rows_ * ch + (rows_ - 1) * gap
    styles: dict[str, Style] = {
        "page": Style(fill="#ffffff", stroke=MUTED, width=0.35),
        "header": Style(fill="#f1f0ec", stroke=INK, width=0.3),
        "title": Style(color=INK),
    }
    for d in drawings:
        styles.update(d.styles)
    out = Drawing(view=(-margin, -margin, width + 2 * margin, height + 2 * margin), units="mm",
                  stroke=0.3, font=2.4, title=title or "Bedsheet",
                  desc=f"{len(drawings)} sheets.", styles=styles)  # fmt: skip
    if title:
        out.add(Rect(0, 0, width, PITCH * 2, style="header"))
        out.add(Text(width / 2, PITCH, truncate(title, 4.0, width - 4), 4.0, style="title"))
    for i, d in enumerate(drawings):
        x = (i % cols) * (cw + gap)
        y = top + (i // cols) * (ch + gap)
        vx, vy, vw, vh = d.view
        out.add(Rect(x, y, cw, ch, style="page", title=d.title))
        # Centre the sheet across its page and keep it at the top.
        dx, dy = x + (cw - vw) / 2 - vx, y + margin - vy
        out.add(Group(tuple(d.items), transform=Transform.translate(dx, dy), title=d.title,
                      meta=Meta.of(id=f"sheet-{i + 1}", kind="sheet")))  # fmt: skip
    return out