From 889870f8a7eb26f81c9a295d79b05c94d853d694 Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Mon, 19 Feb 2024 17:35:06 +0100 Subject: [PATCH] Folded remaining tests into base --- .../extensions/chaeo/tests/test_accessors.py | 73 ------------------- model_server/extensions/ilastik/validators.py | 5 -- tests/test_accessors.py | 72 +++++++++++++++++- 3 files changed, 71 insertions(+), 79 deletions(-) delete mode 100644 model_server/extensions/chaeo/tests/test_accessors.py delete mode 100644 model_server/extensions/ilastik/validators.py diff --git a/model_server/extensions/chaeo/tests/test_accessors.py b/model_server/extensions/chaeo/tests/test_accessors.py deleted file mode 100644 index c51f31ca..00000000 --- a/model_server/extensions/chaeo/tests/test_accessors.py +++ /dev/null @@ -1,73 +0,0 @@ -import unittest - -import numpy as np - -from model_server.conf.testing import monozstackmask -from base.accessors import PatchStack, make_patch_stack_from_file, FileNotFoundError - - -class TestMultipositionCziImageFileAccess(unittest.TestCase): - def setUp(self) -> None: - pass - - def test_make_patch_stack_from_3d_array(self): - w = 256 - h = 512 - n = 4 - acc = PatchStack(np.random.rand(n, h, w, 1, 1)) - self.assertEqual(acc.count, n) - self.assertEqual(acc.hw, (h, w)) - self.assertEqual(acc.pyxcz.shape, (n, h, w, 1, 1)) - - def test_make_patch_stack_from_list(self): - w = 256 - h = 512 - n = 4 - acc = PatchStack([np.random.rand(h, w, 1, 1) for _ in range(0, n)]) - self.assertEqual(acc.count, n) - self.assertEqual(acc.hw, (h, w)) - self.assertEqual(acc.pyxcz.shape, (n, h, w, 1, 1)) - return acc - - - def test_make_patch_stack_from_file(self): - h = monozstackmask['h'] - w = monozstackmask['w'] - c = monozstackmask['c'] - n = monozstackmask['z'] - - acc = make_patch_stack_from_file(monozstackmask['path']) - self.assertEqual(acc.hw, (h, w)) - self.assertEqual(acc.count, n) - self.assertEqual(acc.pyxcz.shape, (n, h, w, c, 1)) - - def test_raises_filenotfound(self): - with self.assertRaises(FileNotFoundError): - acc = make_patch_stack_from_file('c:/fake/file/name.tif') - - def test_make_3d_patch_stack_from_nonuniform_list(self): - w = 256 - h = 512 - c = 1 - nz = 5 - n = 4 - - patches = [np.random.rand(h, w, c, nz) for _ in range(0, n)] - patches.append(np.random.rand(h, 2 * w, c, nz)) - acc = PatchStack(patches) - self.assertEqual(acc.count, n + 1) - self.assertEqual(acc.hw, (h, 2 * w)) - self.assertEqual(acc.chroma, c) - self.assertEqual(acc.iat(0).shape, (h, 2 * w, c, nz)) - self.assertEqual(acc.iat_yxcz(0).shape, (h, 2 * w, c, nz)) - - def test_pczyx(self): - w = 256 - h = 512 - n = 4 - nz = 15 - nc = 2 - acc = PatchStack(np.random.rand(n, h, w, nc, nz)) - self.assertEqual(acc.count, n) - self.assertEqual(acc.pczyx.shape, (n, nc, nz, h, w)) - self.assertEqual(acc.hw, (h, w)) diff --git a/model_server/extensions/ilastik/validators.py b/model_server/extensions/ilastik/validators.py deleted file mode 100644 index 28d92c15..00000000 --- a/model_server/extensions/ilastik/validators.py +++ /dev/null @@ -1,5 +0,0 @@ -from model_server.base.accessors import GenericImageDataAccessor - -def is_object_map(img: GenericImageDataAccessor): - # TODO: implement - pass \ No newline at end of file diff --git a/tests/test_accessors.py b/tests/test_accessors.py index 3bad0c96..d622a368 100644 --- a/tests/test_accessors.py +++ b/tests/test_accessors.py @@ -2,6 +2,9 @@ import unittest import numpy as np +from base.accessors import PatchStack, make_patch_stack_from_file, FileNotFoundError +from conf.testing import monozstackmask + from model_server.conf.testing import czifile, output_path, monopngfile, rgbpngfile, tifffile, monozstackmask from model_server.base.accessors import CziImageFileAccessor, DataShapeError, generate_file_accessor, InMemoryDataAccessor, PngFileAccessor, write_accessor_data_to_file, TifSingleSeriesFileAccessor @@ -115,4 +118,71 @@ class TestCziImageFileAccess(unittest.TestCase): def test_read_in_pixel_scale_from_czi(self): cf = CziImageFileAccessor(czifile['path']) pxs = cf.pixel_scale_in_micrometers - self.assertAlmostEqual(pxs['X'], czifile['um_per_pixel'], places=3) \ No newline at end of file + self.assertAlmostEqual(pxs['X'], czifile['um_per_pixel'], places=3) + + +class TestPatchStackAccessor(unittest.TestCase): + def setUp(self) -> None: + pass + + def test_make_patch_stack_from_3d_array(self): + w = 256 + h = 512 + n = 4 + acc = PatchStack(np.random.rand(n, h, w, 1, 1)) + self.assertEqual(acc.count, n) + self.assertEqual(acc.hw, (h, w)) + self.assertEqual(acc.pyxcz.shape, (n, h, w, 1, 1)) + + def test_make_patch_stack_from_list(self): + w = 256 + h = 512 + n = 4 + acc = PatchStack([np.random.rand(h, w, 1, 1) for _ in range(0, n)]) + self.assertEqual(acc.count, n) + self.assertEqual(acc.hw, (h, w)) + self.assertEqual(acc.pyxcz.shape, (n, h, w, 1, 1)) + return acc + + + def test_make_patch_stack_from_file(self): + h = monozstackmask['h'] + w = monozstackmask['w'] + c = monozstackmask['c'] + n = monozstackmask['z'] + + acc = make_patch_stack_from_file(monozstackmask['path']) + self.assertEqual(acc.hw, (h, w)) + self.assertEqual(acc.count, n) + self.assertEqual(acc.pyxcz.shape, (n, h, w, c, 1)) + + def test_raises_filenotfound(self): + with self.assertRaises(FileNotFoundError): + acc = make_patch_stack_from_file('c:/fake/file/name.tif') + + def test_make_3d_patch_stack_from_nonuniform_list(self): + w = 256 + h = 512 + c = 1 + nz = 5 + n = 4 + + patches = [np.random.rand(h, w, c, nz) for _ in range(0, n)] + patches.append(np.random.rand(h, 2 * w, c, nz)) + acc = PatchStack(patches) + self.assertEqual(acc.count, n + 1) + self.assertEqual(acc.hw, (h, 2 * w)) + self.assertEqual(acc.chroma, c) + self.assertEqual(acc.iat(0).shape, (h, 2 * w, c, nz)) + self.assertEqual(acc.iat_yxcz(0).shape, (h, 2 * w, c, nz)) + + def test_pczyx(self): + w = 256 + h = 512 + n = 4 + nz = 15 + nc = 2 + acc = PatchStack(np.random.rand(n, h, w, nc, nz)) + self.assertEqual(acc.count, n) + self.assertEqual(acc.pczyx.shape, (n, nc, nz, h, w)) + self.assertEqual(acc.hw, (h, w)) -- GitLab