Skip to content

Commit 9bd1bfa

Browse files
committed
Merge branch 'numpydoc-pre-commit' of github.com:tkknight/iris into numpydoc-pre-commit
* 'numpydoc-pre-commit' of github.com:tkknight/iris: Update CF standard names to v84. (SciTools#5761) Regrid docs fix (SciTools#5758) Improve ncdata and CF information on "iris heart xarray" page (SciTools#5752) Pin ASV - airspeed-velocity/asv#1385. (SciTools#5756) Normalise units of coordinate bounds (SciTools#5746) Add "Which Regridder?" Documentation (SciTools#5742) Document `Coord.ignore_axis` (SciTools#5744) Disable navidation with keys for docs HTML theme options (SciTools#5747) Shapefile masking (SciTools#5470) [pre-commit.ci] pre-commit autoupdate (SciTools#5739) DOCS: Add whatsnew for ruff pydocstyle compliance (SciTools#5700) update docstring (SciTools#5737) Updated environment lockfiles (SciTools#5738) Consider NaNs equal when comparing cubes (SciTools#5713)
2 parents d534748 + f8b5edd commit 9bd1bfa

30 files changed

+2906
-1083
lines changed

.github/workflows/benchmarks_run.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
- name: Install ASV & Nox
4444
run: |
45-
pip install asv nox
45+
pip install "asv!=0.6.2" nox
4646
4747
- name: Cache environment directories
4848
id: cache-env-dir

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
- id: no-commit-to-branch
3030

3131
- repo: https://github.com/astral-sh/ruff-pre-commit
32-
rev: "v0.1.14"
32+
rev: "v0.2.1"
3333
hooks:
3434
- id: ruff
3535
types: [file, python]

docs/src/community/iris_xarray.rst

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,28 @@ There are multiple ways to convert between Iris and Xarray objects.
3838
feasible to save a NetCDF file using one package then load that file using
3939
the other package. This will be lossy in places, as both Iris and Xarray
4040
are opinionated on how certain NetCDF concepts relate to their data models.
41-
* The Iris development team are exploring an improved 'bridge' between the two
42-
packages. Follow the conversation on GitHub: `iris#4994`_. This project is
43-
expressly intended to be as lossless as possible.
41+
* `ncdata <https://github.com/pp-mo/ncdata/blob/main/README.md>`_ is a package which
42+
the Iris development team have developed to manage netcdf data, which can act as an
43+
improved 'bridge' between Iris and Xarray :
44+
45+
Ncdata can convert Iris cubes to an Xarray dataset, or vice versa, with minimal
46+
overhead and as lossless as possible.
47+
48+
For example :
49+
50+
.. code-block:: python
51+
52+
from ncdata.iris_xarray import cubes_from_xarray, cubes_to_xarray
53+
cubes = cubes_from_xarray(dataset)
54+
xrds = cubes_to_xarray(cubes)
55+
56+
Ncdata avoids the feature limitations previously mentioned regarding Xarray's
57+
:meth:`~xarray.DataArray.to_iris` and :meth:`~xarray.DataArray.from_iris`,
58+
because it doesn't replicate any logic of either Xarray or Iris.
59+
Instead, it uses the netcdf file interfaces of both to exchange data
60+
"as if" via a netcdf file. So, these conversions *behave* just like exchanging data
61+
via a file, but are far more efficient because they can transfer data without copying
62+
arrays or fetching lazy data.
4463

4564
Regridding
4665
----------
@@ -98,7 +117,7 @@ Iris :class:`~iris.cube.Cube`\ s, although an ambition for the future.
98117

99118
NetCDF File Control
100119
-------------------
101-
(More info: :term:`NetCDF Format`)
120+
(More info: :ref:`netcdf_io`)
102121

103122
Unlike Iris, Xarray generally provides full control of major file structures,
104123
i.e. dimensions + variables, including their order in the file. It mostly
@@ -107,15 +126,41 @@ However, attribute handling is not so complete: like Iris, it interprets and
107126
modifies some recognised aspects, and can add some extra attributes not in the
108127
input.
109128

110-
.. todo:
111-
More detail on dates and fill values (@pp-mo suggestion).
112-
113-
Handling of dates and fill values have some special problems here.
114-
115-
Ultimately, nearly everything wanted in a particular desired result file can
116-
be achieved in Xarray, via provided override mechanisms (`loading keywords`_
129+
Whereas Iris is primarily designed to handle netCDF data encoded according to
130+
`CF Conventions <https://cfconventions.org/>`_ , this is not so important to Xarray,
131+
which therefore may make it harder to correctly manage this type of data.
132+
While Xarray CF support is not complete, it may improve, and obviously
133+
:ref:`cfxarray` may be relevant here.
134+
There is also relevant documentation
135+
`at this page <https://docs.xarray.dev/en/stable/user-guide/weather-climate.html#weather-and-climate-data>`_.
136+
137+
In some particular aspects, CF data is not loaded well (or at all), and in many cases
138+
output is not fully CF compliant (as-per `the cf checker <https://cfchecker.ncas.ac.uk/>`_).
139+
140+
* xarray has it's own interpretation of coordinates, which is different from the CF-based
141+
approach in Iris, and means that the use of the "coordinates" attribute in output is
142+
often not CF compliant.
143+
* dates are converted to datetime-like objects internally. There are special features
144+
providing `support for non-standard calendars <https://docs.xarray.dev/en/stable/user-guide/weather-climate.html#non-standard-calendars-and-dates-outside-the-nanosecond-precision-range>`_,
145+
however date units may not always be saved correctly.
146+
* CF-style coordinate bounds variables are not fully understood. The CF approach
147+
where bounds variables do not usually define their units or standard_names can cause
148+
problems. Certain files containing bounds variables with more than 2 bounds (e.g.
149+
unstructured data) may not load at all.
150+
* missing points are always represented as NaNs, as-per Pandas usage.
151+
(See :ref:`xarray_missing_data` ).
152+
This means that fill values are not preserved, and that masked integer data is
153+
converted to floats.
154+
The netCDF default fill-values are not supported, so that variables with no
155+
"_FillValue" attribute will have missing points equal to the fill-value
156+
in place of NaNs. By default, output variables generally have ``_FillValue = NaN``.
157+
158+
Ultimately, however, nearly everything wanted in a particular desired result file
159+
**can** be achieved in Xarray, via provided override mechanisms (`loading keywords`_
117160
and the '`encoding`_' dictionaries).
118161

162+
.. _xarray_missing_data:
163+
119164
Missing Data
120165
------------
121166
Xarray uses :data:`numpy.nan` to represent missing values and this will support

docs/src/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ def _dotv(version):
193193

194194
# sphinx.ext.todo configuration -----------------------------------------------
195195
# See https://www.sphinx-doc.org/en/master/usage/extensions/todo.html
196-
todo_include_todos = True
196+
todo_include_todos = False
197+
todo_emit_warnings = False
197198

198199
# sphinx.ext.autodoc configuration --------------------------------------------
199200
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_default_options
@@ -244,6 +245,7 @@ def _dotv(version):
244245
intersphinx_mapping = {
245246
"cartopy": ("https://scitools.org.uk/cartopy/docs/latest/", None),
246247
"dask": ("https://docs.dask.org/en/stable/", None),
248+
"iris-esmf-regrid": ("https://iris-esmf-regrid.readthedocs.io/en/stable/", None),
247249
"matplotlib": ("https://matplotlib.org/stable/", None),
248250
"numpy": ("https://numpy.org/doc/stable/", None),
249251
"python": ("https://docs.python.org/3/", None),
@@ -300,6 +302,7 @@ def _dotv(version):
300302
"footer_start": ["copyright", "sphinx-version"],
301303
"footer_end": ["custom_footer"],
302304
"navigation_depth": 3,
305+
"navigation_with_keys": False,
303306
"show_toc_level": 2,
304307
"show_prev_next": True,
305308
"navbar_align": "content",
@@ -404,6 +407,7 @@ def _dotv(version):
404407
"https://biggus.readthedocs.io/",
405408
"https://stickler-ci.com/",
406409
"https://twitter.com/scitools_iris",
410+
"https://stackoverflow.com/questions/tagged/python-iris",
407411
]
408412

409413
# list of sources to exclude from the build.

docs/src/further_topics/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Extra information on specific technical issues.
1717
missing_data_handling
1818
netcdf_io
1919
dask_best_practices/index
20-
ugrid/index
20+
ugrid/index
21+
which_regridder_to_use

docs/src/further_topics/netcdf_io.rst

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,49 @@ Deferred Saving
134134
TBC
135135

136136

137-
Guess Axis
138-
-----------
139-
140-
TBC
137+
Guessing Coordinate Axes
138+
------------------------
139+
140+
Iris will attempt to add an ``axis`` attribute when saving any coordinate
141+
variable in a NetCDF file. E.g:
142+
143+
::
144+
145+
float longitude(longitude) ;
146+
longitude:axis = "X" ;
147+
148+
This is achieved by calling :func:`iris.util.guess_coord_axis` on each
149+
coordinate being saved.
150+
151+
Disabling Axis-Guessing
152+
^^^^^^^^^^^^^^^^^^^^^^^
153+
154+
For some coordinates, :func:`~iris.util.guess_coord_axis` will derive an
155+
axis that is not appropriate. If you have such a coordinate, you can disable
156+
axis-guessing by setting the coordinate's
157+
:attr:`~iris.coords.Coord.ignore_axis` property to ``True``.
158+
159+
One example (from https://github.com/SciTools/iris/issues/5003) is a
160+
coordinate describing pressure thresholds, measured in hecto-pascals.
161+
Iris interprets pressure units as indicating a Z-dimension coordinate, since
162+
pressure is most commonly used to describe altitude/depth. But a
163+
**pressure threshold** coordinate is instead describing alternate
164+
**scenarios** - not a spatial dimension at all - and it is therefore
165+
inappropriate to assign an axis to it.
166+
167+
Worked example:
168+
169+
.. doctest::
170+
171+
>>> from iris.coords import DimCoord
172+
>>> from iris.util import guess_coord_axis
173+
>>> my_coord = DimCoord(
174+
... points=[1000, 1010, 1020],
175+
... long_name="pressure_threshold",
176+
... units="hPa",
177+
... )
178+
>>> print(guess_coord_axis(my_coord))
179+
Z
180+
>>> my_coord.ignore_axis = True
181+
>>> print(guess_coord_axis(my_coord))
182+
None

0 commit comments

Comments
 (0)