Physical units interface to xarray using Pint
Project description
pint-xarray
A convenience wrapper for using pint with xarray.
Usage
To convert the variables of a Dataset
to quantities:
In [1]: import pint_xarray
...: import xarray as xr
In [2]: ds = xr.Dataset({"a": ("x", [0, 1, 2]), "b": ("y", [-3, 5, 1], {"units": "m"})})
...: ds
Out[2]:
<xarray.Dataset>
Dimensions: (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
a (x) int64 0 1 2
b (y) int64 -3 5 1
In [3]: q = ds.pint.quantify(a="s")
...: q
Out[3]:
<xarray.Dataset>
Dimensions: (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
a (x) int64 [s] 0 1 2
b (y) int64 [m] -3 5 1
to convert to different units:
In [4]: c = q.pint.to({"a": "ms", "b": "km"})
...: c
Out[4]:
<xarray.Dataset>
Dimensions: (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
a (x) float64 [ms] 0.0 1e+03 2e+03
b (y) float64 [km] -0.003 0.005 0.001
to convert back to non-quantities:
In [5]: d = c.pint.dequantify()
...: d
Out[5]:
<xarray.Dataset>
Dimensions: (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
a (x) float64 0.0 1e+03 2e+03
b (y) float64 -0.003 0.005 0.001
For more, see the documentation
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pint_xarray-0.4.tar.gz
(47.8 kB
view details)
Built Distribution
pint_xarray-0.4-py3-none-any.whl
(32.7 kB
view details)
File details
Details for the file pint_xarray-0.4.tar.gz
.
File metadata
- Download URL: pint_xarray-0.4.tar.gz
- Upload date:
- Size: 47.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6b737a9c46dfb14a8598c27a71100496994c9d79dab61fd77f0d2685ae7065e |
|
MD5 | 17db064454cfc667ffa209c669e70e1c |
|
BLAKE2b-256 | 3197f2ee67b46ac14073b58e5245946f615cbd2875ea7713405ba960471edef3 |
File details
Details for the file pint_xarray-0.4-py3-none-any.whl
.
File metadata
- Download URL: pint_xarray-0.4-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcbbd6e6257817828b5cf7915254a8031d7a1e94df110218d280f3a1b956d4f5 |
|
MD5 | 5d0ebace1d46bc598bf5a4de12768ee3 |
|
BLAKE2b-256 | b05c9b205b9acd844c758cb013f22fa9576a043ec9d1819c237030dc29ef3744 |