Skip to content

Commit

Permalink
Merge pull request #13 from fmicompbio/fix-plate-sort
Browse files Browse the repository at this point in the history
Sort layout and img_paths jointly
  • Loading branch information
mbstadler authored Aug 5, 2024
2 parents f8d40ed + 316d84e commit 3fadeef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ez_zarr/ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
17 changes: 17 additions & 0 deletions tests/test_ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..............................................
Expand Down

0 comments on commit 3fadeef

Please sign in to comment.