parser.add_argument('-k', '--api_key', type=str, required=True, help='API key for the Petal Metrics API') args = parser.parse_args() # get the LSL inlet print(f'looking for a stream with name {args.stream_name}...') streams = pylsl.resolve_stream('name', args.stream_name) if len(streams) == 0: raise RuntimeError(f'Found no LSL streams with name {args.stream_name}') inlet = pylsl.StreamInlet(streams[0]) # make API calls in a loop while True: # construct the call based on the received sample chunk # lsl chunks group 4-channel samples in a 2D array as follows: # samples: [[ch1, ch2, ch3, ch4], [ch1, ch2, ch3, ch4], ...] # the timestamp array corresponds to each received 4-channel grouping: # timestamps: [ts1, ts2, ...] chunk, timestamps = inlet.pull_chunk(timeout=5.0, max_samples=256) eeg_data = [[samples[channel] for samples in chunk] for channel in range(4)] calculations = api.request_metrics( api_key=args.api_key, eeg_data=eeg_data, metrics=['eye', 'blink', 'bandpower', 'artifact_detect'], ) pprint.pprint(calculations)
''' This script contains an example of checking channels for artifacts in a Petal Metrics API call. You will need a valid developer API key to access. Usage: python api_artifacts.py -k $API_KEY ''' import argparse import pprint import random import api parser = argparse.ArgumentParser() parser.add_argument('-k', '--api_key', type=str, required=True, help='API key for the Petal Metrics API') args = parser.parse_args() random_eeg_data = [[random.randint(0, 100) / 100 for i in range(256)] for num in range(4)] calculations = api.request_metrics( api_key=args.api_key, eeg_data=random_eeg_data, metrics=['artifact_count'], ) pprint.pprint(calculations['artifact_count'])
''' This script contains an example of a bandpower Petal Metrics API call. You will need a valid developer API key to access. Usage: python api_bandpower.py -k $API_KEY ''' import argparse import pprint import random import api parser = argparse.ArgumentParser() parser.add_argument('-k', '--api_key', type=str, required=True, help='API key for the Petal Metrics API') args = parser.parse_args() random_eeg_data = [[random.randint(0, 100) / 100 for i in range(256)] for num in range(4)] calculations = api.request_metrics( api_key=args.api_key, eeg_data=random_eeg_data, metrics=['bandpower'], ) pprint.pprint(calculations['bandpower'])
import api parser = argparse.ArgumentParser() parser.add_argument('-k', '--api_key', type=str, required=True, help='API key for the Petal Metrics API') args = parser.parse_args() random_eeg_data = [ [random.randint(0,100) / 100 for i in range(150)] for num in range(4) ] calculations = api.request_metrics( api_key=args.api_key, eeg_data=random_eeg_data, metrics=['preprocessed_data', 'artifact_count', 'bandpower'], ) # parse api result and get bandpower bandpower = calculations["bandpower"] alphaAverage = 0 for channel in bandpower: print(f'channel {channel} alpha: {bandpower[channel]["alpha"]}') alphaAverage += bandpower[channel]['alpha'] # calculate average alpha and print alphaAverage = alphaAverage/4 print(f'alpha average: {alphaAverage}')
''' This script contains an example of a preprocessed data Petal Metrics API call. You will need a valid developer API key to access. Usage: python api_preprocess.py -k $API_KEY ''' import argparse import random import api parser = argparse.ArgumentParser() parser.add_argument('-k', '--api_key', type=str, required=True, help='API key for the Petal Metrics API') args = parser.parse_args() random_eeg_data = [[random.randint(0, 100) / 100 for i in range(150)] for num in range(4)] calculations = api.request_metrics( api_key=args.api_key, eeg_data=random_eeg_data, metrics=['preprocessed_data'], ) print(calculations['data'])