Skip to content

Commit 499526c

Browse files
authored
Merge pull request #111 from rohangirishrao/master
Add method to save Fiji script parameters, and add example to opening an image
2 parents 6cb1c87 + 8145904 commit 499526c

5 files changed

Lines changed: 80 additions & 5 deletions

File tree

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poetry.lock.md

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ version = "0.0.0"
2020
# - or: python = ">=3.10"
2121

2222
[tool.poetry.dependencies]
23-
imcf-fiji-mocks = ">=0.10.0"
23+
imcf-fiji-mocks = ">=0.13.0"
2424
python = ">=2.7"
2525
python-micrometa = "^15.2.2"
2626
sjlogging = ">=0.5.2"

src/imcflibs/imagej/misc.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from . import bioformats as bf
1717
from . import prefs
1818

19+
from org.scijava.widget import WidgetStyle
20+
from org.scijava.widget import TextWidget
21+
1922

2023
def show_status(msg):
2124
"""Update the ImageJ status bar and issue a log message.
@@ -713,3 +716,57 @@ def run_imarisconvert(file_path, pixel_calibration=None):
713716
IJ.log("Conversion to .ims is finished.")
714717
else:
715718
IJ.log("Conversion failed with error code: %d" % result)
719+
720+
721+
def save_script_parameters(destination, save_file_name="script_parameters.txt"):
722+
"""Save all Fiji script parameters to a text file.
723+
724+
Parameters
725+
----------
726+
destination : str
727+
Directory where the script parameters file will be saved.
728+
save_file_name : str, optional
729+
Name of the script parameters file, by default "script_parameters.txt".
730+
731+
Notes
732+
-----
733+
This function records all input parameters defined in the Fiji script header
734+
(e.g. `#@ String`) to a text file.
735+
736+
The following parameters are excluded:
737+
- Parameters explicitly declared with `style="password"` are ignored.
738+
- Runtime keys (e.g. 'SJLOG', 'COMMAND', 'RM') are also skipped.
739+
"""
740+
# Get the ScriptModule object from globals made by Fiji
741+
module = globals().get("org.scijava.script.ScriptModule")
742+
if module is None:
743+
IJ.log("No ScriptModule found - skipping saving script parameters.")
744+
return
745+
746+
destination = str(destination)
747+
out_path = os.path.join(destination, save_file_name)
748+
749+
# Access script metadata and inputs
750+
script_info = module.getInfo()
751+
inputs = module.getInputs()
752+
753+
# Keys to skip explicitly
754+
skip_keys = ["USERNAME", "SJLOG", "COMMAND", "RM"]
755+
756+
with open(out_path, "w") as f:
757+
for item in script_info.inputs():
758+
key = item.getName()
759+
760+
# Skip if any keys are in the skip list
761+
if any(skip in key.upper() for skip in skip_keys):
762+
continue
763+
764+
# Skip if parameter is declared with password style
765+
if WidgetStyle.isStyle(item, TextWidget.PASSWORD_STYLE):
766+
continue
767+
768+
if inputs.containsKey(key):
769+
val = inputs.get(key)
770+
f.write("%s: %s\n" % (key, str(val)))
771+
772+
print("Saved script parameters to: %s" % out_path)

src/imcflibs/imagej/omerotools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ def parse_url(client, omero_str):
4747
-------
4848
list(fr.igred.omero.repository.ImageWrapper)
4949
List of ImageWrappers parsed from the string.
50+
51+
Examples
52+
--------
53+
>>> from fr.igred.omero import Client
54+
>>> client = Client()
55+
>>> OMERO_LINK = "123456"
56+
>>> img_wrappers = omerotools.parse_url(client, OMERO_LINK)
57+
>>> for wrapper in img_wrappers:
58+
>>> imp = wpr.toImagePlus(client)
5059
"""
5160
image_ids = []
5261
dataset_ids = []

0 commit comments

Comments
 (0)