Skip to content

Commit

Permalink
Merge pull request #123 from fmi-faim/issue-122
Browse files Browse the repository at this point in the history
Issue 122
  • Loading branch information
imagejan authored May 3, 2024
2 parents f419135 + 6409436 commit ca9fe96
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ cov-report = [
"- coverage combine",
"coverage report",
]
cov-html = [
"test-cov",
"- coverage combine",
"coverage html",
]
cov = [
"test-cov",
"cov-report",
Expand Down
17 changes: 13 additions & 4 deletions src/faim_ipa/hcs/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __init__(
self,
ngff_plate: NGFFPlate,
yx_binning: int = 1,
stitching_yx_chunk_size_factor: int = 1,
warp_func: Callable = stitching_utils.translate_tiles_2d,
fuse_func: Callable = stitching_utils.fuse_mean,
client: Client = None,
Expand All @@ -67,7 +66,6 @@ def __init__(
), "yx_binning must be an integer >= 1."
self._ngff_plate = ngff_plate
self._yx_binning = yx_binning
self._stitching_yx_chunk_size_factor = stitching_yx_chunk_size_factor
self._warp_func = warp_func
self._fuse_func = fuse_func
self._client = client
Expand Down Expand Up @@ -159,6 +157,7 @@ def run(
plate,
well_acquisition,
well_sub_group,
add_to_well_images=not build_acquisition_mask,
)
group = well_group[well_sub_group]
self._write_stitched_image(
Expand Down Expand Up @@ -365,11 +364,21 @@ def _stitch_well_image(
)
return image_da

def _create_well_group(self, plate, well_acquisition, well_sub_group):
def _create_well_group(
self, plate, well_acquisition, well_sub_group, add_to_well_images=True
):
row, col = well_acquisition.get_row_col()
well_group = plate.require_group(row).require_group(col)
well_group.require_group(well_sub_group)
write_well_metadata(well_group, [{"path": well_sub_group}])
if add_to_well_images:
zattrs = well_group.attrs.asdict()
if "well" in zattrs.keys() and "images" in zattrs["well"].keys():
existing_images = well_group.attrs.asdict()["well"]["images"]
else:
existing_images = []
write_well_metadata(
well_group, existing_images + [{"path": well_sub_group}]
)
return well_group

@staticmethod
Expand Down
24 changes: 24 additions & 0 deletions tests/hcs/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@ def test__create_well_group(tmp_dir, plate_acquisition, hcs_plate):
assert exists(join(tmp_dir, "plate_name.zarr", "D", "08", "0"))
assert isinstance(well_group, zarr.Group)

mask_group = converter._create_well_group(
plate=zarr_plate,
well_acquisition=plate_acquisition.get_well_acquisitions()[0],
well_sub_group="0/mask",
add_to_well_images=False,
)
assert exists(join(tmp_dir, "plate_name.zarr", "D", "08", "0", "mask"))
assert isinstance(mask_group, zarr.Group)

assert mask_group.attrs.asdict()["well"]["images"] == [{"path": "0"}]

another_group = converter._create_well_group(
plate=zarr_plate,
well_acquisition=plate_acquisition.get_well_acquisitions()[0],
well_sub_group="0/another",
add_to_well_images=True,
)
assert exists(join(tmp_dir, "plate_name.zarr", "D", "08", "0", "another"))
assert isinstance(another_group, zarr.Group)
assert another_group.attrs.asdict()["well"]["images"] == [
{"path": "0"},
{"path": "0/another"},
]


def test__stitch_well_image_2d(tmp_dir, plate_acquisition_2d, hcs_plate):
converter = ConvertToNGFFPlate(hcs_plate)
Expand Down

0 comments on commit ca9fe96

Please sign in to comment.