Skip to content
Edit this page

ictdesigntools.optical.grid

Wavelength grids for WDM: where channels may sit, and whether a channel plan fits.

  • DWDM, ITU-T G.694.1 (10/2020): every grid is anchored at 193.1 THz. A fixed grid puts channels at 193.1 + n × spacing THz for a spacing of 12.5, 25, 50 or 100 GHz. The flexible grid puts a slot's centre at 193.1 + n × 0.00625 THz and gives it a width of m × 12.5 GHz (n an integer, m a positive integer).
  • CWDM, ITU-T G.694.2 (12/2003): 18 nominal centre wavelengths from 1271 nm to 1611 nm, 20 nm apart.
  • Spectral bands O, E, S, C, L and U, as ITU-T G-series Supplement 39 names them.

Frequencies are in THz and wavelengths in nm (in vacuum), converted with c = 299 792 458 m/s.

>>> round(frequency_thz(0, 100), 4), round(frequency_thz(-1, 100), 4)
(193.1, 193.0)
>>> round(wavelength_nm(193.1), 2)
1552.52
>>> s = Slot(0, 4)  # 50 GHz wide, centred on 193.1 THz
>>> round(s.lower_thz, 3), round(s.upper_thz, 3)
(193.075, 193.125)
>>> slot_at(193.1375, 75)
Slot(n=6, m=6)
>>> band(1550)
'C'
>>> cwdm_channels()[:3]
(1271, 1291, 1311)
>>> len(fixed_grid(100, "C"))
42

GridError

Bases: ValueError

A frequency, wavelength or slot that is not on its grid.

Slot dataclass

Slot(n: int, m: int)

A G.694.1 flexible-grid frequency slot: centre 193.1 + n × 6.25 GHz, width m × 12.5 GHz.

overlaps

overlaps(other: Slot) -> bool

Whether two slots share any spectrum (touching edges do not).

Source code in src/ictdesigntools/optical/grid.py
def overlaps(self, other: Slot) -> bool:
    """Whether two slots share any spectrum (touching edges do not)."""
    return self.lower_thz < other.upper_thz - _TOL and other.lower_thz < self.upper_thz - _TOL

wavelength_nm

wavelength_nm(frequency_thz: float) -> float

The vacuum wavelength of frequency_thz.

Source code in src/ictdesigntools/optical/grid.py
def wavelength_nm(frequency_thz: float) -> float:
    """The vacuum wavelength of ``frequency_thz``."""
    if frequency_thz <= 0:
        raise GridError("A frequency must be positive.")
    return LIGHT / (frequency_thz * 1e12) * 1e9

frequency_thz_at

frequency_thz_at(wavelength_nm_: float) -> float

The frequency of a vacuum wavelength in nm.

Source code in src/ictdesigntools/optical/grid.py
def frequency_thz_at(wavelength_nm_: float) -> float:
    """The frequency of a vacuum wavelength in nm."""
    if wavelength_nm_ <= 0:
        raise GridError("A wavelength must be positive.")
    return LIGHT / (wavelength_nm_ * 1e-9) / 1e12

spacing_nm

spacing_nm(
    spacing_ghz: float, at_nm: float = 1550.0
) -> float

A frequency spacing expressed in nm near at_nm (Δλ ≈ λ²·Δf / c).

Source code in src/ictdesigntools/optical/grid.py
def spacing_nm(spacing_ghz: float, at_nm: float = 1550.0) -> float:
    """A frequency spacing expressed in nm near ``at_nm`` (Δλ ≈ λ²·Δf / c)."""
    return at_nm**2 * 1e-9 * spacing_ghz * 1e9 / LIGHT

frequency_thz

frequency_thz(n: int, spacing_ghz: float = 100.0) -> float

Channel n of a G.694.1 fixed grid: 193.1 + n × spacing.

Source code in src/ictdesigntools/optical/grid.py
def frequency_thz(n: int, spacing_ghz: float = 100.0) -> float:
    """Channel ``n`` of a G.694.1 fixed grid: ``193.1 + n × spacing``."""
    _check_spacing(spacing_ghz)
    return ANCHOR_THZ + n * spacing_ghz / 1000

channel_number

channel_number(
    frequency_thz_: float, spacing_ghz: float = 100.0
) -> int

The n of a frequency on a fixed grid; raises GridError when it is off the grid.

Source code in src/ictdesigntools/optical/grid.py
def channel_number(frequency_thz_: float, spacing_ghz: float = 100.0) -> int:
    """The n of a frequency on a fixed grid; raises GridError when it is off the grid."""
    _check_spacing(spacing_ghz)
    n = round((frequency_thz_ - ANCHOR_THZ) * 1000 / spacing_ghz)
    if abs(frequency_thz(n, spacing_ghz) - frequency_thz_) > _TOL:
        raise GridError(f"{frequency_thz_:g} THz is not on the {spacing_ghz:g} GHz grid.")
    return n

band

band(wavelength_nm_: float) -> str

The spectral band holding a wavelength; a band edge belongs to the band above it.

Source code in src/ictdesigntools/optical/grid.py
def band(wavelength_nm_: float) -> str:
    """The spectral band holding a wavelength; a band edge belongs to the band above it."""
    for name, (lo, hi) in BANDS.items():
        if lo <= wavelength_nm_ < hi:
            return name
    raise GridError(f"{wavelength_nm_:g} nm is outside the O to U bands (1260 to 1675 nm).")

fixed_grid

fixed_grid(
    spacing_ghz: float = 100.0,
    band_name: str = "C",
    lower_thz: float | None = None,
    upper_thz: float | None = None,
) -> tuple[float, ...]

Every channel frequency of a fixed grid whose whole width, spacing_ghz, fits in a band (or between lower_thz and upper_thz), lowest frequency first.

Source code in src/ictdesigntools/optical/grid.py
def fixed_grid(spacing_ghz: float = 100.0, band_name: str = "C",
               lower_thz: float | None = None,
               upper_thz: float | None = None) -> tuple[float, ...]:  # fmt: skip
    """Every channel frequency of a fixed grid whose whole width, ``spacing_ghz``, fits in a
    band (or between ``lower_thz`` and ``upper_thz``), lowest frequency first."""
    _check_spacing(spacing_ghz)
    lo, hi = _band_thz(band_name)
    lo = lo if lower_thz is None else lower_thz
    hi = hi if upper_thz is None else upper_thz
    half = spacing_ghz / 2000
    first = math.ceil((lo + half - ANCHOR_THZ) * 1000 / spacing_ghz - 1e-9)
    last = math.floor((hi - half - ANCHOR_THZ) * 1000 / spacing_ghz + 1e-9)
    return tuple(frequency_thz(n, spacing_ghz) for n in range(first, last + 1))

slot_at

slot_at(centre_thz: float, width_ghz: float) -> Slot

The flexible-grid slot with this centre and width; raises GridError when either is not a whole number of grid steps.

Source code in src/ictdesigntools/optical/grid.py
def slot_at(centre_thz: float, width_ghz: float) -> Slot:
    """The flexible-grid slot with this centre and width; raises GridError when either is not
    a whole number of grid steps."""
    n = round((centre_thz - ANCHOR_THZ) * 1000 / FLEX_CENTRE_STEP_GHZ)
    m = round(width_ghz / FLEX_WIDTH_STEP_GHZ)
    if abs(n * FLEX_CENTRE_STEP_GHZ / 1000 + ANCHOR_THZ - centre_thz) > _TOL:
        raise GridError(f"A centre of {centre_thz:g} THz is not on the 6.25 GHz flexible grid.")
    if m < 1 or abs(m * FLEX_WIDTH_STEP_GHZ - width_ghz) > 1e-6:
        raise GridError(f"A width of {width_ghz:g} GHz is not a multiple of 12.5 GHz.")
    return Slot(n, m)

fixed_slot

fixed_slot(n: int, spacing_ghz: float = 100.0) -> Slot

Channel n of a fixed grid as the flexible-grid slot it occupies.

Source code in src/ictdesigntools/optical/grid.py
def fixed_slot(n: int, spacing_ghz: float = 100.0) -> Slot:
    """Channel ``n`` of a fixed grid as the flexible-grid slot it occupies."""
    return slot_at(frequency_thz(n, spacing_ghz), spacing_ghz)

cwdm_channels

cwdm_channels() -> tuple[int, ...]

The 18 G.694.2 CWDM nominal centre wavelengths, in nm.

Source code in src/ictdesigntools/optical/grid.py
def cwdm_channels() -> tuple[int, ...]:
    """The 18 G.694.2 CWDM nominal centre wavelengths, in nm."""
    return tuple(CWDM_FIRST_NM + i * CWDM_SPACING_NM for i in range(CWDM_COUNT))

cwdm_channel

cwdm_channel(wavelength_nm_: float) -> int

The G.694.2 nominal centre a wavelength belongs to, when it lies within half a spacing; raises GridError otherwise.

Source code in src/ictdesigntools/optical/grid.py
def cwdm_channel(wavelength_nm_: float) -> int:
    """The G.694.2 nominal centre a wavelength belongs to, when it lies within half a spacing;
    raises GridError otherwise."""
    for c in cwdm_channels():
        if abs(wavelength_nm_ - c) < CWDM_SPACING_NM / 2:
            return c
    raise GridError(f"{wavelength_nm_:g} nm is outside the CWDM grid (1261 to 1621 nm).")

check_plan

check_plan(
    slots,
    band_name: str | None = "C",
    lower_thz: float | None = None,
    upper_thz: float | None = None,
) -> list[str]

Problems with a DWDM channel plan: slots that overlap, or that fall outside the band (or the lower_thz/upper_thz limits). An empty list means the plan fits.

Source code in src/ictdesigntools/optical/grid.py
def check_plan(slots, band_name: str | None = "C",
               lower_thz: float | None = None,
               upper_thz: float | None = None) -> list[str]:  # fmt: skip
    """Problems with a DWDM channel plan: slots that overlap, or that fall outside the band
    (or the ``lower_thz``/``upper_thz`` limits). An empty list means the plan fits."""
    slots = list(slots)
    lo = hi = None
    if band_name:
        lo, hi = _band_thz(band_name)
    lo = lo if lower_thz is None else lower_thz
    hi = hi if upper_thz is None else upper_thz
    where = f"the {band_name} band" if band_name and lower_thz is upper_thz is None else "limits"
    problems = []
    ordered = sorted(slots, key=lambda s: s.lower_thz)
    for a, b in combinations(ordered, 2):
        if a.overlaps(b):
            problems.append(f"Slots at {a.centre_thz:.5f} and {b.centre_thz:.5f} THz overlap.")
    for s in ordered:
        below = lo is not None and s.lower_thz < lo - _TOL
        above = hi is not None and s.upper_thz > hi + _TOL
        if below or above:
            problems.append(f"The slot at {s.centre_thz:.5f} THz falls outside {where}.")
    return problems