Skip to content

Commit d583eba

Browse files
committed
Rename Channel->OmeroChannel and BaseChannel->Channel (ref #404)
1 parent a46bfec commit d583eba

10 files changed

+74
-73
lines changed

fractal_tasks_core/__FRACTAL_MANIFEST__.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"title": "Allowed Channels",
4646
"type": "array",
4747
"items": {
48-
"$ref": "#/definitions/Channel"
48+
"$ref": "#/definitions/OmeroChannel"
4949
},
50-
"description": "A list of channel dictionaries, where each channel must include the ``wavelength_id`` key and where the corresponding values should be unique across channels. # TODO: improve after Channel input refactor See issue 386"
50+
"description": "A list of ``OmeroChannel``s, where each channel must include the ``wavelength_id`` attribute and where the ``wavelength_id`` values must be unique across the list."
5151
},
5252
"num_levels": {
5353
"title": "Num Levels",
@@ -76,8 +76,8 @@
7676
],
7777
"additionalProperties": false,
7878
"definitions": {
79-
"ChannelWindow": {
80-
"title": "ChannelWindow",
79+
"Window": {
80+
"title": "Window",
8181
"description": "Custom class for Omero-channel window, related to OME-NGFF v0.4\n\nSee https://ngff.openmicroscopy.org/0.4/#omero-md.\nMain difference from the specs:\n\n 1. ``min`` and ``max`` are optional, since we have custom logic to set\n their values.",
8282
"type": "object",
8383
"properties": {
@@ -103,8 +103,8 @@
103103
"end"
104104
]
105105
},
106-
"Channel": {
107-
"title": "Channel",
106+
"OmeroChannel": {
107+
"title": "OmeroChannel",
108108
"description": "Custom class for Omero channels, related to OME-NGFF v0.4.\n\nDifferences from OME-NGFF v0.4 specs\n(https://ngff.openmicroscopy.org/0.4/#omero-md)\n\n 1. Additional attributes ``wavelength_id`` and ``index``.\n 2. We make ``color`` an optional attribute, since we have custom\n logic to set its value.\n 3. We make ``window`` an optional attribute, so that we can also\n process zarr arrays which do not have this attribute.",
109109
"type": "object",
110110
"properties": {
@@ -117,7 +117,7 @@
117117
"type": "integer"
118118
},
119119
"window": {
120-
"$ref": "#/definitions/ChannelWindow"
120+
"$ref": "#/definitions/Window"
121121
},
122122
"color": {
123123
"title": "Color",
@@ -352,11 +352,11 @@
352352
"description": "Pyramid level of the image to be segmented. Choose 0 to process at full resolution."
353353
},
354354
"channel": {
355-
"$ref": "#/definitions/BaseChannel",
355+
"$ref": "#/definitions/Channel",
356356
"description": "Primary channel for segmentation; requires either ``wavelength_id`` (e.g. ``A01_C01``) or ``label`` (e.g. ``DAPI``)."
357357
},
358358
"channel2": {
359-
"$ref": "#/definitions/BaseChannel",
359+
"$ref": "#/definitions/Channel",
360360
"description": "Second channel for segmentation (in the same format as ``channel``). If specified, cellpose runs in dual channel mode. For dual channel segmentation of cells, the first channel should contain the membrane marker, the second channel should contain the nuclear marker."
361361
},
362362
"input_ROI_table": {
@@ -456,8 +456,8 @@
456456
],
457457
"additionalProperties": false,
458458
"definitions": {
459-
"BaseChannel": {
460-
"title": "BaseChannel",
459+
"Channel": {
460+
"title": "Channel",
461461
"description": "A channel which is specified by either ``wavelength_id`` or ``label``.",
462462
"type": "object",
463463
"properties": {
@@ -639,8 +639,8 @@
639639
],
640640
"additionalProperties": false,
641641
"definitions": {
642-
"BaseChannel": {
643-
"title": "BaseChannel",
642+
"Channel": {
643+
"title": "Channel",
644644
"description": "A channel which is specified by either ``wavelength_id`` or ``label``.",
645645
"type": "object",
646646
"properties": {
@@ -672,7 +672,7 @@
672672
"type": "string"
673673
},
674674
"channel": {
675-
"$ref": "#/definitions/BaseChannel"
675+
"$ref": "#/definitions/Channel"
676676
}
677677
},
678678
"required": [
@@ -760,10 +760,10 @@
760760
"additionalProperties": {
761761
"type": "array",
762762
"items": {
763-
"$ref": "#/definitions/Channel"
763+
"$ref": "#/definitions/OmeroChannel"
764764
}
765765
},
766-
"description": "A dictionary of channel dictionaries, where each channel must include the ``wavelength_id`` key and where the corresponding values should be unique across channels. Values are the integers of the channel order, i.e. ``\"0\"``, ``\"1\"`` etc. # TODO: improve after Channel input refactor https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/386"
766+
"description": "A dictionary of lists of ``OmeroChannel``s, where each channel must include the ``wavelength_id`` attribute and where the ``wavelength_id`` values must be unique across each list. Dictionary keys represent channel indices (``\"0\",\"1\",..``)."
767767
},
768768
"num_levels": {
769769
"title": "Num Levels",
@@ -805,8 +805,8 @@
805805
],
806806
"additionalProperties": false,
807807
"definitions": {
808-
"ChannelWindow": {
809-
"title": "ChannelWindow",
808+
"Window": {
809+
"title": "Window",
810810
"description": "Custom class for Omero-channel window, related to OME-NGFF v0.4\n\nSee https://ngff.openmicroscopy.org/0.4/#omero-md.\nMain difference from the specs:\n\n 1. ``min`` and ``max`` are optional, since we have custom logic to set\n their values.",
811811
"type": "object",
812812
"properties": {
@@ -832,8 +832,8 @@
832832
"end"
833833
]
834834
},
835-
"Channel": {
836-
"title": "Channel",
835+
"OmeroChannel": {
836+
"title": "OmeroChannel",
837837
"description": "Custom class for Omero channels, related to OME-NGFF v0.4.\n\nDifferences from OME-NGFF v0.4 specs\n(https://ngff.openmicroscopy.org/0.4/#omero-md)\n\n 1. Additional attributes ``wavelength_id`` and ``index``.\n 2. We make ``color`` an optional attribute, since we have custom\n logic to set its value.\n 3. We make ``window`` an optional attribute, so that we can also\n process zarr arrays which do not have this attribute.",
838838
"type": "object",
839839
"properties": {
@@ -846,7 +846,7 @@
846846
"type": "integer"
847847
},
848848
"window": {
849-
"$ref": "#/definitions/ChannelWindow"
849+
"$ref": "#/definitions/Window"
850850
},
851851
"color": {
852852
"title": "Color",

fractal_tasks_core/lib_channels.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333

3434

35-
class ChannelWindow(BaseModel):
35+
class Window(BaseModel):
3636
"""
3737
Custom class for Omero-channel window, related to OME-NGFF v0.4
3838
@@ -53,7 +53,7 @@ class ChannelWindow(BaseModel):
5353
"""TBD"""
5454

5555

56-
class Channel(BaseModel):
56+
class OmeroChannel(BaseModel):
5757
"""
5858
Custom class for Omero channels, related to OME-NGFF v0.4.
5959
@@ -74,7 +74,7 @@ class Channel(BaseModel):
7474
"""TBD"""
7575

7676
# From OME-NGFF v0.4 transitional metadata
77-
window: Optional[ChannelWindow]
77+
window: Optional[Window]
7878
"""TBD"""
7979
color: Optional[str]
8080
"""TBD"""
@@ -97,7 +97,7 @@ class ChannelNotFoundError(ValueError):
9797
pass
9898

9999

100-
def check_unique_wavelength_ids(channels: List[Channel]):
100+
def check_unique_wavelength_ids(channels: List[OmeroChannel]):
101101
"""
102102
Check that the `wavelength_id` attributes of a channel list are unique
103103
"""
@@ -149,7 +149,7 @@ def check_well_channel_labels(*, well_zarr_path: str) -> None:
149149

150150
def get_channel_from_image_zarr(
151151
*, image_zarr_path: str, label: str = None, wavelength_id: str = None
152-
) -> Channel:
152+
) -> OmeroChannel:
153153
"""
154154
Extract a channel from OME-NGFF zarr attributes
155155
@@ -169,7 +169,7 @@ def get_channel_from_image_zarr(
169169
return channel
170170

171171

172-
def get_omero_channel_list(*, image_zarr_path: str) -> List[Channel]:
172+
def get_omero_channel_list(*, image_zarr_path: str) -> List[OmeroChannel]:
173173
"""
174174
Extract the list of channels from OME-NGFF zarr attributes
175175
@@ -178,13 +178,16 @@ def get_omero_channel_list(*, image_zarr_path: str) -> List[Channel]:
178178
"""
179179
group = zarr.open_group(image_zarr_path, mode="r+")
180180
channels_dicts = group.attrs["omero"]["channels"]
181-
channels = [Channel(**c) for c in channels_dicts]
181+
channels = [OmeroChannel(**c) for c in channels_dicts]
182182
return channels
183183

184184

185185
def get_channel_from_list(
186-
*, channels: List[Channel], label: str = None, wavelength_id: str = None
187-
) -> Channel:
186+
*,
187+
channels: List[OmeroChannel],
188+
label: str = None,
189+
wavelength_id: str = None,
190+
) -> OmeroChannel:
188191
"""
189192
Find matching channel in a list
190193
@@ -245,7 +248,7 @@ def get_channel_from_list(
245248

246249
def define_omero_channels(
247250
*,
248-
channels: List[Channel],
251+
channels: List[OmeroChannel],
249252
bit_depth: int,
250253
label_prefix: str = None,
251254
) -> List[Dict[str, Union[str, int, bool, Dict[str, int]]]]:

fractal_tasks_core/tasks/_input_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pydantic import validator
2121

2222

23-
class BaseChannel(BaseModel):
23+
class Channel(BaseModel):
2424
"""
2525
A channel which is specified by either ``wavelength_id`` or ``label``.
2626
"""
@@ -55,7 +55,7 @@ class NapariWorkflowsInput(BaseModel):
5555

5656
type: Literal["image", "label"]
5757
label_name: Optional[str]
58-
channel: Optional[BaseChannel]
58+
channel: Optional[Channel]
5959

6060
@validator("label_name", always=True)
6161
def label_name_is_present(cls, v, values):

fractal_tasks_core/tasks/cellpose_segmentation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
from pydantic.decorator import validate_arguments
3737

3838
import fractal_tasks_core
39-
from fractal_tasks_core.lib_channels import Channel
4039
from fractal_tasks_core.lib_channels import ChannelNotFoundError
4140
from fractal_tasks_core.lib_channels import get_channel_from_image_zarr
41+
from fractal_tasks_core.lib_channels import OmeroChannel
4242
from fractal_tasks_core.lib_masked_loading import masked_loading_wrapper
4343
from fractal_tasks_core.lib_pyramid_creation import build_pyramid
4444
from fractal_tasks_core.lib_regions_of_interest import (
@@ -53,7 +53,7 @@
5353
from fractal_tasks_core.lib_ROI_overlaps import get_overlapping_pairs_3D
5454
from fractal_tasks_core.lib_zattrs_utils import extract_zyx_pixel_sizes
5555
from fractal_tasks_core.lib_zattrs_utils import rescale_datasets
56-
from fractal_tasks_core.tasks._input_models import BaseChannel
56+
from fractal_tasks_core.tasks._input_models import Channel
5757

5858
logger = logging.getLogger(__name__)
5959

@@ -154,8 +154,8 @@ def cellpose_segmentation(
154154
metadata: Dict[str, Any],
155155
# Task-specific arguments
156156
level: int,
157-
channel: BaseChannel,
158-
channel2: Optional[BaseChannel] = None,
157+
channel: Channel,
158+
channel2: Optional[Channel] = None,
159159
input_ROI_table: str = "FOV_ROI_table",
160160
output_ROI_table: Optional[str] = None,
161161
output_label_name: Optional[str] = None,
@@ -301,7 +301,7 @@ def cellpose_segmentation(
301301

302302
# Find channel index
303303
try:
304-
tmp_channel: Channel = get_channel_from_image_zarr(
304+
tmp_channel: OmeroChannel = get_channel_from_image_zarr(
305305
image_zarr_path=zarrurl,
306306
wavelength_id=channel.wavelength_id,
307307
label=channel.label,
@@ -317,7 +317,7 @@ def cellpose_segmentation(
317317
# Find channel index for second channel, if one is provided
318318
if channel2:
319319
try:
320-
tmp_channel_c2: Channel = get_channel_from_image_zarr(
320+
tmp_channel_c2: OmeroChannel = get_channel_from_image_zarr(
321321
image_zarr_path=zarrurl,
322322
wavelength_id=channel2.wavelength_id,
323323
label=channel2.label,

fractal_tasks_core/tasks/create_ome_zarr.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
from pydantic.decorator import validate_arguments
2828

2929
import fractal_tasks_core
30-
from fractal_tasks_core.lib_channels import Channel
3130
from fractal_tasks_core.lib_channels import check_unique_wavelength_ids
3231
from fractal_tasks_core.lib_channels import check_well_channel_labels
3332
from fractal_tasks_core.lib_channels import define_omero_channels
33+
from fractal_tasks_core.lib_channels import OmeroChannel
3434
from fractal_tasks_core.lib_glob import glob_with_multiple_patterns
3535
from fractal_tasks_core.lib_metadata_parsing import parse_yokogawa_metadata
3636
from fractal_tasks_core.lib_parse_filename_metadata import parse_filename
@@ -54,7 +54,7 @@ def create_ome_zarr(
5454
metadata: Dict[str, Any],
5555
image_extension: str = "tif",
5656
image_glob_patterns: Optional[list[str]] = None,
57-
allowed_channels: List[Channel],
57+
allowed_channels: List[OmeroChannel],
5858
num_levels: int = 5,
5959
coarsening_xy: int = 2,
6060
metadata_table: str = "mrf_mlf",
@@ -107,12 +107,11 @@ def create_ome_zarr(
107107
:param coarsening_xy: Linear coarsening factor between subsequent levels.
108108
If set to 2, level 1 is 2x downsampled, level 2 is
109109
4x downsampled etc.
110-
:param allowed_channels: A list of channel dictionaries, where each channel
111-
must include the ``wavelength_id`` key and where
112-
the corresponding values should be unique across
113-
channels.
114-
# TODO: improve after Channel input refactor
115-
See issue 386
110+
111+
:param allowed_channels: A list of ``OmeroChannel``s, where each channel
112+
must include the ``wavelength_id`` attribute and
113+
where the ``wavelength_id`` values must be unique
114+
across the list.
116115
:param metadata_table: If equal to ``"mrf_mlf"``, parse Yokogawa metadata
117116
from mrf/mlf files in the input_path folder; else,
118117
the full path to a csv file containing

fractal_tasks_core/tasks/create_ome_zarr_multiplex.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
from pydantic.decorator import validate_arguments
3030

3131
import fractal_tasks_core
32-
from fractal_tasks_core.lib_channels import Channel
3332
from fractal_tasks_core.lib_channels import check_unique_wavelength_ids
3433
from fractal_tasks_core.lib_channels import check_well_channel_labels
3534
from fractal_tasks_core.lib_channels import define_omero_channels
35+
from fractal_tasks_core.lib_channels import OmeroChannel
3636
from fractal_tasks_core.lib_glob import glob_with_multiple_patterns
3737
from fractal_tasks_core.lib_metadata_parsing import parse_yokogawa_metadata
3838
from fractal_tasks_core.lib_parse_filename_metadata import parse_filename
@@ -56,7 +56,7 @@ def create_ome_zarr_multiplex(
5656
metadata: Dict[str, Any],
5757
image_extension: str = "tif",
5858
image_glob_patterns: Optional[list[str]] = None,
59-
allowed_channels: Dict[str, list[Channel]],
59+
allowed_channels: Dict[str, list[OmeroChannel]],
6060
num_levels: int = 5,
6161
coarsening_xy: int = 2,
6262
metadata_table: Union[Literal["mrf_mlf"], Dict[str, str]] = "mrf_mlf",
@@ -107,14 +107,11 @@ def create_ome_zarr_multiplex(
107107
:param coarsening_xy: Linear coarsening factor between subsequent levels.
108108
If set to 2, level 1 is 2x downsampled, level 2 is
109109
4x downsampled etc.
110-
:param allowed_channels: A dictionary of channel dictionaries, where each
111-
channel must include the ``wavelength_id`` key
112-
and where the corresponding values should be
113-
unique across channels.
114-
Values are the integers of the channel order,
115-
i.e. ``"0"``, ``"1"`` etc.
116-
# TODO: improve after Channel input refactor
117-
https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/386
110+
:param allowed_channels: A dictionary of lists of ``OmeroChannel``s, where
111+
each channel must include the ``wavelength_id``
112+
attribute and where the ``wavelength_id`` values
113+
must be unique across each list. Dictionary keys
114+
represent channel indices (``"0","1",..``).
118115
:param metadata_table: If equal to ``"mrf_mlf"``, parse Yokogawa metadata
119116
from mrf/mlf files in the input_path folder;
120117
else, a dictionary of key-value pairs like

fractal_tasks_core/tasks/illumination_correction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
from pydantic.decorator import validate_arguments
3131
from skimage.io import imread
3232

33-
from fractal_tasks_core.lib_channels import Channel
3433
from fractal_tasks_core.lib_channels import get_omero_channel_list
34+
from fractal_tasks_core.lib_channels import OmeroChannel
3535
from fractal_tasks_core.lib_pyramid_creation import build_pyramid
3636
from fractal_tasks_core.lib_regions_of_interest import (
3737
convert_ROI_table_to_indices,
@@ -197,7 +197,7 @@ def illumination_correction(
197197
logger.info(f" {zarrurl_new=}")
198198

199199
# Read channels from .zattrs
200-
channels: list[Channel] = get_omero_channel_list(
200+
channels: list[OmeroChannel] = get_omero_channel_list(
201201
image_zarr_path=zarrurl_old
202202
)
203203
num_channels = len(channels)

0 commit comments

Comments
 (0)