Variables
Juggling longs paths in command-lines can be nightmare, which is the reason
the spectral-data-converter library offers support for variables.
Variables can be used to shorten paths and making command-lines easier
to transfer to another environment or user. Variables (format {PH})
get expanded dynamically at runtime, taking the current state into account.
Variable types#
There are different types of variables:
-
System-defined ones:
{HOME}- the user's home directory{CWD}- the current working directory{TMP}- the temporary directory
-
Input-based ones, which are based on the current input file being processed:
{INPUT_PATH}- the directory component of the current file{INPUT_NAMEEXT}- the name (incl ext) of the current file{INPUT_NAMENOEXT}- the name (excl ext) of the current file{INPUT_EXT}- the extension of the current file{INPUT_PARENT_PATH}- the path of the file's parent{INPUT_PARENT_NAME}- the name of the file's parent
-
User-defined ones, which are supplied to the tool itself, e.g., via the
-p/--variablesoption of thesdc-converttool. The same script can be executed using different directories when using different variable setups. The format for the variables files is simple, one variable per line usingvariable=valueas format. Empty lines and ones starting with#get ignored. -
Runtime ones, which can be set with the
set-variableplugin. These variables can be based on other variables. The reason for this plugin is that the output of some filters may not have any directory associated with them anymore, only a file name. That renders all the input-based variables unusable. Usingset-variablebeforehand allows saving the input directory in another variable for later use. Meta-data can be used as variables as well using themetadata-to-variableplugin, which extracts a particular key from the metadata passing through and updates the specified variable accordingly.
Examples#
Relative to input#
The following command places the converted data on the same level as the
input directory adams in a directory called asc:
sdc-convert \
-l INFO \
from-adams \
-l INFO \
-i "/some/where/adams/*.spec" \
--labels a b c \
to-asc \
-l INFO \
-o {INPUT_PARENT_PATH}/asc
In-place predictions#
When trying to convert spectra into another format and place them in the
same location as the input spectra, manually copying files is rather tedious.
Also, filters that get rid of the file path and only forward the file name,
like savitzky-golay, invalidate the use of input-based variables like {INPUT_PATH}.
For that reason, the set-variable plugin can be used to
back up such variables in other user-defined variables. The following
pipeline backs up {INPUT_PATH} in the new variable {OUTPUT_DIR} and uses
that for saving the generated .asc files: