convert_dataarray¶
- earthkit.utils.units.convert_dataarray(data: xarray.DataArray, target_units: str | Unit | Units | dict[str, str | Unit | Units] | None = None, source_units: str | Unit | Units | dict[str, str | Unit | Units] | None = None) xarray.DataArray[source]¶
Convert the units of an xarray.DataArray.
- Parameters:
data (xarray.DataArray) – The DataArray to convert.
target_units (str or dict, optional) – The units to convert to. If a dict, looks up the DataArray’s
namein the mapping. If the name is not found, no conversion is performed.source_units (str or dict, optional) – The units of the data. If a dict, looks up the DataArray’s
namein the mapping, falling back todata.attrs["units"]. If a str, used directly as the source units. If None, tries to read fromdata.attrs["units"].
- Returns:
The converted DataArray, or the original if conversion is not possible.
- Return type: