Skip to content

Commit 5901354

Browse files
committed
document netcdf-format issues, intersphinx h5netcdf, adapt docstrings, add to whats-new.rst
1 parent 47be135 commit 5901354

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

doc/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
"cftime": ("https://unidata.github.io/cftime", None),
334334
"rasterio": ("https://rasterio.readthedocs.io/en/latest", None),
335335
"sparse": ("https://sparse.pydata.org/en/latest/", None),
336+
"h5netcdf": ("https://h5netcdf.org/", None),
336337
}
337338

338339

doc/user-guide/io.rst

+18-8
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ netCDF are based on the even more widely used HDF5 file-format.
3737

3838
__ https://www.unidata.ucar.edu/software/netcdf/
3939

40+
Reading and writing netCDF files with xarray requires :std:doc:`scipy <scipy:index>`, `netCDF4-Python`__ or :std:doc:`h5netcdf <h5netcdf:index>` libraries to be installed (the two latter are able
41+
to read/write netCDF V4 files and use the compression options described below).
42+
4043
.. tip::
4144

4245
If you aren't familiar with this data format, the `netCDF FAQ`_ is a good
43-
place to start.
46+
place to start. A comprehensive documentation is available in the Unidata NetCDF Users Guide's `The netCDF File Format`_ section.
4447

4548
.. _netCDF FAQ: https://www.unidata.ucar.edu/software/netcdf/docs/faq.html#What-Is-netCDF
46-
47-
Reading and writing netCDF files with xarray requires scipy or the
48-
`netCDF4-Python`__ library to be installed (the latter is required to
49-
read/write netCDF V4 files and use the compression options described below).
49+
.. _The netCDF File Format: https://docs.unidata.ucar.edu/nug/current/netcdf_introduction.html#netcdf_format
5050

5151
__ https://github.com/Unidata/netcdf4-python
5252

@@ -70,6 +70,15 @@ By default, the file is saved as netCDF4 (assuming netCDF4-Python is
7070
installed). You can control the format and engine used to write the file with
7171
the ``format`` and ``engine`` arguments.
7272

73+
.. warning::
74+
75+
There are several `Limitations of NetCDF`_ which can have influence on `Large File Support`_, `Data Types`_, `Dealing with strings`_ or the like depending on the requested ``format`` (see :py:meth:`Dataset.to_netcdf` for details). In general, using ``netcdf4``/``h5netcdf`` engine with ``format="NETCDF4"`` (default) is recommended.
76+
77+
.. _Limitations of NetCDF: https://docs.unidata.ucar.edu/nug/current/netcdf_introduction.html#limitations
78+
.. _Large File Support: https://docs.unidata.ucar.edu/nug/current/file_structure_and_performance.html#large_file_support
79+
.. _Data Types: https://docs.unidata.ucar.edu/nug/current/md_types.html
80+
.. _Dealing with strings: https://unidata.github.io/netcdf4-python/#dealing-with-strings
81+
7382
.. tip::
7483

7584
Using the `h5netcdf <https://github.com/h5netcdf/h5netcdf>`_ package
@@ -540,8 +549,7 @@ Invalid netCDF files
540549
~~~~~~~~~~~~~~~~~~~~
541550

542551
The library ``h5netcdf`` allows writing some dtypes (booleans, complex, ...) that aren't
543-
allowed in netCDF4 (see
544-
`h5netcdf documentation <https://github.com/shoyer/h5netcdf#invalid-netcdf-files>`_).
552+
allowed in netCDF4 (see :std:ref:`h5netcdf:invalid netcdf`).
545553
This feature is available through :py:meth:`DataArray.to_netcdf` and
546554
:py:meth:`Dataset.to_netcdf` when used with ``engine="h5netcdf"``
547555
and currently raises a warning unless ``invalid_netcdf=True`` is set:
@@ -923,6 +931,7 @@ installed, xarray can convert a ``DataArray`` into a ``Cube`` using
923931
:py:meth:`DataArray.to_iris`:
924932

