@@ -844,13 +844,18 @@ def ds(self):
844
844
return self .zarr_group
845
845
846
846
def open_store_variable (self , name ):
847
+ print (f"DEBUG OPEN: Reading variable '{ name } '" )
847
848
zarr_array = self .members [name ]
849
+ print (
850
+ f"DEBUG OPEN: zarr_array.dtype={ zarr_array .dtype } , fill_value={ zarr_array .fill_value } "
851
+ )
848
852
data = indexing .LazilyIndexedArray (ZarrArrayWrapper (zarr_array ))
849
853
try_nczarr = self ._mode == "r"
850
854
dimensions , attributes = _get_zarr_dims_and_attrs (
851
855
zarr_array , DIMENSION_KEY , try_nczarr
852
856
)
853
857
attributes = dict (attributes )
858
+ print (f"DEBUG OPEN: Original attributes: { attributes } " )
854
859
855
860
encoding = {
856
861
"chunks" : zarr_array .chunks ,
@@ -875,32 +880,60 @@ def open_store_variable(self, name):
875
880
}
876
881
)
877
882
883
+ print (
884
+ f"DEBUG OPEN: _use_zarr_fill_value_as_mask={ self ._use_zarr_fill_value_as_mask } "
885
+ )
886
+ print (f"DEBUG OPEN: '_FillValue' in attributes: { '_FillValue' in attributes } " )
887
+
878
888
if self ._use_zarr_fill_value_as_mask :
879
889
# Setting this attribute triggers CF decoding for missing values
880
890
# by interpreting Zarr's fill_value to mean the same as netCDF's _FillValue
891
+ print (f"DEBUG OPEN: Using zarr fill_value as mask for '{ name } '" )
892
+ print ("===========" )
893
+ print (f"DEBUG DTYPE: zarr array fill value: { zarr_array .fill_value .dtype } " )
881
894
if zarr_array .fill_value is not None :
882
895
attributes ["_FillValue" ] = zarr_array .fill_value
896
+ print (
897
+ f"\t DEBUG OPEN: Set _FillValue to { zarr_array .fill_value } for '{ name } '"
898
+ )
899
+ print ("===========" )
883
900
elif "_FillValue" in attributes :
884
901
# TODO update version check for the released version with dtypes
885
902
# probably be 3.1
886
903
import zarr
887
904
888
- #
905
+ print (f"DEBUG: Processing _FillValue for { name } " )
906
+ print (f"DEBUG: Original _FillValue: { attributes ['_FillValue' ]} " )
907
+ print (
908
+ f"DEBUG: zarr_array.metadata.data_type: { zarr_array .metadata .data_type } "
909
+ )
910
+
889
911
if Version (zarr .__version__ ) >= Version ("3.0.6" ):
912
+ native_dtype = zarr_array .metadata .data_type .to_native_dtype ()
913
+ print (f"DEBUG: native_dtype: { native_dtype } " )
890
914
attributes ["_FillValue" ] = (
891
915
# Use the new dtype infrastructure instead of doing xarray
892
916
# specific fill value decoding
893
917
FillValueCoder .decode (
894
918
attributes ["_FillValue" ],
895
- zarr_array . metadata . data_type . to_native_dtype () ,
919
+ native_dtype ,
896
920
)
897
921
)
898
922
else :
923
+ dtype_value = zarr_array .metadata .data_type .value
924
+ print (f"DEBUG: dtype_value: { dtype_value } " )
899
925
attributes ["_FillValue" ] = FillValueCoder .decode (
900
- attributes ["_FillValue" ], zarr_array . metadata . data_type . value
926
+ attributes ["_FillValue" ], dtype_value
901
927
)
902
928
903
- return Variable (dimensions , data , attributes , encoding )
929
+ print (f"DEBUG: Decoded _FillValue: { attributes ['_FillValue' ]} " )
930
+ print (f"DEBUG: Decoded _FillValue type: { type (attributes ['_FillValue' ])} " )
931
+
932
+ print (f"DEBUG OPEN: Final attributes for '{ name } ': { attributes } " )
933
+ variable = Variable (dimensions , data , attributes , encoding )
934
+ print (f"DEBUG OPEN: Created variable '{ name } ' with dtype: { variable .dtype } " )
935
+
936
+ return variable
904
937
905
938
def get_variables (self ):
906
939
return FrozenDict ((k , self .open_store_variable (k )) for k in self .array_keys ())
@@ -1015,22 +1048,36 @@ def store(
1015
1048
variables_encoded , attributes = self .encode (
1016
1049
{vn : variables [vn ] for vn in new_variable_names }, attributes
1017
1050
)
1018
- print (f" { variables_encoded = } " )
1051
+ print ("HERE " )
1019
1052
1020
1053
if existing_variable_names :
1021
1054
# We make sure that values to be appended are encoded *exactly*
1022
1055
# as the current values in the store.
1023
1056
# To do so, we decode variables directly to access the proper encoding,
1024
1057
# without going via xarray.Dataset to avoid needing to load
1025
1058
# index variables into memory.
1059
+ print (
1060
+ f"DEBUG APPEND: Processing existing variables: { existing_variable_names } "
1061
+ )
1062
+ store_vars = {
1063
+ k : self .open_store_variable (name = k ) for k in existing_variable_names
1064
+ }
1065
+ print (
1066
+ f"DEBUG APPEND: Store vars dtypes: { [(name , var .dtype ) for name , var in store_vars .items ()]} "
1067
+ )
1068
+
1026
1069
existing_vars , _ , _ = conventions .decode_cf_variables (
1027
- variables = {
1028
- k : self .open_store_variable (name = k ) for k in existing_variable_names
1029
- },
1070
+ variables = store_vars ,
1030
1071
# attributes = {} since we don't care about parsing the global
1031
1072
# "coordinates" attribute
1032
1073
attributes = {},
1033
1074
)
1075
+ print (
1076
+ f"DEBUG APPEND: After CF decode dtypes: { [(name , var .dtype ) for name , var in existing_vars .items ()]} "
1077
+ )
1078
+ print (
1079
+ f"DEBUG APPEND: Variables to append dtypes: { [(name , var .dtype ) for name , var in variables_encoded .items () if name in existing_variable_names ]} "
1080
+ )
1034
1081
# Modified variables must use the same encoding as the store.
1035
1082
vars_with_encoding = {}
1036
1083
for vn in existing_variable_names :
@@ -1068,7 +1115,6 @@ def store(
1068
1115
else :
1069
1116
variables_to_set = variables_encoded
1070
1117
1071
- print (f"{ variables_to_set = } " )
1072
1118
self .set_variables (
1073
1119
variables_to_set , check_encoding_set , writer , unlimited_dims = unlimited_dims
1074
1120
)
@@ -1077,7 +1123,6 @@ def store(
1077
1123
if _zarr_v3 ():
1078
1124
kwargs ["zarr_format" ] = self .zarr_group .metadata .zarr_format
1079
1125
zarr .consolidate_metadata (self .zarr_group .store , ** kwargs )
1080
- print ("DONE STORE.STORE" )
1081
1126
1082
1127
def sync (self ):
1083
1128
pass
@@ -1151,8 +1196,6 @@ def _create_new_array(
1151
1196
if c in encoding :
1152
1197
encoding ["config" ][c ] = encoding .pop (c )
1153
1198
1154
- print ("create" )
1155
- print (dtype )
1156
1199
zarr_array = self .zarr_group .create (
1157
1200
name ,
1158
1201
shape = shape ,
@@ -1259,8 +1302,6 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No
1259
1302
1260
1303
encoding ["overwrite" ] = True if self ._mode == "w" else False
1261
1304
1262
- print (dtype )
1263
- print (";sdf" )
1264
1305
zarr_array = self ._create_new_array (
1265
1306
name = name ,
1266
1307
dtype = dtype ,
@@ -1269,8 +1310,6 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No
1269
1310
encoding = encoding ,
1270
1311
attrs = encoded_attrs ,
1271
1312
)
1272
- print (zarr_array )
1273
- print (type (zarr_array ))
1274
1313
1275
1314
writer .add (v .data , zarr_array , region )
1276
1315
0 commit comments