From 03786d1444782252b336c6630b5bb2eb91d0aa0a Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Mon, 3 Jun 2024 16:11:50 +0200 Subject: [PATCH] Renamed get_one_channel_data to get_mono --- model_server/base/accessors.py | 2 +- model_server/base/roiset.py | 2 +- model_server/base/workflows.py | 2 +- model_server/extensions/ilastik/models.py | 2 +- model_server/extensions/ilastik/tests/test_ilastik.py | 4 ++-- tests/test_accessors.py | 10 +++++----- tests/test_model.py | 2 +- tests/test_roiset.py | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/model_server/base/accessors.py b/model_server/base/accessors.py index 73cafd08..6f596ab7 100644 --- a/model_server/base/accessors.py +++ b/model_server/base/accessors.py @@ -56,7 +56,7 @@ class GenericImageDataAccessor(ABC): nda = self.data.take(indices=carr, axis=self._ga('C')) return self._derived_accessor(nda) - def get_one_channel_data(self, channel: int, mip: bool = False): + def get_mono(self, channel: int, mip: bool = False): return self.get_channels([channel], mip=mip) def _gc(self, channels): diff --git a/model_server/base/roiset.py b/model_server/base/roiset.py index 11deff15..69c45e39 100644 --- a/model_server/base/roiset.py +++ b/model_server/base/roiset.py @@ -358,7 +358,7 @@ class RoiSet(object): raw_acc = self.get_patches_acc(channels=channels, expanded=False, pad_to=None) # all channels if derived_channel_functions is not None: - mono_data = [raw_acc.get_one_channel_data(c).data for c in range(0, raw_acc.chroma)] + mono_data = [raw_acc.get_mono(c).data for c in range(0, raw_acc.chroma)] for fcn in derived_channel_functions: der = fcn(raw_acc) # returns patch stack if der.shape != mono_data[0].shape or der.dtype not in ['uint8', 'uint16']: diff --git a/model_server/base/workflows.py b/model_server/base/workflows.py index 912f6062..9ff6f57c 100644 --- a/model_server/base/workflows.py +++ b/model_server/base/workflows.py @@ -42,7 +42,7 @@ def classify_pixels(fpi: Path, model: SemanticSegmentationModel, where_output: P """ ti = Timer() ch = kwargs.get('channel') - img = generate_file_accessor(fpi).get_one_channel_data(ch) + img = generate_file_accessor(fpi).get_mono(ch) ti.click('file_input') outdata = model.label_pixel_class(img) diff --git a/model_server/extensions/ilastik/models.py b/model_server/extensions/ilastik/models.py index e8afb238..b40ed066 100644 --- a/model_server/extensions/ilastik/models.py +++ b/model_server/extensions/ilastik/models.py @@ -313,7 +313,7 @@ class IlastikObjectClassifierFromPixelPredictionsModel(IlastikModel, ImageToImag raise InvalidInputImageError('Expecting input image and pixel probabilities to be the same shape') pxch = kwargs.get('pixel_classification_channel', 0) pxtr = kwargs.get('pixel_classification_threshold', 0.5) - mask = img._derived_accessor(pxmap.get_one_channel_data(pxch).data > pxtr) + mask = img._derived_accessor(pxmap.get_mono(pxch).data > pxtr) obmap, _ = self.infer(img, mask) return obmap diff --git a/model_server/extensions/ilastik/tests/test_ilastik.py b/model_server/extensions/ilastik/tests/test_ilastik.py index f4e0b41c..c9358796 100644 --- a/model_server/extensions/ilastik/tests/test_ilastik.py +++ b/model_server/extensions/ilastik/tests/test_ilastik.py @@ -22,7 +22,7 @@ class TestIlastikPixelClassification(unittest.TestCase): self.model = ilm.IlastikPixelClassifierModel( params=ilm.IlastikPixelClassifierParams(project_file=ilastik_classifiers['px'].__str__()) ) - self.mono_image = self.cf.get_one_channel_data(self.channel) + self.mono_image = self.cf.get_mono(self.channel) def test_faulthandler(self): # recreate error that is messing up ilastik @@ -436,7 +436,7 @@ class TestIlastikOnMultichannelInputs(TestServerBaseClass): class TestIlastikObjectClassification(unittest.TestCase): def setUp(self): stack = generate_file_accessor(roiset_test_data['multichannel_zstack']['path']) - stack_ch_pa = stack.get_one_channel_data(roiset_test_data['pipeline_params']['patches_channel']) + stack_ch_pa = stack.get_mono(roiset_test_data['pipeline_params']['patches_channel']) seg_mask = generate_file_accessor(roiset_test_data['multichannel_zstack']['mask_path']) self.roiset = RoiSet( diff --git a/tests/test_accessors.py b/tests/test_accessors.py index 0375ee1a..d2f06655 100644 --- a/tests/test_accessors.py +++ b/tests/test_accessors.py @@ -45,7 +45,7 @@ class TestCziImageFileAccess(unittest.TestCase): nz = 11 c = 3 cf = InMemoryDataAccessor(_random_int(h, w, nc, nz)) - sc = cf.get_one_channel_data(c) + sc = cf.get_mono(c) self.assertEqual(sc.shape, (h, w, 1, nz)) def test_get_single_channel_mip_from_zstack(self): @@ -55,13 +55,13 @@ class TestCziImageFileAccess(unittest.TestCase): nz = 11 c = 3 cf = InMemoryDataAccessor(np.random.rand(h, w, nc, nz)) - sc = cf.get_one_channel_data(c, mip=True) + sc = cf.get_mono(c, mip=True) self.assertEqual(sc.shape, (h, w, 1, 1)) def test_write_single_channel_tif(self): ch = 4 cf = CziImageFileAccessor(czifile['path']) - mono = cf.get_one_channel_data(ch) + mono = cf.get_mono(ch) self.assertTrue( write_accessor_data_to_file( output_path / f'{cf.fpath.stem}_ch{ch}.tif', @@ -246,7 +246,7 @@ class TestPatchStackAccessor(unittest.TestCase): def test_get_one_channel(self): acc = self.test_pczyx() - mono = acc.get_one_channel_data(channel=1) + mono = acc.get_mono(channel=1) for a in 'PXYZ': self.assertEqual(mono.shape_dict[a], acc.shape_dict[a]) self.assertEqual(mono.shape_dict['C'], 1) @@ -261,7 +261,7 @@ class TestPatchStackAccessor(unittest.TestCase): def test_get_one_channel_mip(self): acc = self.test_pczyx() - mono_mip = acc.get_one_channel_data(channel=1, mip=True) + mono_mip = acc.get_mono(channel=1, mip=True) for a in 'PXY': self.assertEqual(mono_mip.shape_dict[a], acc.shape_dict[a]) for a in 'CZ': diff --git a/tests/test_model.py b/tests/test_model.py index 3f9f2872..91043f24 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -25,7 +25,7 @@ class TestCziImageFileAccess(unittest.TestCase): def test_dummy_pixel_segmentation(self): model = DummySemanticSegmentationModel() - img = self.cf.get_one_channel_data(0) + img = self.cf.get_mono(0) mask = model.label_pixel_class(img) w = czifile['w'] diff --git a/tests/test_roiset.py b/tests/test_roiset.py index ed1327de..efc0779f 100644 --- a/tests/test_roiset.py +++ b/tests/test_roiset.py @@ -19,7 +19,7 @@ class BaseTestRoiSetMonoProducts(object): def setUp(self) -> None: # set up test raw data and segmentation from file self.stack = generate_file_accessor(roiset_test_data['multichannel_zstack']['path']) - self.stack_ch_pa = self.stack.get_one_channel_data(roiset_test_data['pipeline_params']['patches_channel']) + self.stack_ch_pa = self.stack.get_mono(roiset_test_data['pipeline_params']['patches_channel']) self.seg_mask = generate_file_accessor(roiset_test_data['multichannel_zstack']['mask_path']) @@ -376,7 +376,7 @@ class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCa ) result = generate_file_accessor(where / df_res.patch_path.iloc[0]) self.assertEqual(result.chroma, 3) - self.assertEqual(result.get_one_channel_data(2).data.max(), 0) # blue channel is black + self.assertEqual(result.get_mono(2).data.max(), 0) # blue channel is black def test_multichannel_to_multichannel_tif_patches(self): where = output_path / 'multichannel' / 'multichannel_tif_patches' @@ -523,7 +523,7 @@ class TestRoiSetSerialization(unittest.TestCase): def setUp(self) -> None: # set up test raw data and segmentation from file self.stack = generate_file_accessor(roiset_test_data['multichannel_zstack']['path']) - self.stack_ch_pa = self.stack.get_one_channel_data(roiset_test_data['pipeline_params']['segmentation_channel']) + self.stack_ch_pa = self.stack.get_mono(roiset_test_data['pipeline_params']['segmentation_channel']) self.seg_mask_3d = generate_file_accessor(roiset_test_data['multichannel_zstack']['mask_path_3d']) @staticmethod -- GitLab