Jython scripts use getParam to get inputs. The command uses up to four parameters, which are:
1. the name of the variable
2. the default value of the variable, which also constrains the type.
3. documentation string
4. constraints on inputs.
Item 4 is what is proposed for extension. I'd like to allow constraints on range, and Craig has asked for human-readable documentation for enumerations.
Just playing with this a little:
Note the underscore is a hint that these are reserved words. Dictionaries loose their sorting, so maybe instead
Another reserved value would be '*' indicating any value is allowed.
Other reserved words:
_gt,_ge,_lt,_le
_length
Last edit: Jeremy Faden 2014-05-13
setOutputParam has been planned for a while, and I put in forward-compatibility code so that old Autoplots would still handle this when it is a full feature.
I'd really like to get these new constraints in before AGU.
This is a left-over feature request which would be really nice to use. Often I'd like to show some example inputs, but I don't want to say the examples are the only inputs.
Often I use "case" to be an enumeration of valid inputs to a script, so saying case=1 sets all the other parameters. This works fairly well for interactive use, but doesn't work with the "run batch" (batchmaster) tool, where there's another ticket for this problem. See also https://sourceforge.net/p/autoplot/bugs/2065/
Last edit: Jeremy Faden 2019-06-14
For the human labels on an enumeration, I would use:
constraint= { values:[1,2,3,9], labels:['good', 'okay', 'bad', 'unknown'] }
sc= getParam( 'quality', 1, 'Quality', constaint )
More constraints:
constraint= { 'min':0, 'max':100 }
constraint= { 'min':0.0, 'max':100.0, 'step':5.0 } # used when generating inputs. 2.5 is a valid entry.
constraint= { 'regex':'sc[1234]' }
constraint= { 'enum':[1,2,3,9] }
constraint= { 'subset':'ant1,ant2,ant3,ant4,ant5,' } # a subset of these should be selected
constraint= { 'examples':[1,2,3,9] } # like enum, but any value outside of the set is also valid
Last edit: Jeremy Faden 2019-10-09
I just noticed in autoplot2017.py, I claim that constraint can be a dictionary with QDataSet properties like VALID_MIN and VALID_MAX. I think there's a lot of things that ignores (like subset or examples), but it's worth mentioning on this ticket. I'd like to make sure with this next release that if a dictionary is used, then it will be ignored, future-proofing the getParam call.
Also I'm adding setScriptTitle, setScriptDescription, setScriptLabel and setScriptIcon, which presently do nothing.
When writing a different code I put in "values" instead of "enum", and I think this is probably a better name. (enum is more computer-sciencey, but isn't any more precise.) I also looked at "oneOf" and "anyOf" but I think the capitalization is going to cause problems, and anyOf seems ambiguous.
I've introduced a color-type for the parameters. The GUI is still lacking and could be made more effective.
See also https://sourceforge.net/p/autoplot/feature-requests/704/ .
I've added examples, used instead of values, which allows other things to be specified. So for example:
orbit= getParam( 'orbit', 24, 'orbit number', { 'examples':[ 24,25,26, 27, 28, 29, 30 ]} )
has the advantage that it works with orbit=23 and orbit=31.
With somewhat strange scripts running on a server, being run by strangers, this provides an important way for scripts to control parameters. I showed the script dev/demos/2021/20210408/demo1000000RGBColorPoints.jy to a friend and they immediately started putting huge values in for the symbol size to try and break the server. Being able to constrain the min and max values would address this issue.
Another nice constraint for timeranges would be to limit the length of time requested (to limit processing time), to require a specific length (1 day to support file boundaries) and boundaries. This might be something like { 'formatsTo';'$Y-$m' } to mean only months are accepted.
In the Run Batch Tool I now look at the min and max properties.
See https://github.com/autoplot/documentation/blob/master/docs/jython/getParamConstraints.md
where I start to work out documentation for the scientists.
I also thought it would be useful to have { 'format':'$Y-$m-$d' } which would allow the time range to be constrained to just days.
Here's a Python code which starts to implement the new logic:
See also https://sourceforge.net/p/autoplot/feature-requests/773/
See also https://github.com/autoplot/dev/tree/master/rfe/sf/360
I think there should be a way to hint if slider, droplist, or exclusive checkbox should be used.
I'm experimenting with adding "stringType" which can be "file", instead of using a File object. This way a whole bunch of new types can be added without relying on Java types.
See also https://sourceforge.net/p/autoplot/feature-requests/805/.
It would be nice in some cases for a script to declare outputs, be it a file written to disk, plot made on the canvas, or text sent to stdout. This would allow https://cottagesystems.com/AutoplotServlet/ScriptGUIServlet
to know what it needs to look for and how to generate an output screen without running the script.
Also, for png output, it could declare the size of the png and if the script doesn't create the right size, handle the error.