MCPcopy Create free account
hub / github.com/pydata/xarray / H5netcdfBackendEntrypoint

Class H5netcdfBackendEntrypoint

xarray/backends/h5netcdf_.py:484–716  ·  view source on GitHub ↗

Backend for netCDF files based on the h5netcdf package. It can open ".nc", ".nc4", ".cdf" files but will only be selected as the default if the "netcdf4" engine is not available. Additionally it can open valid HDF5 files, see https://h5netcdf.org/#invalid-netcdf-files for more

Source from the content-addressed store, hash-verified

482
483
484class H5netcdfBackendEntrypoint(BackendEntrypoint):
485 """
486 Backend for netCDF files based on the h5netcdf package.
487
488 It can open ".nc", ".nc4", ".cdf" files but will only be
489 selected as the default if the "netcdf4" engine is not available.
490
491 Additionally it can open valid HDF5 files, see
492 https://h5netcdf.org/#invalid-netcdf-files for more info.
493 It will not be detected as valid backend for such files, so make
494 sure to specify ``engine="h5netcdf"`` in ``open_dataset``.
495
496 For more information about the underlying library, visit:
497 https://h5netcdf.org
498
499 See Also
500 --------
501 backends.H5NetCDFStore
502 backends.NetCDF4BackendEntrypoint
503 backends.ScipyBackendEntrypoint
504 """
505
506 description = (
507 "Open netCDF (.nc, .nc4 and .cdf) and most HDF5 files using h5netcdf in Xarray"
508 )
509 url = "https://docs.xarray.dev/en/stable/generated/xarray.backends.H5netcdfBackendEntrypoint.html"
510 supports_groups = True
511
512 def guess_can_open(self, filename_or_obj: T_PathFileOrDataStore) -> bool:
513 from xarray.core.utils import is_remote_uri
514
515 filename_or_obj = _normalize_filename_or_obj(filename_or_obj)
516
517 # Try to read magic number for local files only
518 is_remote = isinstance(filename_or_obj, str) and is_remote_uri(filename_or_obj)
519 if not is_remote:
520 magic_number = try_read_magic_number_from_file_or_path(filename_or_obj)
521 if magic_number is not None:
522 return magic_number.startswith(b"\211HDF\r\n\032\n")
523
524 if isinstance(filename_or_obj, str | os.PathLike):
525 _, ext = os.path.splitext(filename_or_obj)
526 return ext in {".nc", ".nc4", ".cdf"}
527
528 return False
529
530 def open_dataset(
531 self,
532 filename_or_obj: T_PathFileOrDataStore,
533 *,
534 mask_and_scale=True,
535 decode_times=True,
536 concat_characters=True,
537 decode_coords=True,
538 drop_variables: str | Iterable[str] | None = None,
539 use_cftime=None,
540 decode_timedelta=None,
541 format="NETCDF4",

Callers 1

test_h5netcdf_entrypointFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_h5netcdf_entrypointFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…