Skip to content

Commit

Permalink
Reference ncdata in iris conversion docs. (#9847)
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo authored Dec 3, 2024
1 parent f810185 commit 66e13a2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions ci/requirements/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- jupyter_client
- matplotlib-base
- nbsphinx
- ncdata
- netcdf4>=1.5
- numba
- numpy>=2
Expand Down
6 changes: 3 additions & 3 deletions doc/getting-started-guide/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ integration with Cartopy_.

We think the design decisions we have made for xarray (namely, basing it on
pandas) make it a faster and more flexible data analysis tool. That said, Iris
has some great domain specific functionality, and xarray includes
methods for converting back and forth between xarray and Iris. See
:py:meth:`~xarray.DataArray.to_iris` for more details.
has some great domain specific functionality, and there are dedicated methods for
converting back and forth between xarray and Iris. See
:ref:`Reading and Writing Iris data <io.iris>` for more details.

What other projects leverage xarray?
------------------------------------
Expand Down
38 changes: 35 additions & 3 deletions doc/user-guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ format (recommended).
import os
import iris
import ncdata.iris_xarray
import numpy as np
import pandas as pd
import xarray as xr
Expand Down Expand Up @@ -1072,8 +1074,11 @@ Iris

The Iris_ tool allows easy reading of common meteorological and climate model formats
(including GRIB and UK MetOffice PP files) into ``Cube`` objects which are in many ways very
similar to ``DataArray`` objects, while enforcing a CF-compliant data model. If iris is
installed, xarray can convert a ``DataArray`` into a ``Cube`` using
similar to ``DataArray`` objects, while enforcing a CF-compliant data model.

DataArray ``to_iris`` and ``from_iris``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If iris is installed, xarray can convert a ``DataArray`` into a ``Cube`` using
:py:meth:`DataArray.to_iris`:

.. ipython:: python
Expand All @@ -1095,9 +1100,36 @@ Conversely, we can create a new ``DataArray`` object from a ``Cube`` using
da_cube = xr.DataArray.from_iris(cube)
da_cube
Ncdata
~~~~~~
Ncdata_ provides more sophisticated means of transferring data, including entire
datasets. It uses the file saving and loading functions in both projects to provide a
more "correct" translation between them, but still with very low overhead and not
using actual disk files.

.. _Iris: https://scitools.org.uk/iris
For example:

.. ipython:: python
:okwarning:
ds = xr.tutorial.open_dataset("air_temperature_gradient")
cubes = ncdata.iris_xarray.cubes_from_xarray(ds)
print(cubes)
print(cubes[1])
.. ipython:: python
:okwarning:
ds = ncdata.iris_xarray.cubes_to_xarray(cubes)
print(ds)
Ncdata can also adjust file data within load and save operations, to fix data loading
problems or provide exact save formatting without needing to modify files on disk.
See for example : `ncdata usage examples`_

.. _Iris: https://scitools.org.uk/iris
.. _Ncdata: https://ncdata.readthedocs.io/en/latest/index.html
.. _ncdata usage examples: https://github.com/pp-mo/ncdata/tree/v0.1.2?tab=readme-ov-file#correct-a-miscoded-attribute-in-iris-input

OPeNDAP
-------
Expand Down

0 comments on commit 66e13a2

Please sign in to comment.