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

Class ScipyBackendEntrypoint

xarray/backends/scipy_.py:375–460  ·  view source on GitHub ↗

Backend for netCDF files based on the scipy package. It can open ".nc", ".cdf", and "nc..gz" files but will only be selected as the default if the "netcdf4" and "h5netcdf" engines are not available. It has the advantage that is is a lightweight engine that has no system require

Source from the content-addressed store, hash-verified

373
374
375class ScipyBackendEntrypoint(BackendEntrypoint):
376 """
377 Backend for netCDF files based on the scipy package.
378
379 It can open ".nc", ".cdf", and "nc..gz" files but will only be
380 selected as the default if the "netcdf4" and "h5netcdf" engines are
381 not available. It has the advantage that is is a lightweight engine
382 that has no system requirements (unlike netcdf4 and h5netcdf).
383
384 Additionally it can open gzip compressed (".gz") files.
385
386 For more information about the underlying library, visit:
387 https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.netcdf_file.html
388
389 See Also
390 --------
391 backends.ScipyDataStore
392 backends.NetCDF4BackendEntrypoint
393 backends.H5netcdfBackendEntrypoint
394 """
395
396 description = "Open netCDF files (.nc, .cdf and .nc.gz) using scipy in Xarray"
397 url = "https://docs.xarray.dev/en/stable/generated/xarray.backends.ScipyBackendEntrypoint.html"
398
399 def guess_can_open(
400 self,
401 filename_or_obj: T_PathFileOrDataStore,
402 ) -> bool:
403 from xarray.core.utils import is_remote_uri
404
405 filename_or_obj = _normalize_filename_or_obj(filename_or_obj)
406
407 # scipy can only handle local files - check this before trying to read magic number
408 if isinstance(filename_or_obj, str) and is_remote_uri(filename_or_obj):
409 return False
410
411 magic_number = try_read_magic_number_from_file_or_path(filename_or_obj)
412 if magic_number is not None and magic_number.startswith(b"\x1f\x8b"):
413 with gzip.open(filename_or_obj) as f: # type: ignore[arg-type]
414 magic_number = try_read_magic_number_from_file_or_path(f)
415 if magic_number is not None:
416 return magic_number.startswith(b"CDF")
417
418 if isinstance(filename_or_obj, str | os.PathLike):
419 from pathlib import Path
420
421 suffix = "".join(Path(filename_or_obj).suffixes)
422 return suffix in {".nc", ".cdf", ".nc.gz"}
423
424 return False
425
426 def open_dataset(
427 self,
428 filename_or_obj: T_PathFileOrDataStore,
429 *,
430 mask_and_scale: bool = True,
431 decode_times: bool = True,
432 concat_characters: bool = True,

Callers 1

test_scipy_entrypointFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_scipy_entrypointFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…