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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pint_xarray-0.6.1-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pint_xarray-0.6.1.tar.gz
Algorithm Hash digest
SHA256 a0febf909b69342fde39b8e053875c52bb75a65e4fc56d95bd146f74449aed84
MD5 5acf198f9cd912aec67780a520eaec94
BLAKE2b-256 a192b402b6e58a4f9ea2718ada67171586dc2ebd494ffcaf0c08f2b634714ad5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pint_xarray-0.6.1.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.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pint_xarray-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f96682bda1234c3be652db2f9b7cfb8d858cc870c8e7a51213163e743d8ccf7
MD5 a61fce35bdf7e41bfb57bde0d844dd5e
BLAKE2b-256 f40de20fbbf036a88fc7be7438f6fc1c7606e8806064f933f7eb6d4f110bc622

See more details on using hashes here.

Provenance

The following attestation bundles were made for pint_xarray-0.6.1-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 Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page