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

Method open

xarray/backends/h5netcdf_.py:172–265  ·  view source on GitHub ↗
(
        cls,
        filename,
        mode="r",
        format="NETCDF4",
        group=None,
        lock=None,
        autoclose=False,
        invalid_netcdf=None,
        phony_dims=None,
        decode_vlen_strings=True,
        driver=None,
        driver_kwds=None,
        storage_options: dict[str, Any] | None = None,
        open_kwargs: dict[str, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

170
171 @classmethod
172 def open(
173 cls,
174 filename,
175 mode="r",
176 format="NETCDF4",
177 group=None,
178 lock=None,
179 autoclose=False,
180 invalid_netcdf=None,
181 phony_dims=None,
182 decode_vlen_strings=True,
183 driver=None,
184 driver_kwds=None,
185 storage_options: dict[str, Any] | None = None,
186 open_kwargs: dict[str, Any] | None = None,
187 ):
188 import h5netcdf
189
190 if isinstance(filename, str) and is_remote_uri(filename) and driver is None:
191 mode_ = "rb" if mode == "r" else mode
192
193 open_kwargs = open_kwargs or {}
194
195 # Use blockcache with size 4MB by default
196 if "cache_type" not in open_kwargs:
197 open_kwargs["cache_type"] = "blockcache"
198 if (
199 open_kwargs["cache_type"] == "blockcache"
200 and "block_size" not in open_kwargs
201 ):
202 open_kwargs["block_size"] = 4 * 1024 * 1024
203
204 filename = _open_remote_file(
205 filename,
206 mode=mode_,
207 storage_options=storage_options,
208 open_kwargs=open_kwargs,
209 )
210
211 if isinstance(filename, BytesIOProxy):
212 source = filename
213 filename = io.BytesIO()
214 source.getvalue = filename.getbuffer
215
216 if isinstance(filename, io.IOBase) and mode == "r":
217 magic_number = read_magic_number_from_file(filename)
218 if not magic_number.startswith(b"\211HDF\r\n\032\n"):
219 raise ValueError(
220 f"{magic_number!r} is not the signature of a valid netCDF4 file"
221 )
222
223 if format is None:
224 format = "NETCDF4"
225
226 if format not in ["NETCDF4", "NETCDF4_CLASSIC"]:
227 raise ValueError(f"invalid format for h5netcdf backend: {format}")
228
229 kwargs = {

Callers 2

open_datasetMethod · 0.45
open_groups_as_dictMethod · 0.45

Calls 7

is_remote_uriFunction · 0.90
_open_remote_fileFunction · 0.90
combine_locksFunction · 0.90
get_write_lockFunction · 0.90
startswithMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected