Add open_dataset and open_mfdataset wrappers to mpas_tools.io#737
Open
xylar wants to merge 3 commits into
Open
Add open_dataset and open_mfdataset wrappers to mpas_tools.io#737xylar wants to merge 3 commits into
open_dataset and open_mfdataset wrappers to mpas_tools.io#737xylar wants to merge 3 commits into
Conversation
Add thin wrappers around xarray.open_dataset and xarray.open_mfdataset that select the NetCDF engine from the module-level mpas_tools.io.default_engine variable when no engine is passed explicitly. xarray.open_dataset sniffs a file for "magic bits" to auto-select a backend, and that probe can crash on NETCDF3_64BIT_DATA (CDF5) files (see E3SM-Project/polaris#624). Specifying an engine explicitly avoids the sniffing. Since xarray has no global default-engine setting, reusing the existing default_engine variable (already consumed by write_netcdf) gives downstream tools a single, process-wide knob for both reading and writing without modifying every call site. The logger argument is included for API symmetry with write_netcdf and future diagnostics; no error recovery is performed because the CDF5 failure is a hard crash that cannot be caught. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Cover the new wrappers: a basic write/read round trip, opening a NETCDF3_64BIT_DATA (CDF5) file with an explicit engine (exercising the backend-sniffing crash the wrappers work around), resolving the engine from mpas_tools.io.default_engine when engine is None (restoring the global afterward), and a multi-file open_mfdataset smoke test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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>
Contributor
|
@xylar Thanks! |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds thin wrappers around
xarray.open_dataset()andxarray.open_mfdataset()that select the NetCDF engine from the module-levelmpas_tools.io.default_enginevariable when no engine is passed explicitly.xarray.open_dataset()tries to open a file looking for "magic bits" to auto-select a backend, and that probe can crash onNETCDF3_64BIT_DATA(CDF5) files (see E3SM-Project/polaris#624). Specifying an engine explicitly avoids the sniffing. Since xarray has no global default-engine setting, reusing the existingdefault_enginevariable (already consumed bywrite_netcdf()) gives downstream tools a single, process-wide knob for both reading and writing without modifying every call site.The logger argument is included for API symmetry with write_netcdf and future diagnostics; no error recovery is performed because the CDF5 failure is a hard crash that cannot be caught.