Preprocessing

OpenBCI

octopus_sensing.preprocessing.openbci.openbci_preprocess(input_path: str, file_name: str, output_path: str, channels: List[str], saving_mode: int = 0, sampling_rate: int = 128, signal_preprocess: bool = True)[source]

Preprocess openbci recorded files to prepare them for visualizing and analysis It applys data cleaning (according to signal_preprocess), resampling (according to sampling_rate), and splits data if data has been recorded continuously. This method uses mne library for EEG data processing

Parameters
  • input_path (str) – The path to recorded openbci data

  • file_name (str) – The file name of recorded openbci data

  • output_path (str) – preprocessed file path

  • channels (List(str)) – a list of recorded channels name

  • saving_mode (int, default: SavingModeEnum.CONTINIOUS_SAVING_MODE) – The saving mode of recorded data. If it is CONTINIOUS_SAVING_MODE, data will be splitted according to markers and will be recorded in the separated files

  • sampling_rate (int, default: 128) – The desired sampling_rate. Data will be resampled according to this sampling rate

  • signal_preprocess (bool, default: True) – If True will apply preliminary preprocessing steps to clean line noises

Note

Sometimes recorded data in one second with Openbci are less or more than the specified sampling rate. So, we resample data by replicating the last samples or removing some samples to achieve the desired sampling_rate

class octopus_sensing.preprocessing.openbci.EegPreprocessing(data: numpy.ndarray, channel_names: List[str] = None, sampling_rate: int = 128)[source]

Bases: object

Converts EEG data to mne raw data format for furthur analysis

Parameters
  • data (numpy.ndarray) – The channels’ time series (n_samples*n_channels)

  • channel_names (List[str], default: None) – A list of channels’ names

  • sampling_rate (int, default: 128) – Sampling rate of data

get_data()[source]

Gets EEG data as a raw mne data

Returns

mne_raw_data – EEG data as a mne.io.RawArray

Return type

mne.io.RawArray

filter_data(low_frequency: float = 1, high_frequency: float = 45, notch_frequencies: List[int] = [60])[source]

Apply notch filter, low pass and high pass (bandpass) filter on mne data

Parameters
  • low_frequency (float, default: 1) – The low cut frequency for filtering

  • high_frequency (float, default: 45) – The high cut frequency for filtering

  • notch_frequencies (List[int] default: [60]) – the frequencies to be used in the notch filter

octopus_sensing.preprocessing.openbci.clean_eeg(data, channel_names: List[str] = None, low_frequency: float = 1, high_frequency: float = 45, sampling_rate: int = 128)[source]

Cleans EEG data

Parameters
  • low_frequency (float, default: 1) – The low cut frequency for filtering

  • high_frequency (float, default: 45) – The high cut frequency for filtering

  • smpling_rate (int, default: 128) – sampling rate

Shimmer3

octopus_sensing.preprocessing.shimmer3.shimmer3_preprocess(input_path: str, file_name: str, output_path: str, saving_mode: int = 0, sampling_rate: int = 128, signal_preprocess: bool = True)[source]

Preprocess shimmer recorded files to prepare them for visualizing and analysis It applys data cleaning (according to signal_preprocess), resampling (according to sampling_rate), and splits data if data has been recorded continuously. It will save PPG and GSR data in separated files

Parameters
  • input_path (str) – The path to recorded shimmer data

  • file_name (str) – The file name of recorded shimmer data

  • output_path (str) – preprocessed file path

  • saving_mode (int, default: SavingModeEnum.CONTINIOUS_SAVING_MODE) – The saving mode of recorded data. If it is CONTINIOUS_SAVING_MODE, data will be splitted according to markers and will be recorded in the separated files

  • sampling_rate (int, default: 128) – The desired sampling_rate. Data will be resampled according to this sampling rate

  • signal_preprocess (bool, default: True) – If True will apply preliminary preprocessing steps to clean line noises

Note

Sometimes recorded data in one second with Shimmer3 are less or more than the specified sampling rate. So, we resample data by replicating the last samples or removing some samples to achieve the desired sampling_rate

octopus_sensing.preprocessing.shimmer3.clean_gsr(data, sampling_rate: int, low_pass: float = 0.1, high_pass: float = 15)[source]

Removes high frequency and rapid transient noises

Parameters
  • data (numpy.array) – An 1D array of GSR data

  • smpling_rate (int, default: 128) – sampling rate

  • low_pass (float, default: 0.7) – The low cut frequency for filtering

  • high_pass (float, default: 2.5) – The high cut frequency for filtering

Returns

cleaned_data – An 1D array of cleaned GSR data

Return type

numpy.array

octopus_sensing.preprocessing.shimmer3.clean_ppg(data: numpy.ndarray, sampling_rate: int, low_pass: float = 0.7, high_pass: float = 2.5)[source]

Removes high frequency noises

It uses heartpy <https://github.com/paulvangentcom/heartrate_analysis_python> library

Parameters
  • data (numpy.ndarray) – An 1D array of PPG data

  • smpling_rate (int, default: 128) – sampling rate

  • low_pass (float, default: 0.7) – The low cut frequency for filtering

  • high_pass (float, default: 2.5) – The high cut frequency for filtering

Returns

cleaned_data – An 1D array of cleaned PPG data

Return type

numpy.array

Preprocess Devices

octopus_sensing.preprocessing.preprocess_devices.preprocess_devices(device_coordinator: octopus_sensing.device_coordinator.DeviceCoordinator, output_path: str, openbci_sampling_rate: int = 128, shimmer3_sampling_rate: int = 128, signal_preprocess: bool = True)[source]

Preprocees recorded files for all devices that are added to device_coordinator and has a preprocessing module. Some devices do not have any preprocessing, so this function will ignore them

Parameters
  • device_coordinator (DeviceCoordinator) – an instance of DeviceCoordinator

  • output_path (str) – Path for preprocessed Files

  • openbci_sampling_rate (int) – New sampling rate for openbci resampling

  • shimmer3_sampling_rate (int) – New sampling rate for shimmer3 resampling

octopus_sensing.preprocessing.preprocess_devices.preprocess_devices_by_path(devices_path: Dict[str, str], output_path: str, openbci_channels: List[str] = ['Fp1', 'Fp2', 'F7', 'F3', 'F4', 'F8', 'T3', 'C3', 'C4', 'T4', 'T5', 'P3', 'P4', 'T6', 'O1', 'O2'], openbci_sampling_rate: int = 128, shimmer3_sampling_rate: int = 128, signal_preprocess: bool = True)[source]

Gets a list of path to the recorded data from different devices and preprocess them if they have preprocessing module. Some devices do not have any preprocessing, so this function will ignore them

Parameters
  • devices_path (dict[str, str]) – a dictionary of device_name: data_path that specify the path to recorded data by each device

  • output_path (str) – Path for preprocessed Files

  • openbci_channels (List[str]) – default is [“Fp1”, “Fp2”, “F7”, “F3”, “F4”, “F8”, “T3”, “C3”, “C4”, “T4”, “T5”, “P3”, “P4”, “T6”, “O1”, “O2”] A list of OpenBCI channels’ names

  • openbci_sampling_rate (int) – New sampling rate for openbci resampling

  • shimmer3_sampling_rate (int) – New sampling rate for shimmer3 resampling