@@ -174,7 +174,9 @@ def cellpose_segmentation(
174
174
# Core parameters
175
175
level : int ,
176
176
channel : CellposeChannel1InputModel ,
177
- channel2 : CellposeChannel2InputModel = Field (default_factory = CellposeChannel2InputModel ),
177
+ channel2 : CellposeChannel2InputModel = Field (
178
+ default_factory = CellposeChannel2InputModel
179
+ ),
178
180
input_ROI_table : str = "FOV_ROI_table" ,
179
181
output_ROI_table : Optional [str ] = None ,
180
182
output_label_name : Optional [str ] = None ,
@@ -185,7 +187,9 @@ def cellpose_segmentation(
185
187
pretrained_model : Optional [str ] = None ,
186
188
relabeling : bool = True ,
187
189
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
+ ),
189
193
overwrite : bool = True ,
190
194
) -> None :
191
195
"""
@@ -254,8 +258,13 @@ def cellpose_segmentation(
254
258
actual_res_pxl_sizes_zyx = ngff_image_meta .get_pixel_sizes_zyx (level = level )
255
259
logger .info (f"NGFF image has { num_levels = } " )
256
260
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
+ )
259
268
260
269
# Find channel index
261
270
omero_channel = channel .get_omero_channel (zarr_url )
@@ -292,9 +301,14 @@ def cellpose_segmentation(
292
301
ROI_table = ad .read_zarr (ROI_table_path )
293
302
294
303
# 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
+ )
296
307
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
+ )
298
312
use_masks = False
299
313
logger .info (f"{ use_masks = } " )
300
314
@@ -321,7 +335,9 @@ def cellpose_segmentation(
321
335
if do_3D :
322
336
if advanced_cellpose_model_params .anisotropy is None :
323
337
# 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
+ )
325
341
logger .info (f"Anisotropy: { advanced_cellpose_model_params .anisotropy } " )
326
342
327
343
# Rescale datasets (only relevant for level>0)
@@ -347,7 +363,11 @@ def cellpose_segmentation(
347
363
{
348
364
"name" : output_label_name ,
349
365
"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
+ ],
351
371
"datasets" : new_datasets ,
352
372
}
353
373
],
@@ -362,7 +382,9 @@ def cellpose_segmentation(
362
382
logger = logger ,
363
383
)
364
384
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
+ )
366
388
logger .info (f"Output label path: { zarr_url } /labels/{ output_label_name } /0" )
367
389
store = zarr .storage .FSStore (f"{ zarr_url } /labels/{ output_label_name } /0" )
368
390
label_dtype = np .uint32
@@ -384,12 +406,17 @@ def cellpose_segmentation(
384
406
dimension_separator = "/" ,
385
407
)
386
408
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
+ )
388
413
389
414
# Initialize cellpose
390
415
gpu = advanced_cellpose_model_params .use_gpu and cellpose .core .use_gpu ()
391
416
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
+ )
393
420
else :
394
421
model = models .CellposeModel (gpu = gpu , model_type = model_type )
395
422
@@ -500,7 +527,9 @@ def cellpose_segmentation(
500
527
# Check that total number of labels is under control
501
528
if num_labels_tot > np .iinfo (label_dtype ).max :
502
529
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 } "
504
533
)
505
534
506
535
if output_ROI_table :
@@ -514,9 +543,13 @@ def cellpose_segmentation(
514
543
515
544
overlap_list = []
516
545
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
+ )
518
549
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
+ )
520
553
521
554
# Compute and store 0-th level to disk
522
555
da .array (new_label_img ).to_zarr (
@@ -525,7 +558,10 @@ def cellpose_segmentation(
525
558
compute = True ,
526
559
)
527
560
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
+ )
529
565
530
566
# Starting from on-disk highest-resolution data, build and write to disk a
531
567
# pyramid of coarser levels
@@ -560,7 +596,10 @@ def cellpose_segmentation(
560
596
561
597
# Write to zarr group
562
598
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
+ )
564
603
table_attrs = {
565
604
"type" : "masking_roi_table" ,
566
605
"region" : {"path" : f"../labels/{ output_label_name } " },
0 commit comments