Skip to content

Commit c276511

Browse files
authored
Merge pull request #100 from lguerard/imaris_convert_location
Add option to save IMS file in a specified location
2 parents 4f26f83 + 1a0f954 commit c276511

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def locate_latest_imaris(paths_to_check=None):
681681
return imaris_paths[-1]
682682

683683

684-
def run_imarisconvert(file_path, pixel_calibration=None):
684+
def run_imarisconvert(file_path, pixel_calibration=None, output_folder=""):
685685
"""Convert a given file to Imaris format using ImarisConvert.
686686
687687
Convert the input image file to Imaris format (Imaris5) using the
@@ -693,8 +693,18 @@ def run_imarisconvert(file_path, pixel_calibration=None):
693693
file_path : str
694694
Absolute path to the input image file.
695695
pixel_calibration : tuple or list, optional
696-
Sequence of 3 values (x, y, z) representing voxel dimensions to be set during
697-
conversion, by default None.
696+
Sequence of 3 values (x, y, z) representing voxel dimensions to be set
697+
during conversion, by default None.
698+
output_folder : str, optional
699+
Folder where the newly created IMS file will be saved. If empty (or not
700+
supplied), the directory of the input file will be used.
701+
702+
Notes
703+
-----
704+
- The output filename is constructed by replacing extension of the input
705+
filename with `.ims` (e.g. `/path/to/image.czi` -> `/path/to/image.ims`).
706+
- If the input has an `.ids` extension (part of an ICS-1 pair), the
707+
corresponding `.ics` file is used instead.
698708
"""
699709
# in case the given file has the suffix `.ids` (meaning it is part of an
700710
# ICS-1 `.ics`+`.ids` pair), point ImarisConvert to the `.ics` file instead:
@@ -705,9 +715,12 @@ def run_imarisconvert(file_path, pixel_calibration=None):
705715

706716
imaris_path = locate_latest_imaris()
707717

718+
if not output_folder:
719+
output_folder = os.path.dirname(file_path)
720+
708721
command = 'ImarisConvert.exe -i "%s" -of Imaris5 -o "%s"' % (
709722
file_path,
710-
file_path.replace(file_extension, ".ims"),
723+
os.path.join(output_folder, file_path.replace(file_extension, ".ims")),
711724
)
712725
if pixel_calibration:
713726
command = command + " --voxelsizex %s --voxelsizey %s --voxelsizez %s" % (
@@ -720,9 +733,9 @@ def run_imarisconvert(file_path, pixel_calibration=None):
720733
timed_log("Converting to Imaris5 .ims...")
721734
result = subprocess.call(command, shell=True, cwd=imaris_path)
722735
if result == 0:
723-
timed_log("Conversion to .ims is finished.")
736+
timed_log("Conversion to .ims is finished: %s" % file_path)
724737
else:
725-
timed_log("Conversion failed with error code: %d" % result)
738+
timed_log("Error converting [%s]: %d" % (file_path, result))
726739

727740

728741
def save_script_parameters(destination, save_file_name="script_parameters.txt"):

0 commit comments

Comments
 (0)