@@ -45,10 +45,14 @@ def create_synthetic_data(zarr_url, zarr_url_3d, label_name, z_spacing=1.0):
4545 label_img .set_array (label_array )
4646 label_img .consolidate ()
4747
48- # Create a masking roi table in the 2D image
49- masking_roi_table = ome_zarr_2d .get_masked_image (label_name ).build_image_roi_table (
50- name = "masking_ROI_table"
48+ image_roi_table = ome_zarr_2d .build_image_roi_table (name = "image_ROI_table" )
49+ ome_zarr_2d .add_table (
50+ name = "image_ROI_table" ,
51+ table = image_roi_table ,
5152 )
53+
54+ # Create a masking roi table in the 2D image
55+ masking_roi_table = ome_zarr_2d .build_masking_roi_table (label = label_name )
5256 ome_zarr_2d .add_table (
5357 name = "masking_ROI_table" ,
5458 table = masking_roi_table ,
@@ -119,6 +123,44 @@ def test_2d_to_3d_table_renaming(tmp_path: Path, new_table_names):
119123 assert ome_zarr_3d .list_tables () == new_table_names
120124
121125
126+ def test_2d_to_3d_table_copying (tmp_path : Path ):
127+ """Test that the z-spacing is copied correctly."""
128+ zarr_url = str (tmp_path / "plate_mip.zarr" / "B" / "03" / "0" )
129+ zarr_url_3d = str (tmp_path / "plate.zarr" / "B" / "03" / "0" )
130+ label_name = "nuclei"
131+
132+ create_synthetic_data (zarr_url , zarr_url_3d , label_name , z_spacing = 1.0 )
133+ ome_zarr_2d = ngio .open_ome_zarr_container (zarr_url )
134+ rois = ome_zarr_2d .get_table (
135+ "masking_ROI_table" , check_type = "masking_roi_table"
136+ ).rois ()
137+ assert rois [0 ].z_length == 1.0
138+
139+ convert_2D_segmentation_to_3D (
140+ zarr_url = zarr_url ,
141+ label_name = label_name ,
142+ tables_to_copy = ["masking_ROI_table" , "image_ROI_table" ],
143+ )
144+ ome_zarr_3d = ngio .open_ome_zarr_container (zarr_url_3d )
145+ # Validate correctness of tables
146+ assert ome_zarr_3d .list_tables () == ["masking_ROI_table" , "image_ROI_table" ]
147+ rois = ome_zarr_3d .get_table (
148+ "masking_ROI_table" , check_type = "masking_roi_table"
149+ ).rois ()
150+ assert len (rois ) == 1
151+ assert rois [0 ].name == "1"
152+ assert rois [0 ].x_length == 10.0
153+ # z_length goes from 1 to 10 because we have 10 z planes
154+ assert rois [0 ].z_length == 10.0
155+
156+ rois = ome_zarr_3d .get_table ("image_ROI_table" , check_type = "roi_table" ).rois ()
157+ assert len (rois ) == 1
158+ assert rois [0 ].name == "image_ROI_table"
159+ assert rois [0 ].x_length == 50.0
160+ # z_length goes from 1 to 10 because we have 10 z planes
161+ assert rois [0 ].z_length == 10.0
162+
163+
122164@pytest .mark .parametrize ("z" , [0.5 , 1.0 , 2.0 ])
123165def test_2d_to_3d_z_spacing (tmp_path : Path , z ):
124166 """Test that the z-spacing is copied correctly."""
0 commit comments