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

Method open_store_variable

xarray/backends/netCDF4_.py:540–581  ·  view source on GitHub ↗
(self, name: str, var)

Source from the content-addressed store, hash-verified

538 return self._acquire()
539
540 def open_store_variable(self, name: str, var):
541 import netCDF4
542
543 dimensions = var.dimensions
544 attributes = {k: var.getncattr(k) for k in var.ncattrs()}
545 data = indexing.LazilyIndexedArray(NetCDF4ArrayWrapper(name, self))
546 encoding: dict[str, Any] = {}
547 if isinstance(var.datatype, netCDF4.EnumType):
548 encoding["dtype"] = np.dtype(
549 data.dtype,
550 metadata={
551 "enum": var.datatype.enum_dict,
552 "enum_name": var.datatype.name,
553 },
554 )
555 else:
556 encoding["dtype"] = var.dtype
557 _ensure_fill_value_valid(data, attributes)
558 # netCDF4 specific encoding; save _FillValue for later
559 filters = var.filters()
560 if filters is not None:
561 encoding.update(filters)
562 chunking = var.chunking()
563 if chunking is not None:
564 if chunking == "contiguous":
565 encoding["contiguous"] = True
566 encoding["chunksizes"] = None
567 else:
568 encoding["contiguous"] = False
569 encoding["chunksizes"] = tuple(chunking)
570 encoding["preferred_chunks"] = dict(
571 zip(var.dimensions, chunking, strict=True)
572 )
573 # TODO: figure out how to round-trip "endian-ness" without raising
574 # warnings from netCDF4
575 # encoding['endian'] = var.endian()
576 pop_to(attributes, encoding, "least_significant_digit")
577 # save source so __repr__ can detect if it's local or not
578 encoding["source"] = self._filename
579 encoding["original_shape"] = data.shape
580
581 return Variable(dimensions, data, attributes, encoding)
582
583 def get_variables(self):
584 return FrozenDict(

Callers 1

get_variablesMethod · 0.95

Calls 6

VariableClass · 0.90
NetCDF4ArrayWrapperClass · 0.85
_ensure_fill_value_validFunction · 0.85
pop_toFunction · 0.85
dtypeMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected