Skip to content

Commit

Permalink
Add channel and time to workflow data frames
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Aug 14, 2024
1 parent 14627c5 commit 4a3791c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion core/lls_core/models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ def process(self) -> Iterable[Tuple[RoiIndex, ProcessedWorkflowOutput]]:

# Handle each ROI separately
for roi, roi_results in groupby(self.slices, key=lambda it: it.roi_index):
values: list[Writer, dict, tuple, list] = []
values: list[Writer | list] = []
for result in roi_results:
# Ensure the data is in a tuple
data = (result.data,) if is_arraylike(result.data) else result.data
for i, element in enumerate(data):
# If the element is array like, we assume it's an image to write to disk
if is_arraylike(element):
# Make the writer the first time only
if len(values) <= i:
Expand All @@ -114,10 +115,20 @@ def process(self) -> Iterable[Tuple[RoiIndex, ProcessedWorkflowOutput]]:
)
)
else:
# Otherwise, we assume it's one row to be added to a data frame
if len(values) <= i:
values.append([])

rows = cast(list, values[i])

if isinstance(element, list):
# If the row is a list, it has no column names
# We add the channel and time
element = [f"T{result.time_index}", f"C{result.channel_index}"] + element
elif isinstance(element, dict):
# If the row is a dict, it has column names
element = {"time": f"T{result.time_index}", "channel": f"C{result.channel_index}", **element}

rows.append(element)

for element in values:
Expand Down
5 changes: 4 additions & 1 deletion core/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ def test_table_workflow(minimal_image_path: Path, table_workflow: Workflow):
workflow = table_workflow,
save_dir = tmpdir
)
for roi, output in params.process_workflow().process():
for _roi, output in params.process_workflow().process():
assert isinstance(output, (DataFrame, Path))
if isinstance(output, DataFrame):
nrow, ncol = output.shape
assert nrow == params.nslices
assert ncol > 0
# Check that time and channel are included
assert output.iloc[0, 0] == "T0"
assert output.iloc[0, 1] == "C0"
else:
assert valid_image_path(output)

Expand Down

0 comments on commit 4a3791c

Please sign in to comment.