Skip to content
Edit this page

ictdesigntools.optical.testing

Acceptance testing for installed optical channels, worked out from the design.

  • Tier 1 loss limits (loss_limit): the most a light source and power meter may read across a channel at each wavelength. That is the channel's own designed loss plus the connections to the test cords that the reference method leaves in the reading. A one-cord reference zeroes the meter through a single launch cord, so the reading includes the connections at both ends of the link. Two cords leave one end connection in, and three cords leave neither.
  • Expected OTDR events (otdr_events): where along the fibre each connection, splice and splitter sits, the loss each should show, and its reflectance limit when a return loss grade is given. A splice's true loss is the average of the two directions' readings (bidirectional_loss_db), because a mismatch in backscatter makes one direction read high and the other low.
  • End-face inspection (inspect): defects and scratches against the IEC 61300-3-35 zone limits in data/inspection.toml.
  • acceptance() gathers all of these for one channel.
>>> from ictdesigntools.cabling.channels import Bulk, Channel, Equipment, Part
>>> from ictdesigntools.cabling.assemblies import End
>>> ch = Channel((Equipment("ODF A", "lc"), Bulk("Pigtail", "smf-os2", 2, a=End("lc")),
...               Part("fusion-splice-40"), Bulk("Feeder", "smf-os2", 500),
...               Part("fusion-splice-40"), Bulk("Pigtail", "smf-os2", 2, b=End("lc")),
...               Equipment("ODF B", "lc")))
>>> lim = loss_limit(ch, 1310)
>>> round(lim.channel_db, 3), lim.end_connections, round(lim.limit_db, 3)
(1.104, 2, 2.604)
>>> [(round(e.position_m), e.kind) for e in otdr_events(ch, 1310)]
[(2, 'splice'), (502, 'splice')]
>>> inspect("sm-pc-35", defects=[("A", 2.5)], scratches=[("A", 3.5), ("A", 3.2)]).passes
False

AcceptanceError

Bases: ValueError

An unknown method, criteria table or zone.

Acceptance dataclass

Acceptance(
    channel: Channel,
    limits: tuple[LossLimit, ...],
    events: tuple[Event, ...],
    inspection: Criteria,
)

lines

lines() -> list[str]

The acceptance criteria as lines for a test plan or a drawing note.

Source code in src/ictdesigntools/optical/testing.py
def lines(self) -> list[str]:
    """The acceptance criteria as lines for a test plan or a drawing note."""
    out = [f"Acceptance: {self.channel.name or 'channel'}"]
    out += [f"  Loss (Tier 1): {lim.line}" for lim in self.limits]
    for e in self.events:
        r = "" if e.reflectance_db is None else f", reflectance ≤ {e.reflectance_db:g} dB"
        out.append(f"  OTDR: {e.kind} at {e.position_m:g} m ({e.name}): "
                   f"≤ {e.loss_db:.2f} dB{r}")  # fmt: skip
    out.append(f"  End faces: {self.inspection.name} ({self.inspection.source})")
    return out

loss_limit

loss_limit(
    ch: Channel,
    wavelength_nm: int,
    method: str = "one-cord",
    grade: str = "",
) -> LossLimit

The Tier 1 loss limit for ch at wavelength_nm, with the test cords referenced by method (one-cord, two-cord or three-cord) and mated pairs at the ANSI/TIA-568.3 maximum or an attenuation grade.

Source code in src/ictdesigntools/optical/testing.py
def loss_limit(ch: chn.Channel, wavelength_nm: int, method: str = "one-cord",
               grade: str = "") -> LossLimit:  # fmt: skip
    """The Tier 1 loss limit for ``ch`` at ``wavelength_nm``, with the test cords referenced by
    ``method`` (``one-cord``, ``two-cord`` or ``three-cord``) and mated pairs at the ANSI/TIA-568.3
    maximum or an attenuation ``grade``."""
    if method not in REFERENCE_METHODS:
        raise AcceptanceError(f"“{method}” is not a reference method (use "
                           f"{', '.join(REFERENCE_METHODS)}).")  # fmt: skip
    n = REFERENCE_METHODS[method]
    each = components.grade(grade).max_db if grade else chn.CONNECTION_LOSS_DB
    link = ch.total_loss(wavelength_nm, grade)
    return LossLimit(wavelength_nm, method, link, n, each, link + n * each)

otdr_events

otdr_events(
    ch: Channel,
    wavelength_nm: int,
    grade: str = "",
    rl_grade: str = "",
) -> list[Event]

The events an OTDR trace of ch should show, A end to B end: each part's position, the loss it may add, and, given a return loss rl_grade, the reflectance it may show at its connections. Parts at one place (a cassette's rear and front) are one event.

