xarray_units package#
- units(accessed: TDataArray, /, *, chain: int = 1, of: Sequence[Hashable] | Hashable = None) Units[TDataArray] [source]#
Return a units accessor of a DataArray.
- Parameters:
accessed (TDataArray) – DataArray to be accessed.
chain (int) – Length of method chain. If it is greater than 1, each accessor method (or operation) will return not the resulting DataArray but an accessor of it with the length of
chain - 1
. Note that, while this simplifies the method chain notation, static type checking may not work correctly in the middle of it.of (Sequence[Hashable] | Hashable) – Coordinate(s) of the DataArray to be accessed. If specified, each accessor method will be applied not to the DataArray itself but to the selected coordinates, and return the DataArray with the updated coordinates.
- Returns:
Units accessor of the DataArray.
- Raises:
TypeError – Raised if options of the accessor are not valid.
- Return type:
Units[TDataArray]
- unitsof(obj: Any, /, *, format: str | None = None, strict: bool = False, **kwargs: Any) UnitBase | str | None [source]#
Return units of an object if they exist and are valid.
- Parameters:
obj (Any) – Any object from which units are extracted.
format (str | None) – Format of units. If given, the return value will be
string
. Otherwise, it will beUnitBase
.strict (bool) – Whether to allow
None
as the return value when units do not exist in the object.**kwargs (Any) – Keyword arguments of the formatting.
- Returns:
Extracted units from the object.
- Raises:
UnitsConversionError – Raised if
format
is given but units cannot be formatted to it.UnitsNotFoundError – Raised if
strict
isTrue
but units do not exist in the object.UnitsNotValidError – Raised if units exist in the object but they cannot be converted to
UnitBase
.
- Return type:
UnitBase | str | None