Skip to content

Commit c35e312

Browse files
committed
Run black formatting (restore default line length of 88)
1 parent a65fe41 commit c35e312

8 files changed

Lines changed: 51 additions & 160 deletions

File tree

src/imcflibs/imagej/bioformats.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ def export(imp, filename, overwrite=False):
159159
log.debug("Detected calibration unit: %s", unit)
160160
except Exception as err:
161161
log.error("Unable to detect spatial unit: %s", err)
162-
raise RuntimeError(
163-
"Error detecting image calibration: %s" % err
164-
)
162+
raise RuntimeError("Error detecting image calibration: %s" % err)
165163
if unit == "pixel" and (suffix == "ics" or suffix == "ids"):
166164
log.warn(
167165
"Forcing unit to be 'm' instead of 'pixel' to avoid "
@@ -178,9 +176,7 @@ def export(imp, filename, overwrite=False):
178176
log.debug("Exporting finished.")
179177

180178

181-
def export_using_orig_name(
182-
imp, path, orig_name, tag, suffix, overwrite=False
183-
):
179+
def export_using_orig_name(imp, path, orig_name, tag, suffix, overwrite=False):
184180
"""Export an image to a given path, deriving the name from the input file.
185181
186182
The input filename is stripped to its pure file name, without any path or
@@ -442,12 +438,8 @@ def get_stage_coords(source, filenames):
442438
log.debug("no z calibration found, trying to recover")
443439
first_plane = omeMeta.getPlanePositionZ(0, 0)
444440
next_plane_imagenumber = frame_size_c + frame_size_t - 1
445-
second_plane = omeMeta.getPlanePositionZ(
446-
0, next_plane_imagenumber
447-
)
448-
z_interval = abs(
449-
abs(first_plane.value()) - abs(second_plane.value())
450-
)
441+
second_plane = omeMeta.getPlanePositionZ(0, next_plane_imagenumber)
442+
z_interval = abs(abs(first_plane.value()) - abs(second_plane.value()))
451443
log.debug("z-interval seems to be: " + str(z_interval))
452444

453445
# create an image calibration
@@ -480,14 +472,12 @@ def get_stage_coords(source, filenames):
480472

481473
physSizeX_max = (
482474
physSizeX.value()
483-
if physSizeX.value()
484-
>= omeMeta.getPixelsPhysicalSizeX(series).value()
475+
if physSizeX.value() >= omeMeta.getPixelsPhysicalSizeX(series).value()
485476
else omeMeta.getPixelsPhysicalSizeX(series).value()
486477
)
487478
physSizeY_max = (
488479
physSizeY.value()
489-
if physSizeY.value()
490-
>= omeMeta.getPixelsPhysicalSizeY(series).value()
480+
if physSizeY.value() >= omeMeta.getPixelsPhysicalSizeY(series).value()
491481
else omeMeta.getPixelsPhysicalSizeY(series).value()
492482
)
493483
if omeMeta.getPixelsPhysicalSizeZ(series):
@@ -506,9 +496,7 @@ def get_stage_coords(source, filenames):
506496
pos_y = current_position_y.value()
507497

508498
if current_position_z is None:
509-
log.debug(
510-
"the z-position is missing in the ome-xml metadata."
511-
)
499+
log.debug("the z-position is missing in the ome-xml metadata.")
512500
pos_z = 1.0
513501
else:
514502
pos_z = current_position_z.value()
@@ -531,9 +519,7 @@ def get_stage_coords(source, filenames):
531519
rel_pos_y = (
532520
stage_coordinates_y[i] - stage_coordinates_y[0]
533521
) / physSizeY.value()
534-
rel_pos_z = (
535-
stage_coordinates_z[i] - stage_coordinates_z[0]
536-
) / z_interval
522+
rel_pos_z = (stage_coordinates_z[i] - stage_coordinates_z[0]) / z_interval
537523

538524
relative_coordinates_x_px.append(rel_pos_x)
539525
relative_coordinates_y_px.append(rel_pos_y)

src/imcflibs/imagej/labelimage.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def label_image_to_roi_list(label_image, low_thresh=None):
3131
max_value = 0
3232

3333
for slice in range(1, label_image.getNSlices() + 1):
34-
label_image_slice = Duplicator().run(
35-
label_image, 1, 1, slice, slice, 1, 1
36-
)
34+
label_image_slice = Duplicator().run(label_image, 1, 1, slice, slice, 1, 1)
3735

3836
image_processor = label_image_slice.getProcessor()
3937
pixels = image_processor.getFloatArray()
@@ -59,9 +57,7 @@ def label_image_to_roi_list(label_image, low_thresh=None):
5957
elif value == 0:
6058
continue
6159
# print(value)
62-
float_processor.setThreshold(
63-
value, value, ImageProcessor.NO_LUT_UPDATE
64-
)
60+
float_processor.setThreshold(value, value, ImageProcessor.NO_LUT_UPDATE)
6561
roi = ThresholdToSelection.run(img_float_copy)
6662
roi.setName(str(value))
6763
roi.setPosition(slice)
@@ -98,9 +94,7 @@ def cookie_cut_labels(label_image_ref, label_image_to_relate):
9894
Prefs.blackBackground = True
9995
IJ.run(imp_dup, "Convert to Mask", "")
10096
IJ.run(imp_dup, "Divide...", "value=255")
101-
return ImageCalculator.run(
102-
label_image_ref, imp_dup, "Multiply create"
103-
)
97+
return ImageCalculator.run(label_image_ref, imp_dup, "Multiply create")
10498

10599

106100
def relate_label_images(outer_label_imp, inner_label_imp):
@@ -203,9 +197,7 @@ def measure_objects_size_shape_2d(label_image):
203197
return regions.process(label_image)
204198

205199

206-
def binary_to_label(
207-
imp, title, min_thresh=1, min_vol=None, max_vol=None
208-
):
200+
def binary_to_label(imp, title, min_thresh=1, min_vol=None, max_vol=None):
209201
"""Segment a binary image to get a label image (2D/3D).
210202
211203
Works on: 2D and 3D binary data.
@@ -286,14 +278,10 @@ def dilate_labels_2d(imp, dilation_radius):
286278
# Iterate over each slice of the input ImagePlus
287279
for i in range(1, imp.getNSlices() + 1):
288280
# Duplicate the current slice
289-
current_imp = Duplicator().run(
290-
imp, 1, 1, i, imp.getNSlices(), 1, 1
291-
)
281+
current_imp = Duplicator().run(imp, 1, 1, i, imp.getNSlices(), 1, 1)
292282

293283
# Perform a dilation of the labels in the current slice
294-
dilated_labels_imp = li.dilateLabels(
295-
current_imp, dilation_radius
296-
)
284+
dilated_labels_imp = li.dilateLabels(current_imp, dilation_radius)
297285

298286
# Append the dilated labels to the list
299287
dilated_labels_list.append(dilated_labels_imp)

src/imcflibs/imagej/misc.py

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def show_progress(cur, final):
4343
-----
4444
`ij.IJ.showProgress` internally increments the given `cur` value by 1.
4545
"""
46-
log.info(
47-
"Progress: %s / %s (%s)", cur + 1, final, (1.0 + cur) / final
48-
)
46+
log.info("Progress: %s / %s (%s)", cur + 1, final, (1.0 + cur) / final)
4947
IJ.showProgress(cur, final)
5048

5149

@@ -82,9 +80,7 @@ def elapsed_time_since(start, end=None):
8280

8381
hours, rem = divmod(end - start, 3600)
8482
minutes, seconds = divmod(rem, 60)
85-
return "{:0>2}:{:0>2}:{:05.2f}".format(
86-
int(hours), int(minutes), seconds
87-
)
83+
return "{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), seconds)
8884

8985

9086
def percentage(part, whole):
@@ -125,13 +121,9 @@ def calculate_mean_and_stdv(values_list, round_decimals=0):
125121
if not filtered_list:
126122
return 0, 0
127123

128-
mean = round(
129-
sum(filtered_list) / len(filtered_list), round_decimals
130-
)
131-
variance = sum((x - mean) ** 2 for x in filtered_list) / len(
132-
filtered_list
133-
)
134-
std_dev = round(variance**0.5, round_decimals)
124+
mean = round(sum(filtered_list) / len(filtered_list), round_decimals)
125+
variance = sum((x - mean) ** 2 for x in filtered_list) / len(filtered_list)
126+
std_dev = round(variance ** 0.5, round_decimals)
135127

136128
return mean, std_dev
137129

@@ -168,9 +160,7 @@ def find_focus(imp):
168160
# Check if more than 1 channel
169161
# FUTURE Could be improved for multi channel
170162
if imp_dimensions[2] != 1:
171-
sys.exit(
172-
"Image has more than one channel, please reduce dimensionality"
173-
)
163+
sys.exit("Image has more than one channel, please reduce dimensionality")
174164

175165
# Loop through each time point
176166
for plane in range(1, imp_dimensions[4] + 1):
@@ -186,9 +176,7 @@ def find_focus(imp):
186176
# pix_array = pix_array*pix_array
187177

188178
sumpix_array = sum(pix_array)
189-
var = sumpix_array / (
190-
imp_dimensions[0] * imp_dimensions[1] * mean
191-
)
179+
var = sumpix_array / (imp_dimensions[0] * imp_dimensions[1] * mean)
192180

193181
if var > norm_var:
194182
norm_var = var
@@ -217,14 +205,10 @@ def send_mail(job_name, recipient, filename, total_execution_time):
217205

218206
# Ensure the sender and server are configured from Prefs
219207
if not sender:
220-
log.info(
221-
"Sender email is not configured. Please check IJ_Prefs.txt."
222-
)
208+
log.info("Sender email is not configured. Please check IJ_Prefs.txt.")
223209
return
224210
if not server:
225-
log.info(
226-
"SMTP server is not configured. Please check IJ_Prefs.txt."
227-
)
211+
log.info("SMTP server is not configured. Please check IJ_Prefs.txt.")
228212
return
229213

230214
# Ensure the recipient is provided
@@ -305,12 +289,7 @@ def timed_log(message, as_string=False):
305289
Flag to request the formatted string to be returned instead of printing
306290
it to the log. By default False.
307291
"""
308-
formatted = (
309-
time.strftime("%H:%M:%S", time.localtime())
310-
+ ": "
311-
+ message
312-
+ " "
313-
)
292+
formatted = time.strftime("%H:%M:%S", time.localtime()) + ": " + message + " "
314293
if as_string:
315294
return formatted
316295
IJ.log(formatted)
@@ -497,23 +476,17 @@ def write_ordereddict_to_csv(out_file, content):
497476
if not os.path.exists(out_file):
498477
# If the file does not exist, create it and write the header
499478
with open(out_file, "wb") as f:
500-
dict_writer = csv.DictWriter(
501-
f, content[0].keys(), delimiter=";"
502-
)
479+
dict_writer = csv.DictWriter(f, content[0].keys(), delimiter=";")
503480
dict_writer.writeheader()
504481
dict_writer.writerows(content)
505482
else:
506483
# If the file exists, append the results
507484
with open(out_file, "ab") as f:
508-
dict_writer = csv.DictWriter(
509-
f, content[0].keys(), delimiter=";"
510-
)
485+
dict_writer = csv.DictWriter(f, content[0].keys(), delimiter=";")
511486
dict_writer.writerows(content)
512487

513488

514-
def save_image_in_format(
515-
imp, format, out_dir, series, pad_number, split_channels
516-
):
489+
def save_image_in_format(imp, format, out_dir, series, pad_number, split_channels):
517490
"""Save an ImagePlus object in the specified format.
518491
519492
This function provides flexible options for saving ImageJ images in various
@@ -596,9 +569,7 @@ def save_image_in_format(
596569
imp.getNFrames(),
597570
)
598571
)
599-
dir_to_save.append(
600-
os.path.join(out_dir, "C" + str(channel))
601-
)
572+
dir_to_save.append(os.path.join(out_dir, "C" + str(channel)))
602573
else:
603574
imp_to_use.append(imp)
604575
dir_to_save.append(out_dir)

src/imcflibs/imagej/objects3d.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def imgplus_to_population3d(imp):
7575
return Objects3DPopulation(img)
7676

7777

78-
def segment_3d_image(
79-
imp, title=None, min_thresh=1, min_vol=None, max_vol=None
80-
):
78+
def segment_3d_image(imp, title=None, min_thresh=1, min_vol=None, max_vol=None):
8179
"""Segment a 3D binary image to get a labelled stack.
8280
8381
Parameters
@@ -123,9 +121,7 @@ def segment_3d_image(
123121
return seg.getImagePlus()
124122

125123

126-
def get_objects_within_intensity(
127-
obj_pop, imp, min_intensity, max_intensity
128-
):
124+
def get_objects_within_intensity(obj_pop, imp, min_intensity, max_intensity):
129125
"""Filter a population for objects within the given intensity range.
130126
131127
Parameters
@@ -152,10 +148,7 @@ def get_objects_within_intensity(
152148
# Calculate the mean intensity of the object
153149
mean_intensity = obj.getPixMeanValue(ImageHandler.wrap(imp))
154150
# Check if the object is within the specified intensity range
155-
if (
156-
mean_intensity >= min_intensity
157-
and mean_intensity < max_intensity
158-
):
151+
if mean_intensity >= min_intensity and mean_intensity < max_intensity:
159152
objects_within_intensity.append(obj)
160153

161154
# Return the new population with the filtered objects
@@ -239,9 +232,7 @@ def seeded_watershed(imp_binary, imp_peaks, threshold=10):
239232
img_seed = ImagePlusAdapter.convertFloat(imp_peaks).copy()
240233

241234
if threshold:
242-
watersheded_result = WatershedLabeling.watershed(
243-
img, img_seed, threshold
244-
)
235+
watersheded_result = WatershedLabeling.watershed(img, img_seed, threshold)
245236
else:
246237
watersheded_result = WatershedLabeling.watershed(img, img_seed)
247238

0 commit comments

Comments
 (0)