Scripts

Defining scripts

In operational radar product generation, a frequent need is to repeat a routine to several inputs, say tens or even hundreds of input volumes.
Rack supports defining such routines as scripts that can be invoked repeatedly using a single command line. A script is command sequence that is then executed automatically for each input:

rack --script '<cnd> <cmd2> ...' <file> <file2> <file3> ...
Definition: DataSelector.cpp:44

So, –inputFile <file> command – or simply <file> – implicitly triggers the script.

One can also invoke the script explicitly with –execScript command. Defining a script also turns on variable expansion – see also examples in Formatting metadata output using templates .

Example: product generation for each volume.

In the following example, several measurement volume files are read. For each file, two products (Pseudo CAPPI at 500 meters and Echo Top with 20 dBZ threshold) are computed, then converted to Cartesian projections and finally stored to files.

rack --script '--pCappi 500 -c -o cappi-${NOD}.h5 --pEchoTop 20 -c -o echoTop-${NOD}.h5' data/pvol_fi*.h5

In the example, special internal variable ${NOD} is derived automatically from compound ${what:source} variable of the input. One may likewise use ${what:date} and ${what:time} , for example.

Note
Rack denotes variables ${...} like shell environments, so single hyphens are often useful for preventing variable expansion in shell. Supported variable values can be listed with –status command.

By default, unless –append data was used, the resulting meteorological product is kept in the local context. This means that data from several radars can be processed and also stored as parallel processes.

Scripting becomes even more powerful when combined with Parallel computation .

Inserting commands directly

An alternative to predefined scripts is to read commands from a file and insert them directly, equivalently to inserting them among command line arguments.

Commands as text files

An example illustrates this. Assume that file cmdExample.txt contains:

# intermediate result (data) of anomaly detection will be stored
--store 2
# Run a detector (no data correction in this example)
--aSpeckle '-20,area=16'
# Prepare to store meteorological products in separate dataset<n>'s
--append dataset
# Compute a meteorological product
--pEchoTop 10
# Define a string format for debugging
--format "${what:quantity}\n${what:date}${what:time}\n"
# Display that debug string in std output
--outputFile "-"
# Compute a meteorological product
--pCappi "500,aboveSeaLevel=true"
# --pCappi "aboveSeaLevel=true,"
# reset string format (re-enables text file output to use default output)
--format ""

Then, consider the following command line:

rack volume.h5 --execFile cmdExample.txt -o result.h5

As a result, the program will run as if the command in the file had been inserted on command line.

Commands as JSON files

The latest versions of Rack support also JSON files, which are useful in environments involving, say, graphical user interfaces – for example, a user may adjust a single product parameter at a time using dedicated widgets, and the system stores the values in a JSON structure. The above commands are equivalently defined in JSON as follows.

{
"store": 2,
"aSpeckle": {
"threshold": -20,
"area": 16
},
"append": "dataset",
"format": "${what:quantity}\n${what:date}${what:time}\n",
"pEchoTop": 10,
"outputFile": "-",
"pCappi": {"altitude": 500, "aboveSeaLevel": true},
"format": ""
}

In the above JSON code, layout style varies on purpose; a group can be set on a single line or several lines, with indentation. For Rack, parameters can be set as a single element (string or number) or as a group, as illustrated. Note that commands that have no parameters must still have a value (empty string "" or empty group {} ).

Hint: Remember that plain filenames are implicit –inputFile <file> commands; hence the file can also be a list of input files (in above line format only, so excluding JSON). Using such a file together with –script yields compact command lines especially in compositing.