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

Can create accessor that concatenates two channels

parent a6e13287
No related branches found
No related tags found
No related merge requests found
......@@ -180,6 +180,14 @@ class GenericImageDataAccessor(ABC):
'filepath': '',
}
def append_channels(self, acc):
return self._derived_accessor(
np.concatenate(
(self.data, acc.data),
axis=self._ga('C')
)
)
class InMemoryDataAccessor(GenericImageDataAccessor):
def __init__(self, data):
self._data = self.conform_data(data)
......
......@@ -207,6 +207,27 @@ class TestCziImageFileAccess(unittest.TestCase):
pxs = cf.pixel_scale_in_micrometers
self.assertAlmostEqual(pxs['X'], data['czifile']['um_per_pixel'], places=3)
def test_append_channels(self):
w = 256
h = 512
nc = 2
nz = 11
acc1 = InMemoryDataAccessor(np.random.rand(h, w, nc, nz))
acc2 = InMemoryDataAccessor(np.random.rand(h, w, nc, nz))
app = acc1.append_channels(acc2)
self.assertEqual(app.shape, (h, w, 2 * nc, nz))
self.assertTrue(
np.all(
app.get_channels([0, 1]).data == acc1.data
)
)
self.assertTrue(
np.all(
app.get_channels([2, 3]).data == acc2.data
)
)
class TestPatchStackAccessor(unittest.TestCase):
def setUp(self) -> None:
......@@ -352,4 +373,20 @@ class TestPatchStackAccessor(unittest.TestCase):
fp = output_path / 'patch_hyperstack.tif'
acc.export_pyxcz(fp)
acc2 = make_patch_stack_from_file(fp)
self.assertEqual(acc.shape, acc2.shape)
\ No newline at end of file
self.assertEqual(acc.shape, acc2.shape)
def test_append_channels(self):
acc = self.test_pczyx()
app = acc.append_channels(acc)
p, h, w, nc, nz = acc.shape
self.assertEqual(app.shape, (p, h, w, 2 * nc, nz))
self.assertTrue(
np.all(
app.get_channels([0, 1, 2]).data == acc.data
)
)
self.assertTrue(
np.all(
app.get_channels([3, 4, 5]).data == acc.data
)
)
\ 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