Skip to content

Commit

Permalink
Merge pull request #95 from multimeric/faster-ci
Browse files Browse the repository at this point in the history
Faster CI
  • Loading branch information
multimeric authored Nov 19, 2024
2 parents baaec71 + dec1d66 commit 5c6d189
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
11 changes: 10 additions & 1 deletion core/lls_core/models/deskew.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,17 @@ def read_image(cls, values: dict):
aics = AICSImage(fspath(img))
elif isinstance(img, AICSImage):
aics = img
elif isinstance(img, DataArray):
if set(img.dims) >= {"Z", "Y", "X"}:
# If it's already a DataArray with the right dimensions, we're done
return values
else:
raise ValueError("If passing a DataArray, it should at least have Z Y and X dimensions, appropriately labelled.")
elif is_arraylike(img):
values["input_image"] = DataArray(img)
if len(img.shape) == 3:
values["input_image"] = DataArray(img, dims=["Z", "Y", "X"])
else:
raise ValueError("Only 3D numpy arrays are currently supported. If you have a different shape, please use a DataArray and name your dimensions C, T, Z, Y and/or Z.")
else:
raise ValueError("Value of input_image was neither a path, an AICSImage, or array-like.")

Expand Down
5 changes: 5 additions & 0 deletions core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
def runner() -> CliRunner:
return CliRunner()

@pytest.fixture
def lls7_t1_ch1():
with as_file(resources / "LLS7_t1_ch1.czi") as image_path:
yield image_path

@pytest.fixture
def rbc_tiny():
with as_file(resources / "RBC_tiny.czi") as image_path:
Expand Down
52 changes: 27 additions & 25 deletions core/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from napari_workflows import Workflow
from pytest import FixtureRequest


from .params import parameterized

root = Path(__file__).parent / "data"
Expand Down Expand Up @@ -86,31 +87,33 @@ def test_process_time_range(multi_channel_time: Path):


@pytest.mark.parametrize(["background"], [(1,), ("auto",), ("second_last",)])
@parameterized
def test_process_deconvolution(args: dict, background: Any):
for slice in (
LatticeData.parse_obj(
{
"input_image": root / "raw.tif",
"deconvolution": {
"psf": [root / "psf.tif"],
"background": background,
},
**args,
}
)
.process()
.slices
):
assert slice.data.ndim == 3
def test_process_deconvolution(background: Any):
import numpy as np
with tempfile.TemporaryDirectory() as outdir:
for slice in (
LatticeData.parse_obj(
{
# Use random sample data here, since we're not testing the correctness of the deconvolution
# but rather that all the code paths are functional
"input_image": np.random.random_sample((128, 128, 64)),
"deconvolution": {
"psf": [np.random.random_sample((28, 28, 28))],
"background": background,
},
"save_dir": outdir
}
)
.process()
.slices
):
assert slice.data.ndim == 3


@parameterized
@pytest.mark.parametrize(
["workflow_name"], [("image_workflow",), ("table_workflow",)]
)
def test_process_workflow(
args: dict, request: FixtureRequest, workflow_name: str
request: FixtureRequest, lls7_t1_ch1: Path, workflow_name: str
):
from pandas import DataFrame

Expand All @@ -119,10 +122,9 @@ def test_process_workflow(
for output in (
LatticeData.parse_obj(
{
"input_image": root / "raw.tif",
"input_image": lls7_t1_ch1,
"workflow": workflow,
"save_dir": tmpdir,
**args,
"save_dir": tmpdir
}
)
.process_workflow()
Expand All @@ -132,19 +134,19 @@ def test_process_workflow(
assert isinstance(output.data, (Path, DataFrame))

def test_table_workflow(
rbc_tiny: Path, table_workflow: Workflow
lls7_t1_ch1: Path, table_workflow: Workflow
):
with tempfile.TemporaryDirectory() as _tmpdir:
tmpdir = Path(_tmpdir)
results = set(LatticeData.parse_obj(
{
"input_image": rbc_tiny,
"input_image": lls7_t1_ch1,
"workflow": table_workflow,
"save_dir": tmpdir
}
).process_workflow().save())
# There should be one output for each element of the tuple
assert {result.name for result in results} == {'RBC_tiny_deskewed_output_3.csv', 'RBC_tiny_deskewed.h5', 'RBC_tiny_deskewed_output_1.csv', 'RBC_tiny_deskewed_output_2.csv'}
assert {result.name for result in results} == {'LLS7_t1_ch1_deskewed_output_3.csv', 'LLS7_t1_ch1_deskewed.h5', 'LLS7_t1_ch1_deskewed_output_1.csv', 'LLS7_t1_ch1_deskewed_output_2.csv'}

@pytest.mark.parametrize(
["roi_subset"],
Expand Down
12 changes: 6 additions & 6 deletions core/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ def test_workflow_cli(workflow_config_cli: dict, save_func: Callable, cli_param:
assert label_img.shape == (3, 14, 5)
assert label_img[1, 6, 2] == 1

def test_image_workflow(minimal_image_path: Path, image_workflow: Workflow):
def test_image_workflow(lls7_t1_ch1: Path, image_workflow: Workflow):
# Test that a regular workflow that returns an image directly works
with tempfile.TemporaryDirectory() as tmpdir:
for output in LatticeData(
input_image = minimal_image_path,
input_image = lls7_t1_ch1,
workflow = image_workflow,
save_dir = tmpdir
).process_workflow().process():
assert isinstance(output.data, Path)
assert valid_image_path(output.data)

def test_table_workflow(minimal_image_path: Path, table_workflow: Workflow):
def test_table_workflow(lls7_t1_ch1: Path, table_workflow: Workflow):
# Test a complex workflow that returns a tuple of images and data
with tempfile.TemporaryDirectory() as tmpdir:
params = LatticeData(
input_image = minimal_image_path,
input_image = lls7_t1_ch1,
workflow = table_workflow,
save_dir = tmpdir
)
Expand Down Expand Up @@ -111,12 +111,12 @@ def test_sum_preview(rbc_tiny: Path):
assert len(previews) == 1, "There should be 1 preview when cropping is disabled"
assert previews[0].ndim == 3, "A preview should be a 3D image"

def test_crop_workflow(rbc_tiny: Path):
def test_crop_workflow(lls7_t1_ch1: Path):
# Tests that crop workflows only process each ROI lazily

with tempfile.TemporaryDirectory() as tmpdir:
params = LatticeData(
input_image = rbc_tiny,
input_image = lls7_t1_ch1,
workflow = "core/tests/workflows/binarisation/workflow.yml",
save_dir = tmpdir,
crop=CropParams(
Expand Down
2 changes: 1 addition & 1 deletion plugin/tests/test_dock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def image_data(request: pytest.FixtureRequest):
Fixture function that yields test images as file paths
"""
with as_file(resources / request.param) as image_path:
yield AICSImage(image_path)
yield AICSImage(image_path, )

def set_debug(cls: MagicTemplate):
"""
Expand Down

0 comments on commit 5c6d189

Please sign in to comment.