-
Notifications
You must be signed in to change notification settings - Fork 3
Add method to save Fiji script parameters, and add example to opening an image #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0e19239
Add example to docstring for clarity
rohangirishrao 7834a92
Add method to save Fiji script parameters to file
rohangirishrao 02d84d8
Add keys to skip logging
rohangirishrao c7c0d3e
Update method to save Fiji script parameters
rohangirishrao cdda918
Run black formatter
rohangirishrao eed68d8
Remove redundant ScriptModule import
rohangirishrao cd9795f
Remove redundant comments
rohangirishrao 1b74c4e
Change from string literal to public constant
rohangirishrao 38376ec
Change mocks version to 0.12.0
rohangirishrao bf7fd7d
Update poetry.lock for mocks v0.12.0
ehrenfeu b7e32fb
Replace UTF-8 dash with an ASCII minus
ehrenfeu fc32cca
Use IJ.log() instead of print()
ehrenfeu 1be7625
Minor syntax / rendering fix
ehrenfeu d50577f
Update mocks dependency to version to 0.13.0
ehrenfeu 8145904
Add instructions for working around poetry's stubborn cache
ehrenfeu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -701,3 +701,58 @@ 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: | ||
| print("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 style="password" | ||
| style = item.getWidgetStyle() | ||
| if style is not None and style.lower() == "password": | ||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cf. #45 |
||
|
ehrenfeu marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use
WidgetStyle.isStyle(ModuleItem<?> item, String target)here:Note also the use of public constants instead of hard-coded strings here 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like @imagejan's suggestion. @rohangirishrao could you look into it?