Skip to main content

Physical units interface to xarray using astropy

Project description

CI code coverage docs PyPI version codestyle conda-forge

astropy-xarray

A convenience wrapper for using astropy with xarray.

Usage

To convert the variables of a Dataset to quantities:

In [1]: import astropy_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> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) int64 24B 0 1 2
    b        (y) int64 24B -3 5 1

In [3]: q = ds.astropy.quantify(a="s")
   ...: q
Out[3]:
<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) float64 24B [s] 0.0 1.0 2.0
    b        (y) float64 24B [m] -3.0 5.0 1.0

to convert to different units:

In [4]: c = q.astropy.to({"a": "ms", "b": "km"})
   ...: c
Out[4]:
<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) float64 24B [ms] 0.0 1e+03 2e+03
    b        (y) float64 24B [km] -0.003 0.005 0.001

to convert back to non-quantities:

In [5]: d = c.astropy.dequantify()
   ...: d
Out[5]:
<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) float64 24B 0.0 1e+03 2e+03
    b        (y) float64 24B -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

astropy_xarray-0.1.0.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

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

astropy_xarray-0.1.0-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file astropy_xarray-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for astropy_xarray-0.1.0.tar.gz
Algorithm Hash digest
SHA256 31dac44b6174a05cd8119df4df65f91bbab74a4e9652dcd238fcbc85188c42d8
MD5 ce79e88d9412da29ea3820097ad51493
BLAKE2b-256 582a941f601c10c2c9ff626418b80693c6c485db6080f96f5617b594399ea11a

See more details on using hashes here.

Provenance

The following attestation bundles were made for astropy_xarray-0.1.0.tar.gz:

Publisher: pypi.yaml on calgray/astropy-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 astropy_xarray-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for astropy_xarray-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cccf94d32aabb3cf39d24b993616b4cf7fd30b909124023bfdcdfa9e5ec611e5
MD5 8b5231589edc707c5ce09fecec345716
BLAKE2b-256 f7d2e1e903d79bd14dc92344f80e66cb172ea45c473b2bd0630b5124416aeb63

See more details on using hashes here.

Provenance

The following attestation bundles were made for astropy_xarray-0.1.0-py3-none-any.whl:

Publisher: pypi.yaml on calgray/astropy-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