Difference between revisions of "AnyWave:MATLAB Batch"
(→ui.json) |
|||
Line 79: | Line 79: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | =GUI representation of ui.json= | ||
+ | See below the GUI representation of keys inserted in the ui.json:<br/> | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! key !! GUI | ||
+ | |- | ||
+ | | "hp" : ["High Pass", "double"] || [[File:Json_ui_key_double.png]] | ||
+ | |} | ||
=Example= | =Example= |
Revision as of 09:32, 31 March 2020
Contents
Introduction
One of the features of AnyWave is to run some processes in batch.
This means that you can use a dedicated GUI to program several processing on many files and execute them all.
This feature is accessible from here:
Make my plugin compatible
This is quite simple. First, you need to edit the desc.txt and add the CanRunFromCommandLine flag:
edit desc.txt
Note: you can also use the NoDataRequired if your plugin does not a file to be open in AnyWave to run.
In this case the flags line will be: flags = CanRunFromCommandLine:NoDataRequired
name = MyPlugin description = do something in MATLAB category = Process:Test:MyPlugin flags = CanRunFromCommandLine
JSON Files
After you've modified the desc.txt you will need to create two json files and place them in your plugin folder.
ui.json
There are some important things to setup in ui.json file:
There is a key describing the input parameters of the plugin. Suppose that you want to compute something on several files, you must then set several input_keys in the json file.
This is done by creating the input_keys key.
This key will hold the names of all the other keys that must be considered as files that AnyWave will provide to our plugin when running it.
In our example below, there is only ONE file key, that we called input_file which is the default key name for the file argument.
Hence, AnyWave will bring a GUI to pick up all the files we want, and run our plugin on all those files.
Once you setup the FILES entries keys, you must also describe them in the file by setting two values to the corresponding key.
The first value is always the decorated readable name of the key that will be used to create the GUI.
The second value is a string. If you set "check" as the value, that will tell AnyWave to check that the file setup is a data file and not a side car file.
If you don't want a data file to be set, just set an empty string as the value.
Let's setup an example using one input file and two parameters:
{ "input_keys" : [ "input_file"], "input_file" : ["Input File", "check"], "hp" : ["High Pass Filter", "double"], "lp" : ["Low Pass Filter", "double"], "fields_ordering" : ["hp", "lp"] }
input_keys : mandatory key. Here, we setup only one input file, and the key is called "input_file".
Then we must describe that key:
- "Input File" is the name used in the GUI to describe the parameter.
- "check" indicates that the file MUST be a data file that AnyWave can read.
fields_ordering: mandatory key. Describe the GUI fields order. Here we set up HP before LP in the GUI.
Between the mandatory keys, you have the other parameters:
- hp described as High Pass Filter, and "double" indicates this parameter is a double value.
- lp described as Low Pass Filter, and "double" indicates this parameter is a double value.
Others possible parameter values:
value | description |
---|---|
"double" | double precision value |
"int" | integer value |
"list" | indicates we want a combo list selection among predefined item. |
"string" | string value |
"stringList" | an array of strings. |
default.json
This file comes to se the default values for parameters described in ui.json.
So you need to define the same keys and set a default value for them.
In our skeleton that will be:
{ "input_file" : "", "hp" : 0., "lp" : 0. }
GUI representation of ui.json
See below the GUI representation of keys inserted in the ui.json:
key | GUI |
---|---|
"hp" : ["High Pass", "double"] |
Example
A small test plugin that takes TWO files as input:
- a MEG file
- an EEG file
desc.txt
name = MAT_BATCH description = TEST_BATCH category = Process:TEST:MAT_BATCHING flags = CanRunFromCommandLine:NoDataRequired
ui.json
{ "input_keys" : [ "meg_file", "eeg_file"], "meg_file" : ["MEG File", "check"], "eeg_file" : ["EEG File", "check"], "output_file_prefix" : ["Output File Prefix", "string"], "fields_ordering": [ "output_file_prefix" ] }
We set up two files as input (eeg_file, meg_file).
output_file_prefix is a string variable we will use to prefix our output filename.
There is only one field because meg_file and eeg_file are input files keys, so they won't appear in the left part of the GUI but in the input file part.
default.json
{ "meg_file" : "", "eeg_file" : "", "output_file_prefix" : "resampled" }
main.m
function main(varargin) global args; if isdeployed % STANDALONE AnyWave Plugin code global host; global port; global pid; if (nargin < 3) error('missing arguments.'); end host = varargin{1}; port = str2num(varargin{2}); pid = str2num(varargin{3}); if (nargin > 3) args = varargin{4}; end assignin('base', 'host', host); assignin('base', 'port', port); assignin('base', 'pid', pid); assignin('base', 'args', args); % end of STANDALONE AnyWave Plugin code end % we assume here that the code will always run in batch mode. % To check if the plugin was called in batch mode, just check if args variable is empty or not. if isempty(args) error('this plugin will only run in batch mode'); end pathMEG = args.meg_file; pathEEG = args.eeg_file; infosMEG = aw_getfileinfo(pathMEG); if isempty(infosMEG) error('Could not open MEG file'); end infosEEG = aw_getfileinfo(pathEEG); if isempty(infosEEG) error('Could not open EEG file'); end cfg=[]; cfg.file = pathEEG; markersEEG = aw_getmarkers(cfg); cfg.file = pathMEG; cfg.channels = { 'Trigger' }; markersMEG = aw_gettriggers(cfg); cfg = []; cfg.file = pathEEG; cfg.filtering = 'yes'; cfg.start = 0; cfg.duration = -1; cfg.eeg_lp = infosEEG.max_sr / 3; eegdata = aw_getdata(cfg); assert(~isempty(eegdata)); disp(eegdata); end