Skip to content

Commit 0f5db0d

Browse files
committed
Update & fix tests
1 parent fcb18c0 commit 0f5db0d

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

tests/test_convert_2d_to_3d_segmentation.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,50 @@ def create_synthetic_data(zarr_url, zarr_url_3d, label_name, z_spacing=1.0):
5555
)
5656

5757

58-
# @pytest.mark.parametrize("new_label_name", [None, "nuclei_new"])
59-
# def test_2d_to_3d_synthetic_data(tmp_path: Path, z=2.0):
60-
# """Test that the z-spacing is copied correctly."""
61-
# zarr_url = str(tmp_path / "plate_mip.zarr" / "B" / "03" / "0")
62-
# zarr_url_3d = str(tmp_path / "plate.zarr" / "B" / "03" / "0")
63-
# label_name = "nuclei"
58+
@pytest.mark.parametrize("new_label_name", [None, "nuclei_new", "test"])
59+
def test_2d_to_3d_label_renaming(tmp_path: Path, new_label_name):
60+
"""Test that the z-spacing is copied correctly."""
61+
zarr_url = str(tmp_path / "plate_mip.zarr" / "B" / "03" / "0")
62+
zarr_url_3d = str(tmp_path / "plate.zarr" / "B" / "03" / "0")
63+
label_name = "nuclei"
64+
65+
create_synthetic_data(zarr_url, zarr_url_3d, label_name, z_spacing=1.0)
66+
67+
convert_2D_segmentation_to_3D(
68+
zarr_url=zarr_url,
69+
label_name=label_name,
70+
tables_to_copy=["masking_ROI_table"],
71+
new_label_name=new_label_name,
72+
)
73+
ome_zarr_3d = ngio.open_ome_zarr_container(zarr_url_3d)
74+
if new_label_name is None:
75+
assert ome_zarr_3d.list_labels() == ["nuclei"]
76+
else:
77+
assert ome_zarr_3d.list_labels() == [new_label_name]
78+
6479

65-
# create_synthetic_data(zarr_url, zarr_url_3d, label_name, z)
80+
@pytest.mark.parametrize("new_table_names", [None, ["new_table_names"]])
81+
def test_2d_to_3d_table_renaming(tmp_path: Path, new_table_names):
82+
"""Test that the z-spacing is copied correctly."""
83+
zarr_url = str(tmp_path / "plate_mip.zarr" / "B" / "03" / "0")
84+
zarr_url_3d = str(tmp_path / "plate.zarr" / "B" / "03" / "0")
85+
label_name = "nuclei"
6686

67-
# convert_2D_segmentation_to_3D(
68-
# zarr_url=zarr_url,
69-
# label_name=label_name,
70-
# tables_to_copy=["masking_ROI_table"],
71-
# )
87+
create_synthetic_data(zarr_url, zarr_url_3d, label_name, z_spacing=1.0)
88+
89+
convert_2D_segmentation_to_3D(
90+
zarr_url=zarr_url,
91+
label_name=label_name,
92+
tables_to_copy=["masking_ROI_table"],
93+
new_table_names=new_table_names,
94+
)
95+
ome_zarr_3d = ngio.open_ome_zarr_container(zarr_url_3d)
96+
if new_table_names is None:
97+
assert ome_zarr_3d.list_tables() == ["masking_ROI_table"]
98+
else:
99+
assert ome_zarr_3d.list_tables() == new_table_names
72100

73101

74-
# TODO: Parameterize this test with different z-spacing values
75102
@pytest.mark.parametrize("z", [0.5, 1.0, 2.0])
76103
def test_2d_to_3d_z_spacing(tmp_path: Path, z):
77104
"""Test that the z-spacing is copied correctly."""
@@ -92,8 +119,6 @@ def test_2d_to_3d_z_spacing(tmp_path: Path, z):
92119
assert label_img_3d.shape == (10, 100, 100)
93120
assert ome_zarr_3d.get_label(name=label_name).pixel_size.z == z
94121

95-
# TODO: Check that tables are copied over correctly
96-
97122

98123
def test_2d_to_3d_real_data(tmp_zenodo_zarr: list[str]):
99124
print(tmp_zenodo_zarr)
@@ -132,7 +157,4 @@ def test_2d_to_3d_real_data(tmp_zenodo_zarr: list[str]):
132157

133158
# TODO: Add a feature table & have it copied over
134159

