Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
86a3447
Add method for associating label images using 3DImageJSuite
lguerard Mar 11, 2025
97084b6
Fix the filtering of objects to use the calibrated method
lguerard Mar 11, 2025
408131c
Use the morpholibj package to 2D dilate labels
lguerard Mar 11, 2025
c542b19
Format imports
lguerard Mar 11, 2025
886613a
Add method to write results to CSV
lguerard Mar 11, 2025
831d771
Add methods for 3D Maxima Finder and 3D Watershed
lguerard Mar 11, 2025
4dc4504
Add processing library to do basic methods
lguerard Mar 11, 2025
6fa4d69
Add methods to get different metadata using bioformats
lguerard Mar 13, 2025
0bdd98e
Update method to support NaN (discarding them) and rounding results
lguerard Mar 13, 2025
34d5880
Add method to save in different file format
lguerard Mar 13, 2025
15bc0c4
Add method to pad a string
lguerard Mar 13, 2025
6189088
Add methods to find imaris and convert an image to IMS
lguerard Mar 13, 2025
272df1f
Add missing imports and formatting
lguerard Mar 13, 2025
c1a9332
Add methods to get different metadata from OMERO
lguerard Mar 13, 2025
05e6a2e
Add method to delete annotation from OMERO
lguerard Mar 13, 2025
fae0930
Add methods to save an OMERO.table
lguerard Mar 13, 2025
de5c84a
Add method to save IJ-ROIs to OMERO
lguerard Mar 13, 2025
16dd961
Add missing imports and formatting
lguerard Mar 13, 2025
04a9f84
Formatting
lguerard Mar 13, 2025
8a041de
Use `imp` instead of `imageplus`
lguerard Mar 19, 2025
309360f
Improve method name and docstring
lguerard Mar 19, 2025
170ac0c
Improve method name and docstring
lguerard Mar 19, 2025
cca38ba
Add missing import
lguerard Mar 19, 2025
e858900
Change method to use the one added to pathtools
lguerard Mar 19, 2025
b42cec3
Formatting
lguerard Mar 19, 2025
184a943
Update the formatting
lguerard Mar 19, 2025
f072877
Merge branch 'devel' into coding-session/2025-03-11
ehrenfeu Mar 19, 2025
54ee5f9
Format docstring's Returns `dict`
ehrenfeu Mar 19, 2025
88ee3a8
Add back `create_directory` with better docstring
lguerard Mar 19, 2025
7466838
Fix linting
lguerard Mar 19, 2025
5bea0ad
Formatting
lguerard Mar 19, 2025
0e81c37
Fix linting issues
lguerard Mar 19, 2025
1b222d0
Update docstring of write_ordereddict_to_csv()
ehrenfeu Mar 19, 2025
f9375c5
Rework docstring
ehrenfeu Mar 19, 2025
e99dcdb
Update docstring of locate_latest_imaris()
ehrenfeu Mar 19, 2025
d2a4991
Improve docstring
ehrenfeu Mar 19, 2025
6eb32db
Improve docstring
ehrenfeu Mar 19, 2025
bfbe585
Shorten docstring
ehrenfeu Mar 19, 2025
18131a8
Update dependency for mocks to 0.8.0.a0
ehrenfeu Mar 20, 2025
b3110ec
Merge branch 'devel' into coding-session/2025-03-11
ehrenfeu Mar 20, 2025
b520c28
Revert "Fix linting issues"
lguerard Mar 24, 2025
2b6a8d8
Revert "Formatting"
lguerard Mar 24, 2025
82b8683
Revert "Fix linting"
lguerard Mar 24, 2025
ebb1413
Rename functions
lguerard Mar 24, 2025
b59b597
Change returns to use dictionaries instead
lguerard Mar 24, 2025
98b9ca8
Change input variable name
lguerard Mar 24, 2025
14d2efc
Use logging instead
lguerard Mar 24, 2025
0045e65
Format using Ruff
lguerard Mar 24, 2025
0ff3433
Add comments and notes to docstring, fix missing inputs
lguerard Mar 24, 2025
74ffe42
Change output to inform if command has failed
lguerard Mar 24, 2025
a094dc9
Change method to return faster in case of empty list
lguerard Mar 24, 2025
25ee6ed
Add module docstring for ImageJ processing utilities
lguerard Mar 24, 2025
00dc641
Move minor implementation detail into code comment
ehrenfeu Mar 25, 2025
51248a4
Docstring cleanups
ehrenfeu Mar 25, 2025
d81e682
Shorten docstring example
ehrenfeu Mar 25, 2025
6b641bb
Indent to show as a fixed-width block
ehrenfeu Mar 25, 2025
51f2cec
One example should be enough
ehrenfeu Mar 25, 2025
a65fe41
Add empty line to fix docstring rendering
ehrenfeu Mar 25, 2025
c35e312
Run black formatting (restore default line length of 88)
ehrenfeu Mar 25, 2025
caa1370
Notes section comes before Examples
ehrenfeu Mar 25, 2025
99ab0f0
Minor updates on Notes section
ehrenfeu Mar 25, 2025
07f3064
Update function details
ehrenfeu Mar 25, 2025
4333086
Place Notes section after Returns
ehrenfeu Mar 25, 2025
ec158ff
Docstring conventions
ehrenfeu Mar 25, 2025
047d913
Docstring conventions
ehrenfeu Mar 25, 2025
98cfaff
Reformat dict in Returns section
ehrenfeu Mar 25, 2025
f0a1c9c
Merge branch 'devel' into pr/laurent/coding-session/2025-03-11
ehrenfeu Mar 25, 2025
8cef7bf
Merge branch 'devel' into pr/laurent/coding-session/2025-03-11
ehrenfeu Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/imcflibs/imagej/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
-----
`ij.IJ.showProgress` internally increments the given `cur` value by 1.
"""
log.info(

Check warning on line 46 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L46

Added line #L46 was not covered by tests
"Progress: %s / %s (%s)", cur + 1, final, (1.0 + cur) / final
)
IJ.showProgress(cur, final)
Expand Down Expand Up @@ -82,7 +82,7 @@

hours, rem = divmod(end - start, 3600)
minutes, seconds = divmod(rem, 60)
return "{:0>2}:{:0>2}:{:05.2f}".format(

Check warning on line 85 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L85

Added line #L85 was not covered by tests
int(hours), int(minutes), seconds
)

Expand Down Expand Up @@ -120,18 +120,20 @@
tuple of (float, float)
Mean and standard deviation of the input list.
"""
filtered_list = filter(None, values_list)
filtered_list = [x for x in values_list if x is not None]

