Skip to content

Commit d5b0d6d

Browse files
committed
Fix level choice in 2d to 3d task
1 parent e6b89ef commit d5b0d6d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/fractal_helper_tasks/convert_2D_segmentation_to_3D.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def convert_2D_segmentation_to_3D(
5050
the 3D OME-Zarr
5151
new_table_names: Optionally overwriting the names of the tables
5252
in the 3D OME-Zarr
53-
level: Level of the 2D OME-Zarr label to copy from
53+
level: Level of the 2D OME-Zarr label to copy from. Valid choices are
54+
"0", "1", etc. (depending on which levels are available in the
55+
OME-Zarr label).
5456
plate_suffix: Suffix of the 2D OME-Zarr that needs to be removed to
5557
generate the path to the 3D OME-Zarr. If the 2D OME-Zarr is
5658
"/path/to/my_plate_mip.zarr/B/03/0" and the 3D OME-Zarr is located
@@ -75,8 +77,6 @@ def convert_2D_segmentation_to_3D(
7577
# Normalize zarr_url
7678
zarr_url = zarr_url.rstrip("/")
7779
# 0) Preparation
78-
if level != 0:
79-
raise NotImplementedError("Only level 0 is supported at the moment")
8080
if new_table_names:
8181
if not tables_to_copy:
8282
raise ValueError(
@@ -116,7 +116,7 @@ def convert_2D_segmentation_to_3D(
116116

117117
# 1) Load a 2D label image
118118
ome_zarr_container_2d = ngio.open_ome_zarr_container(zarr_url)
119-
label_img = ome_zarr_container_2d.get_label(label_name, path=str(level))
119+
label_img = ome_zarr_container_2d.get_label(label_name, path=level)
120120

121121
if not label_img.is_2d:
122122
raise ValueError(

tests/test_convert_2d_to_3d_segmentation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ def test_2d_to_3d_label_renaming(tmp_path: Path, new_label_name):
7777
assert ome_zarr_3d.list_labels() == [new_label_name]
7878

7979

80+
@pytest.mark.parametrize("level", ["0", "1", "2"])
81+
def test_2d_to_3d_varying_levels(tmp_path: Path, level):
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"
86+
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+
level=level,
92+
label_name=label_name,
93+
tables_to_copy=["masking_ROI_table"],
94+
)
95+
ome_zarr_3d = ngio.open_ome_zarr_container(zarr_url_3d)
96+
label_img = ome_zarr_3d.get_label(name="nuclei")
97+
assert label_img.pixel_size.x == 0.5 * (2 ** int(level))
98+
99+
80100
@pytest.mark.parametrize("new_table_names", [None, ["new_table_names"]])
81101
def test_2d_to_3d_table_renaming(tmp_path: Path, new_table_names):
82102
"""Test that the z-spacing is copied correctly."""

0 commit comments

Comments
 (0)