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

Function get_writable_netcdf_store

xarray/backends/writers.py:48–78  ·  view source on GitHub ↗

Create a store for writing to a netCDF file.

(
    target,
    engine: T_NetcdfEngine,
    *,
    format: T_NetcdfTypes | None,
    mode: NetcdfWriteModes,
    autoclose: bool,
    invalid_netcdf: bool,
    auto_complex: bool | None,
)

Source from the content-addressed store, hash-verified

46
47
48def get_writable_netcdf_store(
49 target,
50 engine: T_NetcdfEngine,
51 *,
52 format: T_NetcdfTypes | None,
53 mode: NetcdfWriteModes,
54 autoclose: bool,
55 invalid_netcdf: bool,
56 auto_complex: bool | None,
57) -> AbstractWritableDataStore:
58 """Create a store for writing to a netCDF file."""
59 try:
60 store_open = WRITEABLE_STORES[engine]
61 except KeyError as err:
62 raise ValueError(f"unrecognized engine for to_netcdf: {engine!r}") from err
63
64 if format is not None:
65 format = format.upper() # type: ignore[assignment]
66
67 kwargs = dict(autoclose=True) if autoclose else {}
68 if invalid_netcdf:
69 if engine == "h5netcdf":
70 kwargs["invalid_netcdf"] = invalid_netcdf
71 else:
72 raise ValueError(
73 f"unrecognized option 'invalid_netcdf' for engine {engine}"
74 )
75 if auto_complex is not None:
76 kwargs["auto_complex"] = auto_complex
77
78 return store_open(target, mode=mode, format=format, **kwargs)
79
80
81def _validate_dataset_names(dataset: Dataset) -> None:

Callers 2

to_netcdfFunction · 0.85
_datatree_to_netcdfFunction · 0.85

Calls 1

upperMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…