\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": "divine-boost",
"metadata": {},
"outputs": [],
"source": [
"quantified = data.pint.quantify()\n",
"quantified"
]
},
{
"cell_type": "markdown",
"id": "whole-momentum",
"metadata": {},
"source": [
"## work with the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dried-friday",
"metadata": {},
"outputs": [],
"source": [
"monthly_means = quantified.pint.to(\"degC\").sel(time=\"2013\").groupby(\"time.month\").mean()\n",
"monthly_means"
]
},
{
"cell_type": "markdown",
"id": "14ea5eb8",
"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": "93e4ca4e",
"metadata": {},
"outputs": [],
"source": [
"monthly_means.pint.sel(\n",
" lat=ureg.Quantity(4350, \"angular_minute\"),\n",
" lon=ureg.Quantity(12000, \"angular_minute\"),\n",
")"
]
},
{
"cell_type": "markdown",
"id": "still-ebony",
"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": "united-machine",
"metadata": {},
"outputs": [],
"source": [
"monthly_means.pint.dequantify(format=\"~P\").plot.imshow(col=\"month\", col_wrap=4)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
pint-xarray-0.3/docs/index.rst 0000664 0000000 0000000 00000001540 14270207013 0016417 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.3/docs/installation.rst 0000664 0000000 0000000 00000000712 14270207013 0020011 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.3/docs/requirements.txt 0000664 0000000 0000000 00000000246 14270207013 0020044 0 ustar 00root root 0000000 0000000 pint>=0.14
xarray>=0.16.0
pooch
netCDF4
cf-xarray>=0.6
sphinx
sphinx_rtd_theme>=1.0
ipython
ipykernel
jupyter_client
nbsphinx
matplotlib
sphinx-autosummary-accessors
pint-xarray-0.3/docs/terminology.rst 0000664 0000000 0000000 00000000375 14270207013 0017665 0 ustar 00root root 0000000 0000000 Terminology
===========
.. glossary::
unit-like
A `pint`_ unit definition, as accepted by :py:class:`pint.Unit`.
May be either a :py:class:`str` or a :py:class:`pint.Unit` instance.
.. _pint: https://pint.readthedocs.io/en/stable
pint-xarray-0.3/docs/whats-new.rst 0000664 0000000 0000000 00000012104 14270207013 0017223 0 ustar 00root root 0000000 0000000 .. currentmodule:: xarray
What's new
==========
0.3 (27 Jul 2022)
-----------------
- drop support for python 3.7 (:pull:`153`)
By `Justus Magin