wonambi.datatype module

Module contains the different types of data formats.

The main class is Data, all the other classes should depend on it. The other classes are given only as convenience, but they should not overwride Data.__call__, which needs to be very general.

class wonambi.datatype.ChanFreq[source]

Bases: Data

Specific class for channel-frequency recordings, with axes:

channdarray (dtype=’O’)

for each trial, channels in the data (dtype=’U’)

freqndarray (dtype=’O’)

for each trial, 1d matrix with the frequency (dtype=’f’)

Notes

Conceptually, it is reasonable that each trial has the same frequency band, so it might be more convenient to use only one array, but it can happen that different trials have different frequency bands, so we keep the format more open.

class wonambi.datatype.ChanTime[source]

Bases: Data

Specific class for chan-time recordings, with axes:

channdarray (dtype=’O’)

for each trial, channels in the data (dtype=’U’)

timendarray (dtype=’O’)

for each trial, 1d matrix with the time stamp (dtype=’f’)

class wonambi.datatype.ChanTimeFreq[source]

Bases: Data

Specific class for channel-time-frequency representation, with axes:

channdarray (dtype=’O’)

for each trial, channels in the data (dtype=’U’)

timendarray (dtype=’O’)

for each trial, 1d matrix with the time stamp (dtype=’f’)

freqndarray (dtype=’O’)

for each trial, 1d matrix with the frequency (dtype=’f’)

class wonambi.datatype.Data(data=None, s_freq=None, **kwargs)[source]

Bases: object

General class containing recordings.

Parameters:
  • data (ndarray) – one matrix with dimension matching the number of axes. You can pass only one trial.

  • s_freq (int) – sampling frequency

  • axes (dict) – dictionary where the key is the name of the axis and the values must be a numpy vector with the actual values.

data

the data as trials. Each trial is a ndarray (dtype=’d’ or ‘f’)

Type:

ndarray (dtype=’O’)

axis

dictionary with axiss (standard names are ‘chan’, ‘time’, ‘freq’); values should be numpy array

Type:

OrderedDict

s_freq

sampling frequency

Type:

int

start_time

the start time of the recording

Type:

instance of datetime.datetime

attr
contains additional information about the dataset, with keys:
  • surf

  • chan

  • scores

Type:

dict

Notes

Something which is not immediately clear for chan. dtype=’U’ (meaning Unicode) actually creates string of type str_, while if you use dtype=’S’ (meaning String) it creates strings of type bytes_.

export(filename, export_format='FieldTrip', **options)[source]

Export data in other formats.

Parameters:
  • filename (path to file) – file to write

  • export_format (str, optional) – supported export format is currently FieldTrip, EDF, FIFF, Wonambi, BrainVision

Notes

‘edf’ takes an optional argument “physical_max”, see write_edf.

‘wonambi’ takes an optional argument “subj_id”, see write_wonambi. wonambi format creates two files, one .won with the dataset info as json file and one .dat with the memmap recordings.

‘brainvision’ takes an additional argument (“markers”) which is a list of dictionaries with fields:

“name” : str (name of the marker), “start” : float (start time in seconds) “end” : float (end time in seconds)

‘bids’ has an optional argument “markers”, like in ‘brainvision’

index_of(axis)[source]

Return the index of a axis.

Parameters:

axis (str) – Name of the axis (such as ‘trial’, ‘time’, etc)

Returns:

int or ndarray (dtype=’int’) – number of trial (as int) or number of element in the selected axis (if any of the other axiss) as 1d array.

Raises:

ValueError – If the requested axis is not in the data.

property list_of_axes

Return the name of all the axes in the data.

number_of(axis)[source]

Return the number of in one axis, as generally as possible.

Parameters:

axis (str) – Name of the axis (such as ‘trial’, ‘time’, etc)

Returns:

int or ndarray (dtype=’int’) – number of trial (as int) or number of element in the selected axis (if any of the other axiss) as 1d array.

Raises:

KeyError – If the requested axis is not in the data.

Notes

or is it better to catch the exception?