Skip to content

Commit

Permalink
Tests for float ROIs
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Nov 17, 2023
1 parent 60a1c15 commit 5addbcc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/lls_core/models/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ def read_roi(cls, v: Any) -> List[Roi]:
elif isinstance(item, Roi):
rois.append(item)
else:
raise ValueError(f"{item} cannot be intepreted as an ROI")
# Try converting an iterable to ROI
try:
rois.append(Roi(*item))
except:
raise ValueError(f"{item} cannot be intepreted as an ROI")

return rois

@validator("roi_subset", pre=True)
@validator("roi_subset", pre=True, always=True)
def default_roi_range(cls, v: Any, values: dict):
# If the roi range isn't provided, assume all rois should be processed
if v is None:
Expand Down
30 changes: 29 additions & 1 deletion core/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def test_process_workflow(args: dict, request: FixtureRequest, workflow_name: st
[[0, 1]],
])
@parameterized
def test_process_crop(args: dict, roi_subset: Optional[List[int]]):
def test_process_crop_roi_file(args: dict, roi_subset: Optional[List[int]]):
# Test cropping with a roi zip file, selecting different subsets from that file
with as_file(resources / "RBC_tiny.czi") as lattice_path:
rois = root / "crop" / "two_rois.zip"
for slice in LatticeData.parse_obj({
Expand All @@ -81,3 +82,30 @@ def test_process_crop(args: dict, roi_subset: Optional[List[int]]):
**args
}).process().slices:
assert slice.data.ndim == 3

@pytest.mark.parametrize(["roi"], [
[[[
(174.0, 24.0),
(174.0, 88.0),
(262.0, 88.0),
(262.0, 24.0)
]]],
[[[
(174.13, 24.2),
(173.98, 87.87),
(262.21, 88.3),
(261.99, 23.79)
]]],
])
@parameterized
def test_process_crop_roi_manual(args: dict, roi: List):
# Test manually provided ROIs, both with integer and float values
with as_file(resources / "RBC_tiny.czi") as lattice_path:
for slice in LatticeData.parse_obj({
"input_image": lattice_path,
"crop": {
"roi_list": roi
},
**args
}).process().slices:
assert slice.data.ndim == 3

0 comments on commit 5addbcc

Please sign in to comment.