@@ -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
4564Regridding
4665----------
@@ -98,7 +117,7 @@ Iris :class:`~iris.cube.Cube`\ s, although an ambition for the future.
98117
99118NetCDF File Control
100119-------------------
101- (More info: :term: ` NetCDF Format `)
120+ (More info: :ref: ` netcdf_io `)
102121
103122Unlike Iris, Xarray generally provides full control of major file structures,
104123i.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
107126modifies some recognised aspects, and can add some extra attributes not in the
108127input.
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 `_
117160and the '`encoding `_' dictionaries).
118161
162+ .. _xarray_missing_data :
163+
119164Missing Data
120165------------
121166Xarray uses :data: `numpy.nan ` to represent missing values and this will support
0 commit comments