\n",
"
Note: this example uses the data provided by the
xarray.tutorial functions. As such, the
units attributes follow the CF conventions, which
pint does not understand by default. To still be able to read them we are using the registry provided by
cf-xarray.\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"quantified = data.pint.quantify()\n",
"quantified"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"## work with the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"monthly_means = quantified.pint.to(\"degC\").sel(time=\"2013\").groupby(\"time.month\").mean()\n",
"monthly_means"
]
},
{
"cell_type": "markdown",
"id": "9",
"metadata": {},
"source": [
"Most operations will preserve the units but there are some which will drop them (see the [duck array integration status](https://xarray.pydata.org/en/stable/user-guide/duckarrays.html#missing-features) page). To work around that there are unit-aware versions on the `.pint` accessor. For example, to select data use `.pint.sel` instead of `.sel`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"outputs": [],
"source": [
"monthly_means.sel(\n",
" lat=ureg.Quantity(4350, \"angular_minute\"),\n",
" lon=ureg.Quantity(12000, \"angular_minute\"),\n",
")"
]
},
{
"cell_type": "markdown",
"id": "11",
"metadata": {},
"source": [
"## plot\n",
"\n",
"`xarray`'s plotting functions will cast the data to `numpy.ndarray`, so we need to \"dequantify\" first."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"outputs": [],
"source": [
"monthly_means.pint.dequantify(format=\"~P\").plot.imshow(col=\"month\", col_wrap=4)"
]
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
pint-xarray-0.6.0/docs/index.rst 0000664 0000000 0000000 00000001540 15055074153 0016571 0 ustar 00root root 0000000 0000000 pint-xarray
===========
A convenience wrapper for using `pint`_ in `xarray`_ objects.
.. _pint: https://pint.readthedocs.io/en/stable
.. _xarray: https://xarray.pydata.org/en/stable
.. warning::
This package is experimental, and new versions might introduce backwards incompatible
changes.
Documentation
-------------
**Getting Started**:
- :doc:`installation`
- :doc:`examples`
.. toctree::
:maxdepth: 1
:caption: Getting Started
:hidden:
installation
examples
**User Guide**:
- :doc:`terminology`
- :doc:`creation`
- :doc:`conversion`
.. toctree::
:maxdepth: 1
:caption: User Guide
:hidden:
terminology
creation
conversion
**Help & Reference**:
- :doc:`whats-new`
- :doc:`api`
- :doc:`contributing`
.. toctree::
:maxdepth: 1
:caption: Help & Reference
:hidden:
whats-new
api
contributing
pint-xarray-0.6.0/docs/installation.rst 0000664 0000000 0000000 00000000712 15055074153 0020163 0 ustar 00root root 0000000 0000000 Installation
------------
Install from ``conda-forge``:
.. code:: sh
conda install -c conda-forge pint-xarray
or from ``PyPI``:
.. code:: sh
python -m pip install pint-xarray
or from source, either directly from github:
.. code:: sh
python -m pip install git+https://github.com/xarray-contrib/pint-xarray
or from a local copy:
.. code:: sh
git clone https://github.com/xarray-contrib/pint-xarray
python -m pip install ./pint-xarray
pint-xarray-0.6.0/docs/terminology.rst 0000664 0000000 0000000 00000000416 15055074153 0020033 0 ustar 00root root 0000000 0000000 Terminology
===========
.. glossary::
unit-like
A `pint`_ unit definition, as accepted by :py:class:`pint.Unit`.
May be a :py:class:`str`, a :py:class:`pint.Unit` instance or
:py:obj:`None`.
.. _pint: https://pint.readthedocs.io/en/stable
pint-xarray-0.6.0/docs/whats-new.rst 0000664 0000000 0000000 00000017532 15055074153 0017407 0 ustar 00root root 0000000 0000000 .. currentmodule:: xarray
What's new
==========
0.6.0 (31 Aug 2025)
-------------------
- Bump dependency versions (:pull:`313`):
============ ============== ==============
dependency old minimum new minimum
============ ============== ==============
python 3.10 3.11
xarray 2022.06.0 2023.07.0
numpy 1.23 1.26
pint 0.21 0.24
============ ============== ==============
By `Justus Magin