def run(profName=""): global settings global profile global inputFaker global bciDevice global current global keycodelistlabels global niaDirectFeedbackApp inputFaker = OutputManager.InputFaker() if inputFaker == -1: print "Import-Error: You need either Win32con (Windows) or XLib (Linux, Mac)" else: keycodelistlabels = sorted( ["Action: " + each for each in inputFaker.actions.keys()]) profile = ProfileSettings() if (profName == ""): if len(sys.argv) == 2: profilefile = sys.argv[1] if os.path.exists(profilefile + ".feedback"): workfile = open(profilefile + ".feedback", "r") profile = pickle.load(workfile) workfile.close() else: print "no " + profilefile + ".feedback" + " file found" selection = WXElements.selection( "Select your Device", InputManager.SupportedDevices.keys()[0], InputManager.SupportedDevices.keys()) profile.deviceName = selection else: selection = WXElements.selection( "Select your Device", InputManager.SupportedDevices.keys()[0], InputManager.SupportedDevices.keys()) profile.deviceName = selection else: profilefile = profName if os.path.exists(profilefile + ".feedback"): workfile = open(profilefile + ".feedback", "r") profile = pickle.load(workfile) workfile.close() else: profile.profileName = profilefile bciDevice = InputManager.BCIDevice(profile.deviceName) current = Current_Data() niaDirectFeedbackApp = NiaDirectFeedbackApp() niaDirectFeedbackApp.MainLoop() bciDevice.quit()
def run(profName=""): global settings global neuralNetBreederApp datafile = "" if (profName==""): if len(sys.argv)<2: path = os.getcwd() fileList = os.listdir(path) profileList = [] for fileName in fileList: if fileName[-5:] == "train": profileList.append(fileName[:-6]) if len(profileList) > 0: datafile = str(WXElements.selection("Select your Sample-set",profileList[0], profileList)) else: print "Error: no profiles found" else: datafile = sys.argv[1] if len(datafile)==0: print ( "If you want to breed a neural net based on myProfile.train and myProfile.test,\n"+ "use: python Triathlon-Breeder.py myProfile") else: if os.path.exists(datafile+".train") and os.path.exists(datafile+".test"): settings = AppSettings(datafile) neuralNetBreederApp = NeuralNetBreederApp() breedTimer = BreedingEventTimer() neuralNetBreederApp.MainLoop() else: print "Error: no "+datafile+".train file\nor no "+datafile+".test file found." else: settings = AppSettings(profName) neuralNetBreederApp = NeuralNetBreederApp() breedTimer = BreedingEventTimer() neuralNetBreederApp.MainLoop()
def run(profName=""): global settings global profile global inputFaker global bciDevice global current global keycodelistlabels global niaDirectFeedbackApp inputFaker = OutputManager.InputFaker() if inputFaker == -1: print "Import-Error: You need either Win32con (Windows) or XLib (Linux, Mac)" else: keycodelistlabels = sorted(["Action: "+each for each in inputFaker.actions.keys()]) profile = ProfileSettings() if (profName==""): if len(sys.argv)==2: profilefile = sys.argv[1] if os.path.exists(profilefile+".feedback"): workfile = open(profilefile+".feedback", "r") profile = pickle.load(workfile) workfile.close() else: print "no "+profilefile+".feedback"+" file found" selection = WXElements.selection("Select your Device",InputManager.SupportedDevices.keys()[0],InputManager.SupportedDevices.keys()) profile.deviceName = selection else: selection = WXElements.selection("Select your Device",InputManager.SupportedDevices.keys()[0],InputManager.SupportedDevices.keys()) profile.deviceName = selection else: profilefile = profName if os.path.exists(profilefile+".feedback"): workfile = open(profilefile+".feedback", "r") profile = pickle.load(workfile) workfile.close() else: profile.profileName = profilefile bciDevice = InputManager.BCIDevice(profile.deviceName) current = Current_Data() niaDirectFeedbackApp = NiaDirectFeedbackApp() niaDirectFeedbackApp.MainLoop() bciDevice.quit()
def run(profName=""): global settings global neuralNetBreederApp datafile = "" if (profName == ""): if len(sys.argv) < 2: path = os.getcwd() fileList = os.listdir(path) profileList = [] for fileName in fileList: if fileName[-5:] == "train": profileList.append(fileName[:-6]) if len(profileList) > 0: datafile = str( WXElements.selection("Select your Sample-set", profileList[0], profileList)) else: print "Error: no profiles found" else: datafile = sys.argv[1] if len(datafile) == 0: print( "If you want to breed a neural net based on myProfile.train and myProfile.test,\n" + "use: python Triathlon-Breeder.py myProfile") else: if os.path.exists(datafile + ".train") and os.path.exists(datafile + ".test"): settings = AppSettings(datafile) neuralNetBreederApp = NeuralNetBreederApp() breedTimer = BreedingEventTimer() neuralNetBreederApp.MainLoop() else: print "Error: no " + datafile + ".train file\nor no " + datafile + ".test file found." else: settings = AppSettings(profName) neuralNetBreederApp = NeuralNetBreederApp() breedTimer = BreedingEventTimer() neuralNetBreederApp.MainLoop()
def calibrateAll(self): for i in range(len(self.devices)): self.calibrate(i) def working_Data(self, i): return self.devices[i].Working_Data def calibration(self, i): return self.devices[i].Calibration def setPoints(self, po): for i in range(len(self.devices)): self.devices[i].Points = po def quit(self): for i in range(len(self.devices)): self.devices[i].timer.cancel() sleep(0.5) for i in range(len(self.devices)): self.devices[i].close() if __name__ == "__main__": import WXElements selection = WXElements.selection("Select your Device", SupportedDevices.keys()[0], SupportedDevices.keys()) bciDevice = BCIDevice(selection) #print bciDevice.frequenciesCombined(10,30) #bciDevice.quit()
self.devices.append(NIA_Data(25,1)) def frequencies(self,i,fromFreq,toFreq): return self.devices[i].Frequencies[fromFreq:toFreq] def frequenciesCombined(self,fromFreq,toFreq): result = [] for i in range(len(self.devices)): result.extend(self.frequencies(i,fromFreq,toFreq)) return result def process(self,i): self.devices[i].process() def record(self,i): self.devices[i].record() def calibrate(self,i): self.devices[i].calibrate() def calibrateAll(self): for i in range(len(self.devices)): self.calibrate(i) def working_Data(self,i): return self.devices[i].Working_Data def calibration(self,i): return self.devices[i].Calibration def setPoints(self,po): for i in range(len(self.devices)): self.devices[i].Points = po if __name__ == "__main__": import WXElements selection = WXElements.selection("Select your Device",SupportedDevices.keys()[0],SupportedDevices.keys()) bciDevice = BCIDevice(selection) print bciDevice.frequenciesCombined(10,30)
array[:,:,:] = color_gradient image = wx.EmptyImage(width, height) image.SetData(array.tostring()) return wx.BitmapFromImage(image) if __name__ == "__main__": datafile = "" if len(sys.argv)<2: path = os.getcwd() fileList = os.listdir(path) profileList = [] for fileName in fileList: if fileName[-5:] == "train": profileList.append(fileName[:-6]) if len(profileList) > 0: datafile = str(WXElements.selection("Select your Sample-set",profileList[0], profileList)) else: print "Error: no profiles found" else: datafile = sys.argv[1] if not len(datafile): print ( "If you want to breed a neural net based on myProfile.train and myProfile.test,\nuse: python Triathlon-Breeder.py myProfile") else: if os.path.exists(datafile+".train") and os.path.exists(datafile+".test"): settings = AppSettings(datafile) neuralNetBreederApp = NeuralNetBreederApp() breedTimer = BreedingEventTimer() neuralNetBreederApp.MainLoop() else: print "Error: no", datafile+".train file\nor no", datafile+".test file found."
data_thread2.start() bciDevice.process(0) bciDevice.process(1) else: data_thread = threading.Thread(target=bciDevice.record,args=([0])) data_thread.start() bciDevice.process(0) self.rawvisualizationCanvas.newReading() self.spectogramCanvas.newReading() self.visualizationCanvas.newReading() self.historyCanvas.newReading() ev.Skip() class NiaEEGApp(wx.App): def __init__(self, redirect = False): wx.App.__init__(self) self.mainWindow = GUIMain() self.mainWindow.Show(True) bciDevice.setPoints(int(500.0/settings.niaFPS)) self.mainWindow.timer.Start(int(1000.0/settings.niaFPS)) if __name__ == "__main__": settings = AppSettings() selection = WXElements.selection("Select your Device",InputManager.SupportedDevices.keys()[0],InputManager.SupportedDevices.keys()) settings.deviceName = selection bciDevice = InputManager.BCIDevice(settings.deviceName) argcp = '' glutInit(argcp, sys.argv) niaEEGApp = NiaEEGApp() niaEEGApp.MainLoop()
def run(profName=""): global profile global inputFaker global bciDevice global keycodelistlabels global current global fannToOutputApp global ann inputFaker = OutputManager.InputFaker() if inputFaker == -1: print "Import-Error: You need either Win32con (Windows) or XLib (Linux, Mac)" else: profilefile = "" keycodelistlabels = sorted(["Action: "+each for each in inputFaker.actions.keys()]) if (profName==""): if len(sys.argv)<2: path = os.getcwd() fileList = os.listdir(path) profileList = [] for fileName in fileList: if fileName[-7:] == "profile": profileList.append(fileName[:-8]) if len(profileList) > 0: profilefile = str(WXElements.selection("Select your Profile",profileList[0], profileList)) else: print "Error: no profiles found" else: profilefile = sys.argv[1] if len(profilefile)==0: print "Error: no profile name given.\nExample: python nia-Triathlon-Player.py myProfile" else: if len(profilefile)==0: profilefile = sys.argv[1] profileLoaded = False netLoaded = False if os.path.exists(profilefile+".profile"): workfile = open(profilefile+".profile", "r") profile = pickle.load(workfile) workfile.close() profileLoaded = True else: print "no "+profilefile+".profile"+" file found" ann = libfann.neural_net() if os.path.exists(profilefile+".net"): ann.create_from_file(profilefile+".net") netLoaded = True else: print "no "+profilefile+".net"+" file found" if (profileLoaded and netLoaded): bciDevice = InputManager.BCIDevice(profile.deviceName) current = Current_Data() fannToOutputApp = FannToOutputApp() fannToOutputApp.MainLoop() bciDevice.quit() else: print "Cannot start without .profile and .net files" else: profilefile=profName workfile = open(profilefile+".profile", "r") profile = pickle.load(workfile) workfile.close() ann = libfann.neural_net() ann.create_from_file(profilefile+".net") bciDevice = InputManager.BCIDevice(profile.deviceName) current = Current_Data() fannToOutputApp = FannToOutputApp() fannToOutputApp.MainLoop() bciDevice.quit()
if __name__ == "__main__": inputFaker = OutputManager.InputFaker() if inputFaker == -1: print "Import-Error: You need either SendKeys (Windows) or XLib (Linux, Mac)" else: profilefile = "" keycodelistlabels = sorted(["Action: "+each for each in inputFaker.actions.keys()]) if len(sys.argv)<2: path = os.getcwd() fileList = os.listdir(path) profileList = [] for fileName in fileList: if fileName[-7:] == "profile": profileList.append(fileName[:-8]) if len(profileList) > 0: profilefile = str(WXElements.selection("Select your Profile",profileList[0], profileList)) else: print "Error: no profiles found" else: profilefile = sys.argv[1] if not len(profilefile): print "Error: no profile name given.\nExample: python nia-Triathlon-Player.py myProfile" else: if not len(profilefile): profilefile = sys.argv[1] profileLoaded = False netLoaded = False if os.path.exists(profilefile+".profile"): workfile = open(profilefile+".profile", "r") profile = pickle.load(workfile)