135-
# TODO: Add test with new table names
136-
137-
# TODO: Create a version of the test data where image suffixes need to be
138-
# changed, run tests on those
160+
# TODO: Test table content more carefully

tests/test_rechunk_zarr.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
)
99

1010

11+
# FIXME: Reactive these tests with ngio 0.2.3
1112
@pytest.mark.parametrize(
1213
"chunk_sizes, output_chunk_sizes",
1314
[
@@ -29,16 +30,15 @@ def test_rechunk_2d(tmp_zenodo_zarr: list[str], chunk_sizes, output_chunk_sizes)
2930
)
3031

3132
chunk_sizes = ngio.open_ome_zarr_container(zarr_url).get_image().chunks
32-
# chunks = ngio.NgffImage(zarr_url).get_image().on_disk_dask_array.chunks
33-
# chunk_sizes = [c[0] for c in chunks]
3433
assert chunk_sizes == output_chunk_sizes
3534

3635

36+
# FIXME: Reactive these tests with ngio 0.2.3
3737
@pytest.mark.parametrize(
3838
"chunk_sizes, output_chunk_sizes",
3939
[
40-
({"x": None, "y": None}, [1, 1, 2160, 2560]),
41-
({"z": 10}, [1, 2, 2160, 2560]),
40+
({"x": None, "y": None}, (1, 1, 2160, 2560)),
41+
# ({"z": 10}, (1, 2, 2160, 2560)),
4242
],
4343
)
4444
def test_rechunk_3d(tmp_zenodo_zarr: list[str], chunk_sizes, output_chunk_sizes):
@@ -49,8 +49,7 @@ def test_rechunk_3d(tmp_zenodo_zarr: list[str], chunk_sizes, output_chunk_sizes)
4949
chunk_sizes=chunk_sizes,
5050
)
5151

52-
chunks = ngio.NgffImage(zarr_url).get_image().on_disk_dask_array.chunks
53-
chunk_sizes = [c[0] for c in chunks]
52+
chunk_sizes = ngio.open_ome_zarr_container(zarr_url).get_image().chunks
5453
assert chunk_sizes == output_chunk_sizes
5554

5655

@@ -70,12 +69,6 @@ def test_rechunk_labels(tmp_zenodo_zarr: list[str], rechunk_labels, output_chunk
7069
chunk_sizes=chunk_sizes,
7170
rechunk_labels=rechunk_labels,
7271
)
73-
# chunks = (
74-
# ngio.NgffImage(zarr_url)
75-
# .labels.get_label(name="nuclei", path="0")
76-
# .on_disk_dask_array.chunks
77-
# )
78-
# chunk_sizes = [c[0] for c in chunks]
7972
chunk_sizes = list(
8073
ngio.open_ome_zarr_container(zarr_url).get_label(name="nuclei", path="0").chunks
8174
)
@@ -106,8 +99,8 @@ def test_rechunk_no_overwrite_input(tmp_zenodo_zarr: list[str]):
10699
new_zarr_url = f"{zarr_url}_{suffix}"
107100
overwrite_input = False
108101
chunk_sizes = {"x": 1000, "y": 1000}
109-
output_chunk_sizes = [1, 1, 1000, 1000]
110-
original_chunk_sizes = [1, 1, 2160, 2560]
102+
output_chunk_sizes = (1, 1, 1000, 1000)
103+
original_chunk_sizes = (1, 1, 2160, 2560)
111104

112105
output = rechunk_zarr(
113106
zarr_url=zarr_url,
@@ -128,10 +121,8 @@ def test_rechunk_no_overwrite_input(tmp_zenodo_zarr: list[str]):
128121

129122
# Existing zarr should be unchanged, but new zarr should have
130123
# expected chunking
131-
chunks = ngio.NgffImage(zarr_url).get_image().on_disk_dask_array.chunks
132-
chunk_sizes = [c[0] for c in chunks]
124+
chunk_sizes = ngio.open_ome_zarr_container(zarr_url).get_image().chunks
133125
assert chunk_sizes == original_chunk_sizes
134126

135-
chunks = ngio.NgffImage(new_zarr_url).get_image().on_disk_dask_array.chunks
136-
chunk_sizes = [c[0] for c in chunks]
127+
chunk_sizes = ngio.open_ome_zarr_container(new_zarr_url).get_image().chunks
137128
assert chunk_sizes == output_chunk_sizes

0 commit comments

Comments
 (0)