Skip to content

Commit af39b1a

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

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

ngff_zarr/methods/_itk.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,18 @@ def _downsample_itk_bin_shrink(
135135
previous_dim_factors = {d: 1 for d in dims}
136136
spatial_dims = [dim for dim in dims if dim in _spatial_dims]
137137
spatial_dims = _image_dims[: len(spatial_dims)]
138+
breakpoint()
138139
for scale_factor in scale_factors:
139140
dim_factors = _dim_scale_factors(dims, scale_factor, previous_dim_factors)
140141
previous_dim_factors = _update_previous_dim_factors(
141142
scale_factor, spatial_dims, previous_dim_factors
142143
)
143144
previous_image = _align_chunks(previous_image, default_chunks, dim_factors)
144145

145-
shrink_factors = [dim_factors[sd] for sd in spatial_dims]
146+
if "t" in previous_image.dims:
147+
shrink_factors = [dim_factors[sd] for sd in spatial_dims + ("t",)]
148+
else:
149+
shrink_factors = [dim_factors[sd] for sd in spatial_dims]
146150

147151
block_0 = _get_block(previous_image, 0)
148152

ngff_zarr/methods/_support.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ 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

116121
def _update_previous_dim_factors(scale_factor, spatial_dims, previous_dim_factors):

test/test_to_ngff_zarr_itk.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from ngff_zarr import Methods, to_multiscales
3+
from ngff_zarr import Methods, to_multiscales, to_ngff_image
44

55
from ._data import verify_against_baseline
66
import platform
@@ -19,6 +19,39 @@ def test_bin_shrink_isotropic_scale_factors(input_images):
1919
# store_new_multiscales(dataset_name, baseline_name, multiscales)
2020
verify_against_baseline(dataset_name, baseline_name, multiscales)
2121

22+
def test_bin_shrink_tzyxc():
23+
import dask.array as da
24+
from ngff_zarr import Axis
25+
test_array = da.ones((96, 256, 256, 256, 2), chunks=(1, 128, 128, 128, 1), dtype="uint16")
26+
img = to_ngff_image(
27+
test_array,
28+
dims=list("tzyxc"),
29+
scale={
30+
"t": 100_000.0,
31+
"z": 0.98,
32+
"y": 0.98,
33+
"x": 0.98,
34+
"c": 1.0,
35+
},
36+
axes_units={
37+
"t": "millisecond",
38+
"z": "micrometer",
39+
"y": "micrometer",
40+
"x": "micrometer",
41+
},
42+
name="000x_000y_000z",
43+
)
44+
45+
multiscales = to_multiscales(
46+
img,
47+
scale_factors=[
48+
{"z": 2, "y": 2, "x": 2},
49+
{"z": 4, "y": 4, "x": 4}
50+
],
51+
method=Methods.ITK_BIN_SHRINK,
52+
)
53+
assert len(multiscales.images) == 3
54+
2255

2356
@pytest.mark.skipif(
2457
platform.system() == "Linux" and platform.machine() == "aarch64",

test/test_to_ngff_zarr_itkwasm.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ def test_bin_shrink_tczyx():
106106
assert multiscales.images[1].data.shape[1] == 2
107107
assert multiscales.images[1].data.shape[2] == 16
108108

109+
def test_bin_shrink_tzyxc():
110+
import dask.array as da
111+
from ngff_zarr import Axis
112+
test_array = da.ones((96, 256, 256, 256, 2), chunks=(1, 128, 128, 128, 1), dtype="uint16")
113+
img = to_ngff_image(
114+
test_array,
115+
dims=list("tzyxc"),
116+
scale={
117+
"t": 100_000.0,
118+
"z": 0.98,
119+
"y": 0.98,
120+
"x": 0.98,
121+
"c": 1.0,
122+
},
123+
axes_units={
124+
"t": "millisecond",
125+
"z": "micrometer",
126+
"y": "micrometer",
127+
"x": "micrometer",
128+
},
129+
name="000x_000y_000z",
130+
)
131+
132+
multiscales = to_multiscales(
133+
img,
134+
scale_factors=[
135+
{"z": 2, "y": 2, "x": 2},
136+
{"z": 4, "y": 4, "x": 4}
137+
],
138+
method=Methods.ITK_BIN_SHRINK,
139+
)
140+
assert len(multiscales.images) == 3
141+
109142

110143
def test_bin_shrink_isotropic_scale_factors(input_images):
111144
dataset_name = "cthead1"

0 commit comments

Comments
 (0)