Skip to content

Commit 87deb99

Browse files
fix pre-commit
1 parent 4ace11b commit 87deb99

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

fractal_tasks_core/tasks/cellpose_segmentation.py

+55-16
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def cellpose_segmentation(
174174
# Core parameters
175175
level: int,
176176
channel: CellposeChannel1InputModel,
177-
channel2: CellposeChannel2InputModel = Field(default_factory=CellposeChannel2InputModel),
177+
channel2: CellposeChannel2InputModel = Field(
178+
default_factory=CellposeChannel2InputModel
179+
),
178180
input_ROI_table: str = "FOV_ROI_table",
179181
output_ROI_table: Optional[str] = None,
180182
output_label_name: Optional[str] = None,
@@ -185,7 +187,9 @@ def cellpose_segmentation(
185187
pretrained_model: Optional[str] = None,
186188
relabeling: bool = True,
187189
use_masks: bool = True,
188-
advanced_cellpose_model_params: CellposeModelParams = Field(default_factory=CellposeModelParams),
190+
advanced_cellpose_model_params: CellposeModelParams = Field(
191+
default_factory=CellposeModelParams
192+
),
189193
overwrite: bool = True,
190194
) -> None:
191195
"""
@@ -254,8 +258,13 @@ def cellpose_segmentation(
254258
actual_res_pxl_sizes_zyx = ngff_image_meta.get_pixel_sizes_zyx(level=level)
255259
logger.info(f"NGFF image has {num_levels=}")
256260
logger.info(f"NGFF image has {coarsening_xy=}")
257-
logger.info(f"NGFF image has full-res pixel sizes {full_res_pxl_sizes_zyx}")
258-
logger.info(f"NGFF image has level-{level} pixel sizes " f"{actual_res_pxl_sizes_zyx}")
261+
logger.info(
262+
f"NGFF image has full-res pixel sizes {full_res_pxl_sizes_zyx}"
263+
)
264+
logger.info(
265+
f"NGFF image has level-{level} pixel sizes "
266+
f"{actual_res_pxl_sizes_zyx}"
267+
)
259268

260269
# Find channel index
261270
omero_channel = channel.get_omero_channel(zarr_url)
@@ -292,9 +301,14 @@ def cellpose_segmentation(
292301
ROI_table = ad.read_zarr(ROI_table_path)
293302

294303
# Perform some checks on the ROI table
295-
valid_ROI_table = is_ROI_table_valid(table_path=ROI_table_path, use_masks=use_masks)
304+
valid_ROI_table = is_ROI_table_valid(
305+
table_path=ROI_table_path, use_masks=use_masks
306+
)
296307
if use_masks and not valid_ROI_table:
297-
logger.info(f"ROI table at {ROI_table_path} cannot be used for masked " "loading. Set use_masks=False.")
308+
logger.info(
309+
f"ROI table at {ROI_table_path} cannot be used for masked "
310+
"loading. Set use_masks=False."
311+
)
298312
use_masks = False
299313
logger.info(f"{use_masks=}")
300314

@@ -321,7 +335,9 @@ def cellpose_segmentation(
321335
if do_3D:
322336
if advanced_cellpose_model_params.anisotropy is None:
323337
# Compute anisotropy as pixel_size_z/pixel_size_x
324-
advanced_cellpose_model_params.anisotropy = actual_res_pxl_sizes_zyx[0] / actual_res_pxl_sizes_zyx[2]
338+
advanced_cellpose_model_params.anisotropy = (
339+
actual_res_pxl_sizes_zyx[0] / actual_res_pxl_sizes_zyx[2]
340+
)
325341
logger.info(f"Anisotropy: {advanced_cellpose_model_params.anisotropy}")
326342

327343
# Rescale datasets (only relevant for level>0)
@@ -347,7 +363,11 @@ def cellpose_segmentation(
347363
{
348364
"name": output_label_name,
349365
"version": __OME_NGFF_VERSION__,
350-
"axes": [ax.dict() for ax in ngff_image_meta.multiscale.axes if ax.type != "channel"],
366+
"axes": [
367+
ax.dict()
368+
for ax in ngff_image_meta.multiscale.axes
369+
if ax.type != "channel"
370+
],
351371
"datasets": new_datasets,
352372
}
353373
],
@@ -362,7 +382,9 @@ def cellpose_segmentation(
362382
logger=logger,
363383
)
364384

365-
logger.info(f"Helper function `prepare_label_group` returned {label_group=}")
385+
logger.info(
386+
f"Helper function `prepare_label_group` returned {label_group=}"
387+
)
366388
logger.info(f"Output label path: {zarr_url}/labels/{output_label_name}/0")
367389
store = zarr.storage.FSStore(f"{zarr_url}/labels/{output_label_name}/0")
368390
label_dtype = np.uint32
@@ -384,12 +406,17 @@ def cellpose_segmentation(
384406
dimension_separator="/",
385407
)
386408

387-
logger.info(f"mask will have shape {data_zyx.shape} " f"and chunks {data_zyx.chunks}")
409+
logger.info(
410+
f"mask will have shape {data_zyx.shape} "
411+
f"and chunks {data_zyx.chunks}"
412+
)
388413

389414
# Initialize cellpose
390415
gpu = advanced_cellpose_model_params.use_gpu and cellpose.core.use_gpu()
391416
if pretrained_model:
392-
model = models.CellposeModel(gpu=gpu, pretrained_model=pretrained_model)
417+
model = models.CellposeModel(
418+
gpu=gpu, pretrained_model=pretrained_model
419+
)
393420
else:
394421
model = models.CellposeModel(gpu=gpu, model_type=model_type)
395422

@@ -500,7 +527,9 @@ def cellpose_segmentation(
500527
# Check that total number of labels is under control
501528
if num_labels_tot > np.iinfo(label_dtype).max:
502529
raise ValueError(
503-
"ERROR in re-labeling:" f"Reached {num_labels_tot} labels, " f"but dtype={label_dtype}"
530+
"ERROR in re-labeling:"
531+
f"Reached {num_labels_tot} labels, "
532+
f"but dtype={label_dtype}"
504533
)
505534

506535
if output_ROI_table:
@@ -514,9 +543,13 @@ def cellpose_segmentation(
514543

515544
overlap_list = []
516545
for df in bbox_dataframe_list:
517-
overlap_list.extend(get_overlapping_pairs_3D(df, full_res_pxl_sizes_zyx))
546+
overlap_list.extend(
547+
get_overlapping_pairs_3D(df, full_res_pxl_sizes_zyx)
548+
)
518549
if len(overlap_list) > 0:
519-
logger.warning(f"{len(overlap_list)} bounding-box pairs overlap")
550+
logger.warning(
551+
f"{len(overlap_list)} bounding-box pairs overlap"
552+
)
520553

521554
# Compute and store 0-th level to disk
522555
da.array(new_label_img).to_zarr(
@@ -525,7 +558,10 @@ def cellpose_segmentation(
525558
compute=True,
526559
)
527560

528-
logger.info(f"End cellpose_segmentation task for {zarr_url}, " "now building pyramids.")
561+
logger.info(
562+
f"End cellpose_segmentation task for {zarr_url}, "
563+
"now building pyramids."
564+
)
529565

530566
# Starting from on-disk highest-resolution data, build and write to disk a
531567
# pyramid of coarser levels
@@ -560,7 +596,10 @@ def cellpose_segmentation(
560596

561597
# Write to zarr group
562598
image_group = zarr.group(zarr_url)
563-
logger.info("Now writing bounding-box ROI table to " f"{zarr_url}/tables/{output_ROI_table}")
599+
logger.info(
600+
"Now writing bounding-box ROI table to "
601+
f"{zarr_url}/tables/{output_ROI_table}"
602+
)
564603
table_attrs = {
565604
"type": "masking_roi_table",
566605
"region": {"path": f"../labels/{output_label_name}"},

0 commit comments

Comments
 (0)