Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions poetry.lock.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ version = "0.0.0"
# - or: python = ">=3.10"

[tool.poetry.dependencies]
imcf-fiji-mocks = ">=0.10.0"
imcf-fiji-mocks = ">=0.13.0"
python = ">=2.7"
python-micrometa = "^15.2.2"
sjlogging = ">=0.5.2"
Expand Down
57 changes: 57 additions & 0 deletions src/imcflibs/imagej/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from . import bioformats as bf
from . import prefs

from org.scijava.widget import WidgetStyle
from org.scijava.widget import TextWidget


def show_status(msg):
"""Update the ImageJ status bar and issue a log message.
Expand Down Expand Up @@ -701,3 +704,57 @@ def run_imarisconvert(file_path):
IJ.log("Conversion to .ims is finished.")
else:
IJ.log("Conversion failed with error code: %d" % result)


def save_script_parameters(destination, save_file_name="script_parameters.txt"):
"""Save all Fiji script parameters to a text file.

Parameters
----------
destination : str
Directory where the script parameters file will be saved.
save_file_name : str, optional
Name of the script parameters file, by default "script_parameters.txt".

Notes
-----
This function records all input parameters defined in the Fiji script header
(e.g. `#@ String`) to a text file.

The following parameters are excluded:
- Parameters explicitly declared with `style="password"` are ignored.
- Runtime keys (e.g. 'SJLOG', 'COMMAND', 'RM') are also skipped.
"""
# Get the ScriptModule object from globals made by Fiji
module = globals().get("org.scijava.script.ScriptModule")
if module is None:
IJ.log("No ScriptModule found - skipping saving script parameters.")
return

destination = str(destination)
out_path = os.path.join(destination, save_file_name)

# Access script metadata and inputs
script_info = module.getInfo()
inputs = module.getInputs()

# Keys to skip explicitly
skip_keys = ["USERNAME", "SJLOG", "COMMAND", "RM"]

with open(out_path, "w") as f:
for item in script_info.inputs():
key = item.getName()

# Skip if any keys are in the skip list
if any(skip in key.upper() for skip in skip_keys):
continue

# Skip if parameter is declared with password style
if WidgetStyle.isStyle(item, TextWidget.PASSWORD_STYLE):
continue

if inputs.containsKey(key):
val = inputs.get(key)
f.write("%s: %s\n" % (key, str(val)))

print("Saved script parameters to: %s" % out_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf. #45

9 changes: 9 additions & 0 deletions src/imcflibs/imagej/omerotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def parse_url(client, omero_str):
-------
list(fr.igred.omero.repository.ImageWrapper)
List of ImageWrappers parsed from the string.

Examples
--------
>>> from fr.igred.omero import Client
>>> client = Client()
>>> OMERO_LINK = "123456"
>>> img_wrappers = omerotools.parse_url(client, OMERO_LINK)
>>> for wrapper in img_wrappers:
>>> imp = wpr.toImagePlus(client)
"""
image_ids = []
dataset_ids = []
Expand Down
Loading