-
Notifications
You must be signed in to change notification settings - Fork 14
docs update #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
docs update #20
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
8ae029a
extend the docs a bit
keewis 6b3f5e4
include a terminology page
keewis 5823741
add xarray and pint to intersphinx
keewis 0b21b65
use the new term to make the docstrings less ambiguous
keewis f2443e9
Merge branch 'master' into extend-docs
keewis 8ecacfc
Merge branch 'master' into extend-docs
keewis 619b419
update the docs requirements
keewis 2bba268
set up a mapping of type aliases
keewis 61faa84
avoid the use of :param:
keewis 78c6abb
expand the index page
keewis 133aeb5
fix a sidebar caption
keewis 1f6c2df
don't use a custom link text for pint.Unit
keewis 59674a9
move the type information from the definition to the description
keewis 7cd582c
add ipython to the used extensions
keewis 9583f49
add terminology to the toctree
keewis d38ed3d
add blackdoc to pre-commit
keewis 1d8d414
add a rough draft of the quantify howto-guide
keewis 79c3b3f
add netcdf4 to the requirements
keewis 2389189
enable the type preprocessor
keewis ebb1ff7
use ipython prompts in the directives
keewis 9ca8d9f
rephrase the reference to the github repository
keewis 9dcf45d
add a howto-guide for converting units
keewis eed7d04
clean up the sphinx configuration a bit
keewis b241b9b
configure extlinks
keewis 5b7a70f
add an item to the changelog
keewis 99777b3
add some text to the empty examples section
keewis ca6a8e7
update the install instructions
keewis 829d2be
avoid recommending a workflow that would break CF compliance
keewis 78c9e62
rename the changelog to whats-new
keewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Changelog | ||
========= | ||
|
||
0.1 (*unreleased*) | ||
------------------ | ||
- add documentation (:pull:`20`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Contributing | ||
============ | ||
``pint-xarray`` is developed on `github <https://github.com/xarray-contrib/pint-xarray>`_. | ||
|
||
Linters / Autoformatters | ||
------------------------ | ||
In order to keep code consistent, we use | ||
|
||
- `Black <https://black.readthedocs.io/en/stable/>`_ for standardized code formatting | ||
- `blackdoc <https://blackdoc.readthedocs.io/en/stable/>`_ for standardized code formatting in documentation | ||
- `Flake8 <http://flake8.pycqa.org/en/latest/>`_ for general code quality | ||
- `isort <https://github.com/timothycrosley/isort>`_ for standardized order in imports. See also `flake8-isort <https://github.com/gforcada/flake8-isort>`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.. currentmodule:: xarray | ||
|
||
Converting units | ||
================ | ||
.. ipython:: python | ||
:suppress: | ||
|
||
import xarray as xr | ||
|
||
When working with :py:class:`Dataset` or :py:class:`DataArray` objects with | ||
units, we frequently might want to convert the units. Suppose we have: | ||
|
||
.. ipython:: | ||
|
||
In [1]: ds = xr.Dataset( | ||
...: {"a": ("x", [4, 8, 12, 16])}, coords={"u": ("x", [10, 20, 30, 40])} | ||
...: ).pint.quantify({"a": "m", "u": "s"}) | ||
...: ds | ||
|
||
In [2]: da = ds.a | ||
...: da | ||
|
||
To convert the data to different units, we can use the | ||
:py:meth:`Dataset.pint.to` and :py:meth:`DataArray.pint.to` methods: | ||
|
||
.. ipython:: | ||
|
||
In [3]: ds.pint.to(a="feet", u="ks") | ||
|
||
In [4]: da.pint.to({da.name: "nautical_mile", "u": "ms"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
.. currentmodule:: xarray | ||
|
||
Creating and saving objects with units | ||
====================================== | ||
|
||
Attaching units | ||
--------------- | ||
.. ipython:: python | ||
:suppress: | ||
|
||
import xarray as xr | ||
|
||
Usually, when loading data from disk we get a :py:class:`Dataset` or | ||
:py:class:`DataArray` with units in attributes: | ||
|
||
.. ipython:: | ||
|
||
In [1]: ds = xr.tutorial.open_dataset("air_temperature") | ||
...: ds | ||
|
||
In [2]: da = ds.air | ||
...: da | ||
|
||
In order to get :py:class:`pint.Quantity` instances, we can use the | ||
:py:meth:`Dataset.pint.quantify` or :py:meth:`DataArray.pint.quantify` methods: | ||
|
||
.. ipython:: | ||
:okexcept: | ||
|
||
In [3]: ds.pint.quantify() | ||
|
||
As we can see, the dataset uses units like ``degree_north`` or ``degree_east``, | ||
which `pint`_ doesn't know about. To fix that, we can override the units of | ||
specific variables: | ||
|
||
.. ipython:: | ||
|
||
In [4]: ds.pint.quantify(lat="degree", lon="degree") | ||
|
||
In [5]: da.pint.quantify({"lat": "degree", "lon": "degree"}) | ||
|
||
Overriding works, even if there is no ``units`` attribute, so we could use this | ||
to attach units to a ordinary :py:class:`Dataset`: | ||
|
||
.. ipython:: | ||
|
||
In [6]: temporary_ds = xr.Dataset({"a": ("x", [0, 5, 10])}, coords={"x": [1, 2, 3]}) | ||
...: temporary_ds.pint.quantify({"a": "m"}) | ||
|
||
Of course, we could use :py:class:`pint.Unit` instances instead of strings to | ||
specify units, too. If we wanted to change the units of the data of a | ||
:py:class:`DataArray`, we could do so using the :py:attr:`DataArray.name` | ||
attribute: | ||
|
||
.. ipython:: | ||
|
||
In [7]: da.pint.quantify({da.name: "J", "lat": "degree", "lon": "degree"}) | ||
|
||
However, `xarray`_ currently doesn't support `units in indexes`_, so the new units were set | ||
as attributes. To really observe the changes the ``quantify`` methods make, we | ||
have to first swap the dimensions: | ||
|
||
.. ipython:: | ||
|
||
In [8]: ds_with_units = ds.swap_dims({"lon": "x", "lat": "y"}).pint.quantify( | ||
...: {"lat": "degree", "lon": "degree"} | ||
...: ) | ||
...: ds_with_units | ||
|
||
In [9]: da_with_units = da.swap_dims({"lon": "x", "lat": "y"}).pint.quantify( | ||
...: {"lat": "degree", "lon": "degree"} | ||
...: ) | ||
...: da_with_units | ||
|
||
Saving with units | ||
----------------- | ||
In order to not lose the units when saving to disk, we first have to call the | ||
:py:meth:`Dataset.pint.dequantify` and :py:meth:`DataArray.pint.dequantify` | ||
methods: | ||
|
||
.. ipython:: | ||
|
||
In [10]: ds_with_units.pint.dequantify() | ||
|
||
In [11]: da_with_units.pint.dequantify() | ||
|
||
This will get the string representation of a :py:class:`pint.Unit` instance and | ||
attach it as a ``units`` attribute. The data of the variable will now be | ||
whatever `pint`_ wrapped. | ||
|
||
.. _pint: https://pint.readthedocs.org/en/stable | ||
.. _xarray: https://xarray.pydata.org/en/stable | ||
.. _units in indexes: https://github.com/pydata/xarray/issues/1603 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Examples | ||
======== | ||
There are no examples yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,53 @@ | ||
.. accessors documentation master file, created by | ||
sphinx-quickstart on Thu Jul 2 01:49:50 2020. | ||
You can adapt this file completely to your liking, but it should at least | ||
contain the root `toctree` directive. | ||
pint-xarray | ||
=========== | ||
A convenience wrapper for using `pint`_ in `xarray`_ objects. | ||
|
||
Welcome to accessors's documentation! | ||
===================================== | ||
.. _pint: https://pint.readthedocs.io/en/stable | ||
.. _xarray: https://xarray.pydata.org/en/stable | ||
|
||
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:`changelog` | ||
- :doc:`api` | ||
- :doc:`contributing` | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: Contents: | ||
:maxdepth: 1 | ||
:caption: Help & Reference | ||
:hidden: | ||
|
||
changelog | ||
api | ||
contributing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
pint>=0.13 | ||
xarray>=0.15.1 | ||
sphinx>=3.0 | ||
pint>=0.14 | ||
xarray>=0.16.0 | ||
netCDF4 | ||
sphinx>=3.2 | ||
sphinx_rtd_theme | ||
ipython | ||
nbsphinx | ||
sphinx-autosummary-accessors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.