xarray-quantity 0.1.5


pip install xarray-quantity

  Latest version

Released: Jul 27, 2022


Meta
Author: KaoruNishikawa
Requires Python: >=3.8,<4.0

Classifiers

License
  • OSI Approved :: MIT License

Programming Language
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.8
  • Python :: 3.9

xarray-quantity

PyPI Python Test License

xarray extension which supports astropy quantities.

Features

This library provides:

  • xarray DataArray and Dataset with units.

Installation

pip install xarray-quantity

Usage

QuantityArray

To create a DataArray with units, use QuantityArray class. The arguments are compatible with DataArray, except the keyword argument unit.

>>> qa = QuantityArray([1, 2, 3, 4, 5], unit="km")
>>> qa.data
[1, 2, 3, 4, 5] km
>>> qa.unit
km

QuantitySet

To create a Dataset with units, use QuantitySet class. This class also has compatibility with xarray's Dataset.

>>> arrays = {
...     "qa1": QuantityArray([1, 2, 3, 4, 5], unit="km/s"),
...     "qa2": QuantityArray([11, 12, 13, 14, 15]),
...     "da3": xr.DataArray([111, 112, 113, 114, 115])
... }
>>> qs = QuantitySet(arrays)
>>> qs.qa1.data
[1, 2, 3, 4, 5] km / s
>>> qs.qa2
xarray.QuantityArray 'qa2' (dim_0: 5)
<Quantity [11., 12., 13., 14., 15.] km / s>
Coordinates: (0)
Attributes: (0)

This library is using Semantic Versioning.

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
astropy (>5.0.3)
xarray (>2022)