Skip to main content

Physical units interface to xarray using Pint

Project description

CI code coverage docs PyPI version codestyle conda-forge

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.6.0.tar.gz (166.3 kB view details)

Uploaded Source

Built Distribution

pint_xarray-0.6.0-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file pint_xarray-0.6.0.tar.gz.

File metadata

  • Download URL: pint_xarray-0.6.0.tar.gz
  • Upload date:
  • Size: 166.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pint_xarray-0.6.0.tar.gz
Algorithm Hash digest
SHA256 20955ebd3fa5161608eeb9f39268b4ff22e87f8619c652fea0a2822f11774ad7
MD5 38919c4fb8d8446157dfca38349420de
BLAKE2b-256 6953bb6bc9a461e32f61f34f57e26ffa9b5a3168081386bca87f2f41ec550320

See more details on using hashes here.

Provenance

The following attestation bundles were made for pint_xarray-0.6.0.tar.gz:

Publisher: pypi.yaml on xarray-contrib/pint-xarray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pint_xarray-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pint_xarray-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pint_xarray-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0bab1f1342b213a9a28d8d7b3fbf8afa23e29f94c7a8c77bda3779e9e00d51f
MD5 0474241f81bc3b2f1613e4caab3659f8
BLAKE2b-256 23120e888c6c114589d8d32d30525d77dbf9cd5c2811a37bfa61748bf412ed6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pint_xarray-0.6.0-py3-none-any.whl:

Publisher: pypi.yaml on xarray-contrib/pint-xarray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page