Skip to content

Instantly share code, notes, and snippets.

@jplattel
Created June 3, 2012 11:09
Show Gist options
  • Save jplattel/2863063 to your computer and use it in GitHub Desktop.
Save jplattel/2863063 to your computer and use it in GitHub Desktop.
Zeo raw data, frequency bands to CSV
# Imports
from ZeoRawData.BaseLink import BaseLink
from ZeoRawData.Parser import Parser
from ZeoRawData.Utility import filter60hz
d = open('data.txt', 'w')
d.write('timestamp,delta,theta,alpha,beta,gamma\n')
def eventCallback(self, timestamp, version, event):
print event
def sliceCallback(s):
print s['SQI']
try:
d.write(s['ZeoTimestamp'] + ',' + str(s['FrequencyBins']['2-4']) + ',' + str(s['FrequencyBins']['4-8']) + ',' + str(s['FrequencyBins']['8-13']) + ',' + str(s['FrequencyBins']['13-18'] + s['FrequencyBins']['18-21']) + ',' + str(s['FrequencyBins']['30-50']) + '\n')
except:
pass
if s['BadSignal'] == True:
print 'Bad Signal'
if s['Waveform'] is not []:
wave = []
form = filter60hz(s['Waveform'])
for w in form:
wave.append(str(w))
#print wave
#ws.send(",".join(wave))
#print 'Sending Waveform'
# Initialize
port= "/dev/tty.usbserial-FTF6GQ0A"
#ws = create_connection("ws://localhost:9000")
link = BaseLink(port)
parser = Parser()
print "Zeo Connected."
# Add the Parser to the BaseLink's callback
link.addCallback(parser.update)
print "Raw data input initialized."
# Add your callback functions
parser.addEventCallback(eventCallback)
parser.addSliceCallback(sliceCallback)
# Start link
print "Start reading data: "
link.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment