Skip to content

Commit 8d114af

Browse files
committed
Update Cellpose tests
1 parent c98f570 commit 8d114af

3 files changed

+85
-26
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
rev: 3.9.2
1818
hooks:
1919
- id: flake8
20-
args: ["--ignore=E203"]
20+
args: ["--ignore=E203,W503"]
2121
- repo: https://github.com/PyCQA/bandit
2222
rev: '1.7.4'
2323
hooks:

tests/tasks/test_registration.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from devtools import debug
1414
from pytest import MonkeyPatch
1515

16-
from fractal_tasks_core.channels import ChannelInputModel
1716
from fractal_tasks_core.ngff.zarr_utils import load_NgffImageMeta
1817
from fractal_tasks_core.ngff.zarr_utils import load_NgffWellMeta
1918
from fractal_tasks_core.roi import (
@@ -33,6 +32,12 @@
3332
from fractal_tasks_core.tasks.cellpose_segmentation import (
3433
cellpose_segmentation,
3534
)
35+
from fractal_tasks_core.tasks.cellpose_transforms import (
36+
CellposeChannel1InputModel,
37+
)
38+
from fractal_tasks_core.tasks.cellpose_transforms import (
39+
CellposeCustomNormalizer,
40+
)
3641
from fractal_tasks_core.tasks.cellvoyager_to_ome_zarr_compute import (
3742
cellvoyager_to_ome_zarr_compute,
3843
)
@@ -272,10 +277,13 @@ def test_multiplexing_registration(
272277
# Run cellpose to create a label image that needs to be handled in
273278
# registration
274279
# Per-FOV labeling
280+
channel = CellposeChannel1InputModel(
281+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
282+
)
275283
for zarr_url in zarr_urls_2D:
276284
cellpose_segmentation(
277285
zarr_url=zarr_url,
278-
channel=ChannelInputModel(wavelength_id="A01_C01"),
286+
channel=channel,
279287
level=1,
280288
)
281289

tests/tasks/test_workflows_cellpose_segmentation.py

+74-23
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
from ._validation import validate_axes_and_coordinateTransformations
3333
from ._validation import validate_schema
3434
from .lib_empty_ROI_table import _add_empty_ROI_table
35-
from fractal_tasks_core.channels import ChannelInputModel
3635
from fractal_tasks_core.tasks.cellpose_segmentation import (
3736
cellpose_segmentation,
3837
)
38+
from fractal_tasks_core.tasks.cellpose_transforms import (
39+
CellposeChannel1InputModel,
40+
)
41+
from fractal_tasks_core.tasks.cellpose_transforms import (
42+
CellposeCustomNormalizer,
43+
)
3944
from fractal_tasks_core.tasks.cellvoyager_to_ome_zarr_compute import (
4045
cellvoyager_to_ome_zarr_compute,
4146
)
@@ -182,16 +187,24 @@ def test_failures(
182187
level=3,
183188
)
184189
# Attempt 1
190+
channel = CellposeChannel1InputModel(
191+
wavelength_id="invalid_wavelength_id",
192+
normalize=CellposeCustomNormalizer(),
193+
)
185194
cellpose_segmentation(
186195
**kwargs,
187-
channel=ChannelInputModel(wavelength_id="invalid_wavelength_id"),
196+
channel=channel,
188197
)
189198
assert "ChannelNotFoundError" in caplog.records[0].msg
190199

191200
# Attempt 2
201+
channel = CellposeChannel1InputModel(
202+
label="invalid_channel_name",
203+
normalize=CellposeCustomNormalizer(),
204+
)
192205
cellpose_segmentation(
193206
**kwargs,
194-
channel=ChannelInputModel(label="invalid_channel_name"),
207+
channel=channel,
195208
)
196209
assert "ChannelNotFoundError" in caplog.records[0].msg
197210
assert "ChannelNotFoundError" in caplog.records[1].msg
@@ -200,9 +213,10 @@ def test_failures(
200213
with pytest.raises(ValueError):
201214
cellpose_segmentation(
202215
**kwargs,
203-
channel=ChannelInputModel(
216+
channel=CellposeChannel1InputModel(
204217
wavelength_id="A01_C01",
205218
label="invalid_channel_name",
219+
normalize=CellposeCustomNormalizer(),
206220
),
207221
)
208222

@@ -237,11 +251,15 @@ def test_workflow_with_per_FOV_labeling(
237251
debug(zarr_dir)
238252
debug(zarr_urls)
239253

254+
channel = CellposeChannel1InputModel(
255+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
256+
)
257+
240258
# Per-FOV labeling
241259
for zarr_url in zarr_urls:
242260
cellpose_segmentation(
243261
zarr_url=zarr_url,
244-
channel=ChannelInputModel(wavelength_id="A01_C01"),
262+
channel=channel,
245263
level=3,
246264
relabeling=True,
247265
diameter_level0=80.0,
@@ -296,11 +314,17 @@ def test_workflow_with_multi_channel_input(
296314
debug(zarr_urls)
297315

298316
# Per-FOV labeling
317+
channel = CellposeChannel1InputModel(
318+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
319+
)
320+
channel2 = CellposeChannel1InputModel(
321+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
322+
)
299323
for zarr_url in zarr_urls:
300324
cellpose_segmentation(
301325
zarr_url=zarr_url,
302-
channel=ChannelInputModel(wavelength_id="A01_C01"),
303-
channel2=ChannelInputModel(wavelength_id="A01_C01"),
326+
channel=channel,
327+
channel2=channel2,
304328
level=3,
305329
relabeling=True,
306330
diameter_level0=80.0,
@@ -345,11 +369,14 @@ def test_workflow_with_per_FOV_labeling_2D(
345369
remove_labels=True,
346370
)
347371

372+
channel = CellposeChannel1InputModel(
373+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
374+
)
348375
# Per-FOV labeling
349376
for zarr_url in zarr_urls:
350377
cellpose_segmentation(
351378
zarr_url=zarr_url,
352-
channel=ChannelInputModel(wavelength_id="A01_C01"),
379+
channel=channel,
353380
level=2,
354381
relabeling=True,
355382
diameter_level0=80.0,
@@ -429,11 +456,14 @@ def test_workflow_with_per_well_labeling_2D(
429456
overwrite=True,
430457
)["image_list_updates"]
431458

459+
channel = CellposeChannel1InputModel(
460+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
461+
)
432462
# Whole-well labeling
433463
for zarr_url in zarr_urls:
434464
cellpose_segmentation(
435465
zarr_url=zarr_url,
436-
channel=ChannelInputModel(wavelength_id="A01_C01"),
466+
channel=channel,
437467
level=2,
438468
input_ROI_table="well_ROI_table",
439469
relabeling=True,
@@ -483,11 +513,14 @@ def test_workflow_bounding_box(
483513
debug(zarr_dir)
484514
debug(zarr_urls)
485515

516+
channel = CellposeChannel1InputModel(
517+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
518+
)
486519
# Per-FOV labeling
487520
for zarr_url in zarr_urls:
488521
cellpose_segmentation(
489522
zarr_url=zarr_url,
490-
channel=ChannelInputModel(wavelength_id="A01_C01"),
523+
channel=channel,
491524
level=3,
492525
relabeling=True,
493526
diameter_level0=80.0,
@@ -498,7 +531,7 @@ def test_workflow_bounding_box(
498531
for zarr_url in zarr_urls:
499532
cellpose_segmentation(
500533
zarr_url=zarr_url,
501-
channel=ChannelInputModel(wavelength_id="A01_C01"),
534+
channel=channel,
502535
level=3,
503536
relabeling=True,
504537
diameter_level0=80.0,
@@ -511,7 +544,7 @@ def test_workflow_bounding_box(
511544
for zarr_url in zarr_urls:
512545
cellpose_segmentation(
513546
zarr_url=zarr_url,
514-
channel=ChannelInputModel(wavelength_id="A01_C01"),
547+
channel=channel,
515548
level=3,
516549
relabeling=True,
517550
diameter_level0=80.0,
@@ -565,10 +598,13 @@ def test_workflow_bounding_box_with_overlap(
565598
debug(zarr_urls)
566599

567600
# Per-FOV labeling
601+
channel = CellposeChannel1InputModel(
602+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
603+
)
568604
for zarr_url in zarr_urls:
569605
cellpose_segmentation(
570606
zarr_url=zarr_url,
571-
channel=ChannelInputModel(wavelength_id="A01_C01"),
607+
channel=channel,
572608
level=3,
573609
relabeling=True,
574610
diameter_level0=80.0,
@@ -604,7 +640,7 @@ def test_workflow_with_per_FOV_labeling_via_script(
604640
zarr_url = str(zarr_urls[0])
605641
task_args = dict(
606642
zarr_url=zarr_url,
607-
channel=dict(wavelength_id="A01_C01"),
643+
channel=dict(wavelength_id="A01_C01", normalize={"type": "default"}),
608644
level=4,
609645
relabeling=True,
610646
diameter_level0=80.0,
@@ -675,12 +711,15 @@ def test_workflow_with_per_FOV_labeling_with_empty_FOV_table(
675711
table_name=TABLE_NAME,
676712
)
677713

714+
channel = CellposeChannel1InputModel(
715+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
716+
)
678717
# Per-FOV labeling
679718
for zarr_url in zarr_urls:
680719
cellpose_segmentation(
681720
zarr_url=zarr_url,
682721
input_ROI_table=TABLE_NAME,
683-
channel=ChannelInputModel(wavelength_id="A01_C01"),
722+
channel=channel,
684723
level=3,
685724
relabeling=True,
686725
diameter_level0=80.0,
@@ -732,11 +771,14 @@ def test_CYX_input(
732771
make_CYX=True,
733772
)
734773

774+
channel = CellposeChannel1InputModel(
775+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
776+
)
735777
# Per-FOV labeling
736778
for zarr_url in zarr_urls:
737779
cellpose_segmentation(
738780
zarr_url=zarr_url,
739-
channel=ChannelInputModel(wavelength_id="A01_C01"),
781+
channel=channel,
740782
level=0,
741783
relabeling=True,
742784
diameter_level0=80.0,
@@ -781,10 +823,13 @@ def test_workflow_secondary_labeling(
781823
)
782824

783825
# Primary segmentation (organoid)
826+
channel = CellposeChannel1InputModel(
827+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
828+
)
784829
for zarr_url in zarr_urls:
785830
cellpose_segmentation(
786831
zarr_url=zarr_url,
787-
channel=ChannelInputModel(wavelength_id="A01_C01"),
832+
channel=channel,
788833
level=0,
789834
relabeling=True,
790835
input_ROI_table="FOV_ROI_table",
@@ -812,7 +857,7 @@ def test_workflow_secondary_labeling(
812857
for zarr_url in zarr_urls:
813858
cellpose_segmentation(
814859
zarr_url=zarr_url,
815-
channel=ChannelInputModel(wavelength_id="A01_C01"),
860+
channel=channel,
816861
level=0,
817862
relabeling=True,
818863
input_ROI_table="organoid_ROI_table",
@@ -857,11 +902,14 @@ def test_workflow_secondary_labeling_no_labels(
857902
make_CYX=False,
858903
)
859904

905+
channel = CellposeChannel1InputModel(
906+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
907+
)
860908
# Primary segmentation (organoid)
861909
for zarr_url in zarr_urls:
862910
cellpose_segmentation(
863911
zarr_url=zarr_url,
864-
channel=ChannelInputModel(wavelength_id="A01_C01"),
912+
channel=channel,
865913
level=0,
866914
relabeling=True,
867915
input_ROI_table="FOV_ROI_table",
@@ -886,7 +934,7 @@ def test_workflow_secondary_labeling_no_labels(
886934
for zarr_url in zarr_urls:
887935
cellpose_segmentation(
888936
zarr_url=zarr_url,
889-
channel=ChannelInputModel(wavelength_id="A01_C01"),
937+
channel=channel,
890938
level=0,
891939
relabeling=True,
892940
input_ROI_table="organoid_ROI_table",
@@ -927,11 +975,14 @@ def test_workflow_secondary_labeling_two_channels(
927975
make_CYX=False,
928976
)
929977

978+
channel = CellposeChannel1InputModel(
979+
wavelength_id="A01_C01", normalize=CellposeCustomNormalizer()
980+
)
930981
# Primary segmentation (organoid)
931982
for zarr_url in zarr_urls:
932983
cellpose_segmentation(
933984
zarr_url=zarr_url,
934-
channel=ChannelInputModel(wavelength_id="A01_C01"),
985+
channel=channel,
935986
level=0,
936987
relabeling=True,
937988
input_ROI_table="FOV_ROI_table",
@@ -959,8 +1010,8 @@ def test_workflow_secondary_labeling_two_channels(
9591010
for zarr_url in zarr_urls:
9601011
cellpose_segmentation(
9611012
zarr_url=zarr_url,
962-
channel=ChannelInputModel(wavelength_id="A01_C01"),
963-
channel2=ChannelInputModel(wavelength_id="A01_C01"),
1013+
channel=channel,
1014+
channel2=channel,
9641015
level=0,
9651016
relabeling=True,
9661017
input_ROI_table="organoid_ROI_table",

0 commit comments

Comments
 (0)