Skip to content

Command line

AnyWave can be driven from a terminal. The command line lets you:

  • open a data file (or a BIDS folder) in the interface,
  • run a processing plugin without any window (ICA, h2/r2, spectral analysis, export...), file after file, from a script,
  • convert a recording to BIDS,
  • start AnyWave in the debug mode used by MATLAB and Python plugins.

The options of each processing plugin are described in Plugins on the command line.

Starting AnyWave from a terminal

Windows: add the folder of the AnyWave application to the system PATH, or give the full path of the application in your commands.

Linux: the Debian package (and a build from the sources) creates a link in /usr/bin/anywave: the anywave command is always found.

macOS: the installation package creates the link /usr/local/bin/anywave, so anywave works in the Terminal. The program itself is /Applications/AnyWave.app/Contents/MacOS/AnyWave.

anywave                          # opens the interface
anywave recording.edf            # opens the interface on a data file
anywave /data/my_bids_dataset    # a folder is opened as a BIDS dataset
anywave --version                # AnyWave version, build date and Qt version (also: -v)
anywave --help                   # also: -h

Older versions of --help

--help lists the options of this page. AnyWave 2.16.6 and earlier printed spellings that the program never accepted (--input, --args, --plugin-debug, --server-port, --log-level, --output-log and the short forms -r, -i, -o, -l): they fail with Unknown option. Use the names below: --input_file, --plugin_debug, --server_port, --log_dir...

Batch mode and interface mode

command what happens
anywave --run <plugin> ... batch: no window. AnyWave runs the plugin, writes its results and exits
anywave --toBIDS ... batch: converts a recording to BIDS, then exits (see below)
anywave [file or folder] the interface opens (with the file, or the BIDS dataset)
anywave --plugin_debug --server_port <port> [file] the interface opens and listens on <port> for a plugin being debugged

In batch mode AnyWave returns an exit code (see Exit code).

Options

An option and its value are separated by a space: --hp 1. Paths with spaces must be quoted. Option names are lowercase, with underscores, and are case sensitive. The values of --output_format and --create_montage, and the names of plugins, are not.

Input

option value description
--input_file file path the data file to process. Mandatory for every plugin that reads data
--run plugin name, JSON file or JSON string the processing plugin to run, see Running a plugin
--marker_file file path a .mrk file to use instead of the one next to the data
--montage_file file path a .mtg file to apply instead of the default montage
--create_montage bipolar_ieeg, monopolar or none build the montage on the fly, see Channels
--pick_channels list of labels use only these channels, see Channels
--modality eeg, meg, seeg, ieeg... the type of channels processed by the plugins that need one (ICA, spectral analysis...). --bids_modality is accepted too, and gives the same result when --modality is not given
--skip_bad_channels true, false, yes, no (default true) false also processes the channels marked as bad
--use_markers labels separated by commas process only the data covered by markers with these labels
--skip_markers labels separated by commas process the data except what is covered by markers with these labels
--hp, --lp, --notch frequency in Hz high pass, low pass and notch filters applied to the input channels

Output

option value description
--output_dir folder where to write the results. It is created when it does not exist. Default: the folder of the data file
--output_file name name of the result file (without extension)
--output_prefix, --output_suffix text added to the name of the result file. Used by h2/r2, ICA and spectral analysis; ignored by the other plugins
--output_format vhdr, edf, ades, matlab, fiff file format of the result of an export

--output_format only accepts the formats above, and only when the writer of the format is installed. matlab needs the MATLAB writer, which is not part of every AnyWave package: when a format has no writer, AnyWave stops before running anything, with an error and the exit code 255. A job file that names such a format ("output_format": "matlab") is stopped by the export plugin, which logs Plugin matlab format not found, writes nothing and returns a non zero exit code too.

Log

option value description
--log_dir folder the folder where AnyWave writes its log files (default: the AnyWave/Log folder of your home or documents folder)
--log_level debug, info, warning, error drops the messages below this level, in the console and in the log files. Without it every message is kept. Another value is refused (exit code 255)

Interface options

