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 c51f31ca49af2694c0cec8306920ff557d463b75..0000000000000000000000000000000000000000 --- 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 28d92c15b79bf923b1cb4098bfc688e47d7b3896..0000000000000000000000000000000000000000 --- 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 3bad0c96052766a4beb5aaadd4e564de8bd02599..d622a368dae6e89a24dabf1044391092f48b88b5 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))