From 608c584b1177802527df63ac69abdd43df7191e3 Mon Sep 17 00:00:00 2001 From: Heath Patterson Date: Fri, 17 Sep 2021 14:15:35 -0500 Subject: [PATCH 1/3] check if graph contains array like data before writing. --- wsireg/wsireg2d.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wsireg/wsireg2d.py b/wsireg/wsireg2d.py index 0b4a23c..37b72c7 100644 --- a/wsireg/wsireg2d.py +++ b/wsireg/wsireg2d.py @@ -21,7 +21,9 @@ from wsireg.utils.tform_utils import ( prepare_wsireg_transform_data, ) - +from wsireg.utils.im_utils import ( + ARRAYLIKE_CLASSES, +) class WsiReg2D(object): """ @@ -566,11 +568,16 @@ def save_config(self, registered=False): [rge.pop("reg_transforms", None) for rge in reg_graph_edges] + modalities_out = deepcopy(self.modalities) + for mod,data in modalities_out.items(): + if isinstance(data["image_filepath"], ARRAYLIKE_CLASSES): + data["image_filepath"] = "ArrayLike" + config = { "project_name": self.project_name, "output_dir": str(self.output_dir), "cache_images": self.cache_images, - "modalities": self.modalities, + "modalities": modalities_out, "reg_paths": reg_paths, "reg_graph_edges": reg_graph_edges if status == "registered" From f004dde4e23067e07752534778f1dc7e59934fa8 Mon Sep 17 00:00:00 2001 From: Heath Patterson Date: Fri, 17 Sep 2021 14:15:45 -0500 Subject: [PATCH 2/3] add attachment modality test --- tests/test_wsireg.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_wsireg.py b/tests/test_wsireg.py index 15d312c..af4fdfc 100644 --- a/tests/test_wsireg.py +++ b/tests/test_wsireg.py @@ -410,3 +410,38 @@ def test_wsireg_run_reg_wmerge_and_indiv(data_out_dir, disk_im_gry): assert Path(im_fps[2]).exists() is True assert Path(im_fps[3]).exists() is True assert merged_im.im_dims == (2, 2048, 2048) + + +def test_wsireg_run_reg_wattachment(data_out_dir, disk_im_gry): + wsi_reg = WsiReg2D("test_proj-attach", str(data_out_dir)) + im1 = np.random.randint(0, 255, (2048, 2048), dtype=np.uint16) + im2 = np.random.randint(0, 255, (2048, 2048), dtype=np.uint16) + + wsi_reg.add_modality( + "mod1", + im1, + 0.65, + channel_names=["test"], + channel_colors=["red"], + ) + + wsi_reg.add_modality( + "mod2", + im2, + 0.65, + channel_names=["test"], + channel_colors=["red"], + ) + wsi_reg.add_attachment_images("mod2", "attached", im2, image_res=0.65) + + wsi_reg.add_reg_path( + "mod2", "mod1", reg_params=["rigid_test", "affine_test"] + ) + + wsi_reg.register_images() + im_fps = wsi_reg.transform_images(transform_non_reg=False) + + regim = reg_image_loader(im_fps[0], 0.65) + attachim = reg_image_loader(im_fps[1], 0.65) + + assert np.array_equal(regim.image.compute(), attachim.image.compute()) From deec37eaded5342bb0be3f829e6a4c036c6d7421 Mon Sep 17 00:00:00 2001 From: Heath Patterson Date: Fri, 17 Sep 2021 14:16:14 -0500 Subject: [PATCH 3/3] formatting --- wsireg/wsireg2d.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wsireg/wsireg2d.py b/wsireg/wsireg2d.py index 37b72c7..0bdb0ce 100644 --- a/wsireg/wsireg2d.py +++ b/wsireg/wsireg2d.py @@ -25,6 +25,7 @@ ARRAYLIKE_CLASSES, ) + class WsiReg2D(object): """ Class to define a 2D registration graph and execute the registrations and transformations of the graph @@ -569,7 +570,7 @@ def save_config(self, registered=False): [rge.pop("reg_transforms", None) for rge in reg_graph_edges] modalities_out = deepcopy(self.modalities) - for mod,data in modalities_out.items(): + for mod, data in modalities_out.items(): if isinstance(data["image_filepath"], ARRAYLIKE_CLASSES): data["image_filepath"] = "ArrayLike"