From e113d2646d9da523ed2dccca8bfde902069ac633 Mon Sep 17 00:00:00 2001 From: Charlotte Soneson Date: Tue, 30 Jul 2024 22:31:38 +0200 Subject: [PATCH 1/2] Make sure layout and img_paths are sorted jointly --- src/ez_zarr/ome_zarr.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ez_zarr/ome_zarr.py b/src/ez_zarr/ome_zarr.py index 614993c..4bd377e 100644 --- a/src/ez_zarr/ome_zarr.py +++ b/src/ez_zarr/ome_zarr.py @@ -123,8 +123,11 @@ def import_Fractal_plate(path: str, image_name: str = '0') -> "ImageList": # build layout layout = pd.DataFrame({'row_index': row_index, - 'column_index': column_index}) + 'column_index': column_index, + 'img_paths': img_paths}) layout = layout.sort_values(by=['row_index', 'column_index']).reset_index(drop=True) + img_paths = layout.img_paths.tolist() + layout = layout.drop('img_paths', axis='columns') # set nrow, ncol known_plate_dims = [(2, 3), (4, 6), (8, 12), (16, 24)] From 316d84e6c7983d7aec4cf0aeb9fce6f7e16983e5 Mon Sep 17 00:00:00 2001 From: Charlotte Soneson Date: Wed, 31 Jul 2024 08:32:27 +0200 Subject: [PATCH 2/2] Add unit tests for import_Fractal_plate with multiple wells --- tests/test_ome_zarr.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_ome_zarr.py b/tests/test_ome_zarr.py index 30c19d1..49e219d 100644 --- a/tests/test_ome_zarr.py +++ b/tests/test_ome_zarr.py @@ -92,6 +92,23 @@ def test_import_Fractal_plate(tmpdir: str): assert imgL2.nrow == 8 assert imgL2.ncol == 12 + shutil.copytree('tests/example_data/plate_ones_mip.zarr', + str(tmpdir) + '/example_img_multi') + assert tmpdir.join('/example_img_multi/.zattrs').check() + shutil.copytree(str(tmpdir) + '/example_img_multi/B/03', + str(tmpdir) + '/example_img_multi/C/02') + shutil.copytree(str(tmpdir) + '/example_img_multi/B/03', + str(tmpdir) + '/example_img_multi/G/06') + imgL3 = ome_zarr.import_Fractal_plate(str(tmpdir) + '/example_img_multi') + assert imgL3.nrow == 8 + assert imgL3.ncol == 12 + assert imgL3.layout.row_index.tolist() == [2, 3, 7] + assert imgL3.layout.column_index.tolist() == [3, 2, 6] + assert imgL3['B03'].get_path() == str(tmpdir) + '/example_img_multi/B/03/0' + assert imgL3['C02'].get_path() == str(tmpdir) + '/example_img_multi/C/02/0' + assert imgL3['G06'].get_path() == str(tmpdir) + '/example_img_multi/G/06/0' + assert imgL3.paths == [str(tmpdir) + '/example_img_multi/B/03/0', str(tmpdir) + '/example_img_multi/C/02/0', str(tmpdir) + '/example_img_multi/G/06/0'] + assert imgL3.names == ['B03', 'C02', 'G06'] # ome_zarr.Image ---------------------------------------------------- # ... helper functions ..............................................