Check warning on line 123 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L123

Added line #L123 was not covered by tests

try:
mean = round(
sum(filtered_list) / len(filtered_list), round_decimals
)
except ZeroDivisionError:
mean = 0
tot = 0.0
for x in filtered_list:
tot = tot + (x - mean) ** 2
return [mean, (tot / (len(filtered_list))) ** 0.5]
if not filtered_list:
return 0, 0

Check warning on line 126 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L125-L126

Added lines #L125 - L126 were not covered by tests

mean = round(

Check warning on line 128 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L128

Added line #L128 was not covered by tests
sum(filtered_list) / len(filtered_list), round_decimals
)
variance = sum((x - mean) ** 2 for x in filtered_list) / len(

Check warning on line 131 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L131

Added line #L131 was not covered by tests
filtered_list
)
std_dev = round(variance**0.5, round_decimals)

Check warning on line 134 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L134

Added line #L134 was not covered by tests

return mean, std_dev

Check warning on line 136 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L136

Added line #L136 was not covered by tests
Comment thread
ehrenfeu marked this conversation as resolved.


def find_focus(imp):
Expand Down Expand Up @@ -166,7 +168,7 @@
# Check if more than 1 channel
# FUTURE Could be improved for multi channel
if imp_dimensions[2] != 1:
sys.exit(

Check warning on line 171 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L171

Added line #L171 was not covered by tests
"Image has more than one channel, please reduce dimensionality"
)

Expand All @@ -184,7 +186,7 @@
# pix_array = pix_array*pix_array

sumpix_array = sum(pix_array)
var = sumpix_array / (

Check warning on line 189 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L189

Added line #L189 was not covered by tests
imp_dimensions[0] * imp_dimensions[1] * mean
)

Expand Down Expand Up @@ -215,12 +217,12 @@

# Ensure the sender and server are configured from Prefs
if not sender:
log.info(

Check warning on line 220 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L220

Added line #L220 was not covered by tests
"Sender email is not configured. Please check IJ_Prefs.txt."
)
return
if not server:
log.info(

Check warning on line 225 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L225

Added line #L225 was not covered by tests
"SMTP server is not configured. Please check IJ_Prefs.txt."
)
return
Expand Down Expand Up @@ -303,7 +305,7 @@
Flag to request the formatted string to be returned instead of printing
it to the log. By default False.
"""
formatted = (

Check warning on line 308 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L308

Added line #L308 was not covered by tests
time.strftime("%H:%M:%S", time.localtime())
+ ": "
+ message
Expand Down Expand Up @@ -505,21 +507,21 @@
"""

# Check if the output file exists
if not os.path.exists(out_file):

Check warning on line 510 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L510

Added line #L510 was not covered by tests
# If the file does not exist, create it and write the header
with open(out_file, "wb") as f:
dict_writer = csv.DictWriter(

Check warning on line 513 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L512-L513

Added lines #L512 - L513 were not covered by tests
f, content[0].keys(), delimiter=";"
)
dict_writer.writeheader()
dict_writer.writerows(content)

Check warning on line 517 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L516-L517

Added lines #L516 - L517 were not covered by tests
else:
# If the file exists, append the results
with open(out_file, "ab") as f:
dict_writer = csv.DictWriter(

Check warning on line 521 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L520-L521

Added lines #L520 - L521 were not covered by tests
f, content[0].keys(), delimiter=";"
)
dict_writer.writerows(content)

