Skip to content

cmip_branded_variable_mapper#

Mapping from CMIP variable and other information to branded variable names.

Modules:

Name Description
area_label

Determination of the area label

horizontal_label

Determination of the horizontal label

mapper

Mapper from CMIP information to branded variables

mapper_classes

Classes for mapping from variable information to branded variable components

temporal_label

Determination of the temporal label

vertical_label

Determination of the vertical label

Functions:

Name Description
map_to_cmip_branded_variable

Map CMIP variable information into a branded variable

map_to_cmip_branded_variable #

map_to_cmip_branded_variable(
    variable_name: str,
    cell_methods: str | None,
    dimensions: tuple[str, ...],
) -> str

Map CMIP variable information into a branded variable

Parameters:

Name Type Description Default
variable_name str

Variable name

required
cell_methods str | None

Cell methods associated with the variable

required
dimensions tuple[str, ...]

Dimensions of the variable

required

Returns:

Type Description
str

Branded variable

Examples:

>>> map_to_cmip_branded_variable(
...     variable_name="tas",
...     cell_methods="area: time: mean",
...     dimensions=("longitude", "latitude", "time", "height2m"),
... )
'tas_tavg-h2m-hxy-u'
>>>
>>> map_to_cmip_branded_variable(
...     variable_name="hfds",
...     cell_methods="area: mean where sea time: mean",
...     dimensions=("longitude", "latitude", "time"),
... )
'hfds_tavg-u-hxy-sea'
Source code in src/cmip_branded_variable_mapper/mapper.py
def map_to_cmip_branded_variable(
    variable_name: str, cell_methods: str | None, dimensions: tuple[str, ...]
) -> str:
    """
    Map CMIP variable information into a branded variable

    Parameters
    ----------
    variable_name
        Variable name

    cell_methods
        Cell methods associated with the variable

    dimensions
        Dimensions of the variable

    Returns
    -------
    :
        Branded variable

    Examples
    --------
    >>> map_to_cmip_branded_variable(
    ...     variable_name="tas",
    ...     cell_methods="area: time: mean",
    ...     dimensions=("longitude", "latitude", "time", "height2m"),
    ... )
    'tas_tavg-h2m-hxy-u'
    >>>
    >>> map_to_cmip_branded_variable(
    ...     variable_name="hfds",
    ...     cell_methods="area: mean where sea time: mean",
    ...     dimensions=("longitude", "latitude", "time"),
    ... )
    'hfds_tavg-u-hxy-sea'
    """
    temporal_label = get_temporal_label(
        cell_methods=cell_methods, dimensions=dimensions
    )
    vertical_label = get_vertical_label(dimensions=dimensions)
    horizontal_label = get_horizontal_label(dimensions=dimensions)
    area_label = get_area_label(cell_methods=cell_methods)

    suffix = "-".join([temporal_label, vertical_label, horizontal_label, area_label])

    return "_".join([variable_name, suffix])