StreamRecorder: resting-state recording#
A resting-state recording is a simple offline recording during which the brain
activity of a subject is measured in the absence of any stimulus or task. A
resting-state recording can be designed with a
# Authors: Mathieu Scheltienne <email@example.com> # # License: LGPL-2.1
StreamRecorder create a new process
to stream or record data. On Windows, mutliprocessing suffers a couple of
restrictions. The entry-point of a multiprocessing program should be
if __name__ == '__main__': to ensure it can safely
import and run the module. More information on the
documentation for multiprocessing on Windows.
This example will use a sample EEG resting-state dataset that can be retrieve
with bsl.datasets. The dataset is stored in the user home
directory in the folder
To simulate an actual signal coming from an LSL stream, a
is used with a 40 seconds resting-state recording.
<Player: StreamPlayer | ON | /Users/scheltie/bsl_data/eeg_sample/resting_state-raw.fif>
For this example, the folder
bsl_data/examples located in the user home
directory will be used to stored recorded files. To ensure its existence,
os.makedirs is used.
For this simple offline recording, the goal is to start a
StreamRecorder, send an event on a trigger to mark the beginning of
the resting-state recording, wait for a defined duration, and stop the
By default, a
StreamRecorder does not require any argument. The
current working directory is used to record data from all available streams
in files named based on the date/time timestamp at which the recorder is
To record only a subset of the available streams with a specific file name
and in a specific directory, the arguments
stream_name must be provided.
For this example, the directory used to store recordings is
bsl_data/examples and the file name will start with
By default, the
start method is blocking and will
wait for the recording to start. This behavior can be changed with the
<Recorder: All streams | ON | /Users/scheltie/bsl_data/examples>
Now that a
StreamRecorder is started and is acquiring data, a trigger
to mark the beginning of the segment of interest is created. For this
SoftwareTrigger is used, but this example
would be equally valid with a different type of trigger.
All triggers do not need an active
StreamRecorder to be created.
To mark the beginning of the segment of interest in the recording, a signal is sent on the trigger. For this example, the event value (1) is used.
Finally, after the appropriate duration, the recording is interrupted.
SoftwareTrigger must be closed or deleted before
the recorder is stopped. All triggers do not need to be closed or deleted
before the recorder is stopped.
<Recorder: All streams | OFF | /Users/scheltie/bsl_data/examples>
fnameis not provided:
stream is the name of the recorded LSL stream. Thus, one file is
created for each stream being recorded.
<Raw | example-resting-state-StreamPlayer-raw.fif, 65 x 1056 (2.1 s), ~606 kB, data loaded> [[18 0 1]]
the current working directory is
bsl_datain the user home directory
the stream to connect to is named
the recorded file naming scheme is
$ bsl_stream_recorder -d examples -f test -s MyStream
Total running time of the script: ( 0 minutes 9.993 seconds)