Skip to content

climate_ref_core.cmor #

CMOR controlled vocabularies shared across source types.

frequency_from_mip_table(value) #

Reduce a CMOR MIP table name to its CMIP6 frequency CV value.

Some datasets record frequency and not the MIP table. This maps a table (e.g. Amon -> mon) onto the same axis.

A value that is already a valid frequency is returned unchanged, so a caller reading a layout that stores mon or day can use this without branching. day and fx are both a table name and a frequency, and map to themselves either way.

Parameters:

Name Type Description Default
value str

A CMOR MIP table name (Amon, Omon, SIday) or an existing frequency (mon).

required

Returns:

Type Description
str

The corresponding CMIP6 frequency.

Raises:

Type Description
ValueError

If the value is neither a known MIP table nor a known frequency. Failing loudly is deliberate: silently defaulting would let a mis-parsed path collapse two datasets that differ only by frequency onto one instance_id.

Source code in packages/climate-ref-core/src/climate_ref_core/cmor.py
def frequency_from_mip_table(value: str) -> str:
    """
    Reduce a CMOR MIP table name to its CMIP6 ``frequency`` CV value.

    Some datasets record ``frequency`` and not the MIP table.
    This maps a table (e.g. ``Amon`` -> ``mon``) onto the same axis.

    A value that is already a valid frequency is returned unchanged,
    so a caller reading a layout that stores ``mon`` or ``day`` can use this without branching.
    ``day`` and ``fx`` are both a table name and a frequency, and map to themselves either way.

    Parameters
    ----------
    value
        A CMOR MIP table name (``Amon``, ``Omon``, ``SIday``) or an existing frequency (``mon``).

    Returns
    -------
    :
        The corresponding CMIP6 frequency.

    Raises
    ------
    ValueError
        If the value is neither a known MIP table nor a known frequency. Failing loudly is
        deliberate: silently defaulting would let a mis-parsed path collapse two datasets that
        differ only by frequency onto one ``instance_id``.
    """
    if value in _MIP_TABLE_FREQUENCIES:
        return _MIP_TABLE_FREQUENCIES[value]
    if value in _FREQUENCIES:
        return value
    raise ValueError(f"Unknown MIP table or frequency: {value!r}")