mindaffectBCI.decoder.offline package¶
Submodules¶
mindaffectBCI.decoder.offline.load_brainsonfire module¶
mindaffectBCI.decoder.offline.load_brainstream module¶
-
mindaffectBCI.decoder.offline.load_brainstream.
load_brainstream
(datadir, sessdir=None, sessfn=None, fs_out=60, ifs=None, fr=None, stopband=((45, 65), (5, 25, 'bandpass')), verb=0, ch_names=None)[source]¶ Load and pre-process a brainstream offline save-file and return the EEG data, and stimulus information
Parameters: - datadir (str) – root of the data directory tree
- sessdir (str, optional) – sub-directory for the session to load. Defaults to None.
- sessfn (str, optional) – filename for the session information. Defaults to None.
- fs_out (float, optional) – [description]. Defaults to 100.
- ifs (float, optional) – the input data sample rate.
- fr (float, optional) – the input stimulus frame rate.
- stopband (tuple, optional) – Specification for a (cascade of) temporal (IIR) filters, in the format used by mindaffectBCI.decoder.utils.butter_sosfilt. Defaults to ((45,65),(5.5,25,’bandpass’)).
- ch_names (tuple, optional) – Names for the channels of the EEG data.
Returns: the pre-processed per-trial EEG data Y (np.ndarray (nTrl,nSamp,nY)): the up-sampled stimulus information for each output coords (list-of-dicts (3,)): dictionary with meta-info for each dimension of X & Y. As a minimum this contains
”name”- name of the dimension, “unit” - the unit of measurment, “coords” - the ‘value’ of each element along this dimension
Return type: X (np.ndarray (nTrl,nSamp,nCh))
mindaffectBCI.decoder.offline.load_cocktail module¶
mindaffectBCI.decoder.offline.load_mTRF_audio module¶
mindaffectBCI.decoder.offline.load_mark_EMG module¶
mindaffectBCI.decoder.offline.load_mindaffectBCI module¶
-
mindaffectBCI.decoder.offline.load_mindaffectBCI.
load_mindaffectBCI
(source, datadir: str = None, sessdir: str = None, fs_out: float = 100, stopband=((45, 65), (5.5, 25, 'bandpass')), order: int = 6, ftype: str = 'butter', verb: int = 0, iti_ms: float = 1000, trlen_ms: float = None, offset_ms: float = (-500, 500), ch_names=None, **kwargs)[source]¶ Load and pre-process a mindaffectBCI offline save-file and return the EEG data, and stimulus information
Parameters: - source (str, stream) – the source to load the data from, use ‘-’ to load the most recent file from the logs directory.
- fs_out (float, optional) – [description]. Defaults to 100.
- stopband (tuple, optional) – Specification for a (cascade of) temporal (IIR) filters, in the format used by mindaffectBCI.decoder.utils.butter_sosfilt. Defaults to ((45,65),(5.5,25,’bandpass’)).
- order (int, optional) – the order of the temporal filter. Defaults to 6.
- ftype (str, optional) – The type of filter design to use. One of: ‘butter’, ‘bessel’. Defaults to ‘butter’.
- verb (int, optional) – General verbosity/logging level. Defaults to 0.
- iti_ms (int, optional) – Inter-trial interval. Used to detect trial-transitions when gap between stimuli is greater than this duration. Defaults to 1000.
- trlen_ms (float, optional) – Trial duration in milli-seconds. If None then this is deduced from the stimulus information. Defaults to None.
- offset_ms (tuple, (2,) optional) – Offset in milliseconds from the trial start/end for the returned data such that X has range [tr_start+offset_ms[0] -> tr_end+offset_ms[0]]. Defaults to (-500,500).
- ch_names (tuple, optional) – Names for the channels of the EEG data.
Returns: the pre-processed per-trial EEG data Y (np.ndarray (nTrl,nSamp,nY)): the up-sampled stimulus information for each output coords (list-of-dicts (3,)): dictionary with meta-info for each dimension of X & Y. As a minimum this contains
”name”- name of the dimension, “unit” - the unit of measurment, “coords” - the ‘value’ of each element along this dimension
Return type: X (np.ndarray (nTrl,nSamp,nCh))
mindaffectBCI.decoder.offline.load_ninapro_db2 module¶
mindaffectBCI.decoder.offline.load_openBMI module¶
-
mindaffectBCI.decoder.offline.load_openBMI.
get_trl_ep_idx
(trl_idx, iti)[source]¶ convert set stimulus times into trials and epochs
-
mindaffectBCI.decoder.offline.load_openBMI.
load_openBMI
(datadir, sessdir=None, sessfn=None, fs_out=60, stopband=((45, 65), (0, 1), (25, -1)), CAR=False, verb=1, trlen_ms=None, offset_ms=(0, 0), ppMI=True, ch_names=None)[source]¶ Load and pre-process a openBMI <https://academic.oup.com/gigascience/article/8/5/giz002/5304369> offline save-file and return the EEG data, and stimulus information
Parameters: - datadir (str) – root of the data directory tree
- sessdir (str, optional) – sub-directory for the session to load. Defaults to None.
- sessfn (str, optional) – filename for the session information. Defaults to None.
- fs_out (float, optional) – [description]. Defaults to 100.
- stopband (tuple, optional) – Specification for a (cascade of) temporal (IIR) filters, in the format used by mindaffectBCI.decoder.utils.butter_sosfilt. Defaults to ((45,65),(5.5,25,’bandpass’)).
- trlen_ms (float, optional) – Trial duration in milli-seconds. If None then this is deduced from the stimulus information. Defaults to None.
- offset_ms (tuple, (2,) optional) – Offset in milliseconds from the trial start/end for the returned data such that X has range [tr_start+offset_ms[0] -> tr_end+offset_ms[0]]. Defaults to (-500,500).
- ch_names (tuple, optional) – Names for the channels of the EEG data.
- CAR (bool) – flag if we should common-average-reference the raw EEG data
Returns: the pre-processed per-trial EEG data Y (np.ndarray (nTrl,nSamp,nY)): the up-sampled stimulus information for each output coords (list-of-dicts (3,)): dictionary with meta-info for each dimension of X & Y. As a minimum this contains
”name”- name of the dimension, “unit” - the unit of measurment, “coords” - the ‘value’ of each element along this dimension
Return type: X (np.ndarray (nTrl,nSamp,nCh))
mindaffectBCI.decoder.offline.load_p300_prn module¶
mindaffectBCI.decoder.offline.load_twofinger module¶
mindaffectBCI.decoder.offline.read_buffer_offline module¶
-
class
mindaffectBCI.decoder.offline.read_buffer_offline.
ftevent
(s, t, v, o=None, d=None)[source]¶ Bases:
object
mindaffectBCI.decoder.offline.read_mindaffectBCI module¶
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
datapackets2array
(msgs, sample2timestamp='lower_bound_tracker', timestamp_ch=None)[source]¶ Convert a set of datapacket messages to a 2-d numpy array (with timestamp channel)
Parameters: - msgs ([type]) – list of DataPacket messages
- sample2timestamp (str, optional) – filtering function, to filter the data-packet time-stamps using the increasing sample counts. Defaults to ‘lower_bound_tracker’.
- timestamp_ch (int, optional) – If set, channel which contains the timestamp information. Defaults to None.
Returns: the extracted samples in a numpy array
Return type: X( (t,d) np.ndarray)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_DataHeader
(line: str)[source]¶ read a data-header line from a mindaffectBCI offline save file
Parameters: line (str) – the line to read Returns: a mindaffectBCI.utopiaclient.messages.DataPacket object containing (nsamp,d) EEG data Return type: DataPacket
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_DataPacket
(line: str)[source]¶ read a data-packet line from a mindaffectBCI offline save file
Parameters: line (str) – the line to read Returns: a mindaffectBCI.utopiaclient.messages.DataPacket object containing (nsamp,d) EEG data Return type: DataPacket
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_ModeChange
(line: str)[source]¶ read a mode-change line from a mindaffectBCI offline save file
Parameters: line (str) – the line to read Returns: a mode-change object, with the new mode information Return type: ModeChange
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_NewTarget
(line: str)[source]¶ read a newtarget message line from a mindaffectBCI offline save file
Parameters: line (str) – the line to read Returns: a newtarget object Return type: NewTarget
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_Selection
(line: str)[source]¶ read a Selection message line from a mindaffectBCI offline save file
Parameters: line (str) – the line to read Returns: a selection object - Note: currently the selection information is not valid Return type: Selection
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_StimulusEvent
(line: str)[source]¶ read a stimulus event message from a line of a mindaffectBCI offline save file
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_clientip
(line: str)[source]¶ read the client-ip-address from a message line from a mindaffectBCI offline save file
Parameters: line (str) – the line to read Returns: the client ip-address Return type: ip (str)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_clientts
(line: str)[source]¶ read the client-timestamp from a message line from a mindaffectBCI offline save file
Note: the client-timestamp is the raw timestamp sent by the client, in the clients local clock.
Parameters: line (str) – the line to read Returns: the client timestamp Return type: clientts (int)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_mindaffectBCI_data_messages
(source, regress=False, timestamp_wrap_size=16777216, **kwargs)[source]¶ read an offline mindaffectBCI save file, and return raw-data (as a np.ndarray) and messages.
Parameters: - source (str) – the file name to load the data from
- regress (bool, optional) – How to map from client-specific to a common time-stamp basis. Defaults to False.
- timestamp_wrap_size (tuple, optional) – The bit-resolution of the time-stamps. Defaults to (1<<24).
Returns: the time-stamped data stream messages (list messages): the (non-datapacket) messages in the file
Return type: data (np.ndarray (nsamp,d) float)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_mindaffectBCI_message
(line: str)[source]¶ Read a mindaffectBCI message from a line of text
Parameters: line (str) – A line containing a mindaffectBCI message Returns: The decoded message as a message class. Return type: message_type
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_mindaffectBCI_messages
(source, regress: bool = False)[source]¶ read all the messages from a mindaffetBCI offline save file
Parameters: - source ([str, stream]) – the log file messages source, can be file-name, or IO-stream, or string
- regress (bool, optional) – How should we regress the client-time stamps onto the server time-stamps. If False then use the server-time-stamps, if None then leave the client-time-stamps, if True then use robust-regression to map from client to server time-stamps.
- to False. (Defaults) –
Returns: a list of all the decoded messages
Return type: (list, messages)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_recievedts
(line: str)[source]¶ read the recieved-timestamp from a message line from a mindaffectBCI offline save file
Note: the recieved-timestamp is the time the client-message was recieved, measured on the servers clock.
Parameters: line (str) – the line to read Returns: the timestamp Return type: ts (int)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
read_serverts
(line: str)[source]¶ read the server-timestamp from a message line from a mindaffectBCI offline save file
Note: the server-timestamp is the client-timestamp after mapping to the servers local clock. Thus, server timestamps are directly comparable for all clients.
Parameters: line (str) – the line to read Returns: the server timestamp Return type: ts (int)
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
rewrite_timestamps2servertimestamps
(msgs)[source]¶ rewrite message client-timestamps to best-fit server time-stamps
-
mindaffectBCI.decoder.offline.read_mindaffectBCI.
robust_timestamp_regression
(x, y)[source]¶ Given 2 time-stamp streams, e.g. one from server, one from client, compute a robust, outlier resistant linear mapping from one to the other.
Parameters: - x (int/float, (ntimes,)) – the source time-stamps
- y (int/float, (ntimes,)) – the destination time-stamps
Returns: the gain and bias for the linear map such that: y = ab[0]*x + ab[1]
Return type: ab