option value description
--plugin_debug listen for a plugin being debugged. Requires --server_port. See MATLAB debug and Python debug
--server_port TCP port port used by --plugin_debug

Running a plugin

--run takes one of three things:

The name of the plugin, as it is called in AnyWave. Case does not matter (--run ICA and --run ica are the same plugin); quote names that contain spaces.

anywave --run h2 --input_file recording.edf --time_window 4 --step 1 --max_lag 0.1
anywave --run "EEG Artifact Detector" --input_file recording.edf

A JSON file that holds the name of the plugin (key plugin) and any option, with the same names as on the command line:

{
    "plugin": "export",
    "input_file": "recording.edf",
    "output_format": "vhdr",
    "output_dir": "converted",
    "hp": 1,
    "lp": 40
}
anywave --run job.json

A JSON string, with the same content as the file. It is the most compact form in a script (in a Windows shell, prefer a file: quotes inside a JSON string must be escaped, and the escaping rules depend on the shell).

anywave --run '{"plugin": "export", "output_format": "edf", "output_dir": "converted"}' --input_file recording.edf

When an option is given both on the command line and in the JSON, the command line wins.

The Batch tool of the interface works this way: for each file it writes a job_NNN.json file and runs anywave --run job_NNN.json --log_dir <log folder>. You can open one of these files to see what a job looks like, and run it again from a terminal.

Options of the plugins

Besides the options above, every plugin declares its own options. They come in three kinds:

kind on the command line example
parameter --name value --time_window 4
switch --name alone --save_comp_traces
flag --name true or --name false (yes and no are accepted) --several_result_files true

A flag needs its value

--several_result_files followed directly by another option takes that option as its value, and the other option is lost. Always write true or false after a flag.

They are listed, plugin by plugin, in Plugins on the command line. An option that no plugin declares is refused: Unknown option 'name' and exit code 255.

What AnyWave does before running a plugin

Data, markers and montage files

When it opens the data file, AnyWave looks next to it for a montage file and a marker file, which have the name of the data file followed by .mtg and .mrk (recording.edf.mtg), and for the list of bad channels (recording.edf.bad). Those files are used when they exist. --montage_file and --marker_file replace them.

Without a .mrk file there are no markers, except those already stored in the data file by the acquisition system.

Channels

The channels given to the plugin are chosen in this order:

  1. --pick_channels: only the listed channels, in the order of the list (this ignores --montage_file and --create_montage). A channel is written Fp1; a bipolar derivation is written with a dash: Fp1-Cz is the signal of Fp1 minus the signal of Cz.
  2. --create_montage:
    • bipolar_ieeg builds the bipolar montage of the SEEG electrodes (A1-A2, A2-A3...). It stops with an error when the file has no SEEG channels;
    • monopolar and none use the channels as recorded.
  3. --montage_file: the channels of that montage.
  4. Otherwise the default montage: the one of the .mtg file when there is one, the channels as recorded when there is none.
anywave --run h2 --input_file recording.edf --pick_channels "A1,A2,A3" --time_window 4 --step 1 --max_lag 0.1

Runs h2 with the three channels A1, A2 and A3 only. --pick_channels "Fp1-Cz,Cz-O1" gives two derivations, whatever the format of the data file.

Bad channels are left out (the channels of the .bad file, and those the data file marks as bad). --skip_bad_channels false puts them back; they are then added after the other channels.

Markers and filters

--use_markers and --skip_markers select the parts of the file to process. With the markers good (2 s to 5 s) and bad (6 s to 8 s) in a file of 10 s:

options processed data
--use_markers good 3 s: from 2 s to 5 s
--use_markers good,bad 5 s: both segments
--skip_markers bad 8 s: all but 6 s to 8 s

--hp, --lp and --notch filter the channels before the plugin receives them, whatever the plugin.

Results

Results are written in --output_dir; without it, next to the data file. A plugin that writes a single file names it after --output_file, or after the data file when there is no such option.

Exit code

In batch mode the exit code tells whether the run could be done:

