climate.utils.units

Module Contents

climate.utils.units.ensure_units(ds, var, expected_units, strict=False)

Ensure that a variable in the dataset has the expected units for xclim indicators.

Parameters:
  • ds (xarray.Dataset) – Dataset containing the variable.

  • var (str) – Variable name (e.g. “tas”, “pr”).

  • expected_units (str) – Units expected by xclim (e.g. “degC”, “mm/day”).

  • strict (bool, default False) – If True, attempt to physically convert units using pint. If False, only overwrite the unit attribute and issue a warning.

Returns:

The dataset with corrected units.

Return type:

xarray.Dataset