From 25ed79557e98d166a0a302526bcc07a6313d0238 Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Thu, 2 Nov 2023 15:20:24 +0100 Subject: [PATCH] Added method to cast patch as YXCZ array --- extensions/chaeo/accessors.py | 3 +++ extensions/chaeo/tests/test_accessors.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/chaeo/accessors.py b/extensions/chaeo/accessors.py index 5d2987fa..2b23318b 100644 --- a/extensions/chaeo/accessors.py +++ b/extensions/chaeo/accessors.py @@ -44,6 +44,9 @@ class MonoPatchStack(InMemoryDataAccessor): def iat(self, i): return self.data[:, :, 0, i] + def iat_yxcz(self, i): + return np.expand_dims(self.iat(i), (2, 3)) + def get_list(self): n = self.nz return [self.data[:, :, 0, zi] for zi in range(0, n)] diff --git a/extensions/chaeo/tests/test_accessors.py b/extensions/chaeo/tests/test_accessors.py index 40192575..c74fdd86 100644 --- a/extensions/chaeo/tests/test_accessors.py +++ b/extensions/chaeo/tests/test_accessors.py @@ -43,4 +43,11 @@ class TestCziImageFileAccess(unittest.TestCase): def test_raises_filenotfound(self): from extensions.chaeo.accessors import FileNotFoundError with self.assertRaises(FileNotFoundError): - acc = MonoPatchStackFromFile('c:/fake/file/name.tif') \ No newline at end of file + acc = MonoPatchStackFromFile('c:/fake/file/name.tif') + + def test_patch_as_yxcz_array(self): + w = 256 + h = 512 + n = 4 + acc = MonoPatchStack([np.random.rand(h, w) for _ in range(0, 4)]) + self.assertEqual(acc.iat_yxcz(0).shape, (h, w, 1, 1)) \ No newline at end of file -- GitLab