MCPcopy
hub / github.com/pydata/xarray / open

Method open

xarray/backends/netCDF4_.py:447–529  ·  view source on GitHub ↗
(
        cls,
        filename,
        mode="r",
        format="NETCDF4",
        group=None,
        clobber=True,
        diskless=False,
        persist=False,
        auto_complex=None,
        lock=None,
        lock_maker=None,
        autoclose=False,
    )

Source from the content-addressed store, hash-verified

445
446 @classmethod
447 def open(
448 cls,
449 filename,
450 mode="r",
451 format="NETCDF4",
452 group=None,
453 clobber=True,
454 diskless=False,
455 persist=False,
456 auto_complex=None,
457 lock=None,
458 lock_maker=None,
459 autoclose=False,
460 ):
461 import netCDF4
462
463 if isinstance(filename, os.PathLike):
464 filename = os.fspath(filename)
465
466 if isinstance(filename, IOBase):
467 raise TypeError(
468 f"file objects are not supported by the netCDF4 backend: {filename}"
469 )
470
471 if not isinstance(filename, str | bytes | memoryview | BytesIOProxy):
472 raise TypeError(f"invalid filename for netCDF4 backend: {filename}")
473
474 if format is None:
475 format = "NETCDF4"
476
477 if lock is None:
478 if mode == "r":
479 if isinstance(filename, str) and is_remote_uri(filename):
480 lock = NETCDFC_LOCK
481 else:
482 lock = NETCDF4_PYTHON_LOCK
483 else:
484 if format is None or format.startswith("NETCDF4"):
485 lock = NETCDF4_PYTHON_LOCK
486 else:
487 lock = NETCDFC_LOCK
488
489 if isinstance(filename, str):
490 lock = combine_locks([lock, get_write_lock(filename)])
491
492 kwargs = dict(
493 clobber=clobber,
494 diskless=diskless,
495 persist=persist,
496 format=format,
497 )
498 if auto_complex is not None:
499 kwargs["auto_complex"] = auto_complex
500
501 if isinstance(filename, BytesIOProxy):
502 assert mode == "w"
503 # Size hint used for creating netCDF3 files. Per the documentation
504 # for nc__create(), the special value NC_SIZEHINT_DEFAULT (which is

Callers 2

open_datasetMethod · 0.45
open_groups_as_dictMethod · 0.45

Calls 8

is_remote_uriFunction · 0.90
combine_locksFunction · 0.90
get_write_lockFunction · 0.90
DummyFileManagerClass · 0.90
CachingFileManagerClass · 0.90
_CloseWithCopyClass · 0.85
startswithMethod · 0.80

Tested by

no test coverage detected