Skip to content

Commit df2b459

Browse files
committed
WIP: BUG: tzyxc bin shrink crash
Re: #157
1 parent 4ac1fc0 commit df2b459

File tree

5 files changed

+182
-99
lines changed

5 files changed

+182
-99
lines changed

ngff_zarr/methods/_itk.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def _downsample_itk_bin_shrink(
149149
# For consistency for now, do not utilize direction until there is standardized support for
150150
# direction cosines / orientation in OME-NGFF
151151
# block_0.attrs.pop("direction", None)
152+
if "c" in previous_image.dims:
153+
raise ValueError(
154+
"Downsampling with ITK BinShrinkImageFilter does not support channel dimension 'c'. "
155+
"Use ITK Gaussian downsampling instead."
156+
)
152157
block_input = itk.image_from_array(np.ones_like(block_0))
153158
spacing = [previous_image.scale[d] for d in spatial_dims]
154159
block_input.SetSpacing(spacing)

ngff_zarr/methods/_support.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,25 @@ def _dim_scale_factors(dims, scale_factor, previous_dim_factors):
111111
result_scale_factors = {
112112
d: int(scale_factor[d] / previous_dim_factors[d]) for d in scale_factor
113113
}
114+
# if a dim is not in the scale_factors, add it with a scale factor of 1
115+
for d in dims:
116+
if d not in result_scale_factors:
117+
result_scale_factors[d] = 1
118+
114119
return result_scale_factors
115120

121+
116122
def _update_previous_dim_factors(scale_factor, spatial_dims, previous_dim_factors):
123+
previous_dim_factors = copy.copy(previous_dim_factors)
117124
if isinstance(scale_factor, int):
118-
previous_dim_factors = { d : scale_factor for d in spatial_dims }
125+
for d in spatial_dims:
126+
previous_dim_factors[d] = scale_factor
119127
else:
120-
previous_dim_factors = scale_factor
128+
for d in scale_factor:
129+
previous_dim_factors[d] = scale_factor[d]
121130
return previous_dim_factors
122131

132+
123133
def _align_chunks(previous_image, default_chunks, dim_factors):
124134
block_0_shape = [c[0] for c in previous_image.data.chunks]
125135

0 commit comments

Comments
 (0)