Skip to content

Commit

Permalink
Add fix for CLE array output by workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Aug 22, 2024
1 parent 938d2ed commit 399fd74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/lls_core/models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

if TYPE_CHECKING:
from lls_core.models.lattice_data import LatticeData
from numpy.typing import NDArray

T = TypeVar("T")
S = TypeVar("S")
Expand Down Expand Up @@ -150,14 +151,14 @@ def process(self) -> Iterable[Tuple[RoiIndex, ProcessedWorkflowOutput]]:
else:
yield roi, pd.DataFrame(element)

def extract_preview(self) -> ArrayLike:
def extract_preview(self) -> NDArray:
import numpy as np
for slice in self.slices:
for value in slice.as_tuple():
if is_arraylike(value):
return value
return np.asarray(value)
raise Exception("No image was returned from this workflow")


def save(self) -> Iterable[Path]:
"""
Processes all workflow outputs and saves them to disk.
Expand Down
12 changes: 12 additions & 0 deletions core/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ def test_argument_order(rbc_tiny: Path):
)
for roi, output in params.process_workflow().process():
print(output)

def test_sum_preview(rbc_tiny: Path):
import numpy as np
# Tests that we can sum the preview result. This is required for the plugin
with tempfile.TemporaryDirectory() as tmpdir:
params = LatticeData(
input_image = rbc_tiny,
workflow = "core/tests/workflows/binarisation/workflow.yml",
save_dir = tmpdir
)
preview = params.process_workflow().extract_preview()
np.sum(preview, axis=(1, 2))

0 comments on commit 399fd74

Please sign in to comment.