Skip to content

run

run makes AnyWave run another plugin on a data file, exactly as if you launched it from the command line (anywave --run ...). Any plugin that can run from the command line can be used: ICA, h2, Spectral, the artifact detectors...

aw.run(cfg)

cfg is a dict:

key content required
'plugin' name of the plugin, as AnyWave lists it ('h2', 'Spectral', 'ICA'...) yes
'input_file' path of the data file to process the file that is open in AnyWave when it is not given
any other key an option of the plugin: the name of the command line option without the -- depends on the plugin

The options of every plugin are listed in its Command line page (h2, ICA, Spectral...). The options common to all plugins also work: output_dir, output_prefix, output_suffix, use_markers, skip_markers, marker_file, montage_file...

Example: compute h2 on the current file

import os
import sys
import anywave as aw

aw.init(sys.argv)
props = aw.get_props()

output_dir = os.path.join(props['data_dir'], 'h2_results')
os.makedirs(output_dir, exist_ok=True)

try:
    aw.run({
        'plugin': 'h2',
        'input_file': props['data_path'],       # the file open in AnyWave
        'time_window': 2,                       # options of the h2 plugin (--time_window 2)
        'step': 1,                              #                          (--step 1)
        'max_lag': 0.1,                         #                          (--max_lag 0.1)
        'output_dir': output_dir,               # where the result file goes (default: next to the data file)
    })
except ValueError:                              # json.JSONDecodeError: see the warning below
    pass

How it works

  • With input_file, AnyWave starts another AnyWave process with the plugin and the options you gave, and run waits until it is finished. The results are files, written in output_dir (by default next to the data file).
  • Choose the data with use_markers or skip_markers, as in the command line:
cfg = {'plugin': 'h2', 'input_file': props['data_path'], 'time_window': 4, 'step': 1, 'max_lag': 0.1,
       'use_markers': ['H2'], 'hp': 1, 'lp': 40}

Warning

AnyWave answers run with a JSON text of what the plugin produced. When the plugin produces nothing, and this is always the case with input_file, the answer is empty and the package raises a json.JSONDecodeError (a ValueError) when the other process is finished. Catch it:

try:
    aw.run(cfg)
except ValueError:
    pass                                    # the answer was empty

Errors

message cause
ERROR: plugin key is not specified in struct/dict parameter. no 'plugin' key
ERROR: Unable to find process plugin named ... wrong plugin name
ERROR: the process is not compatible (must be able to run using the command line the plugin cannot run from the command line
ERROR: ... is not available in the current version of AnyWave. this plugin is not part of your version of AnyWave