get_data¶
get_data asks AnyWave for data: the channels you want, on the time selections you want, with or without filters.
out = aw.get_data() # every channel of the current montage, on the whole file
out = aw.get_data(cfg) # cfg is a dict of options
The options are the same in MATLAB and in Python: they are all described in the shared page get_data (channels, time selections, markers, filters, downsampling, another file). This page gives what is specific to Python.
Note
This function needs version 1.0.3 or later of the anywave-plugin-api package. Earlier versions do not read
the answer of AnyWave correctly.
The result¶
out is a list of dicts, one per time selection. There is only one dict, unless you use split_data.
| key | content |
|---|---|
'data' |
numpy array of float32, shape (number of channels, number of samples): one row per channel |
'channels' |
list of Channel objects that describe the rows of 'data' |
'position' |
start of the selection in seconds (the start of the first chunk when chunks are appended) |
'duration' |
duration requested in seconds (the sum of the chunks when they are appended) |
out = aw.get_data({'labels': ['Cz', 'Fp1'], 'start': 0, 'duration': 1})
data = out[0]['data'] # shape (2, 250) for a recording sampled at 250 Hz
names = [c.name for c in out[0]['channels']] # ['Cz', 'Fp1']: the order of the labels
cz = data[names.index('Cz')] # the samples of Cz
The channels¶
Every element of 'channels' has these attributes:
| attribute | content |
|---|---|
name |
label of the channel |
ref |
label of the reference channel for a bipolar channel, empty otherwise |
type |
'EEG', 'SEEG', 'MEG', 'ECG'... |
sr |
sampling rate in Hz |
hp, lp, notch |
filters of the channel in Hz (hp and lp are -1, notch is 0 when there is no filter) |
unit |
unit of the values: µV for EEG and sEEG, pT for MEG |
channel.full_name() gives name for a monopolar channel and name-ref for a bipolar one.
Particular cases¶
- No channel matches the request (a wrong label, a type that is not in the montage):
outis an empty list. Test it withif not out:. - The selection starts after the end of the file:
out[0]['data']has no column,shape == (n_channels, 0). use_markerswith markers that have no duration: the time selection of a marker is its duration, so a single marker gives(n_channels, 0). Use the position of the markers withstartandduration, see get_markers.split_data: one dict per chunk, for instance with{'data_chunks': [1, 2, 5, 1], 'split_data': True}:
out = aw.get_data({'data_chunks': [1, 2, 5, 1], 'split_data': True})
for chunk in out:
print(chunk['position'], chunk['data'].shape) # 1.0 (19, 500) then 5.0 (19, 250)
Errors¶
A request that AnyWave cannot execute raises an Exception:
| message | cause |
|---|---|
data_chunks must contain even number of elements. |
data_chunks has an odd number of values |
ERROR: no file open in AnyWave... |
no file is open in AnyWave and data_path is not set |
ERROR: Unable to open file <path>. |
data_path points to a file that does not exist or that AnyWave cannot read |