Source code in src/ictdesigntools/optical/testing.py
def otdr_events(ch: chn.Channel, wavelength_nm: int, grade: str = "",
                rl_grade: str = "") -> list[Event]:  # fmt: skip
    """The events an OTDR trace of ``ch`` should show, A end to B end: each part's position,
    the loss it may add, and, given a return loss ``rl_grade``, the reflectance it may show at
    its connections. Parts at one place (a cassette's rear and front) are one event."""
    conn_db = components.grade(grade).max_db if grade else chn.CONNECTION_LOSS_DB
    reflect = components.return_loss_grade(rl_grade).reflectance_db if rl_grade else None
    out = []
    pos = 0.0
    for i, it in enumerate(ch.items):
        if isinstance(it, chn.Part):
            j = it.join
            loss = j.connections * conn_db + j.splices * chn.SPLICE_LOSS_DB + j.loss_db
            if loss or j.connections:
                kind = ("splitter" if j.kind == "splitter"
                        else "connection" if j.connections else "splice")  # fmt: skip
                out.append(Event(pos, i, kind, j.name, loss,
                                 reflect if j.connections else None))  # fmt: skip
        else:
            pos += chn._length_m(it)
    return out

bidirectional_loss_db

bidirectional_loss_db(
    a_to_b_db: float, b_to_a_db: float
) -> float

An event's true loss from the readings in each direction: their mean. One direction can read a gain when the fibre after the event backscatters more than the fibre before.

Source code in src/ictdesigntools/optical/testing.py
def bidirectional_loss_db(a_to_b_db: float, b_to_a_db: float) -> float:
    """An event's true loss from the readings in each direction: their mean. One direction
    can read a gain when the fibre after the event backscatters more than the fibre before."""
    return (a_to_b_db + b_to_a_db) / 2

criteria

criteria(slug: str = '') -> Criteria | tuple[Criteria, ...]

One inspection criteria table by slug, or every table.

Source code in src/ictdesigntools/optical/testing.py
def criteria(slug: str = "") -> Criteria | tuple[Criteria, ...]:
    """One inspection criteria table by slug, or every table."""
    if not slug:
        return tuple(_criteria().values())
    found = _criteria().get(slug)
    if found is None:
        raise AcceptanceError(
            f"“{slug}” is not an inspection table (use {', '.join(_criteria())})."
        )
    return found

inspect

inspect(slug: str, defects=(), scratches=()) -> Inspection

An end face against criteria table slug. defects and scratches are (zone, size in µm) pairs, as an inspection probe reports them.

Source code in src/ictdesigntools/optical/testing.py
def inspect(slug: str, defects=(), scratches=()) -> Inspection:
    """An end face against criteria table ``slug``. ``defects`` and ``scratches`` are
    (zone, size in µm) pairs, as an inspection probe reports them."""
    c = criteria(slug)
    failures = []
    for what, found, attr in (("defects", defects, "defects"),
                              ("scratches", scratches, "scratches")):  # fmt: skip
        counts: dict[tuple[str, int], int] = {}
        for zone, size in found:
            z = c.zone(zone)
            bands = getattr(z, attr)
            k = next(n for n, b in enumerate(bands) if b.holds(size))
            counts[(z.zone, k)] = counts.get((z.zone, k), 0) + 1
        for (zone, k), n in sorted(counts.items()):
            band = getattr(c.zone(zone), attr)[k]
            if band.max is not None and n > band.max:
                failures.append(f"zone {zone}: {n} {what} {band.label} (at most {band.max})")
    return Inspection(c, tuple(failures))

acceptance

acceptance(
    ch: Channel,
    wavelengths=(1310, 1550),
    method: str = "one-cord",
    grade: str = "",
    rl_grade: str = "",
    inspection: str = "",
) -> Acceptance

Everything a channel must meet when it is tested: a loss limit per wavelength, the OTDR events at the first wavelength, and the end-face criteria (inspection, by default multimode or single-mode PC at 35 dB as the channel's fibre suggests).

Source code in src/ictdesigntools/optical/testing.py
def acceptance(ch: chn.Channel, wavelengths=(1310, 1550), method: str = "one-cord",
               grade: str = "", rl_grade: str = "",
               inspection: str = "") -> Acceptance:  # fmt: skip
    """Everything a channel must meet when it is tested: a loss limit per wavelength, the
    OTDR events at the first wavelength, and the end-face criteria (``inspection``, by default
    multimode or single-mode PC at 35 dB as the channel's fibre suggests)."""
    wavelengths = tuple(wavelengths)
    if not wavelengths:
        raise AcceptanceError("Give at least one wavelength.")
    if not inspection:
        mm = any(getattr(it, "type", "").startswith("mmf") for it in ch.items)
        inspection = "mm-pc-apc" if mm else "sm-pc-35"
    return Acceptance(
        ch,
        tuple(loss_limit(ch, w, method, grade) for w in wavelengths),
        tuple(otdr_events(ch, wavelengths[0], grade, rl_grade)),
        criteria(inspection),
    )