explorepy¶
Main API¶
-
class
explore.
Explore
(n_device=1)[source]¶ Bases:
object
Mentalab Explore device
Parameters: n_device (int) – Number of devices to be connected -
connect
(device_name=None, device_addr=None, device_id=0)[source]¶ Connects to the nearby device. If there are more than one device, the user is asked to choose one of them.
Parameters: - device_name (str) – Device name in the format of “Explore_XXXX”
- device_addr (str) – The MAC address in format “XX:XX:XX:XX:XX:XX” Either Address or name should be in the input
- device_id (int) – device id (not needed in the current version)
-
disconnect
(device_id=None)[source]¶ Disconnects from the device
Parameters: device_id (int) – device id (not needed in the current version)
-
acquire
(device_id=0, duration=None)[source]¶ Start getting data from the device
Parameters: - device_id (int) – device id (not needed in the current version)
- duration (float) – duration of acquiring data (if None it streams data endlessly)
-
record_data
(file_name, do_overwrite=False, device_id=0, duration=None, file_type='csv')[source]¶ Records the data in real-time
Parameters: - file_name (str) – Output file name
- device_id (int) – Device id (not needed in the current version)
- do_overwrite (bool) – Overwrite if files exist already
- duration (float) – Duration of recording in seconds (if None records endlessly).
- file_type (str) – File type of the recorded file. Supported file types: ‘csv’, ‘edf’
-
push2lsl
(device_id=0, duration=None)[source]¶ Push samples to two lsl streams
Parameters: - device_id (int) – device id (not needed in the current version)
- duration (float) – duration of data acquiring (if None it streams endlessly).
-
visualize
(device_id=0, bp_freq=(1, 30), notch_freq=50, calibre_file=None)[source]¶ Visualization of the signal in the dashboard :Parameters: * device_id (int) – Device ID (not needed in the current version)
- bp_freq (tuple) – Bandpass filter cut-off frequencies (low_cutoff_freq, high_cutoff_freq), No bandpass filter
- if it is None.
- notch_freq (int) – Line frequency for notch filter (50 or 60 Hz), No notch filter if it is None
- calibre_file (str) – Calibration data file name
-
measure_imp
(device_id=0, notch_freq=50)[source]¶ Visualization of the electrode impedances
Parameters: - device_id (int) – Device ID
- notch_freq (int) – Notch frequency for filtering the line noise (50 or 60 Hz)
-
set_marker
(code)[source]¶ Sets an event marker during the recording
Parameters: code (int) – Marker code. It must be an integer larger than 7 (codes from 0 to 7 are reserved for hardware markers).
-
change_settings
(command, device_id=0)[source]¶ sends a message to the device :Parameters: * device_id (int) – Device ID
- command (explorepy.command.Command) – Command object
Returns:
-
calibrate_orn
(file_name, device_id=0, do_overwrite=False)[source]¶ Calibrate the orientation module of the specified device
Parameters: - device_id (int) – device id
- file_name (str) – filename to be used for calibration. If you pass this parameter, ORN module should be ACTIVE!
- do_overwrite (bool) – Overwrite if files exist already
-
Bluetooth API¶
-
class
bt_client.
BtClient
[source]¶ Bases:
object
Responsible for Connecting and reconnecting explore devices via bluetooth
-
init_bt
(device_name=None, device_addr=None)[source]¶ Initialize Bluetooth connection
Parameters: - device_name (str) – Name of the device (either device_name or device address should be given)
- device_addr (str) – Devices MAC address
-
Parser¶
-
parser.
generate_packet
(pid, timestamp, bin_data)[source]¶ Generates the packets according to the pid
Parameters: - pid (int) – Packet ID
- timestamp (int) – Timestamp
- bin_data – Binary dat
Returns: Packet
-
class
parser.
Parser
(bp_freq=None, notch_freq=None, socket=None, fid=None)[source]¶ Bases:
object
Parser class for explore device
Parameters: - socket (BluetoothSocket) – Bluetooth Socket (Should be None if fid is provided)
- fid (file object) – File object for reading data (Should be None if socket is provided)
- bp_freq (tuple) – Tuple of cut-off frequencies of bandpass filter (low cut-off frequency, high cut-off frequency)
- notch_freq (int) – Notch filter frequency (50 or 60 Hz)
-
filter
¶
-
parse_packet
(mode='print', recorders=None, outlets=None, dashboard=None)[source]¶ Reads and parses a package from a file or socket
Parameters: - mode (str) – Parsing mode {‘print’, ‘record’, ‘lsl’, ‘visualize’, ‘impedance’, None}
- recorders (tuple) – Tuple of recorder objects (ExG_recorder, ORN_recorder, Marker_recorder)
- outlets (tuple) – Tuple of lsl StreamOutlet (orientation_outlet, EEG_outlet, marker_outlet)
- dashboard (Dashboard) – Dashboard object for visualization
Returns: packet object
-
class
packet.
PACKET_ID
[source]¶ Bases:
enum.IntEnum
An enumeration.
-
ORN
= 13¶
-
ENV
= 19¶
-
TS
= 27¶
-
DISCONNECT
= 111¶
-
INFO
= 99¶
-
EEG94
= 144¶
-
EEG98
= 146¶
-
EEG99S
= 30¶
-
EEG99
= 62¶
-
EEG94R
= 208¶
-
EEG98R
= 210¶
-
CMDRCV
= 192¶
-
CMDSTAT
= 193¶
-
MARKER
= 194¶
-
CALIBINFO
= 195¶
-
-
class
packet.
Packet
(timestamp, payload)[source]¶ Bases:
object
An abstract base class for Explore packet
Gets the timestamp and payload and initializes the packet object
Parameters: payload (bytearray) – a byte array including binary data and fletcher
-
class
packet.
EEG
(timestamp, payload)[source]¶ Bases:
packet.Packet
Gets the timestamp and payload and initializes the packet object
Parameters: payload (bytearray) – a byte array including binary data and fletcher -
apply_bp_filter_noise
(exg_filter)[source]¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_notch_filter
(exg_filter)[source]¶ Band_stop filtering of ExG data
Parameters: exg_filter – Filter object
-
push_to_lsl
(outlet)[source]¶ Push data to lsl socket
Parameters: outlet (lsl.StreamOutlet) – lsl stream outlet
-
calculate_impedance
(imp_calib_info)[source]¶ calculate impedance with the help of impedance calibration info
Parameters: imp_calib_info (dict) – dictionary of impedance calibration info including slope, offset and noise level
-
__str__
()¶ Print the data/info
-
_check_fletcher
(fletcher)¶ Checks if the fletcher is valid
-
_convert
(bin_data)¶ Read the binary data and convert it to real values
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
-
class
packet.
EEG94
(timestamp, payload)[source]¶ Bases:
packet.EEG
EEG packet for 4 channel device
-
apply_bp_filter
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_bp_filter_noise
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_notch_filter
(exg_filter)¶ Band_stop filtering of ExG data
Parameters: exg_filter – Filter object
-
calculate_impedance
(imp_calib_info)¶ calculate impedance with the help of impedance calibration info
Parameters: imp_calib_info (dict) – dictionary of impedance calibration info including slope, offset and noise level
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
push_to_imp_dashboard
(dashboard, imp_calib_info)¶
-
push_to_lsl
(outlet)¶ Push data to lsl socket
Parameters: outlet (lsl.StreamOutlet) – lsl stream outlet
-
write_to_file
(recorder)¶
-
-
class
packet.
EEG98
(timestamp, payload)[source]¶ Bases:
packet.EEG
EEG packet for 8 channel device
-
apply_bp_filter
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_bp_filter_noise
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_notch_filter
(exg_filter)¶ Band_stop filtering of ExG data
Parameters: exg_filter – Filter object
-
calculate_impedance
(imp_calib_info)¶ calculate impedance with the help of impedance calibration info
Parameters: imp_calib_info (dict) – dictionary of impedance calibration info including slope, offset and noise level
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
push_to_imp_dashboard
(dashboard, imp_calib_info)¶
-
push_to_lsl
(outlet)¶ Push data to lsl socket
Parameters: outlet (lsl.StreamOutlet) – lsl stream outlet
-
write_to_file
(recorder)¶
-
-
class
packet.
EEG99s
(timestamp, payload)[source]¶ Bases:
packet.EEG
EEG packet for 8 channel device
-
apply_bp_filter
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_bp_filter_noise
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_notch_filter
(exg_filter)¶ Band_stop filtering of ExG data
Parameters: exg_filter – Filter object
-
calculate_impedance
(imp_calib_info)¶ calculate impedance with the help of impedance calibration info
Parameters: imp_calib_info (dict) – dictionary of impedance calibration info including slope, offset and noise level
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
push_to_imp_dashboard
(dashboard, imp_calib_info)¶
-
push_to_lsl
(outlet)¶ Push data to lsl socket
Parameters: outlet (lsl.StreamOutlet) – lsl stream outlet
-
write_to_file
(recorder)¶
-
-
class
packet.
EEG99
(timestamp, payload)[source]¶ Bases:
packet.EEG
EEG packet for 8 channel device
-
apply_bp_filter
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_bp_filter_noise
(exg_filter)¶ Bandpass filtering of ExG data
Args: exg_filter: Filter object
-
apply_notch_filter
(exg_filter)¶ Band_stop filtering of ExG data
Parameters: exg_filter – Filter object
-
calculate_impedance
(imp_calib_info)¶ calculate impedance with the help of impedance calibration info
Parameters: imp_calib_info (dict) – dictionary of impedance calibration info including slope, offset and noise level
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
push_to_imp_dashboard
(dashboard, imp_calib_info)¶
-
push_to_lsl
(outlet)¶ Push data to lsl socket
Parameters: outlet (lsl.StreamOutlet) – lsl stream outlet
-
write_to_file
(recorder)¶
-
-
class
packet.
Orientation
(timestamp, payload)[source]¶ Bases:
packet.Packet
Orientation data packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
static
-
class
packet.
Environment
(timestamp, payload)[source]¶ Bases:
packet.Packet
Environment data packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
static
-
class
packet.
TimeStamp
(timestamp, payload)[source]¶ Bases:
packet.Packet
Time stamp data packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
static
-
class
packet.
MarkerEvent
(timestamp, payload)[source]¶ Bases:
packet.Packet
Marker packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
static
-
class
packet.
Disconnect
(timestamp, payload)[source]¶ Bases:
packet.Packet
Disconnect packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
static
-
class
packet.
DeviceInfo
(timestamp, payload)[source]¶ Bases:
packet.Packet
Device information packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
static
-
class
packet.
CommandRCV
(timestamp, payload)[source]¶ Bases:
packet.Packet
Command Status packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
static
-
class
packet.
CommandStatus
(timestamp, payload)[source]¶ Bases:
packet.Packet
Command Status packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
static
-
class
packet.
CalibrationInfo
(timestamp, payload)[source]¶ Bases:
packet.Packet
Calibration Info packet
-
static
int24to32
(bin_data)¶ converts binary data to int32
Parameters: bin_data (list) – list of bytes with the structure of int24 Returns: np.ndarray of int values
-
push_to_dashboard
(dashboard)¶
-
static
Dashboard¶
-
class
dashboard.dashboard.
Dashboard
(n_chan, exg_fs, mode='signal', firmware_version='NA')[source]¶ Bases:
object
Explorepy dashboard class
Parameters: - n_chan (int) – Number of channels
- exg_fs (int) – Sampling rate of ExG signal
- mode (str) – Visualization mode {‘signal’, ‘impedance’}
- firmware_version
-
update_exg
(self, time_vector, ExG)[source]¶ update_exg() Update ExG data in the visualization
Parameters: - time_vector (list) – time vector
- ExG (np.ndarray) – array of new data
-
update_exg
()[source] Update ExG data in the visualization
Parameters: - time_vector (list) – time vector
- ExG (np.ndarray) – array of new data
-
update_orn
(timestamp, orn_data)[source]¶ Update orientation data
Parameters: - timestamp (float) – timestamp of the sample
- orn_data (float vector) – Vector of orientation data with shape of (9,)
Additional tools¶
-
tools.
bt_scan
()[source]¶ “Scan for bluetooth devices Scans for available explore devices. Prints out MAC address and name of each found device
Args:
Returns:
-
tools.
bin2csv
(bin_file, do_overwrite=False, out_dir='')[source]¶ Binary to CSV file converter. This function converts the given binary file to ExG and ORN csv files.
Parameters: - bin_file (str) – Binary file full address
- out_dir (str) – Relative output directory (if not given, it uses the current working directory.)
- do_overwrite (bool) – Overwrite if files exist already
-
tools.
bin2edf
(bin_file, do_overwrite=False, out_dir='')[source]¶ Binary to EDF file converter. This function converts the given binary file to ExG and ORN csv files.
Parameters: - bin_file (str) – Binary file full address
- out_dir (str) – Output directory (if None, uses the same directory as binary file)
- do_overwrite (bool) – Overwrite if files exist already
-
class
tools.
HeartRateEstimator
(fs=250, smoothing_win=20)[source]¶ Bases:
object
Real-time heart Rate Estimator class This class provides the tools for heart rate estimation. It basically detects R-peaks in ECG signal using the method explained in Hamilton 2002 [2].
Parameters: - fs (int) – Sampling frequency
- smoothing_win (int) – Length of smoothing window
References
[1] Hamilton, P. S. (2002). Open source ECG analysis software documentation. Computers in cardiology, 2002.
[2] Hamilton, P. S., & Tompkins, W. J. (1986). Quantitative investigation of QRS detection rules using the MIT/BIH arrhythmia database. IEEE transactions on biomedical engineering.
-
average_noise_peak
¶
-
average_qrs_peak
¶
-
decision_threshold
¶
-
average_rr_interval
¶
-
heart_rate
¶
-
class
tools.
FileRecorder
(file_name, ch_label, fs, ch_unit, ch_min=None, ch_max=None, device_name='Explore', file_type='edf', do_overwrite=False)[source]¶ Bases:
object
Explorepy file recorder class.
This class can write ExG, orientation and environment data into (separated) EDF+ files. It can write data while streaming from Explore device. The incoming data will be stored in a buffer and after it reached fs samples, it writes the buffer in EDF file.
Attributes:
Parameters: - file_name (str) – File name
- ch_label (list) – List of channel labels.
- fs (int) – Sampling rate (must be identical for all channels)
- ch_unit (list) – List of channels unit (e.g. ‘V’, ‘mG’, ‘s’, etc.)
- ch_min (list) – List of minimum value of each channel. Only needed in edf mode (can be None in csv mode)
- ch_max (list) – List of maximum value of each channel. Only needed in edf mode (can be None in csv mode)
- device_name (str) – Recording device name
- file_type (str) – File type. current options: ‘edf’ and ‘csv’.
- do_overwrite (bool) – Overwrite file if a file with the same name exists already.
-
fs
¶
-
write_data
(data)[source]¶ writes data to the file
Notes
If file type is set to EDF, this function writes each 1 seconds of data. If the input is less than 1 second, it will be buffered in the memory and it will be written in the file when enough data is in the buffer.
Parameters: data (np.array) – Array of data to be written in the file with dimension of n_chan x n_sample