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

Added and tested apply function to support pipeline-line operations

parent 03786d14
No related branches found
No related tags found
No related merge requests found
...@@ -110,6 +110,16 @@ class GenericImageDataAccessor(ABC): ...@@ -110,6 +110,16 @@ class GenericImageDataAccessor(ABC):
def shape_dict(self): def shape_dict(self):
return dict(zip(('Y', 'X', 'C', 'Z'), self.data.shape)) return dict(zip(('Y', 'X', 'C', 'Z'), self.data.shape))
def apply(self, func):
"""
Apply func to data and return as a new in-memory accessor
:param func: function that receives and returns the same size np.ndarray
:return: InMemoryDataAccessor
"""
return InMemoryDataAccessor(
func(self.data)
)
class InMemoryDataAccessor(GenericImageDataAccessor): class InMemoryDataAccessor(GenericImageDataAccessor):
def __init__(self, data): def __init__(self, data):
self._data = self.conform_data(data) self._data = self.conform_data(data)
......
...@@ -73,11 +73,10 @@ class TestCziImageFileAccess(unittest.TestCase): ...@@ -73,11 +73,10 @@ class TestCziImageFileAccess(unittest.TestCase):
def test_write_two_channel_png(self): def test_write_two_channel_png(self):
from model_server.base.process import resample_to_8bit from model_server.base.process import resample_to_8bit
ch = 2
cf = CziImageFileAccessor(czifile['path']) cf = CziImageFileAccessor(czifile['path'])
acc = cf.get_channels([0, 1]) acc = cf.get_channels([0, 1])
opa = output_path / f'{cf.fpath.stem}_2ch.png' opa = output_path / f'{cf.fpath.stem}_2ch.png'
acc_out = InMemoryDataAccessor(resample_to_8bit(acc.data)) acc_out = acc.apply(resample_to_8bit)
self.assertTrue( self.assertTrue(
write_accessor_data_to_file(opa, acc_out) write_accessor_data_to_file(opa, acc_out)
......
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