diff --git a/extensions/chaeo/accessors.py b/extensions/chaeo/accessors.py index 60cc2c70e285d173021ea7e81b4b900862dd874c..c24ab7d6c3b00a7371ae36b18d1df72ea4c5fd30 100644 --- a/extensions/chaeo/accessors.py +++ b/extensions/chaeo/accessors.py @@ -12,9 +12,13 @@ class MonoPatchStack(InMemoryDataAccessor): :param data: either np.ndarray of dimensions YXn, or a list of np.ndarrays of size YX """ - if isinstance(data, np.ndarray): # interpret as YXZ - assert data.ndim == 3 - self._data = np.expand_dims(data, 2) + if isinstance(data, np.ndarray): + if data.ndim == 3: # interpret as YXZ + self._data = np.expand_dims(data, 2) + elif data.ndim == 4: # interpret as a copy another patch stack + self._data = data + else: + raise InvalidDataForPatchStackError() elif isinstance(data, list): # list of YX patches if len(data) == 0: self._data = np.ndarray([0, 0, 0, 0], dtype='uin9') diff --git a/extensions/chaeo/tests/test_accessors.py b/extensions/chaeo/tests/test_accessors.py index c2194581a7e41aba1269b3eeb3368b434bc4d718..52935598591bbf18a00d10c1c0a17b0a4635f5d9 100644 --- a/extensions/chaeo/tests/test_accessors.py +++ b/extensions/chaeo/tests/test_accessors.py @@ -28,6 +28,14 @@ class TestCziImageFileAccess(unittest.TestCase): self.assertEqual(acc.count, n) self.assertEqual(acc.hw, (h, w)) self.assertEqual(acc.make_tczyx().shape, (n, 1, 1, h, w)) + return acc + + def test_make_patch_stack_clone(self): + w = 256 + h = 512 + n = 4 + acc = MonoPatchStack([np.random.rand(h, w) for _ in range(0, n)]) + self.assertEqual(MonoPatchStack(acc.data).shape, acc.shape) def test_make_patch_stack_from_file(self): h = monozstackmask['h']