def _stop_brainflow(self): """This functions kills the brainflow backend and saves the data to a CSV file.""" # Collect session data and kill session data = self.board.get_board_data() # will clear board buffer self.board.stop_stream() self.board.release_session() # transform data for saving data = data.T # transpose data ch_names = BRAINFLOW_CHANNELS[self.device_name] num_channels = len(ch_names) eeg_data = data[:, 1:num_channels + 1] timestamps = data[:, -1] # Create a column for the stimuli to append to the EEG data stim_array = create_stim_array(timestamps, self.markers) timestamps = timestamps[ ..., None] # Add an additional dimension so that shapes match total_data = np.append(timestamps, eeg_data, 1) total_data = np.append(total_data, stim_array, 1) # Append the stim array to data. # Subtract five seconds of settling time from beginning total_data = total_data[5 * self.sfreq:] data_df = pd.DataFrame(total_data, columns=['timestamps'] + ch_names + ['stim']) data_df.to_csv(self.save_fn, index=False)
def _stop_brainflow(self): """This functions kills the brainflow backend and saves the data to a CSV file.""" # Collect session data and kill session data = self.board.get_board_data() # will clear board buffer self.board.stop_stream() self.board.release_session() # transform data for saving data = data.T # transpose data # get the channel names for EEG data if self.brainflow_id == BoardIds.GANGLION_BOARD.value: # if a ganglion is used, use recommended default EEG channel names ch_names = ['fp1', 'fp2', 'tp7', 'tp8'] else: # otherwise select eeg channel names via brainflow API ch_names = BoardShim.get_eeg_names(self.brainflow_id) # pull EEG channel data via brainflow API eeg_data = data[:, BoardShim.get_eeg_channels(self.brainflow_id)] timestamps = data[:, BoardShim.get_timestamp_channel(self.brainflow_id)] # Create a column for the stimuli to append to the EEG data stim_array = create_stim_array(timestamps, self.markers) timestamps = timestamps[..., None] # Add an additional dimension so that shapes match total_data = np.append(timestamps, eeg_data, 1) total_data = np.append(total_data, stim_array, 1) # Append the stim array to data. # Subtract five seconds of settling time from beginning total_data = total_data[5 * self.sfreq:] data_df = pd.DataFrame(total_data, columns=['timestamps'] + ch_names + ['stim']) data_df.to_csv(self.save_fn, index=False)
def get_data(self) -> pd.DataFrame: from eegnb.devices.utils import create_stim_array data = self.board.get_board_data() # will clear board buffer # transform data for saving data = data.T # transpose data print(data) # get the channel names for EEG data if self.brainflow_id == BoardIds.GANGLION_BOARD.value: # if a ganglion is used, use recommended default EEG channel names ch_names = ["fp1", "fp2", "tp7", "tp8"] else: # otherwise select eeg channel names via brainflow API ch_names = BoardShim.get_eeg_names(self.brainflow_id) # pull EEG channel data via brainflow API eeg_data = data[:, BoardShim.get_eeg_channels(self.brainflow_id)] timestamps = data[:, BoardShim.get_timestamp_channel(self.brainflow_id)] # Create a column for the stimuli to append to the EEG data stim_array = create_stim_array(timestamps, self.markers) timestamps = timestamps[ ..., None] # Add an additional dimension so that shapes match total_data = np.append(timestamps, eeg_data, 1) total_data = np.append(total_data, stim_array, 1) # Append the stim array to data. # Subtract five seconds of settling time from beginning # total_data = total_data[5 * self.sfreq :] df = pd.DataFrame(total_data, columns=["timestamps"] + ch_names + ["stim"]) return df
def _stop_brainflow(self): """This functions kills the brainflow backend and saves the data to a CSV file.""" # Collect session data and kill session data = self.board.get_board_data() # will clear board buffer self.board.stop_stream() self.board.release_session() # Extract relevant metadata from board ch_names, eeg_data, timestamps = self._brainflow_extract(data) # Create a column for the stimuli to append to the EEG data stim_array = create_stim_array(timestamps, self.markers) timestamps = timestamps[..., None] # Add an additional dimension so that shapes match total_data = np.append(timestamps, eeg_data, 1) # Append the stim array to data. total_data = np.append(total_data, stim_array, 1) # Subtract five seconds of settling time from beginning total_data = total_data[5 * self.sfreq:] data_df = pd.DataFrame(total_data, columns=["timestamps"] + ch_names + ["stim"]) data_df.to_csv(self.save_fn, index=False)