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

Method open_store_variable

xarray/backends/zarr.py:904–946  ·  view source on GitHub ↗
(self, name)

Source from the content-addressed store, hash-verified

902 return self.zarr_group
903
904 def open_store_variable(self, name):
905 zarr_array = self.members[name]
906 data = indexing.LazilyIndexedArray(ZarrArrayWrapper(zarr_array))
907 try_nczarr = self._mode == "r"
908 dimensions, attributes = _get_zarr_dims_and_attrs(
909 zarr_array, DIMENSION_KEY, try_nczarr
910 )
911 attributes = dict(attributes)
912
913 encoding = {
914 "chunks": zarr_array.chunks,
915 "preferred_chunks": dict(zip(dimensions, zarr_array.chunks, strict=True)),
916 }
917
918 if _zarr_v3():
919 encoding.update(
920 {
921 "compressors": zarr_array.compressors,
922 "filters": zarr_array.filters,
923 "shards": zarr_array.shards,
924 }
925 )
926 if self.zarr_group.metadata.zarr_format == 3:
927 encoding.update({"serializer": zarr_array.serializer})
928 else:
929 encoding.update(
930 {
931 "compressor": zarr_array.compressor,
932 "filters": zarr_array.filters,
933 }
934 )
935
936 if self._use_zarr_fill_value_as_mask:
937 # Setting this attribute triggers CF decoding for missing values
938 # by interpreting Zarr's fill_value to mean the same as netCDF's _FillValue
939 if zarr_array.fill_value is not None:
940 attributes["_FillValue"] = zarr_array.fill_value
941 elif "_FillValue" in attributes:
942 attributes["_FillValue"] = FillValueCoder.decode(
943 attributes["_FillValue"], zarr_array.dtype
944 )
945
946 return Variable(dimensions, data, attributes, encoding)
947
948 def get_variables(self):
949 return FrozenDict((k, self.open_store_variable(k)) for k in self.array_keys())

Callers 3

get_variablesMethod · 0.95
storeMethod · 0.95
_auto_detect_regionsMethod · 0.95

Calls 6

VariableClass · 0.90
ZarrArrayWrapperClass · 0.85
_get_zarr_dims_and_attrsFunction · 0.85
_zarr_v3Function · 0.85
updateMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected