Skip to content

Sensors — Registry#

Sensor / channel metadata and radiometric calibration for EO instruments (MTG-FCI, MSG-SEVIRI). The channel tables live in sensors/registry/data/*.yaml; the calibration functions turn raw L1 radiances into reflectance / brightness temperature. The registry also holds the per-sensor tasseled-cap coefficient tables (get_tasseled_cap, sensors/registry/data/tasseled_cap.yaml), consumed by pyramids_eo.spectral.tasseled_cap.

pyramids_eo.sensors.registry #

Sensor metadata registry.

Maps a sensor's bands to their wavelengths, native resolution, radiometric kind, and (nominal) calibration constants, backed by YAML tables under sensors/registry/data/. Also exposes the radiometric calibration functions and the tasseled-cap coefficient tables:

  • get_sensor / Sensor / Channel — the channel metadata tables.
  • radiance_to_reflectance — solar-channel radiance → reflectance.
  • radiance_to_brightness_temperature — thermal-channel radiance → brightness temperature (EUMETSAT inverse Planck).
  • get_tasseled_cap / TasseledCapCoefficients / available_tasseled_cap_sensors — the per-sensor tasseled-cap coefficient tables (consumed by pyramids_eo.spectral.tasseled_cap).

Channel dataclass #

One instrument channel and its nominal calibration constants.

Attributes:

Name Type Description
name str

Channel identifier (e.g. "ir_105").

wavelength_um float

Central wavelength in micrometres.

resolution_m int

Native ground sampling distance in metres.

kind str

"solar" (reflective) or "thermal" (emissive).

solar_irradiance float | None

Band-integrated solar irradiance E0 (W m-2 um-1) for a solar channel, else None.

central_wavenumber_cm1 float | None

Central wavenumber (cm-1) for a thermal channel, else None.

alpha float | None

Thermal band-correction slope, else None.

beta float | None

Thermal band-correction offset (kelvin), else None.

Source code in src/pyramids_eo/sensors/registry/sensors.py
@dataclass(frozen=True)
class Channel:
    """One instrument channel and its nominal calibration constants.

    Attributes:
        name: Channel identifier (e.g. `"ir_105"`).
        wavelength_um: Central wavelength in micrometres.
        resolution_m: Native ground sampling distance in metres.
        kind: `"solar"` (reflective) or `"thermal"` (emissive).
        solar_irradiance: Band-integrated solar irradiance `E0` (W m-2 um-1) for
            a solar channel, else `None`.
        central_wavenumber_cm1: Central wavenumber (cm-1) for a thermal channel,
            else `None`.
        alpha: Thermal band-correction slope, else `None`.
        beta: Thermal band-correction offset (kelvin), else `None`.
    """

    name: str
    wavelength_um: float
    resolution_m: int
    kind: str
    solar_irradiance: float | None = None
    central_wavenumber_cm1: float | None = None
    alpha: float | None = None
    beta: float | None = None

Sensor dataclass #

A named sensor and its channel table.

Source code in src/pyramids_eo/sensors/registry/sensors.py
@dataclass(frozen=True)
class Sensor:
    """A named sensor and its channel table."""

    name: str
    channels: Mapping[str, Channel]

    def get_channel(self, name: str) -> Channel:
        """Return the channel named `name`.

        Args:
            name: Channel identifier.

        Returns:
            The matching `Channel`.

        Raises:
            UnknownSensorError: When the channel is not in this sensor's table.
        """
        try:
            return self.channels[name]
        except KeyError as exc:
            raise UnknownSensorError(
                f"{self.name!r} has no channel {name!r}; "
                f"known channels: {sorted(self.channels)}"
            ) from exc

    @property
    def channel_names(self) -> list[str]:
        """Return the sorted channel identifiers."""
        return sorted(self.channels)
channel_names property #

Return the sorted channel identifiers.

get_channel(name) #

Return the channel named name.

Parameters:

Name Type Description Default
name str

Channel identifier.

required

Returns:

Type Description
Channel

The matching Channel.

Raises:

Type Description
UnknownSensorError

When the channel is not in this sensor's table.

Source code in src/pyramids_eo/sensors/registry/sensors.py
def get_channel(self, name: str) -> Channel:
    """Return the channel named `name`.

    Args:
        name: Channel identifier.

    Returns:
        The matching `Channel`.

    Raises:
        UnknownSensorError: When the channel is not in this sensor's table.
    """
    try:
        return self.channels[name]
    except KeyError as exc:
        raise UnknownSensorError(
            f"{self.name!r} has no channel {name!r}; "
            f"known channels: {sorted(self.channels)}"
        ) from exc

TasseledCapCoefficients dataclass #

One sensor's tasseled-cap coefficient table.

Attributes:

Name Type Description
sensor str

Sensor identifier (e.g. "landsat8_oli").

bands tuple[str, ...]

The band roles, in the order the coefficients were derived for (e.g. ("blue", "green", "red", "nir", "swir1", "swir2")).

components Mapping[str, tuple[float, ...]]

Maps each component name (e.g. "brightness") to its coefficients, one per band in bands order.

aliases Mapping[str, tuple[str, ...]]

Maps each band role to the band-name spellings that denote it, so a transform can match a Dataset's band names to roles.

reference str

Citation for the coefficients.

domain str

The reflectance domain the coefficients apply to (e.g. "at-satellite reflectance").

Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
@dataclass(frozen=True)
class TasseledCapCoefficients:
    """One sensor's tasseled-cap coefficient table.

    Attributes:
        sensor: Sensor identifier (e.g. `"landsat8_oli"`).
        bands: The band roles, in the order the coefficients were derived for
            (e.g. `("blue", "green", "red", "nir", "swir1", "swir2")`).
        components: Maps each component name (e.g. `"brightness"`) to its
            coefficients, one per band in `bands` order.
        aliases: Maps each band role to the band-name spellings that denote it,
            so a transform can match a `Dataset`'s band names to roles.
        reference: Citation for the coefficients.
        domain: The reflectance domain the coefficients apply to (e.g.
            `"at-satellite reflectance"`).
    """

    sensor: str
    bands: tuple[str, ...]
    components: Mapping[str, tuple[float, ...]]
    aliases: Mapping[str, tuple[str, ...]]
    reference: str
    domain: str

    @property
    def component_names(self) -> list[str]:
        """Return the component names this table defines, sorted.

        Returns:
            The sorted component identifiers (e.g. `["brightness", "greenness",
            "wetness"]`).

        Examples:
            - The classic three components of a Landsat table, sorted:
                ```python
                >>> from pyramids_eo.sensors.registry import get_tasseled_cap
                >>> get_tasseled_cap("landsat8_oli").component_names
                ['brightness', 'greenness', 'wetness']

                ```
        """
        return sorted(self.components)

    def role_of(self, band_name: str) -> str | None:
        """Return the band role `band_name` denotes, or `None` if unrecognised.

        Matching is case-insensitive and spans the canonical role names in
        `bands` plus every spelling in `aliases`.

        Args:
            band_name: A band name from a `Dataset` (e.g. `"B4"`, `"red"`).

        Returns:
            The canonical role (e.g. `"red"`), or `None` when `band_name`
            matches no role of this sensor.

        Examples:
            - A canonical role, an alias, and an unknown name:
                ```python
                >>> from pyramids_eo.sensors.registry import get_tasseled_cap
                >>> oli = get_tasseled_cap("landsat8_oli")
                >>> oli.role_of("red")
                'red'
                >>> oli.role_of("B5")
                'nir'
                >>> oli.role_of("thermal") is None
                True

                ```
        """
        key = band_name.strip().lower()
        for role in self.bands:
            if key == role.lower() or any(
                key == alias.lower() for alias in self.aliases.get(role, ())
            ):
                return role
        return None
component_names property #

Return the component names this table defines, sorted.

Returns:

Type Description
list[str]

The sorted component identifiers (e.g. `["brightness", "greenness",

list[str]

"wetness"]`).

Examples:

  • The classic three components of a Landsat table, sorted:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> get_tasseled_cap("landsat8_oli").component_names
    ['brightness', 'greenness', 'wetness']
    
role_of(band_name) #

Return the band role band_name denotes, or None if unrecognised.

Matching is case-insensitive and spans the canonical role names in bands plus every spelling in aliases.

Parameters:

Name Type Description Default
band_name str

A band name from a Dataset (e.g. "B4", "red").

required

Returns:

Type Description
str | None

The canonical role (e.g. "red"), or None when band_name

str | None

matches no role of this sensor.

Examples:

  • A canonical role, an alias, and an unknown name:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> oli = get_tasseled_cap("landsat8_oli")
    >>> oli.role_of("red")
    'red'
    >>> oli.role_of("B5")
    'nir'
    >>> oli.role_of("thermal") is None
    True
    
Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
def role_of(self, band_name: str) -> str | None:
    """Return the band role `band_name` denotes, or `None` if unrecognised.

    Matching is case-insensitive and spans the canonical role names in
    `bands` plus every spelling in `aliases`.

    Args:
        band_name: A band name from a `Dataset` (e.g. `"B4"`, `"red"`).

    Returns:
        The canonical role (e.g. `"red"`), or `None` when `band_name`
        matches no role of this sensor.

    Examples:
        - A canonical role, an alias, and an unknown name:
            ```python
            >>> from pyramids_eo.sensors.registry import get_tasseled_cap
            >>> oli = get_tasseled_cap("landsat8_oli")
            >>> oli.role_of("red")
            'red'
            >>> oli.role_of("B5")
            'nir'
            >>> oli.role_of("thermal") is None
            True

            ```
    """
    key = band_name.strip().lower()
    for role in self.bands:
        if key == role.lower() or any(
            key == alias.lower() for alias in self.aliases.get(role, ())
        ):
            return role
    return None

radiance_to_brightness_temperature(radiance, central_wavenumber_cm1, alpha=1.0, beta=0.0) #

Convert thermal-channel radiance to brightness temperature (kelvin).

Applies the EUMETSAT effective-radiance inverse Planck function Tb* = C2 * nu / ln(1 + C1 * nu^3 / L) followed by the per-channel band correction Tb = (Tb* - beta) / alpha, with nu the channel central wavenumber (cm-1) and L in mW m-2 sr-1 (cm-1)-1.

Parameters:

Name Type Description Default
radiance Any

Spectral radiance L (mW m-2 sr-1 (cm-1)-1), scalar or array. Non-positive values yield NaN.

required
central_wavenumber_cm1 float

Channel central wavenumber nu (cm-1).

required
alpha float

Band-correction slope (default 1.0).

1.0
beta float

Band-correction offset in kelvin (default 0.0).

0.0

Returns:

Type Description
ndarray

The brightness temperature in kelvin, same shape as radiance.

Raises:

Type Description
CalibrationError

When central_wavenumber_cm1 is not positive or alpha is zero.

Source code in src/pyramids_eo/sensors/registry/calibration.py
def radiance_to_brightness_temperature(
    radiance: Any,
    central_wavenumber_cm1: float,
    alpha: float = 1.0,
    beta: float = 0.0,
) -> np.ndarray:
    """Convert thermal-channel radiance to brightness temperature (kelvin).

    Applies the EUMETSAT effective-radiance inverse Planck function
    `Tb* = C2 * nu / ln(1 + C1 * nu^3 / L)` followed by the per-channel band
    correction `Tb = (Tb* - beta) / alpha`, with `nu` the channel central
    wavenumber (cm-1) and `L` in mW m-2 sr-1 (cm-1)-1.

    Args:
        radiance: Spectral radiance `L` (mW m-2 sr-1 (cm-1)-1), scalar or array.
            Non-positive values yield NaN.
        central_wavenumber_cm1: Channel central wavenumber `nu` (cm-1).
        alpha: Band-correction slope (default 1.0).
        beta: Band-correction offset in kelvin (default 0.0).

    Returns:
        The brightness temperature in kelvin, same shape as `radiance`.

    Raises:
        CalibrationError: When `central_wavenumber_cm1` is not positive or
            `alpha` is zero.
    """
    if central_wavenumber_cm1 <= 0:
        raise CalibrationError(
            f"central_wavenumber_cm1 must be positive; got {central_wavenumber_cm1}"
        )
    if alpha == 0:
        raise CalibrationError("alpha must be non-zero")
    nu = central_wavenumber_cm1
    radiance_arr = np.asarray(radiance, dtype=float)
    with np.errstate(invalid="ignore", divide="ignore"):
        tb_star = C2 * nu / np.log1p(C1 * nu**3 / radiance_arr)
        tb_star = np.where(radiance_arr > 0, tb_star, np.nan)
    return np.asarray((tb_star - beta) / alpha, dtype=float)

radiance_to_reflectance(radiance, solar_irradiance, sun_earth_distance=1.0, cos_sza=None) #

Convert solar-channel radiance to top-of-atmosphere reflectance.

Computes the bidirectional reflectance factor rho = pi * L * d^2 / E0, optionally normalised by the cosine of the solar zenith angle (/ cos_sza) to give a sun-angle-corrected BRF.

L and E0 must be in consistent spectral units for the ratio to be dimensionless — for MSG/MTG L1 that is the wavenumber form (L in mW m-2 sr-1 (cm-1)-1, E0 the band-effective solar irradiance in mW m-2 (cm-1)-1), which the FCI/SEVIRI registry tables provide.

Parameters:

Name Type Description Default
radiance Any

Spectral radiance L, scalar or array.

required
solar_irradiance float

Band-effective solar irradiance E0, same spectral grid as L.

required
sun_earth_distance float

Sun-earth distance d in astronomical units (default 1.0).

1.0
cos_sza Any

Cosine of the solar zenith angle for the sun-angle correction, or None to skip it.

None

Returns:

Type Description
ndarray

The reflectance, same shape as radiance.

Raises:

Type Description
CalibrationError

When solar_irradiance is not positive.

Source code in src/pyramids_eo/sensors/registry/calibration.py
def radiance_to_reflectance(
    radiance: Any,
    solar_irradiance: float,
    sun_earth_distance: float = 1.0,
    cos_sza: Any = None,
) -> np.ndarray:
    """Convert solar-channel radiance to top-of-atmosphere reflectance.

    Computes the bidirectional reflectance factor
    `rho = pi * L * d^2 / E0`, optionally normalised by the cosine of the solar
    zenith angle (`/ cos_sza`) to give a sun-angle-corrected BRF.

    `L` and `E0` must be in **consistent** spectral units for the ratio to be
    dimensionless — for MSG/MTG L1 that is the wavenumber form (`L` in
    `mW m-2 sr-1 (cm-1)-1`, `E0` the band-effective solar irradiance in
    `mW m-2 (cm-1)-1`), which the FCI/SEVIRI registry tables provide.

    Args:
        radiance: Spectral radiance `L`, scalar or array.
        solar_irradiance: Band-effective solar irradiance `E0`, same spectral
            grid as `L`.
        sun_earth_distance: Sun-earth distance `d` in astronomical units
            (default 1.0).
        cos_sza: Cosine of the solar zenith angle for the sun-angle correction,
            or `None` to skip it.

    Returns:
        The reflectance, same shape as `radiance`.

    Raises:
        CalibrationError: When `solar_irradiance` is not positive.
    """
    if solar_irradiance <= 0:
        raise CalibrationError(
            f"solar_irradiance must be positive; got {solar_irradiance}"
        )
    reflectance = (
        np.pi * np.asarray(radiance, dtype=float) * sun_earth_distance**2
    ) / solar_irradiance
    if cos_sza is not None:
        cos = np.asarray(cos_sza, dtype=float)
        # At/below the terminator (cos_sza <= 0) the sun-angle correction is
        # undefined; map those pixels to NaN instead of emitting inf + a warning.
        with np.errstate(invalid="ignore", divide="ignore"):
            reflectance = np.where(cos > 0, reflectance / cos, np.nan)
    return np.asarray(reflectance, dtype=float)

get_sensor(name) cached #

Load and return the Sensor named name from the bundled tables.

Parameters:

Name Type Description Default
name str

Sensor identifier (e.g. "fci", "seviri"), matching a sensors/registry/data/<name>.yaml table.

required

Returns:

Type Description
Sensor

The Sensor with its channel table (cached across calls).

Raises:

Type Description
UnknownSensorError

When no table exists for name.

Source code in src/pyramids_eo/sensors/registry/sensors.py
@cache
def get_sensor(name: str) -> Sensor:
    """Load and return the `Sensor` named `name` from the bundled tables.

    Args:
        name: Sensor identifier (e.g. `"fci"`, `"seviri"`), matching a
            `sensors/registry/data/<name>.yaml` table.

    Returns:
        The `Sensor` with its channel table (cached across calls).

    Raises:
        UnknownSensorError: When no table exists for `name`.
    """
    path = _DATA_DIR / f"{name.lower()}.yaml"
    if not path.exists():
        available = sorted(p.stem for p in _DATA_DIR.glob("*.yaml"))
        raise UnknownSensorError(f"unknown sensor {name!r}; available: {available}")
    raw: dict[str, Any] = yaml.safe_load(path.read_text(encoding="utf-8"))
    channels = {
        key: Channel(name=key, **value)
        for key, value in raw.get("channels", {}).items()
    }
    # A read-only view so the cached Sensor cannot be mutated by a caller.
    return Sensor(name=raw.get("name", name), channels=MappingProxyType(channels))

available_tasseled_cap_sensors() #

Return the sensor identifiers that have a bundled tasseled-cap table.

Returns:

Type Description
list[str]

The sorted sensor keys from tasseled_cap.yaml (e.g. `["landsat5_tm",

list[str]

"landsat7_etm", "landsat8_oli"]`).

Examples:

  • List the sensors that have a bundled tasseled-cap table:
    >>> from pyramids_eo.sensors.registry import available_tasseled_cap_sensors
    >>> available_tasseled_cap_sensors()
    ['landsat5_tm', 'landsat7_etm', 'landsat8_oli']
    
Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
def available_tasseled_cap_sensors() -> list[str]:
    """Return the sensor identifiers that have a bundled tasseled-cap table.

    Returns:
        The sorted sensor keys from `tasseled_cap.yaml` (e.g. `["landsat5_tm",
        "landsat7_etm", "landsat8_oli"]`).

    Examples:
        - List the sensors that have a bundled tasseled-cap table:
            ```python
            >>> from pyramids_eo.sensors.registry import available_tasseled_cap_sensors
            >>> available_tasseled_cap_sensors()
            ['landsat5_tm', 'landsat7_etm', 'landsat8_oli']

            ```
    """
    return sorted(_load())

get_tasseled_cap(sensor) #

Load and return the TasseledCapCoefficients for sensor.

Parameters:

Name Type Description Default
sensor str

Sensor identifier (e.g. "landsat8_oli", "landsat5_tm"), matching a top-level key in sensors/registry/data/tasseled_cap.yaml. Case-insensitive.

required

Returns:

Type Description
TasseledCapCoefficients

The frozen coefficient table for sensor (cached across calls, so any

TasseledCapCoefficients

casing of the same sensor returns the identical object).

Raises:

Type Description
UnknownSensorError

When no block exists for sensor.

ValueError

When the bundled table is malformed -- a component row whose length does not match the number of bands.

Examples:

  • Load a sensor and read its band order and a coefficient:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> oli = get_tasseled_cap("landsat8_oli")
    >>> oli.bands
    ('blue', 'green', 'red', 'nir', 'swir1', 'swir2')
    >>> oli.components["brightness"][0]
    0.3029
    
  • The lookup is case-insensitive and cites its source:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> tm = get_tasseled_cap("LANDSAT5_TM")
    >>> tm.sensor
    'landsat5_tm'
    >>> tm.reference
    'Crist (1985), Remote Sensing of Environment 17(3):301-306.'
    
Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
def get_tasseled_cap(sensor: str) -> TasseledCapCoefficients:
    """Load and return the `TasseledCapCoefficients` for `sensor`.

    Args:
        sensor: Sensor identifier (e.g. `"landsat8_oli"`, `"landsat5_tm"`),
            matching a top-level key in `sensors/registry/data/tasseled_cap.yaml`.
            Case-insensitive.

    Returns:
        The frozen coefficient table for `sensor` (cached across calls, so any
        casing of the same sensor returns the identical object).

    Raises:
        UnknownSensorError: When no block exists for `sensor`.
        ValueError: When the bundled table is malformed -- a component row whose
            length does not match the number of bands.

    Examples:
        - Load a sensor and read its band order and a coefficient:
            ```python
            >>> from pyramids_eo.sensors.registry import get_tasseled_cap
            >>> oli = get_tasseled_cap("landsat8_oli")
            >>> oli.bands
            ('blue', 'green', 'red', 'nir', 'swir1', 'swir2')
            >>> oli.components["brightness"][0]
            0.3029

            ```
        - The lookup is case-insensitive and cites its source:
            ```python
            >>> from pyramids_eo.sensors.registry import get_tasseled_cap
            >>> tm = get_tasseled_cap("LANDSAT5_TM")
            >>> tm.sensor
            'landsat5_tm'
            >>> tm.reference
            'Crist (1985), Remote Sensing of Environment 17(3):301-306.'

            ```
    """
    # Normalise before the cached lookup so different casings share one entry
    # (and return the same object) rather than caching a duplicate per spelling.
    return _get_tasseled_cap(sensor.lower())

pyramids_eo.sensors.registry.tasseled_cap #

Tasseled-cap (Kauth-Thomas) coefficient tables from the bundled registry.

get_tasseled_cap(sensor) loads a sensor's tasseled-cap coefficients from sensors/registry/data/tasseled_cap.yaml and returns a frozen TasseledCapCoefficients -- the band order the coefficients were derived for, the band-name aliases that let a transform recognise a Dataset's bands, and the per-component coefficient rows. The coefficients are published constants; see the reference on each record and the provenance note in the YAML.

The coefficient tables are sensor reference data (which bands, in which order, with which constants), so they live here with the channel tables; the transform that applies them to a raster is pyramids_eo.spectral.tasseled_cap.

TasseledCapCoefficients dataclass #

One sensor's tasseled-cap coefficient table.

Attributes:

Name Type Description
sensor str

Sensor identifier (e.g. "landsat8_oli").

bands tuple[str, ...]

The band roles, in the order the coefficients were derived for (e.g. ("blue", "green", "red", "nir", "swir1", "swir2")).

components Mapping[str, tuple[float, ...]]

Maps each component name (e.g. "brightness") to its coefficients, one per band in bands order.

aliases Mapping[str, tuple[str, ...]]

Maps each band role to the band-name spellings that denote it, so a transform can match a Dataset's band names to roles.

reference str

Citation for the coefficients.

domain str

The reflectance domain the coefficients apply to (e.g. "at-satellite reflectance").

Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
@dataclass(frozen=True)
class TasseledCapCoefficients:
    """One sensor's tasseled-cap coefficient table.

    Attributes:
        sensor: Sensor identifier (e.g. `"landsat8_oli"`).
        bands: The band roles, in the order the coefficients were derived for
            (e.g. `("blue", "green", "red", "nir", "swir1", "swir2")`).
        components: Maps each component name (e.g. `"brightness"`) to its
            coefficients, one per band in `bands` order.
        aliases: Maps each band role to the band-name spellings that denote it,
            so a transform can match a `Dataset`'s band names to roles.
        reference: Citation for the coefficients.
        domain: The reflectance domain the coefficients apply to (e.g.
            `"at-satellite reflectance"`).
    """

    sensor: str
    bands: tuple[str, ...]
    components: Mapping[str, tuple[float, ...]]
    aliases: Mapping[str, tuple[str, ...]]
    reference: str
    domain: str

    @property
    def component_names(self) -> list[str]:
        """Return the component names this table defines, sorted.

        Returns:
            The sorted component identifiers (e.g. `["brightness", "greenness",
            "wetness"]`).

        Examples:
            - The classic three components of a Landsat table, sorted:
                ```python
                >>> from pyramids_eo.sensors.registry import get_tasseled_cap
                >>> get_tasseled_cap("landsat8_oli").component_names
                ['brightness', 'greenness', 'wetness']

                ```
        """
        return sorted(self.components)

    def role_of(self, band_name: str) -> str | None:
        """Return the band role `band_name` denotes, or `None` if unrecognised.

        Matching is case-insensitive and spans the canonical role names in
        `bands` plus every spelling in `aliases`.

        Args:
            band_name: A band name from a `Dataset` (e.g. `"B4"`, `"red"`).

        Returns:
            The canonical role (e.g. `"red"`), or `None` when `band_name`
            matches no role of this sensor.

        Examples:
            - A canonical role, an alias, and an unknown name:
                ```python
                >>> from pyramids_eo.sensors.registry import get_tasseled_cap
                >>> oli = get_tasseled_cap("landsat8_oli")
                >>> oli.role_of("red")
                'red'
                >>> oli.role_of("B5")
                'nir'
                >>> oli.role_of("thermal") is None
                True

                ```
        """
        key = band_name.strip().lower()
        for role in self.bands:
            if key == role.lower() or any(
                key == alias.lower() for alias in self.aliases.get(role, ())
            ):
                return role
        return None
component_names property #

Return the component names this table defines, sorted.

Returns:

Type Description
list[str]

The sorted component identifiers (e.g. `["brightness", "greenness",

list[str]

"wetness"]`).

Examples:

  • The classic three components of a Landsat table, sorted:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> get_tasseled_cap("landsat8_oli").component_names
    ['brightness', 'greenness', 'wetness']
    
role_of(band_name) #

Return the band role band_name denotes, or None if unrecognised.

Matching is case-insensitive and spans the canonical role names in bands plus every spelling in aliases.

Parameters:

Name Type Description Default
band_name str

A band name from a Dataset (e.g. "B4", "red").

required

Returns:

Type Description
str | None

The canonical role (e.g. "red"), or None when band_name

str | None

matches no role of this sensor.

Examples:

  • A canonical role, an alias, and an unknown name:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> oli = get_tasseled_cap("landsat8_oli")
    >>> oli.role_of("red")
    'red'
    >>> oli.role_of("B5")
    'nir'
    >>> oli.role_of("thermal") is None
    True
    
Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
def role_of(self, band_name: str) -> str | None:
    """Return the band role `band_name` denotes, or `None` if unrecognised.

    Matching is case-insensitive and spans the canonical role names in
    `bands` plus every spelling in `aliases`.

    Args:
        band_name: A band name from a `Dataset` (e.g. `"B4"`, `"red"`).

    Returns:
        The canonical role (e.g. `"red"`), or `None` when `band_name`
        matches no role of this sensor.

    Examples:
        - A canonical role, an alias, and an unknown name:
            ```python
            >>> from pyramids_eo.sensors.registry import get_tasseled_cap
            >>> oli = get_tasseled_cap("landsat8_oli")
            >>> oli.role_of("red")
            'red'
            >>> oli.role_of("B5")
            'nir'
            >>> oli.role_of("thermal") is None
            True

            ```
    """
    key = band_name.strip().lower()
    for role in self.bands:
        if key == role.lower() or any(
            key == alias.lower() for alias in self.aliases.get(role, ())
        ):
            return role
    return None

get_tasseled_cap(sensor) #

Load and return the TasseledCapCoefficients for sensor.

Parameters:

Name Type Description Default
sensor str

Sensor identifier (e.g. "landsat8_oli", "landsat5_tm"), matching a top-level key in sensors/registry/data/tasseled_cap.yaml. Case-insensitive.

required

Returns:

Type Description
TasseledCapCoefficients

The frozen coefficient table for sensor (cached across calls, so any

TasseledCapCoefficients

casing of the same sensor returns the identical object).

Raises:

Type Description
UnknownSensorError

When no block exists for sensor.

ValueError

When the bundled table is malformed -- a component row whose length does not match the number of bands.

Examples:

  • Load a sensor and read its band order and a coefficient:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> oli = get_tasseled_cap("landsat8_oli")
    >>> oli.bands
    ('blue', 'green', 'red', 'nir', 'swir1', 'swir2')
    >>> oli.components["brightness"][0]
    0.3029
    
  • The lookup is case-insensitive and cites its source:
    >>> from pyramids_eo.sensors.registry import get_tasseled_cap
    >>> tm = get_tasseled_cap("LANDSAT5_TM")
    >>> tm.sensor
    'landsat5_tm'
    >>> tm.reference
    'Crist (1985), Remote Sensing of Environment 17(3):301-306.'
    
Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
def get_tasseled_cap(sensor: str) -> TasseledCapCoefficients:
    """Load and return the `TasseledCapCoefficients` for `sensor`.

    Args:
        sensor: Sensor identifier (e.g. `"landsat8_oli"`, `"landsat5_tm"`),
            matching a top-level key in `sensors/registry/data/tasseled_cap.yaml`.
            Case-insensitive.

    Returns:
        The frozen coefficient table for `sensor` (cached across calls, so any
        casing of the same sensor returns the identical object).

    Raises:
        UnknownSensorError: When no block exists for `sensor`.
        ValueError: When the bundled table is malformed -- a component row whose
            length does not match the number of bands.

    Examples:
        - Load a sensor and read its band order and a coefficient:
            ```python
            >>> from pyramids_eo.sensors.registry import get_tasseled_cap
            >>> oli = get_tasseled_cap("landsat8_oli")
            >>> oli.bands
            ('blue', 'green', 'red', 'nir', 'swir1', 'swir2')
            >>> oli.components["brightness"][0]
            0.3029

            ```
        - The lookup is case-insensitive and cites its source:
            ```python
            >>> from pyramids_eo.sensors.registry import get_tasseled_cap
            >>> tm = get_tasseled_cap("LANDSAT5_TM")
            >>> tm.sensor
            'landsat5_tm'
            >>> tm.reference
            'Crist (1985), Remote Sensing of Environment 17(3):301-306.'

            ```
    """
    # Normalise before the cached lookup so different casings share one entry
    # (and return the same object) rather than caching a duplicate per spelling.
    return _get_tasseled_cap(sensor.lower())

available_tasseled_cap_sensors() #

Return the sensor identifiers that have a bundled tasseled-cap table.

Returns:

Type Description
list[str]

The sorted sensor keys from tasseled_cap.yaml (e.g. `["landsat5_tm",

list[str]

"landsat7_etm", "landsat8_oli"]`).

Examples:

  • List the sensors that have a bundled tasseled-cap table:
    >>> from pyramids_eo.sensors.registry import available_tasseled_cap_sensors
    >>> available_tasseled_cap_sensors()
    ['landsat5_tm', 'landsat7_etm', 'landsat8_oli']
    
Source code in src/pyramids_eo/sensors/registry/tasseled_cap.py
def available_tasseled_cap_sensors() -> list[str]:
    """Return the sensor identifiers that have a bundled tasseled-cap table.

    Returns:
        The sorted sensor keys from `tasseled_cap.yaml` (e.g. `["landsat5_tm",
        "landsat7_etm", "landsat8_oli"]`).

    Examples:
        - List the sensors that have a bundled tasseled-cap table:
            ```python
            >>> from pyramids_eo.sensors.registry import available_tasseled_cap_sensors
            >>> available_tasseled_cap_sensors()
            ['landsat5_tm', 'landsat7_etm', 'landsat8_oli']

            ```
    """
    return sorted(_load())

pyramids_eo.sensors.registry.sensors #

Sensor / channel metadata loaded from the bundled registry tables.

get_sensor(name) loads a sensor's channel table from sensors/registry/data/<name>.yaml and returns a Sensor of frozen Channel records — band wavelength, native resolution, radiometric kind (solar / thermal), and the nominal calibration constants a reader falls back to when the granule metadata does not carry them.

Channel dataclass #

One instrument channel and its nominal calibration constants.

Attributes:

Name Type Description
name str

Channel identifier (e.g. "ir_105").

wavelength_um float

Central wavelength in micrometres.

resolution_m int

Native ground sampling distance in metres.

kind str

"solar" (reflective) or "thermal" (emissive).

solar_irradiance float | None

Band-integrated solar irradiance E0 (W m-2 um-1) for a solar channel, else None.

central_wavenumber_cm1 float | None

Central wavenumber (cm-1) for a thermal channel, else None.

alpha float | None

Thermal band-correction slope, else None.

beta float | None

Thermal band-correction offset (kelvin), else None.

Source code in src/pyramids_eo/sensors/registry/sensors.py
@dataclass(frozen=True)
class Channel:
    """One instrument channel and its nominal calibration constants.

    Attributes:
        name: Channel identifier (e.g. `"ir_105"`).
        wavelength_um: Central wavelength in micrometres.
        resolution_m: Native ground sampling distance in metres.
        kind: `"solar"` (reflective) or `"thermal"` (emissive).
        solar_irradiance: Band-integrated solar irradiance `E0` (W m-2 um-1) for
            a solar channel, else `None`.
        central_wavenumber_cm1: Central wavenumber (cm-1) for a thermal channel,
            else `None`.
        alpha: Thermal band-correction slope, else `None`.
        beta: Thermal band-correction offset (kelvin), else `None`.
    """

    name: str
    wavelength_um: float
    resolution_m: int
    kind: str
    solar_irradiance: float | None = None
    central_wavenumber_cm1: float | None = None
    alpha: float | None = None
    beta: float | None = None

Sensor dataclass #

A named sensor and its channel table.

Source code in src/pyramids_eo/sensors/registry/sensors.py
@dataclass(frozen=True)
class Sensor:
    """A named sensor and its channel table."""

    name: str
    channels: Mapping[str, Channel]

    def get_channel(self, name: str) -> Channel:
        """Return the channel named `name`.

        Args:
            name: Channel identifier.

        Returns:
            The matching `Channel`.

        Raises:
            UnknownSensorError: When the channel is not in this sensor's table.
        """
        try:
            return self.channels[name]
        except KeyError as exc:
            raise UnknownSensorError(
                f"{self.name!r} has no channel {name!r}; "
                f"known channels: {sorted(self.channels)}"
            ) from exc

    @property
    def channel_names(self) -> list[str]:
        """Return the sorted channel identifiers."""
        return sorted(self.channels)
channel_names property #

Return the sorted channel identifiers.

get_channel(name) #

Return the channel named name.

Parameters:

Name Type Description Default
name str

Channel identifier.

required

Returns:

Type Description
Channel

The matching Channel.

Raises:

Type Description
UnknownSensorError

When the channel is not in this sensor's table.

Source code in src/pyramids_eo/sensors/registry/sensors.py
def get_channel(self, name: str) -> Channel:
    """Return the channel named `name`.

    Args:
        name: Channel identifier.

    Returns:
        The matching `Channel`.

    Raises:
        UnknownSensorError: When the channel is not in this sensor's table.
    """
    try:
        return self.channels[name]
    except KeyError as exc:
        raise UnknownSensorError(
            f"{self.name!r} has no channel {name!r}; "
            f"known channels: {sorted(self.channels)}"
        ) from exc

get_sensor(name) cached #

Load and return the Sensor named name from the bundled tables.

Parameters:

Name Type Description Default
name str

Sensor identifier (e.g. "fci", "seviri"), matching a sensors/registry/data/<name>.yaml table.

required

Returns:

Type Description
Sensor

The Sensor with its channel table (cached across calls).

Raises:

Type Description
UnknownSensorError

When no table exists for name.

Source code in src/pyramids_eo/sensors/registry/sensors.py
@cache
def get_sensor(name: str) -> Sensor:
    """Load and return the `Sensor` named `name` from the bundled tables.

    Args:
        name: Sensor identifier (e.g. `"fci"`, `"seviri"`), matching a
            `sensors/registry/data/<name>.yaml` table.

    Returns:
        The `Sensor` with its channel table (cached across calls).

    Raises:
        UnknownSensorError: When no table exists for `name`.
    """
    path = _DATA_DIR / f"{name.lower()}.yaml"
    if not path.exists():
        available = sorted(p.stem for p in _DATA_DIR.glob("*.yaml"))
        raise UnknownSensorError(f"unknown sensor {name!r}; available: {available}")
    raw: dict[str, Any] = yaml.safe_load(path.read_text(encoding="utf-8"))
    channels = {
        key: Channel(name=key, **value)
        for key, value in raw.get("channels", {}).items()
    }
    # A read-only view so the cached Sensor cannot be mutated by a caller.
    return Sensor(name=raw.get("name", name), channels=MappingProxyType(channels))

pyramids_eo.sensors.registry.calibration #

Radiometric calibration for EO instrument channels.

Two conversions turn raw L1 radiances into physical quantities:

  • solar channels → top-of-atmosphere bidirectional reflectance factor (BRF), via radiance_to_reflectance;
  • thermal (IR) channels → brightness temperature, via radiance_to_brightness_temperature (the EUMETSAT effective-radiance inverse Planck with the per-channel alpha / beta correction).

The math is exact; the per-channel constants come from the file metadata where available, falling back to the bundled registry tables (see pyramids_eo.sensors.registry.get_sensor).

radiance_to_reflectance(radiance, solar_irradiance, sun_earth_distance=1.0, cos_sza=None) #

Convert solar-channel radiance to top-of-atmosphere reflectance.

Computes the bidirectional reflectance factor rho = pi * L * d^2 / E0, optionally normalised by the cosine of the solar zenith angle (/ cos_sza) to give a sun-angle-corrected BRF.

L and E0 must be in consistent spectral units for the ratio to be dimensionless — for MSG/MTG L1 that is the wavenumber form (L in mW m-2 sr-1 (cm-1)-1, E0 the band-effective solar irradiance in mW m-2 (cm-1)-1), which the FCI/SEVIRI registry tables provide.

Parameters:

Name Type Description Default
radiance Any

Spectral radiance L, scalar or array.

required
solar_irradiance float

Band-effective solar irradiance E0, same spectral grid as L.

required
sun_earth_distance float

Sun-earth distance d in astronomical units (default 1.0).

1.0
cos_sza Any

Cosine of the solar zenith angle for the sun-angle correction, or None to skip it.

None

Returns:

Type Description
ndarray

The reflectance, same shape as radiance.

Raises:

Type Description
CalibrationError

When solar_irradiance is not positive.

Source code in src/pyramids_eo/sensors/registry/calibration.py
def radiance_to_reflectance(
    radiance: Any,
    solar_irradiance: float,
    sun_earth_distance: float = 1.0,
    cos_sza: Any = None,
) -> np.ndarray:
    """Convert solar-channel radiance to top-of-atmosphere reflectance.

    Computes the bidirectional reflectance factor
    `rho = pi * L * d^2 / E0`, optionally normalised by the cosine of the solar
    zenith angle (`/ cos_sza`) to give a sun-angle-corrected BRF.

    `L` and `E0` must be in **consistent** spectral units for the ratio to be
    dimensionless — for MSG/MTG L1 that is the wavenumber form (`L` in
    `mW m-2 sr-1 (cm-1)-1`, `E0` the band-effective solar irradiance in
    `mW m-2 (cm-1)-1`), which the FCI/SEVIRI registry tables provide.

    Args:
        radiance: Spectral radiance `L`, scalar or array.
        solar_irradiance: Band-effective solar irradiance `E0`, same spectral
            grid as `L`.
        sun_earth_distance: Sun-earth distance `d` in astronomical units
            (default 1.0).
        cos_sza: Cosine of the solar zenith angle for the sun-angle correction,
            or `None` to skip it.

    Returns:
        The reflectance, same shape as `radiance`.

    Raises:
        CalibrationError: When `solar_irradiance` is not positive.
    """
    if solar_irradiance <= 0:
        raise CalibrationError(
            f"solar_irradiance must be positive; got {solar_irradiance}"
        )
    reflectance = (
        np.pi * np.asarray(radiance, dtype=float) * sun_earth_distance**2
    ) / solar_irradiance
    if cos_sza is not None:
        cos = np.asarray(cos_sza, dtype=float)
        # At/below the terminator (cos_sza <= 0) the sun-angle correction is
        # undefined; map those pixels to NaN instead of emitting inf + a warning.
        with np.errstate(invalid="ignore", divide="ignore"):
            reflectance = np.where(cos > 0, reflectance / cos, np.nan)
    return np.asarray(reflectance, dtype=float)

radiance_to_brightness_temperature(radiance, central_wavenumber_cm1, alpha=1.0, beta=0.0) #

Convert thermal-channel radiance to brightness temperature (kelvin).

Applies the EUMETSAT effective-radiance inverse Planck function Tb* = C2 * nu / ln(1 + C1 * nu^3 / L) followed by the per-channel band correction Tb = (Tb* - beta) / alpha, with nu the channel central wavenumber (cm-1) and L in mW m-2 sr-1 (cm-1)-1.

Parameters:

Name Type Description Default
radiance Any

Spectral radiance L (mW m-2 sr-1 (cm-1)-1), scalar or array. Non-positive values yield NaN.

required
central_wavenumber_cm1 float

Channel central wavenumber nu (cm-1).

required
alpha float

Band-correction slope (default 1.0).

1.0
beta float

Band-correction offset in kelvin (default 0.0).

0.0

Returns:

Type Description
ndarray

The brightness temperature in kelvin, same shape as radiance.

Raises:

Type Description
CalibrationError

When central_wavenumber_cm1 is not positive or alpha is zero.

Source code in src/pyramids_eo/sensors/registry/calibration.py
def radiance_to_brightness_temperature(
    radiance: Any,
    central_wavenumber_cm1: float,
    alpha: float = 1.0,
    beta: float = 0.0,
) -> np.ndarray:
    """Convert thermal-channel radiance to brightness temperature (kelvin).

    Applies the EUMETSAT effective-radiance inverse Planck function
    `Tb* = C2 * nu / ln(1 + C1 * nu^3 / L)` followed by the per-channel band
    correction `Tb = (Tb* - beta) / alpha`, with `nu` the channel central
    wavenumber (cm-1) and `L` in mW m-2 sr-1 (cm-1)-1.

    Args:
        radiance: Spectral radiance `L` (mW m-2 sr-1 (cm-1)-1), scalar or array.
            Non-positive values yield NaN.
        central_wavenumber_cm1: Channel central wavenumber `nu` (cm-1).
        alpha: Band-correction slope (default 1.0).
        beta: Band-correction offset in kelvin (default 0.0).

    Returns:
        The brightness temperature in kelvin, same shape as `radiance`.

    Raises:
        CalibrationError: When `central_wavenumber_cm1` is not positive or
            `alpha` is zero.
    """
    if central_wavenumber_cm1 <= 0:
        raise CalibrationError(
            f"central_wavenumber_cm1 must be positive; got {central_wavenumber_cm1}"
        )
    if alpha == 0:
        raise CalibrationError("alpha must be non-zero")
    nu = central_wavenumber_cm1
    radiance_arr = np.asarray(radiance, dtype=float)
    with np.errstate(invalid="ignore", divide="ignore"):
        tb_star = C2 * nu / np.log1p(C1 * nu**3 / radiance_arr)
        tb_star = np.where(radiance_arr > 0, tb_star, np.nan)
    return np.asarray((tb_star - beta) / alpha, dtype=float)