pint-xarray


Namepint-xarray JSON
Version 0.6.0 PyPI version JSON
download
home_pageNone
SummaryPhysical units interface to xarray using Pint
upload_time2025-08-31 16:32:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords
VCS
bugtrack_url
requirements pint numpy xarray
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![CI](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml)
[![code coverage](https://codecov.io/gh/xarray-contrib/pint-xarray/branch/main/graph/badge.svg)](https://codecov.io/gh/xarray-contrib/pint-xarray)
[![docs](https://readthedocs.org/projects/pint-xarray/badge/?version=latest)](https://pint-xarray.readthedocs.io)
[![PyPI version](https://img.shields.io/pypi/v/pint-xarray.svg)](https://pypi.org/project/pint-xarray)
[![codestyle](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![conda-forge](https://img.shields.io/conda/vn/conda-forge/pint-xarray)](https://github.com/conda-forge/pint-xarray-feedstock)

# pint-xarray

A convenience wrapper for using [pint](https://pint.readthedocs.io) with
[xarray](https://xarray.pydata.org).

## Usage

To convert the variables of a `Dataset` to quantities:

```python
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:

```python
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:

```python
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](https://pint-xarray.readthedocs.io)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pint-xarray",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Tom Nicholas <tomnicholas1@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/69/53/bb6bc9a461e32f61f34f57e26ffa9b5a3168081386bca87f2f41ec550320/pint_xarray-0.6.0.tar.gz",
    "platform": null,
    "description": "[![CI](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml)\n[![code coverage](https://codecov.io/gh/xarray-contrib/pint-xarray/branch/main/graph/badge.svg)](https://codecov.io/gh/xarray-contrib/pint-xarray)\n[![docs](https://readthedocs.org/projects/pint-xarray/badge/?version=latest)](https://pint-xarray.readthedocs.io)\n[![PyPI version](https://img.shields.io/pypi/v/pint-xarray.svg)](https://pypi.org/project/pint-xarray)\n[![codestyle](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)\n[![conda-forge](https://img.shields.io/conda/vn/conda-forge/pint-xarray)](https://github.com/conda-forge/pint-xarray-feedstock)\n\n# pint-xarray\n\nA convenience wrapper for using [pint](https://pint.readthedocs.io) with\n[xarray](https://xarray.pydata.org).\n\n## Usage\n\nTo convert the variables of a `Dataset` to quantities:\n\n```python\nIn [1]: import pint_xarray\n   ...: import xarray as xr\n\nIn [2]: ds = xr.Dataset({\"a\": (\"x\", [0, 1, 2]), \"b\": (\"y\", [-3, 5, 1], {\"units\": \"m\"})})\n   ...: ds\nOut[2]:\n<xarray.Dataset>\nDimensions:  (x: 3, y: 3)\nDimensions without coordinates: x, y\nData variables:\n    a        (x) int64 0 1 2\n    b        (y) int64 -3 5 1\n\nIn [3]: q = ds.pint.quantify(a=\"s\")\n   ...: q\nOut[3]:\n<xarray.Dataset>\nDimensions:  (x: 3, y: 3)\nDimensions without coordinates: x, y\nData variables:\n    a        (x) int64 [s] 0 1 2\n    b        (y) int64 [m] -3 5 1\n```\n\nto convert to different units:\n\n```python\nIn [4]: c = q.pint.to({\"a\": \"ms\", \"b\": \"km\"})\n   ...: c\nOut[4]:\n<xarray.Dataset>\nDimensions:  (x: 3, y: 3)\nDimensions without coordinates: x, y\nData variables:\n    a        (x) float64 [ms] 0.0 1e+03 2e+03\n    b        (y) float64 [km] -0.003 0.005 0.001\n```\n\nto convert back to non-quantities:\n\n```python\nIn [5]: d = c.pint.dequantify()\n   ...: d\nOut[5]:\n<xarray.Dataset>\nDimensions:  (x: 3, y: 3)\nDimensions without coordinates: x, y\nData variables:\n    a        (x) float64 0.0 1e+03 2e+03\n    b        (y) float64 -0.003 0.005 0.001\n```\n\nFor more, see the [documentation](https://pint-xarray.readthedocs.io)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Physical units interface to xarray using Pint",
    "version": "0.6.0",
    "project_urls": {
        "Documentation": "https://pint-xarray.readthedocs.io/en/stable",
        "Home": "https://github.com/xarray-contrib/pint-xarray"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "23120e888c6c114589d8d32d30525d77dbf9cd5c2811a37bfa61748bf412ed6d",
                "md5": "0474241f81bc3b2f1613e4caab3659f8",
                "sha256": "a0bab1f1342b213a9a28d8d7b3fbf8afa23e29f94c7a8c77bda3779e9e00d51f"
            },
            "downloads": -1,
            "filename": "pint_xarray-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0474241f81bc3b2f1613e4caab3659f8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 43950,
            "upload_time": "2025-08-31T16:32:00",
            "upload_time_iso_8601": "2025-08-31T16:32:00.014884Z",
            "url": "https://files.pythonhosted.org/packages/23/12/0e888c6c114589d8d32d30525d77dbf9cd5c2811a37bfa61748bf412ed6d/pint_xarray-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6953bb6bc9a461e32f61f34f57e26ffa9b5a3168081386bca87f2f41ec550320",
                "md5": "38919c4fb8d8446157dfca38349420de",
                "sha256": "20955ebd3fa5161608eeb9f39268b4ff22e87f8619c652fea0a2822f11774ad7"
            },
            "downloads": -1,
            "filename": "pint_xarray-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "38919c4fb8d8446157dfca38349420de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 166335,
            "upload_time": "2025-08-31T16:32:01",
            "upload_time_iso_8601": "2025-08-31T16:32:01.473576Z",
            "url": "https://files.pythonhosted.org/packages/69/53/bb6bc9a461e32f61f34f57e26ffa9b5a3168081386bca87f2f41ec550320/pint_xarray-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-31 16:32:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "xarray-contrib",
    "github_project": "pint-xarray",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pint",
            "specs": [
                [
                    ">=",
                    "0.13"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.17.1"
                ]
            ]
        },
        {
            "name": "xarray",
            "specs": [
                [
                    ">=",
                    "0.15.1"
                ]
            ]
        }
    ],
    "lcname": "pint-xarray"
}
        
Elapsed time: 4.79901s