\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.pint.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.4/docs/index.rst 0000664 0000000 0000000 00000001540 14636026627 0016440 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.4/docs/installation.rst 0000664 0000000 0000000 00000000712 14636026627 0020032 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.4/docs/requirements.txt 0000664 0000000 0000000 00000000251 14636026627 0020061 0 ustar 00root root 0000000 0000000 pint>=0.21
xarray>=2022.06.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.4/docs/terminology.rst 0000664 0000000 0000000 00000000375 14636026627 0017706 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.4/docs/whats-new.rst 0000664 0000000 0000000 00000013543 14636026627 0017254 0 ustar 00root root 0000000 0000000 .. currentmodule:: xarray
What's new
==========
0.4 (23 Jun 2024)
-----------------
- adopt `SPEC0