925933
.. ipython:: python
934+
:okexcept:
926935
927936
da = xr.DataArray(
928937
np.random.rand(4, 5),
@@ -937,6 +946,7 @@ Conversely, we can create a new ``DataArray`` object from a ``Cube`` using
937946
:py:meth:`DataArray.from_iris`:
938947

939948
.. ipython:: python
949+
:okexcept:
940950
941951
da_cube = xr.DataArray.from_iris(cube)
942952
da_cube
@@ -1165,7 +1175,7 @@ rasterio is installed. Here is an example of how to use
11651175

11661176
Deprecated in favor of rioxarray.
11671177
For information about transitioning, see:
1168-
`rioxarray getting started docs<https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html>``
1178+
`rioxarray getting started docs <https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html>`_
11691179

11701180
.. ipython::
11711181
:verbatim:

doc/whats-new.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Bug fixes
3737

3838
- Fix :py:meth:`xr.polyval` with non-system standard integer coeffs (:pull:`7619`).
3939
By `Shreyal Gupta <https://github.com/Ravenin7>`_ and `Michael Niklas <https://github.com/headtr1ck>`_.
40+
- Preserve dtypes (bool, vlen string) within encoding (:pull:`7654`).
41+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
42+
4043

4144
Documentation
4245
~~~~~~~~~~~~~
@@ -6178,7 +6181,7 @@ Enhancements
61786181
The default value for the ``display_width`` option is 80.
61796182

61806183
.. _h5py: http://www.h5py.org/
6181-
.. _h5netcdf: https://github.com/shoyer/h5netcdf
6184+
.. _h5netcdf: https://github.com/h5netcdf/h5netcdf
61826185

61836186
Deprecations
61846187
~~~~~~~~~~~~

xarray/backends/h5netcdf_.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ class H5netcdfBackendEntrypoint(BackendEntrypoint):
351351
selected as the default if the "netcdf4" engine is not available.
352352
353353
Additionally it can open valid HDF5 files, see
354-
https://h5netcdf.org/#invalid-netcdf-files for more info.
354+
:std:ref:`h5netcdf:invalid netcdf` for more info.
355355
It will not be detected as valid backend for such files, so make
356356
sure to specify ``engine="h5netcdf"`` in ``open_dataset``.
357357
358358
For more information about the underlying library, visit:
359-
https://h5netcdf.org
359+
:std:doc:`h5netcdf:index`
360360
361361
See Also
362362
--------

xarray/backends/netCDF4_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class NetCDF4BackendEntrypoint(BackendEntrypoint):
521521
as default for these files.
522522
523523
Additionally it can open valid HDF5 files, see
524-
https://h5netcdf.org/#invalid-netcdf-files for more info.
524+
:std:ref:`h5netcdf:invalid netcdf` for more info.
525525
It will not be detected as valid backend for such files, so make
526526
sure to specify ``engine="netcdf4"`` in ``open_dataset``.
527527

xarray/core/dataarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3914,7 +3914,7 @@ def to_netcdf(
39143914
invalid_netcdf: bool, default: False
39153915
Only valid along with ``engine="h5netcdf"``. If True, allow writing
39163916
hdf5 files which are invalid netcdf as described in
3917-
https://github.com/h5netcdf/h5netcdf.
3917+
:std:ref:`h5netcdf:invalid netcdf`.
39183918
39193919
Returns
39203920
-------

xarray/core/dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ def to_netcdf(
18921892
invalid_netcdf: bool, default: False
18931893
Only valid along with ``engine="h5netcdf"``. If True, allow writing
18941894
hdf5 files which are invalid netcdf as described in
1895-
https://github.com/h5netcdf/h5netcdf.
1895+
:std:ref:`h5netcdf:invalid netcdf`.
18961896
18971897
Returns
18981898
-------

0 commit comments

Comments
 (0)