Check warning on line 524 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L524

Added line #L524 was not covered by tests


def save_image_in_format(
Expand Down Expand Up @@ -583,20 +585,20 @@
# /output/path/C2/image_title_series_001.ome.tif
"""

out_ext = {}
out_ext["ImageJ-TIF"] = ".tif"
out_ext["ICS-1"] = ".ids"
out_ext["ICS-2"] = ".ics"
out_ext["OME-TIFF"] = ".ome.tif"
out_ext["CellH5"] = ".ch5"
out_ext["BMP"] = ".bmp"

Check warning on line 594 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L588-L594

Added lines #L588 - L594 were not covered by tests

imp_to_use = []
dir_to_save = []

Check warning on line 597 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L596-L597

Added lines #L596 - L597 were not covered by tests

if split_channels:
for channel in range(1, imp.getNChannels() + 1):
imp_to_use.append(

Check warning on line 601 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L599-L601

Added lines #L599 - L601 were not covered by tests
Duplicator().run(
imp,
channel,
Expand All @@ -607,34 +609,34 @@
imp.getNFrames(),
)
)
dir_to_save.append(

Check warning on line 612 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L612

Added line #L612 was not covered by tests
os.path.join(out_dir, "C" + str(channel))
)
else:
imp_to_use.append(imp)
dir_to_save.append(out_dir)

Check warning on line 617 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L616-L617

Added lines #L616 - L617 were not covered by tests

for index, current_imp in enumerate(imp_to_use):
basename = imp.getShortTitle()

Check warning on line 620 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L619-L620

Added lines #L619 - L620 were not covered by tests

out_path = os.path.join(

Check warning on line 622 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L622

Added line #L622 was not covered by tests
dir_to_save[index],
basename + "_series_" + str(series).zfill(pad_number),
)

if format == "ImageJ-TIF":
pathtools.create_directory(dir_to_save[index])
IJ.saveAs(current_imp, "Tiff", out_path + ".tif")

Check warning on line 629 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L627-L629

Added lines #L627 - L629 were not covered by tests

elif format == "BMP":
out_folder = os.path.join(out_dir, basename + os.path.sep)
pathtools.create_directory(out_folder)
StackWriter.save(current_imp, out_folder, "format=bmp")

Check warning on line 634 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L631-L634

Added lines #L631 - L634 were not covered by tests

else:
bf.export(current_imp, out_path + out_ext[format])

Check warning on line 637 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L637

Added line #L637 was not covered by tests

current_imp.close()

Check warning on line 639 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L639

Added line #L639 was not covered by tests


def pad_number(index, pad_length=2):
Expand All @@ -659,7 +661,7 @@
>>> pad_number(42, 4)
'0042'
"""
return str(index).zfill(pad_length)

Check warning on line 664 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L664

Added line #L664 was not covered by tests


def locate_latest_imaris(paths_to_check=None):
Expand All @@ -679,22 +681,22 @@
-------
str
"""
if not paths_to_check:
paths_to_check = [

Check warning on line 685 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L684-L685

Added lines #L684 - L685 were not covered by tests
r"C:\Program Files\Bitplane\ImarisFileConverter ",
r"C:\Program Files\Bitplane\Imaris ",
]

imaris_paths = [""]

Check warning on line 690 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L690

Added line #L690 was not covered by tests

for check in paths_to_check:
hits = glob.glob(check + "*")
imaris_paths += sorted(

Check warning on line 694 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L692-L694

Added lines #L692 - L694 were not covered by tests
hits,
key=lambda x: float(x.replace(check, "").replace(".", "")),
)

return imaris_paths[-1]

Check warning on line 699 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L699

Added line #L699 was not covered by tests


def run_imarisconvert(file_path):
Expand All @@ -718,21 +720,21 @@

"""

path_root, file_extension = os.path.splitext(file_path)
if file_extension == ".ids":
file_extension = ".ics"
file_path = path_root + file_extension

Check warning on line 726 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L723-L726

Added lines #L723 - L726 were not covered by tests

imaris_path = locate_latest_imaris()

Check warning on line 728 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L728

Added line #L728 was not covered by tests

command = 'ImarisConvert.exe -i "%s" -of Imaris5 -o "%s"' % (

Check warning on line 730 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L730

Added line #L730 was not covered by tests
file_path,
file_path.replace(file_extension, ".ims"),
)
log.debug("\n%s" % command)
IJ.log("Converting to Imaris5 .ims...")
Comment thread
ehrenfeu marked this conversation as resolved.
result = subprocess.call(command, shell=True, cwd=imaris_path)
if result == 0:
IJ.log("Conversion to .ims is finished")

Check warning on line 738 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L734-L738

Added lines #L734 - L738 were not covered by tests
else:
IJ.log("Conversion failed with error code: %d" % result)

Check warning on line 740 in src/imcflibs/imagej/misc.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/misc.py#L740

Added line #L740 was not covered by tests
Loading