MCPcopy Index your code
hub / github.com/pydata/xarray / open_store_variable

Method open_store_variable

xarray/backends/h5netcdf_.py:278–330  ·  view source on GitHub ↗
(self, name, var)

Source from the content-addressed store, hash-verified

276 return self._acquire()
277
278 def open_store_variable(self, name, var):
279 import h5netcdf.core
280
281 dimensions = var.dimensions
282 data = indexing.LazilyIndexedArray(H5NetCDFArrayWrapper(name, self))
283 attrs = _read_attributes(var)
284
285 # netCDF4 specific encoding
286 encoding = {
287 "chunksizes": var.chunks,
288 "fletcher32": var.fletcher32,
289 "shuffle": var.shuffle,
290 }
291 if var.chunks:
292 encoding["preferred_chunks"] = dict(
293 zip(var.dimensions, var.chunks, strict=True)
294 )
295 # Convert h5py-style compression options to NetCDF4-Python
296 # style, if possible
297 if var.compression == "gzip":
298 encoding["zlib"] = True
299 encoding["complevel"] = var.compression_opts
300 elif var.compression is not None:
301 encoding["compression"] = var.compression
302 encoding["compression_opts"] = var.compression_opts
303
304 # save source so __repr__ can detect if it's local or not
305 encoding["source"] = self._filename
306 encoding["original_shape"] = data.shape
307
308 h5py = var._root._h5py
309 vlen_dtype = h5py.check_dtype(vlen=var.dtype)
310 if vlen_dtype is str:
311 encoding["dtype"] = str
312 elif vlen_dtype is not None: # pragma: no cover
313 # xarray doesn't support writing arbitrary vlen dtypes yet.
314 pass
315 # just check if datatype is available and create dtype
316 # this check can be removed if h5netcdf >= 1.4.0 for any environment
317 elif (datatype := getattr(var, "datatype", None)) and isinstance(
318 datatype, h5netcdf.core.EnumType
319 ):
320 encoding["dtype"] = np.dtype(
321 data.dtype,
322 metadata={
323 "enum": datatype.enum_dict,
324 "enum_name": datatype.name,
325 },
326 )
327 else:
328 encoding["dtype"] = var.dtype
329
330 return Variable(dimensions, data, attrs, encoding)
331
332 def get_variables(self):
333 return FrozenDict(

Callers 1

get_variablesMethod · 0.95

Calls 4

VariableClass · 0.90
_read_attributesFunction · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected