Skip to content

Commit 5741d31

Browse files
committed
Merge branch 'main' into pydantic-v2-second-attempt
2 parents fbf3cf9 + dbf6d75 commit 5741d31

File tree

4 files changed

+49
-23
lines changed

4 files changed

+49
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
# Unreleased
44

55
* Tasks:
6-
* Fix issue with masked ROI & relabeling in Cellpose task (\#785).
7-
* Fix issue with masking ROI label types in masked_loading_wrapper for Cellpose task (\#785).
6+
* Fix issue with masked ROI & relabeling in Cellpose task (\#786).
7+
* Fix issue with masking ROI label types in `masked_loading_wrapper` for Cellpose task (\#786).
8+
* Enable workaround to support yx images in Cellpose task (\#789).
9+
* Fix error handling in `calculate_registration_image_based` (\#799).
10+
* Fix minor issues with call-signature and type hints in `calculate_registration_image_based` (\#799).
811
* Development:
912
* Switch all core models to pydantic v2 (\#790).
1013

@@ -22,7 +25,7 @@
2225
* Rename `task.cellpose_transforms` into `tasks.cellpose_utils` (\#738).
2326
* Fix wrong repeated overlap checks for bounding-boxes in Cellpose task (\#778).
2427
* Fix minor MIP issues related to plate metadata and expecting acquisition metadata in all NGFF plates(\#781).
25-
* Add chi2_shift option to Calculate Registration (image-based) task(\#741).
28+
* Add `chi2_shift` option to Calculate Registration (image-based) task(\#741).
2629
* Development:
2730
* Switch to transitional pydantic.v1 imports, changes pydantic requirement to `==1.10.16` or `>=2.6.3` (\#760).
2831
* Support JSON-Schema generation for `Enum` task arguments (\#749).

fractal_tasks_core/__FRACTAL_MANIFEST__.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@
10761076
},
10771077
"RegistrationMethod": {
10781078
"title": "RegistrationMethod",
1079-
"description": "An enumeration.",
1079+
"description": "RegistrationMethod Enum class",
10801080
"enum": [
10811081
"phase_cross_correlation",
10821082
"chi2_shift"

fractal_tasks_core/tasks/calculate_registration_image_based.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848

4949

5050
class RegistrationMethod(Enum):
51+
"""
52+
RegistrationMethod Enum class
53+
54+
Attributes:
55+
PHASE_CROSS_CORRELATION: phase cross correlation based on scikit-image
56+
(works with 2D & 3D images).
57+
CHI2_SHIFT: chi2 shift based on image-registration library
58+
(only works with 2D images).
59+
"""
60+
5161
PHASE_CROSS_CORRELATION = "phase_cross_correlation"
5262
CHI2_SHIFT = "chi2_shift"
5363

@@ -66,7 +76,7 @@ def calculate_registration_image_based(
6676
init_args: InitArgsRegistration,
6777
# Core parameters
6878
wavelength_id: str,
69-
method: RegistrationMethod = "phase_cross_correlation",
79+
method: RegistrationMethod = RegistrationMethod.PHASE_CROSS_CORRELATION,
7080
roi_table: str = "FOV_ROI_table",
7181
level: int = 2,
7282
) -> None:
@@ -137,11 +147,11 @@ def calculate_registration_image_based(
137147
# Check if data is 3D (as not all registration methods work in 3D)
138148
# TODO: Abstract this check into a higher-level Zarr loading class
139149
if is_3D(data_reference_zyx):
140-
if method == "chi2_shift":
150+
if method == RegistrationMethod(RegistrationMethod.CHI2_SHIFT):
141151
raise ValueError(
142-
"The `chi2_shift` registration method has not been "
143-
"implemented for 3D images and the input image had a shape of "
144-
f"{data_reference_zyx.shape}."
152+
f"The `{RegistrationMethod.CHI2_SHIFT}` registration method "
153+
"has not been implemented for 3D images and the input image "
154+
f"had a shape of {data_reference_zyx.shape}."
145155
)
146156

147157
# Read ROIs

fractal_tasks_core/tasks/cellpose_segmentation.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,21 @@ def cellpose_segmentation(
314314
output_label_name = f"label_{ind_channel}"
315315

316316
# Load ZYX data
317-
data_zyx = da.from_zarr(f"{zarr_url}/{level}")[ind_channel]
317+
# Workaround for #788: Only load channel index when there is a channel
318+
# dimension
319+
if ngff_image_meta.axes_names[0] != "c":
320+
data_zyx = da.from_zarr(f"{zarr_url}/{level}")
321+
if channel2.is_set():
322+
raise ValueError(
323+
"Dual channel input was specified for an OME-Zarr image "
324+
"without a channel axis"
325+
)
326+
else:
327+
data_zyx = da.from_zarr(f"{zarr_url}/{level}")[ind_channel]
328+
if channel2.is_set():
329+
data_zyx_c2 = da.from_zarr(f"{zarr_url}/{level}")[ind_channel_c2]
330+
logger.info(f"Second channel: {data_zyx_c2.shape=}")
318331
logger.info(f"{data_zyx.shape=}")
319-
if channel2.is_set():
320-
data_zyx_c2 = da.from_zarr(f"{zarr_url}/{level}")[ind_channel_c2]
321-
logger.info(f"Second channel: {data_zyx_c2.shape=}")
322332

323333
# Read ROI table
324334
ROI_table_path = f"{zarr_url}/tables/{input_ROI_table}"
@@ -365,18 +375,21 @@ def cellpose_segmentation(
365375
logger.info(f"Anisotropy: {advanced_cellpose_model_params.anisotropy}")
366376

367377
# Rescale datasets (only relevant for level>0)
378+
# Workaround for #788
368379
if ngff_image_meta.axes_names[0] != "c":
369-
raise ValueError(
370-
"Cannot set `remove_channel_axis=True` for multiscale "
371-
f"metadata with axes={ngff_image_meta.axes_names}. "
372-
'First axis should have name "c".'
380+
new_datasets = rescale_datasets(
381+
datasets=[ds.dict() for ds in ngff_image_meta.datasets],
382+
coarsening_xy=coarsening_xy,
383+
reference_level=level,
384+
remove_channel_axis=False,
385+
)
386+
else:
387+
new_datasets = rescale_datasets(
388+
datasets=[ds.dict() for ds in ngff_image_meta.datasets],
389+
coarsening_xy=coarsening_xy,
390+
reference_level=level,
391+
remove_channel_axis=True,
373392
)
374-
new_datasets = rescale_datasets(
375-
datasets=[ds.dict() for ds in ngff_image_meta.datasets],
376-
coarsening_xy=coarsening_xy,
377-
reference_level=level,
378-
remove_channel_axis=True,
379-
)
380393

381394
label_attrs = {
382395
"image-label": {

0 commit comments

Comments
 (0)