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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pint_xarray-0.5.0.tar.gz
.
File metadata
- Download URL: pint_xarray-0.5.0.tar.gz
- Upload date:
- Size: 51.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
f3c6deb290a8e10daec610ae6587cf29fd9051f9017d3f3745a3f4d10146de4f
|
|
MD5 |
7f04f89a9153e7a68eda7733975839ba
|
|
BLAKE2b-256 |
fb32745289065a6b29b0a47f5d93107d3518fe3cc4dbac58243190d67ca7d7fb
|
Provenance
The following attestation bundles were made for pint_xarray-0.5.0.tar.gz
:
Publisher:
pypi.yaml
on xarray-contrib/pint-xarray
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
pint_xarray-0.5.0.tar.gz
-
Subject digest:
f3c6deb290a8e10daec610ae6587cf29fd9051f9017d3f3745a3f4d10146de4f
- Sigstore transparency entry: 233527816
- Sigstore integration time:
-
Permalink:
xarray-contrib/pint-xarray@59e5d348e19c28fa84844048ea1028844faef28b
-
Branch / Tag:
refs/tags/v0.5.0
- Owner: https://github.com/xarray-contrib
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
pypi.yaml@59e5d348e19c28fa84844048ea1028844faef28b
-
Trigger Event:
release
-
Statement type:
File details
Details for the file pint_xarray-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: pint_xarray-0.5.0-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
e1d9daabef606613380807955e81705441d211fe178b790490d9d2058cd47fce
|
|
MD5 |
2a34fe39b0406a07ad2f83b37c147af9
|
|
BLAKE2b-256 |
ae4d8f624e84571fd79ad08a7b428c6abacf85fd68003ea13690875f1c49a413
|
Provenance
The following attestation bundles were made for pint_xarray-0.5.0-py3-none-any.whl
:
Publisher:
pypi.yaml
on xarray-contrib/pint-xarray
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
pint_xarray-0.5.0-py3-none-any.whl
-
Subject digest:
e1d9daabef606613380807955e81705441d211fe178b790490d9d2058cd47fce
- Sigstore transparency entry: 233527819
- Sigstore integration time:
-
Permalink:
xarray-contrib/pint-xarray@59e5d348e19c28fa84844048ea1028844faef28b
-
Branch / Tag:
refs/tags/v0.5.0
- Owner: https://github.com/xarray-contrib
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
pypi.yaml@59e5d348e19c28fa84844048ea1028844faef28b
-
Trigger Event:
release
-
Statement type: