channels
Helper functions to address channels via OME-NGFF/OMERO metadata.
ChannelInputModel
¶
Bases: BaseModel
A channel which is specified by either wavelength_id
or label
.
This model is similar to OmeroChannel
, but it is used for
task-function arguments (and for generating appropriate JSON schemas).
ATTRIBUTE | DESCRIPTION |
---|---|
wavelength_id |
Unique ID for the channel wavelength, e.g. |
label |
Name of the channel. Can only be specified if wavelength_id is not set. |
Source code in fractal_tasks_core/channels.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
mutually_exclusive_channel_attributes()
¶
Check that either label
or wavelength_id
is set.
Source code in fractal_tasks_core/channels.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
ChannelNotFoundError
¶
Bases: ValueError
Custom error for when get_channel_from_list
fails,
that can be captured and handled upstream if needed.
Source code in fractal_tasks_core/channels.py
143 144 145 146 147 148 149 |
|
OmeroChannel
¶
Bases: BaseModel
Custom class for Omero channels, based on OME-NGFF v0.4.
ATTRIBUTE | DESCRIPTION |
---|---|
wavelength_id |
Unique ID for the channel wavelength, e.g.
TYPE:
|
index |
Do not change. For internal use only. |
label |
Name of the channel. |
window |
Optional |
color |
Optional hex colormap to display the channel in napari (it
must be of length 6, e.g. |
active |
Should this channel be shown in the viewer?
TYPE:
|
coefficient |
Do not change. Omero-channel attribute.
TYPE:
|
inverted |
Do not change. Omero-channel attribute.
TYPE:
|
Source code in fractal_tasks_core/channels.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
valid_hex_color(v)
classmethod
¶
Check that color
is made of exactly six elements which are letters
(a-f or A-F) or digits (0-9).
Source code in fractal_tasks_core/channels.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
Window
¶
Bases: BaseModel
Custom class for Omero-channel window, based on OME-NGFF v0.4.
ATTRIBUTE | DESCRIPTION |
---|---|
min |
Do not change. It will be set to |
max |
Do not change. It will be set according to bit-depth of the images by default (e.g. 65535 for 16 bit images). |
start |
Lower-bound rescaling value for visualization.
TYPE:
|
end |
Upper-bound rescaling value for visualization.
TYPE:
|
Source code in fractal_tasks_core/channels.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
_get_new_unique_value(value, existing_values)
¶
Produce a string value that is not present in a given list
Append _1
, _2
, ... to a given string, if needed, until finding a value
which is not already present in existing_values
.
PARAMETER | DESCRIPTION |
---|---|
value |
The first guess for the new value
TYPE:
|
existing_values |
The list of existing values |
RETURNS | DESCRIPTION |
---|---|
str
|
A string value which is not present in |
Source code in fractal_tasks_core/channels.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
check_unique_wavelength_ids(channels)
¶
Check that the wavelength_id
attributes of a channel list are unique.
PARAMETER | DESCRIPTION |
---|---|
channels |
TBD
TYPE:
|
Source code in fractal_tasks_core/channels.py
152 153 154 155 156 157 158 159 160 161 162 163 |
|
check_well_channel_labels(*, well_zarr_path)
¶
Check that the channel labels for a well are unique.
First identify the channel-labels list for each image in the well, then compare lists and verify their intersection is empty.
PARAMETER | DESCRIPTION |
---|---|
well_zarr_path |
path to an OME-NGFF well zarr group.
TYPE:
|
Source code in fractal_tasks_core/channels.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
define_omero_channels(*, channels, bit_depth, label_prefix=None)
¶
Update a channel list to use it in the OMERO/channels metadata.
Given a list of channel dictionaries, update each one of them by: 1. Adding a label (if missing); 2. Adding a set of OMERO-specific attributes; 3. Discarding all other attributes.
The new_channels
output can be used in the attrs["omero"]["channels"]
attribute of an image group.
PARAMETER | DESCRIPTION |
---|---|
channels |
A list of channel dictionaries (each one must include the
TYPE:
|
bit_depth |
bit depth.
TYPE:
|
label_prefix |
Prefix to be added before the default label. Used e.g. to add a prefix for the acquisition round. |
RETURNS | DESCRIPTION |
---|---|
list[dict[str, Union[str, int, bool, dict[str, int]]]]
|
|
Source code in fractal_tasks_core/channels.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
get_channel_from_image_zarr(*, image_zarr_path, label=None, wavelength_id=None)
¶
Extract a channel from OME-NGFF zarr attributes.
This is a helper function that combines get_omero_channel_list
with
get_channel_from_list
.
PARAMETER | DESCRIPTION |
---|---|
image_zarr_path |
Path to an OME-NGFF image zarr group.
TYPE:
|
label |
|
wavelength_id |
|
RETURNS | DESCRIPTION |
---|---|
OmeroChannel
|
A single channel dictionary. |
Source code in fractal_tasks_core/channels.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
get_channel_from_list(*, channels, label=None, wavelength_id=None)
¶
Find matching channel in a list.
Find the channel that has the required values of label
and/or
wavelength_id
, and identify its positional index (which also
corresponds to its index in the zarr array).
PARAMETER | DESCRIPTION |
---|---|
channels |
A list of channel dictionary, where each channel includes (at
least) the
TYPE:
|
label |
The label to look for in the list of channels. |
wavelength_id |
The wavelength_id to look for in the list of channels. |
RETURNS | DESCRIPTION |
---|---|
OmeroChannel
|
A single channel dictionary. |
Source code in fractal_tasks_core/channels.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
get_omero_channel_list(*, image_zarr_path)
¶
Extract the list of channels from OME-NGFF zarr attributes.
PARAMETER | DESCRIPTION |
---|---|
image_zarr_path |
Path to an OME-NGFF image zarr group.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[OmeroChannel]
|
A list of channel dictionaries. |
Source code in fractal_tasks_core/channels.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
update_omero_channels(old_channels)
¶
Make an existing list of Omero channels Fractal-compatible
The output channels all have keys label
, wavelength_id
and color
;
the wavelength_id
values are unique across the channel list.
See https://ngff.openmicroscopy.org/0.4/index.html#omero-md for the definition of NGFF Omero metadata.
PARAMETER | DESCRIPTION |
---|---|
old_channels |
Existing list of Omero-channel dictionaries |
RETURNS | DESCRIPTION |
---|---|
list[dict[str, Any]]
|
New list of Fractal-compatible Omero-channel dictionaries |
Source code in fractal_tasks_core/channels.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
|