Skip to content
Snippets Groups Projects
Commit 5f245c68 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Tests that use random arrays now call a single function to ensure integer type

parent a951fd00
No related branches found
No related tags found
2 merge requests!16Completed (de)serialization of RoiSet,!5Resolve "ilastik models do not validate dimensionality of input data"
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
......@@ -7,6 +7,9 @@ from model_server.base.accessors import PatchStack, make_patch_stack_from_file,
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
def _random_int(*args):
return np.random.randint(0, 2 ** 8, size=args, dtype='uint8')
class TestCziImageFileAccess(unittest.TestCase):
def setUp(self) -> None:
......@@ -40,7 +43,7 @@ class TestCziImageFileAccess(unittest.TestCase):
nc = 4
nz = 11
c = 3
cf = InMemoryDataAccessor(np.random.rand(h, w, nc, nz))
cf = InMemoryDataAccessor(_random_int(h, w, nc, nz))
sc = cf.get_one_channel_data(c)
self.assertEqual(sc.shape, (h, w, 1, nz))
......@@ -70,7 +73,7 @@ class TestCziImageFileAccess(unittest.TestCase):
def test_conform_data_shorter_than_xycz(self):
h = 256
w = 512
data = np.random.rand(h, w, 1)
data = _random_int(h, w, 1)
acc = InMemoryDataAccessor(data)
self.assertEqual(
InMemoryDataAccessor.conform_data(data).shape,
......@@ -82,7 +85,7 @@ class TestCziImageFileAccess(unittest.TestCase):
)
def test_conform_data_longer_than_xycz(self):
data = np.random.rand(256, 512, 12, 8, 3)
data = _random_int(256, 512, 12, 8, 3)
with self.assertRaises(DataShapeError):
acc = InMemoryDataAccessor(data)
......@@ -93,7 +96,7 @@ class TestCziImageFileAccess(unittest.TestCase):
c = 3
nz = 10
yxcz = (2**8 * np.random.rand(h, w, c, nz)).astype('uint8')
yxcz = _random_int(h, w, c, nz)
acc = InMemoryDataAccessor(yxcz)
fp = output_path / f'rand3d.tif'
self.assertTrue(
......@@ -138,7 +141,7 @@ class TestPatchStackAccessor(unittest.TestCase):
w = 256
h = 512
n = 4
acc = PatchStack(np.random.rand(n, h, w, 1, 1))
acc = PatchStack(_random_int(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))
......@@ -147,7 +150,7 @@ class TestPatchStackAccessor(unittest.TestCase):
w = 256
h = 512
n = 4
acc = PatchStack([np.random.rand(h, w, 1, 1) for _ in range(0, n)])
acc = PatchStack([_random_int(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))
......@@ -176,8 +179,8 @@ class TestPatchStackAccessor(unittest.TestCase):
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))
patches = [_random_int(h, w, c, nz) for _ in range(0, n)]
patches.append(_random_int(h, 2 * w, c, nz))
acc = PatchStack(patches)
self.assertEqual(acc.count, n + 1)
self.assertEqual(acc.hw, (h, 2 * w))
......@@ -191,7 +194,8 @@ class TestPatchStackAccessor(unittest.TestCase):
n = 4
nz = 15
nc = 2
acc = PatchStack(np.random.rand(n, h, w, nc, nz))
acc = PatchStack(_random_int(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))
return acc
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment