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.2.tar.gz
(46.1 kB
view details)
Built Distribution
pint_xarray-0.2-py3-none-any.whl
(30.5 kB
view details)
File details
Details for the file pint-xarray-0.2.tar.gz
.
File metadata
- Download URL: pint-xarray-0.2.tar.gz
- Upload date:
- Size: 46.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9908ae6e34969a4f76277db0c754076300825ee52d0f51b46a7ae5bd87e81e3a |
|
MD5 | ce4f7e02f7f0782f9cad48e487d0ae9e |
|
BLAKE2b-256 | 0974c4a63f2d061944ad6523e3a71f073ad8dd33f7834fa44f47c84dee6c920c |
File details
Details for the file pint_xarray-0.2-py3-none-any.whl
.
File metadata
- Download URL: pint_xarray-0.2-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e757bf167d893464e5d8e52437ee095068b632e1b5dc1e048fd6acf8a6e1cd5 |
|
MD5 | c55513d3b762011c96f0058c61dd0f0a |
|
BLAKE2b-256 | 3e9783ad88070e58ad62d633b3bd0372399bd29a9641608ad7d84b63f979ec81 |