Repository navigation
Generalization of save_script_parameters聽#145
Description
Actually... While doing #140 a few more ideas for this function popped 馃挕 up:
-
It would be nice if the function were to automagically determine whether the parameters should be saved or not. Then it could simply always be called from our scripts and do its service. A reasonable 馃 approach would be to have an empty default value for the target location by using
destination=""and skip parameter saving if it's not defined. -
Instead of supplying the saving location explicitly in parameter
destination, we could modify it such that the location is defined within the Script Parameters (see illustration example below) using a default parameter name (e.g.OUTPUT_PATHor similar) and only have an optional parameter forsave_script_parametersthat allows to specify which Script Parameter contains the saving location if it differs from the standard. -
To achieve this, processing 鈿欙笍 of the Script Parameters in
save_script_parameterswould need to be modified such that it works through the items obtained viascript_globalsand assembles a list of things 馃搼 to be saved while determining the saving location 馃捑 at the same time - only usingopen(out_path, "w") as f:after all Script Parameters have been processed (as only thenout_pathwould be known). -
We should consider to construct the file name used to save the parameters and values automatically, e.g. following this pattern:
<calling_script_name>_run-<timestamp>_params.txt- this would allow for saving the parameters at each run without having to worry (too much) about overwriting previously saved ones. For hints on how to identify the name of the calling script, this SO thread might contain useful ideas - 馃毃 careful though, it's pretty old and might not work the same way in ImageJ-Jython! 鈽濔煆糡he.pysuffix should be stripped from the pattern. -
In case saving the parameters in the
OUTPUT_PATHlocation suggested above fails (location might be read-only, ...), falling back to e.g. the user's home directory would be nice (plus issuing a鈿狅笍 warning message obviously).
example1.py
#@ File(label="Input data", style="directory") INPUT_PATH
#@ File(label="Path for results", style="directory") OUTPUT_PATH
from imcflibs.imagej.misc import save_script_parameters
save_script_parameters(script_globals=globals())Running the above with OUTPUT_PATH=/data/project23/results would result in this:
Saved 2 script parameters to: /data/project23/results/example1_run-2026-04-10--10-41_params.txt
example2.py
This illustrates the option of using a different Script Parameter to define where the parameters should be saved:
#@ File(label="Input data", style="directory") INPUT_PATH
#@ File(label="Path for results", style="directory") OUTPUT_PATH
#@ File(label="Path to store parameters", style="directory") PARAMS_PATH
from imcflibs.imagej.misc import save_script_parameters
save_script_parameters(script_globals=globals(), location_param="PARAMS_PATH")Running this with PARAMS_PATH=/data/project23/runs would give:
Saved 3 script parameters to: /data/project23/runs/example2_run-2026-04-10--10-50_params.txt
馃く 馃槼
Now, obviously - these are a lot of changes, and they definitely qualify for a separate issue. In my opinion, the main question (apart from discussing the stuff mentioned above) is whether to have this for the 2.0.0 milestone or if this should go into a subsequent release (馃毃 having a high probability of becoming a breaking change and hence requiring a new major release...)?
Originally posted by @ehrenfeu in #140 (comment)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
Activity
ehrenfeu commentedon Apr 10, 2026
This should better be written as:
in order to prevent the impression an additional Script Parameter is required for this solution / approach.
馃挕Hint: 鉃★笍 it's not.
Running this with
INPUT_PATH=/data/project23would give:rohangirishrao commentedon Sep 17, 2026
(1) Agreed, easy to implement 馃憤馃徑
(2) I'm not so sure this is a super helpful way of doing this, as this assumes that the script parameter path name will be known - e.g. many scripts use RESULTS_DIR as the output path, which would require passing the this path anyway. The added complexity of reading through all parameters, parsing the output path, and then opening the file to write to might be a bit overkill, especially as there is no real consistency across scripts as to the naming of the output path. Of course, this might introduce that consistency..
(3) Same logic as above, linked to (2).
(4) Also makes a lot of sense, timestamp is easy, but the script name might be trickier. I think
script_info.getLocationmight do the trick.(5) is mostly moot if we do not implement 2./3., as the results directory set by the user should always be writable? We can wrap it in a
try/exceptfor the writing and opening file part, so that it fails gracefully if there are permission or path issues.rohangirishrao commentedon Sep 30, 2026
This discussion should continue in PR #156 where some of the changes suggested have already been implemented!