Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main ():
BoardShim.enable_dev_board_logger ()
# use synthetic board for demo
params = BrainFlowInputParams ()
board_id = BoardIds.SYNTHETIC_BOARD.value
board = BoardShim (board_id, params)
board.prepare_session ()
board.start_stream ()
BoardShim.log_message (LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
time.sleep (10)
data = board.get_board_data ()
board.stop_stream ()
board.release_session ()
eeg_channels = BoardShim.get_eeg_channels (board_id)
# demo for transforms
for count, channel in enumerate (eeg_channels):
print ('Original data for channel %d:' % channel)
print (data[channel])
# demo for wavelet transforms
# wavelet_coeffs format is[A(J) D(J) D(J-1) ..... D(1)] where J is decomposition level, A - app coeffs, D - detailed coeffs
# lengths array stores lengths for each block
wavelet_coeffs, lengths = DataFilter.perform_wavelet_transform (data[channel], 'db5', 3)
app_coefs = wavelet_coeffs[0: lengths[0]]
detailed_coeffs_first_block = wavelet_coeffs[lengths[0] : lengths[1]]
params.serial_port = args.serial_port
params.mac_address = args.mac_address
params.other_info = args.other_info
params.ip_address = args.ip_address
params.ip_protocol = args.ip_protocol
if (args.log):
BoardShim.enable_dev_board_logger ()
else:
BoardShim.disable_board_logger ()
# demo how to read data as 2d numpy array
board = BoardShim (args.board_id, params)
board.prepare_session ()
board.start_stream ()
BoardShim.log_message (LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
time.sleep (10)
# data = board.get_current_board_data (256) # get latest 256 packages or less, doesnt remove them from internal buffer
data = board.get_board_data () # get all data and remove it from internal buffer
board.stop_stream ()
board.release_session ()
# demo how to convert it to pandas DF and plot data
eeg_channels = BoardShim.get_eeg_channels (args.board_id)
df = pd.DataFrame (np.transpose (data))
print ('Data From the Board')
print (df.head ())
plt.figure ()
df[eeg_channels].plot (subplots = True)
plt.savefig ('before_processing.png')
# demo for data serialization
params.serial_port = args.serial_port
params.mac_address = args.mac_address
params.other_info = args.other_info
params.ip_address = args.ip_address
params.ip_protocol = args.ip_protocol
if (args.log):
BoardShim.enable_dev_board_logger ()
else:
BoardShim.disable_board_logger ()
# demo how to read data as 2d numpy array
board = BoardShim (args.board_id, params)
board.prepare_session ()
board.start_stream ()
BoardShim.log_message (LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
time.sleep (10)
# data = board.get_current_board_data (256) # get latest 256 packages or less, doesnt remove them from internal buffer
data = board.get_board_data () # get all data and remove it from internal buffer
board.stop_stream ()
board.release_session ()
# demo how to convert it to pandas DF and plot data
eeg_channels = BoardShim.get_eeg_channels (args.board_id)
df = pd.DataFrame (np.transpose (data))
print ('Data From the Board')
print (df.head (10))
plt.figure ()
df[eeg_channels].plot (subplots = True)
plt.savefig ('before_processing.png')
# demo for data serialization