@@ -76,13 +76,23 @@ def image_labeling_whole_well(
76
76
" but there can be only one Z plane."
77
77
)
78
78
79
- # Load . zattrs file
79
+ # Load zattrs file
80
80
zattrs_file = f"{ zarrurl } .zattrs"
81
81
with open (zattrs_file , "r" ) as jsonfile :
82
82
zattrs = json .load (jsonfile )
83
83
84
+ # Preliminary checks on multiscales
85
+ multiscales = zattrs ["multiscales" ]
86
+ if len (multiscales ) > 1 :
87
+ raise Exception (f"ERROR: There are { len (multiscales )} multiscales" )
88
+ if "coordinateTransformations" in multiscales [0 ].keys ():
89
+ raise Exception (
90
+ "ERROR: coordinateTransformations at the multiscales "
91
+ "level are not currently supported"
92
+ )
93
+
84
94
# Extract num_levels
85
- num_levels = len (zattrs [ " multiscales" ] [0 ]["datasets" ])
95
+ num_levels = len (multiscales [0 ]["datasets" ])
86
96
print ("num_levels" , num_levels )
87
97
print ()
88
98
@@ -142,6 +152,26 @@ def image_labeling_whole_well(
142
152
f"da.from_array(upscaled_mask) [with rechunking]: { mask_da } \n \n "
143
153
)
144
154
155
+ # Construct rescaled datasets
156
+ datasets = multiscales [0 ]["datasets" ]
157
+ new_datasets = []
158
+ for ds in datasets :
159
+ new_ds = {}
160
+ for key in ds .keys ():
161
+ if key != "coordinateTransformations" :
162
+ new_ds [key ] = ds [key ]
163
+ old_transformations = ds ["coordinateTransformations" ]
164
+ new_transformations = []
165
+ for t in old_transformations :
166
+ if t ["type" ] == "scale" :
167
+ new_t = t
168
+ new_t ["scale" ][1 ] *= coarsening_xy ** labeling_level
169
+ new_t ["scale" ][2 ] *= coarsening_xy ** labeling_level
170
+ new_transformations .append (new_t )
171
+ else :
172
+ new_transformations .append (t )
173
+ new_datasets .append (new_ds )
174
+
145
175
# Write zattrs for labels and for specific label
146
176
# FIXME deal with: (1) many channels, (2) overwriting
147
177
labels_group = zarr .group (f"{ zarrurl } labels" )
@@ -152,30 +182,8 @@ def image_labeling_whole_well(
152
182
{
153
183
"name" : label_name ,
154
184
"version" : "0.4" ,
155
- "axes" : [
156
- {"name" : axis_name , "type" : "space" }
157
- for axis_name in ["z" , "y" , "x" ]
158
- ],
159
- "datasets" : [
160
- {
161
- "path" : f"{ ind_level } " ,
162
- "coordinateTransformations" : [
163
- {
164
- "type" : "scale" ,
165
- "scale" : [
166
- 1.0 ,
167
- 1.0
168
- * coarsening_xy
169
- ** (labeling_level + ind_level ),
170
- 1.0
171
- * coarsening_xy
172
- ** (labeling_level + ind_level ),
173
- ],
174
- }
175
- ],
176
- }
177
- for ind_level in range (num_levels )
178
- ],
185
+ "axes" : multiscales [0 ]["axes" ],
186
+ "datasets" : new_datasets ,
179
187
}
180
188
]
181
189
0 commit comments