bsl.triggers.TriggerDef

class bsl.triggers.TriggerDef(trigger_file=None)[source]

Class used to store pairs {str: int} of events name and events value.

Each name and each value is unique. The pairs can be read from a .ini file or edited manually with TriggerDef.add() and TriggerDef.remove().

The class will expose the name as attributes self.event_str = event_int for all pairs.

Parameters:
trigger_fileNone | path-like

Path to the .ini file containing the table converting event numbers into event strings.

Note

The .ini file is read with configparser and has to be structured as follows:

[events]
event_str_1 = event_id_1   # comment
event_str_2 = event_id_2   # comment

Example:

[events]
rest = 1
stim = 2

Attributes

by_name

A dictionary with string keys and integers value.

by_value

A dictionary with integers keys and string values.

Methods

add(name, value[, overwrite])

Add an event to the trigger definition instance.

read(trigger_file)

Read events from a .ini trigger definition file.

remove(event)

Remove an event from the trigger definition instance.

write(trigger_file)

Write events to a .ini trigger definition file.

add(name, value, overwrite=False)[source]

Add an event to the trigger definition instance.

Parameters:
namestr

Name of the event.

valueint

Value of the event.

overwritebool

If True, overwrite previous event with the same name or value.

read(trigger_file)[source]

Read events from a .ini trigger definition file.

Note

The .ini file is read with configparser and has to be structured as follows:

[events]
event_str_1 = event_id_1   # comment
event_str_2 = event_id_2   # comment

Example:

[events]
rest = 1
stim = 2
Parameters:
trigger_filepath-like

Path to the .ini file containing the table converting event numbers into event strings.

remove(event)[source]

Remove an event from the trigger definition instance.

The event can be given by name (str) or by value (int).

Parameters:
eventstr | int

If a str is provided, assumes event is the name. If a int is provided, assumes event is the value.

write(trigger_file)[source]

Write events to a .ini trigger definition file.

Parameters:
trigger_fileNone | path-like

Path to the .ini file containing the table converting event numbers into event strings.

Note

The .ini file is read with configparser and has to be structured as follows:

[events]
event_str_1 = event_id_1   # comment
event_str_2 = event_id_2   # comment

Example:

[events]
rest = 1
stim = 2
property by_name

A dictionary with string keys and integers value.

Type:

dict

property by_value

A dictionary with integers keys and string values.

Type:

dict

Examples using bsl.triggers.TriggerDef

StreamPlayer: simulate an LSL stream

StreamPlayer: simulate an LSL stream