Skip to content

Commit 07f776f

Browse files
xylarclaude
andcommitted
Document open_dataset and open_mfdataset
Add the new functions to the I/O autosummary in api.rst and describe them in io.rst, including why specifying an engine via mpas_tools.io.default_engine avoids the CDF5 backend-sniffing crash and an example of setting the default engine. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d47af24 commit 07f776f

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

conda_package/docs/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ I/O
151151
:toctree: generated/
152152

153153
write_netcdf
154+
open_dataset
155+
open_mfdataset
154156

155157
Parallelism
156158
-----------

conda_package/docs/io.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,31 @@ Example usage:
2626
# Create a simple dataset
2727
ds = xr.Dataset({'foo': (('x',), [1, 2, 3])})
2828
write_netcdf(ds, 'output.nc')
29+
30+
open_dataset and open_mfdataset
31+
===============================
32+
33+
The :py:func:`mpas_tools.io.open_dataset()` and
34+
:py:func:`mpas_tools.io.open_mfdataset()` functions are thin wrappers around
35+
:py:func:`xarray.open_dataset()` and :py:func:`xarray.open_mfdataset()`. They
36+
select the NetCDF ``engine`` from the module-level
37+
:py:data:`mpas_tools.io.default_engine` variable when an ``engine`` is not
38+
passed explicitly.
39+
40+
This is useful because :py:func:`xarray.open_dataset()` otherwise sniffs the
41+
file for "magic bits" to auto-select a backend, and that probe can crash on
42+
``NETCDF3_64BIT_DATA`` (CDF5) files. xarray provides no global way to set a
43+
default engine, so ``mpas_tools.io.default_engine`` offers a single,
44+
process-wide knob that applies to both reading and writing.
45+
46+
Example usage:
47+
48+
.. code-block:: python
49+
50+
import mpas_tools.io
51+
from mpas_tools.io import open_dataset
52+
53+
# use the netcdf4 engine everywhere to avoid the CDF5 sniffing crash
54+
mpas_tools.io.default_engine = 'netcdf4'
55+
56+
ds = open_dataset('mesh.nc')

0 commit comments

Comments
 (0)