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:
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:
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:
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:
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:
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:
Return type:

TDataArray

unset(da: TDataArray, /) TDataArray[source]#

Remove units from a DataArray.

When called from an accessor, it runs unset(accessed).

Parameters:

da (TDataArray) – Input DataArray.

Returns:

DataArray with units removed.

Return type:

TDataArray