The anywave package¶
A Python plugin talks to AnyWave through the anywave package, the Python counterpart of the MATLAB function
anywave(). It reads the data and the markers of the recording that is open in AnyWave,
and sends back markers, messages and changes of display.
pip install anywave-plugin-api
The package needs numpy and PyQt5, which pip installs with it. Use version 1.0.3 or later. AnyWave can create the
Python environment and install the package for you, see Write a Python plugin.
import sys
import anywave as aw
aw.init(sys.argv) # always first
props = aw.get_props() # the settings of the plugin
out = aw.get_data() # the data of the current montage
Functions¶
| function | what it does | returns | documentation |
|---|---|---|---|
init(sys.argv) |
connects to AnyWave, must be called first | nothing | init |
get_props() |
reads the settings of the plugin: files, folders, options of the command line... | a dict | get_props |
get_data(cfg) |
requests data (channels, time selections, filters...) | a list of dicts | get_data |
get_markers(cfg) |
requests the markers of the current file | a list of Marker |
get_markers |
send_markers(markers) |
adds markers to the current file | nothing | send_markers |
send_message(text) |
writes a text in the AnyWave log | nothing | send_message |
change_sig_prop(cfg) |
changes the color or the filters of channels | nothing | change_sig_prop |
ica_command(cfg) |
rejects (or restores) independent components | nothing | ica_command |
run(cfg) |
runs another plugin on a file | a dict | run |
debug_connect(port) |
connects to an AnyWave started in debug mode | a dict | debug_connect |
The package also defines two classes: anywave.Marker (see send_markers) and anywave.Channel
(see get_data).
A complete plugin¶
The detector of Write a Python plugin reads the EEG channels, computes the RMS of every channel on windows of one second and sends a marker for each window above a threshold.
Good to know¶
Options are dicts. The second argument of get_data, get_markers, change_sig_prop, ica_command and run is a
dict. Python sends it as JSON: a list with one element is a list ({'labels': ['Cz']}), there is no trap like the one
of MATLAB.
Errors. A request that AnyWave cannot execute raises a regular Python Exception with the message of AnyWave,
which starts with ERROR: when AnyWave detected the problem. Use try / except when you want your plugin to continue:
try:
out = aw.get_data({'data_path': 'D:/data/file.edf'})
except Exception as e:
aw.send_message('get_data failed: ' + str(e))
Single precision. AnyWave stores the positions, durations and values of the markers in single precision: 0.1 comes
back as 0.10000000149011612. Compare positions with a tolerance. The data are float32.
Output of the script. What the script writes with print() goes to the log of the plugin, like the messages of
send_message. See the log in the debug log window.
anywave.properties. After init, the settings of the plugin are not in anywave.properties: read them with
get_props(). The dict anywave.properties is only filled by debug_connect, in a debug session.
One connection per call. Every call opens its own connection to AnyWave, which answers the requests one at a time.