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

Can also pass ndarray to PipelineTrace

parent 0e7adb66
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ from typing import List, Union
from fastapi import HTTPException
from pydantic import BaseModel, Field, root_validator
from ..accessors import GenericImageDataAccessor
from ..accessors import GenericImageDataAccessor, InMemoryDataAccessor
from ..roiset import RoiSet
from ..session import session, AccessorIdError
......@@ -132,13 +132,18 @@ class PipelineTrace(OrderedDict):
self['input'] = start_acc
def __setitem__(self, key, value: GenericImageDataAccessor):
if self.enforce_accessors:
assert isinstance(value, GenericImageDataAccessor), f'Pipeline trace expects data accessor type'
if isinstance(value, GenericImageDataAccessor):
acc = value
else:
if self.enforce_accessors:
raise NoAccessorsFoundError(f'Pipeline trace expects data accessor type')
else:
acc = InMemoryDataAccessor(value)
if not self.allow_overwrite and key in self.keys():
raise KeyAlreadyExists(f'key {key} already exists in pipeline trace')
self.timer.__setitem__(key, self.tfunc() - self.last_time)
self.last_time = self.tfunc()
return super().__setitem__(key, value)
return super().__setitem__(key, acc)
def append(self, tr, skip_first=True):
new_tr = self.copy()
......
......@@ -83,4 +83,10 @@ class TestSegmentationPipelines(unittest.TestCase):
trace4 = trace1.append(trace2, skip_first=True)
self.assertEqual(len(trace4), len(trace1) + len(trace2) - 1)
self.assertTrue(np.all(trace4['input'].data == trace4['double'].data))
\ No newline at end of file
self.assertTrue(np.all(trace4['input'].data == trace4['double'].data))
def test_add_nda_to_trace(self):
acc = generate_file_accessor(zstack['path'])
trace1 = PipelineTrace(acc, enforce_accessors=False)
trace1['halve'] = trace1.last.data * 0.5
self.assertEqual(len(trace1), 2)
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