@@ -783,13 +783,18 @@ def ds(self):
783
783
return self .zarr_group
784
784
785
785
def open_store_variable (self , name ):
786
+ print (f"DEBUG OPEN: Reading variable '{ name } '" )
786
787
zarr_array = self .members [name ]
788
+ print (
789
+ f"DEBUG OPEN: zarr_array.dtype={ zarr_array .dtype } , fill_value={ zarr_array .fill_value } "
790
+ )
787
791
data = indexing .LazilyIndexedArray (ZarrArrayWrapper (zarr_array ))
788
792
try_nczarr = self ._mode == "r"
789
793
dimensions , attributes = _get_zarr_dims_and_attrs (
790
794
zarr_array , DIMENSION_KEY , try_nczarr
791
795
)
792
796
attributes = dict (attributes )
797
+ print (f"DEBUG OPEN: Original attributes: { attributes } " )
793
798
794
799
encoding = {
795
800
"chunks" : zarr_array .chunks ,
@@ -814,31 +819,60 @@ def open_store_variable(self, name):
814
819
}
815
820
)
816
821
822
+ print (
823
+ f"DEBUG OPEN: _use_zarr_fill_value_as_mask={ self ._use_zarr_fill_value_as_mask } "
824
+ )
825
+ print (f"DEBUG OPEN: '_FillValue' in attributes: { '_FillValue' in attributes } " )
826
+
817
827
if self ._use_zarr_fill_value_as_mask :
818
828
# Setting this attribute triggers CF decoding for missing values
819
829
# by interpreting Zarr's fill_value to mean the same as netCDF's _FillValue
830
+ print (f"DEBUG OPEN: Using zarr fill_value as mask for '{ name } '" )
831
+ print ("===========" )
832
+ print (f"DEBUG DTYPE: zarr array fill value: { zarr_array .fill_value .dtype } " )
820
833
if zarr_array .fill_value is not None :
821
834
attributes ["_FillValue" ] = zarr_array .fill_value
835
+ print (
836
+ f"\t DEBUG OPEN: Set _FillValue to { zarr_array .fill_value } for '{ name } '"
837
+ )
838
+ print ("===========" )
822
839
elif "_FillValue" in attributes :
823
840
# TODO update version check for the released version with dtypes
824
841
# probably be 3.1
825
842
import zarr
826
843
827
- #
844
+ print (f"DEBUG: Processing _FillValue for { name } " )
845
+ print (f"DEBUG: Original _FillValue: { attributes ['_FillValue' ]} " )
846
+ print (
847
+ f"DEBUG: zarr_array.metadata.data_type: { zarr_array .metadata .data_type } "
848
+ )
849
+
828
850
if Version (zarr .__version__ ) >= Version ("3.0.6" ):
851
+ native_dtype = zarr_array .metadata .data_type .to_native_dtype ()
852
+ print (f"DEBUG: native_dtype: { native_dtype } " )
829
853
attributes ["_FillValue" ] = (
830
854
# Use the new dtype infrastructure instead of doing xarray
831
855
# specific fill value decoding
832
856
FillValueCoder .decode (
833
857
attributes ["_FillValue" ],
834
- zarr_array . metadata . data_type . to_native_dtype () ,
858
+ native_dtype ,
835
859
)
836
860
)
837
861
else :
862
+ dtype_value = zarr_array .metadata .data_type .value
863
+ print (f"DEBUG: dtype_value: { dtype_value } " )
838
864
attributes ["_FillValue" ] = FillValueCoder .decode (
839
- attributes ["_FillValue" ], zarr_array . metadata . data_type . value
865
+ attributes ["_FillValue" ], dtype_value
840
866
)
841
- return Variable (dimensions , data , attributes , encoding )
867
+
868
+ print (f"DEBUG: Decoded _FillValue: { attributes ['_FillValue' ]} " )
869
+ print (f"DEBUG: Decoded _FillValue type: { type (attributes ['_FillValue' ])} " )
870
+
871
+ print (f"DEBUG OPEN: Final attributes for '{ name } ': { attributes } " )
872
+ variable = Variable (dimensions , data , attributes , encoding )
873
+ print (f"DEBUG OPEN: Created variable '{ name } ' with dtype: { variable .dtype } " )
874
+
875
+ return variable
842
876
843
877
def get_variables (self ):
844
878
return FrozenDict ((k , self .open_store_variable (k )) for k in self .array_keys ())
@@ -953,22 +987,36 @@ def store(
953
987
variables_encoded , attributes = self .encode (
954
988
{vn : variables [vn ] for vn in new_variable_names }, attributes
955
989
)
956
- print (f" { variables_encoded = } " )
990
+ print ("HERE " )
957
991
958
992
if existing_variable_names :
959
993
# We make sure that values to be appended are encoded *exactly*
960
994
# as the current values in the store.
961
995
# To do so, we decode variables directly to access the proper encoding,
962
996
# without going via xarray.Dataset to avoid needing to load
963
997
# index variables into memory.
998
+ print (
999
+ f"DEBUG APPEND: Processing existing variables: { existing_variable_names } "
1000
+ )
1001
+ store_vars = {
1002
+ k : self .open_store_variable (name = k ) for k in existing_variable_names
1003
+ }
1004
+ print (
1005
+ f"DEBUG APPEND: Store vars dtypes: { [(name , var .dtype ) for name , var in store_vars .items ()]} "
1006
+ )
1007
+
964
1008
existing_vars , _ , _ = conventions .decode_cf_variables (
965
- variables = {
966
- k : self .open_store_variable (name = k ) for k in existing_variable_names
967
- },
1009
+ variables = store_vars ,
968
1010
# attributes = {} since we don't care about parsing the global
969
1011
# "coordinates" attribute
970
1012
attributes = {},
971
1013
)
1014
+ print (
1015
+ f"DEBUG APPEND: After CF decode dtypes: { [(name , var .dtype ) for name , var in existing_vars .items ()]} "
1016
+ )
1017
+ print (
1018
+ f"DEBUG APPEND: Variables to append dtypes: { [(name , var .dtype ) for name , var in variables_encoded .items () if name in existing_variable_names ]} "
1019
+ )
972
1020
# Modified variables must use the same encoding as the store.
973
1021
vars_with_encoding = {}
974
1022
for vn in existing_variable_names :
@@ -1006,7 +1054,6 @@ def store(
1006
1054
else :
1007
1055
variables_to_set = variables_encoded
1008
1056
1009
- print (f"{ variables_to_set = } " )
1010
1057
self .set_variables (
1011
1058
variables_to_set , check_encoding_set , writer , unlimited_dims = unlimited_dims
1012
1059
)
@@ -1015,7 +1062,6 @@ def store(
1015
1062
if _zarr_v3 ():
1016
1063
kwargs ["zarr_format" ] = self .zarr_group .metadata .zarr_format
1017
1064
zarr .consolidate_metadata (self .zarr_group .store , ** kwargs )
1018
- print ("DONE STORE.STORE" )
1019
1065
1020
1066
def sync (self ):
1021
1067
pass
@@ -1089,8 +1135,6 @@ def _create_new_array(
1089
1135
if c in encoding :
1090
1136
encoding ["config" ][c ] = encoding .pop (c )
1091
1137
1092
- print ("create" )
1093
- print (dtype )
1094
1138
zarr_array = self .zarr_group .create (
1095
1139
name ,
1096
1140
shape = shape ,
@@ -1229,8 +1273,6 @@ def set_variables(
1229
1273
1230
1274
encoding ["overwrite" ] = self ._mode == "w"
1231
1275
1232
- print (dtype )
1233
- print (";sdf" )
1234
1276
zarr_array = self ._create_new_array (
1235
1277
name = name ,
1236
1278
dtype = dtype ,
@@ -1239,8 +1281,6 @@ def set_variables(
1239
1281
encoding = encoding ,
1240
1282
attrs = encoded_attrs ,
1241
1283
)
1242
- print (zarr_array )
1243
- print (type (zarr_array ))
1244
1284
1245
1285
writer .add (v .data , zarr_array , region )
1246
1286
0 commit comments