From ba86e321c59edfd6cce9b240bc83ccb9aee32e16 Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Mon, 16 Oct 2023 21:36:42 +0200 Subject: [PATCH] mobie: expand test to cover add_labels_view --- tests/test_mobie.py | 55 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/tests/test_mobie.py b/tests/test_mobie.py index 7a21964e..f8811d23 100644 --- a/tests/test_mobie.py +++ b/tests/test_mobie.py @@ -8,11 +8,16 @@ ) from mobie.metadata.project_metadata import add_dataset, create_project_metadata from mobie.validation import validate_project +from skimage.measure import label from faim_hcs.io.MolecularDevicesImageXpress import parse_single_plane_multi_fields from faim_hcs.MetaSeriesUtils import get_well_image_CYX -from faim_hcs.mobie import add_wells_to_project -from faim_hcs.Zarr import build_zarr_scaffold, write_cyx_image_to_well +from faim_hcs.mobie import add_labels_view, add_wells_to_project +from faim_hcs.Zarr import ( + build_zarr_scaffold, + write_cyx_image_to_well, + write_labels_to_group, +) ROOT_DIR = Path(__file__).parent.parent @@ -23,7 +28,12 @@ def files(): @pytest.fixture -def zarr_group(files, zarr_dir): +def threshold(): + return 10000 + + +@pytest.fixture +def zarr_group(files, zarr_dir, threshold): plate = build_zarr_scaffold( root_dir=zarr_dir, files=files, @@ -39,6 +49,12 @@ def zarr_group(files, zarr_dir): ) field = plate[well[0]][str(int(well[1:]))][0] write_cyx_image_to_well(img, hists, ch_metadata, metadata, field) + labels = label(img > threshold) + write_labels_to_group( + labels=labels, + labels_name="simple_threshold", + parent_group=field, + ) return plate @@ -52,7 +68,7 @@ def zarr_dir(tmp_path_factory): return tmp_path_factory.mktemp("zarr") -def test_add_wells_to_project(zarr_group, mobie_project_folder): +def test_full_mobie_project(zarr_group, mobie_project_folder): # setup OME-ZARR folder # setup MoBIE project dataset_name = "mobie_test_dataset" @@ -84,7 +100,23 @@ def test_add_wells_to_project(zarr_group, mobie_project_folder): view_name="default", ) - # assert + # validate 1 + validate_project( + root=mobie_project_folder, + ) + + # add_labels_view + add_labels_view( + plate=zarr_group, + dataset_folder=(mobie_project_folder / dataset_name), + well_group="0", + channel=0, + label_name="simple_threshold", + view_name="default", + extra_properties=("area", "bbox"), + ) + + # validate 2 validate_project( root=mobie_project_folder, ) @@ -99,11 +131,18 @@ def test_add_wells_to_project(zarr_group, mobie_project_folder): assert "sourceDisplays" in json_data["views"]["default"] assert "sourceTransforms" in json_data["views"]["default"] + # wells table table_path: Path = ( mobie_project_folder / dataset_name / "tables" / "wells" / "default.tsv" ) assert table_path.exists() - -def test_add_labels_view(): - pass + # segmentation table for E07 + label_table_path: Path = ( + mobie_project_folder + / dataset_name + / "tables" + / "E07_simple_threshold" + / "default.tsv" + ) + assert label_table_path.exists()