xarray_units.quantity module#
- apply(da: TDataArray, method: str, /, *args: Any, **kwargs: Any) TDataArray [source]#
Apply a method of Astropy Quantity to a DataArray.
When called from an accessor, it runs
apply(accessed, method, ...)
.- Parameters:
da (TDataArray) – Input DataArray with units.
method (str) – Method (or property) name of Astropy Quantity.
*args (Any) – Positional arguments of the method.
*kwargs (Any) – Keyword arguments of the method.
- Returns:
DataArray with the method (or property) applied.
- Raises:
UnitsConversionError – Raised if units cannot be converted.
UnitsNotFoundError – Raised if units are not found.
UnitsNotValidError – Raised if units are not valid.
- Return type:
TDataArray
- decompose(da: TDataArray, /) TDataArray [source]#
Convert a DataArray with units to decomposed ones.
When called from an accessor, it runs
decompose(accessed)
.- Parameters:
da (TDataArray) – Input DataArray with units.
- Returns:
DataArray with the decomposed units.
- Raises:
UnitsConversionError – Raised if units cannot be converted.
UnitsNotFoundError – Raised if units are not found.
UnitsNotValidError – Raised if units are not valid.
- Return type:
TDataArray
- format(da: TDataArray, format: str, /, coords: bool = True, **kwargs: Any) TDataArray [source]#
Format units of a DataArray.
When called from an accessor, it runs
format(accessed, format, ...)
.- Parameters:
da (TDataArray) – Input DataArray with units.
format (str) – Format of units (e.g.
"console"
,"latex"
).coords (bool) – Whether to also format the units of the coordinates.
**kwargs (Any) – Keyword arguments of the formatting.
- Returns:
DataArray with formatted units.
- Raises:
UnitsConversionError – Raised if units cannot be converted.
UnitsNotFoundError – Raised if units are not found.
UnitsNotValidError – Raised if units are not valid.
- Return type:
TDataArray
- like(da: TDataArray, other: DataArray, /, equivalencies: Equivalency | None = None) TDataArray [source]#
Convert a DataArray with units to those of the other.
When called from an accessor, it runs
like(accessed, other, ...)
.- Parameters:
da (TDataArray) – Input DataArray with units.
other (DataArray) – DataArray with units to which the input is converted.
equivalencies (Equivalency | None) – Optional Astropy equivalencies.
- Returns:
DataArray with the converted units.
- Raises:
UnitsConversionError – Raised if units cannot be converted.
UnitsNotFoundError – Raised if units are not found.
UnitsNotValidError – Raised if units are not valid.
- Return type:
TDataArray
- set(da: TDataArray, units: UnitBase | str, /, *, overwrite: bool = False) TDataArray [source]#
Set units to a DataArray.
When called from an accessor, it runs
set(accessed, units, ...)
.- Parameters:
da (TDataArray) – Input DataArray.
units (UnitBase | str) – Units to be set to the input.
overwrite (bool) – Whether to overwrite existing units.
- Returns:
DataArray with given units in
attrs["units"]
.- Raises:
UnitsExistError – Raised if units already exist. Not raised when
overwrite
isTrue
.UnitsNotValidError – Raised if units are not valid.
- Return type:
TDataArray
- to(da: TDataArray, units: UnitBase | str, /, equivalencies: Equivalency | None = None) TDataArray [source]#
Convert a DataArray with units to other units.
When called from an accessor, it runs
to(accessed, units, ...)
.- Parameters:
da (TDataArray) – Input DataArray with units.
units (UnitBase | str) – Units to which the input is converted.
equivalencies (Equivalency | None) – Optional Astropy equivalencies.
- Returns:
DataArray with the converted units.
- Raises:
UnitsConversionError – Raised if units cannot be converted.
UnitsNotFoundError – Raised if units are not found.
UnitsNotValidError – Raised if units are not valid.
- Return type:
TDataArray