diff --git a/core/lls_core/models/crop.py b/core/lls_core/models/crop.py index 65e61609..3e881f93 100644 --- a/core/lls_core/models/crop.py +++ b/core/lls_core/models/crop.py @@ -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: diff --git a/core/tests/test_process.py b/core/tests/test_process.py index 7df0dd02..86c802c1 100644 --- a/core/tests/test_process.py +++ b/core/tests/test_process.py @@ -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({ @@ -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