code meaning
0 the plugin ran to the end
non zero (255 on Linux and macOS, -1 on Windows) an option is wrong or unknown, the plugin does not exist, the input file is missing or cannot be read, the plugin could not start or stopped on an error (a mandatory option of the plugin is missing, no writer for the format, the result file cannot be written...), or a --toBIDS conversion failed

A script can use it to find the files that failed:

for f in /data/study/*.edf; do
    anywave --run export --input_file "$f" --output_format vhdr --output_dir /data/converted \
        || echo "failed: $f"
done

A plugin that stops on an error marks the run as failed: for instance the spectral analysis without --overlap (Missing --overlap argument in the log), trigger_writer without --meg_file, or an export whose writer is missing. AnyWave 2.16.6 and earlier returned 0 in those cases. A plugin written outside AnyWave (MATLAB, Python) or another plugin may still report a problem in the log and return 0: keep a log with --log_dir for the runs you cannot check by hand.

Windows scripts

If your shell goes on without waiting for AnyWave, start it with start /wait in a cmd window or Start-Process -Wait in PowerShell.

Convert to BIDS

--toBIDS converts one recording into a BIDS file set (data file, _channels.tsv and the .json file of the modality), then exits.

anywave --toBIDS --input_file recording.vhdr --bids_modality eeg --bids_sub 01 --bids_task rest \
        --bids_ses pre --bids_run 1 --bids_format edf --output_dir /data/bids/sub-01/ses-pre/eeg

creates, in /data/bids/sub-01/ses-pre/eeg:

sub-01_ses-pre_task-rest_run-1_eeg.edf
sub-01_ses-pre_task-rest_run-1_channels.tsv
sub-01_ses-pre_task-rest_run-1_eeg.json
option value description
--bids_modality eeg, ieeg, meg or anat mandatory
--bids_sub subject mandatory. 01 gives sub-01
--bids_task task mandatory, except for anat
--bids_ses session optional
--bids_run run optional for EEG and iEEG. Mandatory for a 4D/BTi MEG recording
--bids_acq acquisition optional
--bids_proc processing optional
--bids_format edf or vhdr (default) format of the converted EEG or iEEG data
--bids_output all (default) or sidecars sidecars writes only the _channels.tsv and .json files (and the events), without converting the data file. EEG and iEEG only
--bids_suffix T1w, T2w or CT mandatory for anat: the kind of image
--output_dir folder where the files are written. The folder must exist. Default: the folder of the input file
  • For EEG and iEEG the recording is given by --input_file.
  • For MEG give the folder of the acquisition with --input_dir (a 4D/BTi run, a CTF .ds, an Elekta/MEGIN folder). --output_dir is then mandatory. For an Elekta/MEGIN recording --input_file can name one .fif file of the folder.
  • For an anatomical image (--bids_modality anat) give a DICOM folder with --input_dir, or a NIfTI file (.nii, .nii.gz) with --input_file, together with --bids_suffix and --output_dir. The result is sub-<id>[_ses-<s>][_acq-<a>][_run-<r>]_<suffix>.nii.gz for a DICOM folder (a NIfTI file keeps its own extension), and its .json.
  • A missing mandatory option stops AnyWave with an error and the exit code 255. A conversion that fails afterwards (no reader for the file, a wrong --bids_format, a file that cannot be read...) also returns the exit code 255, with the reason in the log. AnyWave 2.16.6 and earlier returned 0 in that case. Create the output folder before the conversion.

Default behaviour in short

  • --run without --input_file only works for plugins that do not read data.
  • No --output_dir: results go next to the data file.
  • No --output_format with the export plugin: AnyWave ADES (.ades and .dat).
  • No montage or marker option: the .mtg and .mrk files next to the data are used when they exist.
  • Bad channels are skipped.

Example

Export a recording to EDF, filtered between 1 and 40 Hz, keeping only the segments marked good:

anywave --run export --input_file /data/subject1/recording.vhdr \
        --marker_file /data/subject1/review.mrk --use_markers good \
        --hp 1 --lp 40 --output_format edf --output_dir /data/converted