def __init__(self, peer_config, mx_addresses=[('localhost', 41921)], catch_signals=True, context=ctx.get_dummy_context('DriverComm')): """ *peer_config* - parameter provider. Should respond to get_param(param_name, value) and has_param(param_name) calls. PeerConfig and PeerControl objects are suitable. *mx_addresses* - list of (host, port) pairs. Port value None means using default amplifier binary value. """ self.config = peer_config if not hasattr(self, "_mx_addresses"): # FIXME self._mx_addresses = mx_addresses if not hasattr(self, "logger"): self.logger = context['logger'] self.driver = self.run_driver(self.get_run_args((socket.gethostbyname( self._mx_addresses[0][0]), self._mx_addresses[0][1]))) self.driver_out_q = Queue() self.driver_out_thr = Thread(target=enqueue_output, args=(self.driver.stdout, self.driver_out_q)) self.driver_out_thr.daemon = True # thread dies with the program self.driver_out_thr.start() self.driver_err_q = Queue() self.driver_err_thr = Thread(target=enqueue_output, args=(self.driver.stderr, self.driver_err_q)) self.driver_err_thr.daemon = True # thread dies with the program self.driver_err_thr.start() if catch_signals: signal.signal(signal.SIGTERM, self.signal_handler()) signal.signal(signal.SIGINT, self.signal_handler())
def __init__(self, send_func, cfg, montage_matrix, sampling, dec_count, context=ctx.get_dummy_context('BCIP300FdaAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix use_channels = cfg['use_channels'] self.nPole = np.zeros( dec_count) self.nMin = cfg['nMin'] self.nMax = cfg['nMax'] # For plotting purpose csp_time = cfg['csp_time'] # For analysis purpose self.csp_time = np.array(csp_time)*self.fs avrM = cfg['avrM'] conN = cfg['conN'] print "cfg['w']: ", cfg['w'] self.p300 = P300_analysis(sampling, cfg, fields= dec_count) self.p300.setPWC( cfg['P'], cfg['w'], cfg['c']) self.debugFlag = cfg['debug_flag'] if self.debugFlag: self.p300_draw = P300_draw(self.fs) self.p300_draw.setTimeLine(conN, avrM, csp_time) self.epochNo = 0
def __init__(self, configs, context=ctx.get_dummy_context('TransformEngine')): self.logger = context['logger'] self._configs = configs self._current_interface = configs['default_mode'] self._is_transforming = False
def __init__(self, send_func, freqs, cfg, montage_matrix, sampling, context=ctx.get_dummy_context('BCISsvepCspAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix allFreqs = freqs self.indexMap = {} k = 0 for i in range(len(allFreqs)): if allFreqs[i] != 0: self.indexMap[allFreqs[i]] = k k += 1 self.freqs = self.indexMap.keys() self.logger.info("Have freqs:") self.logger.info(str(self.freqs)) self.logger.info("indexMap:") self.logger.info(str(self.indexMap)) self.value = cfg['value'] self.mu = cfg['mu'] self.sigma = cfg['sigma'] self.q = cfg['q'] self.out_top = cfg['out_top'] self.out_bottom = cfg['out_bottom']
def __init__( self, send_func, cfg, montage_matrix, sampling, dec_count, context=ctx.get_dummy_context("BCIP300FdaAnalysis") ): self.logger = context["logger"] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix use_channels = cfg["use_channels"] self.nPole = np.zeros(dec_count) self.nMin = cfg["nMin"] self.nMax = cfg["nMax"] # For plotting purpose csp_time = cfg["csp_time"] # For analysis purpose self.csp_time = np.array(csp_time) * self.fs avrM = cfg["avrM"] conN = cfg["conN"] self.logger.info("cfg['w']: " + str(cfg["w"])) self.p300 = P300_analysis(sampling, cfg, fields=dec_count) self.p300.setPWC(cfg["P"], cfg["w"], cfg["c"]) self.debugFlag = cfg["debug_flag"] if self.debugFlag: self.p300_draw = P300_draw(self.fs) self.p300_draw.setTimeLine(conN, avrM, csp_time) self.epochNo = 0
def __init__(self, addresses, context=ctx.get_dummy_context('UgmBlinkingConnection')): self.connection = connect_client(type=peers.UGM_ENGINE, addresses=addresses) self.context = context self.blink_msg = variables_pb2.Blink()
def __init__(self, send_func, cfg, montage_matrix, sampling, dec_count, context=ctx.get_dummy_context('BCIP300FdaAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix use_channels = cfg['use_channels'] self.nPole = np.zeros( dec_count) self.nMin = cfg['nMin'] self.nMax = cfg['nMax'] # For plotting purpose csp_time = cfg['csp_time'] # For analysis purpose self.csp_time = np.array(csp_time)*self.fs avrM = cfg['avrM'] conN = cfg['conN'] self.logger.info("cfg['w']: "+str(cfg['w'])) self.p300 = P300_analysis(sampling, cfg, fields= dec_count) self.p300.setPWC( cfg['P'], cfg['w'], cfg['c']) self.debugFlag = cfg['debug_flag'] if self.debugFlag: self.p300_draw = P300_draw(self.fs) self.p300_draw.setTimeLine(conN, avrM, csp_time) self.epochNo = 0
def __init__(self, send_func, cfg, montage_matrix, sampling, context=ctx.get_dummy_context('BCISsvepCspAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix self.nMin = cfg['nMin'] self.nMax = cfg['nMax'] self.csp_time = cfg['csp_time'] use_channels = cfg['use_channels'] avrM = cfg['avrM'] conN = cfg['conN'] self.cols = cfg['col'] self.rows = cfg['row'] self.nPole = np.zeros(self.cols+self.rows) #~ print "cfg['w']: ", cfg['w'] self.p300 = P300_analysis(sampling, cfg, rows=self.rows, cols=self.cols) self.p300.setPWC( cfg['P'], cfg['w'], cfg['c']) self.debugFlag = cfg['debug_flag'] if self.debugFlag: self.p300_draw = P300_draw(self.fs) self.p300_draw.setTimeLine(conN, avrM, self.csp_time) self.epochNo = 0
def __init__(self, configs, context=ctx.get_dummy_context('SpellerEngine')): self.logger = context['logger'] self._message = "" self.text_id = int(configs["ugm_text_id"]) self.text_ids = [int(i) for i in configs["ugm_text_ids"].split(';')] self.dec_bank = [] self.bankSize = 100
def __init__(self, p_ugm_engine, p_ip, p_use_tagger, context=ctx.get_dummy_context('UdpServer')): """Init server and store ugm engine.""" self.context = context self._ugm_engine = p_ugm_engine self._use_tagger = p_use_tagger if self._use_tagger: self._tagger = tagger.get_tagger() self.socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) self.socket.bind((p_ip, 0))
def __init__(self, p_config_manager, p_connection, context=ctx.get_dummy_context("UgmBlinkingEngine")): """Store config manager.""" super(UgmBlinkingEngine, self).__init__(p_config_manager, p_connection, context) self.time_mgr = ugm_blinking_time_manager.UgmBlinkingTimeManager() self.id_mgr = ugm_blinking_id_manager.UgmBlinkingIdManager() self.ugm_mgr = ugm_blinking_ugm_manager.UgmBlinkingUgmManager() self.count_mgr = ugm_blinking_count_manager.UgmBlinkingCountManager() self.mgrs = [self.time_mgr, self.id_mgr, self.ugm_mgr, self.count_mgr] self.STOP = False self._run_on_start = False
def __init__(self, p_ugm_engine, p_ip, p_use_tagger, context=ctx.get_dummy_context('UdpServer')): """Init server and store ugm engine.""" self.context = context self._ugm_engine = p_ugm_engine self._use_tagger = p_use_tagger if self._use_tagger: self._tagger = tagger.get_tagger() self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind((p_ip, 0))
def __init__(self, p_config_manager, p_connection, context=ctx.get_dummy_context('UgmBlinkingEngine')): """Store config manager.""" super(UgmBlinkingEngine, self).__init__(p_config_manager, p_connection, context) self.time_mgr = ugm_blinking_time_manager.UgmBlinkingTimeManager() self.id_mgr = ugm_blinking_id_manager.UgmBlinkingIdManager() self.ugm_mgr = ugm_blinking_ugm_manager.UgmBlinkingUgmManager() self.count_mgr = ugm_blinking_count_manager.UgmBlinkingCountManager() self.mgrs = [self.time_mgr, self.id_mgr, self.ugm_mgr, self.count_mgr] self.STOP = False self._run_on_start = False
def __init__(self, send_func, cfg, montage_matrix, sampling, context=ctx.get_dummy_context('BCIP300CspAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix self.q = cfg['q'] self.treshold = cfg['treshold'] self.a_features = cfg['a_features'] self.bands = cfg['bands'] #self.analyze = p300.p300analysis(cfg['targets'], cfg['non_targets'], cfg['mean'], cfg['mu'], cfg['sigma'], cfg['left'], cfg['right']) self.analyze = p300.p300analysis2(cfg['cl'], self.q.P, 2, cfg['mean'], cfg['mu'], cfg['sigma'], cfg['left'], cfg['right']) self.b, self.a = ss.butter(3, 2*1.0/self.fs, btype='high') self.b_l, self.a_l = ss.butter(3, 2*20.0/self.fs, btype='low')
def __init__(self, send_func, cfg, montage_matrix, sampling, context=ctx.get_dummy_context('BCIP300CspAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix self.nMin = cfg['nMin'] self.nMax = cfg['nMax'] nLast = cfg['nLast'] csp_time = cfg['csp_time'] self.pVal = float(cfg['pVal']) use_channels = cfg['use_channels'] avrM = cfg['avrM'] conN = cfg['conN'] self.cols = cfg['col_count'] self.rows = cfg['row_count'] self.nPole = np.zeros(self.cols + self.rows) self.epochNo = 0 self.p300 = P300_analysis(sampling, cfg, rows=self.rows, cols=self.cols) self.p300.setPWC(cfg['P'], cfg['w'], cfg['c']) self.debugFlag = cfg['debug_flag'] if self.debugFlag: self.p300_draw = P300_draw(self.fs) self.p300_draw.setTimeLine(conN, avrM, csp_time)
def __init__(self, send_func, cfg, montage_matrix, sampling, context=ctx.get_dummy_context('BCIP300CspAnalysis')): self.logger = context['logger'] self.send_func = send_func self.last_time = time.time() self.fs = sampling self.montage_matrix = montage_matrix self.q = cfg['q'] self.treshold = cfg['treshold'] self.a_features = cfg['a_features'] self.bands = cfg['bands'] #self.analyze = p300.p300analysis(cfg['targets'], cfg['non_targets'], cfg['mean'], cfg['mu'], cfg['sigma'], cfg['left'], cfg['right']) self.analyze = p300.p300analysis2(cfg['cl'], self.q.P, 2, cfg['mean'], cfg['mu'], cfg['sigma'], cfg['left'], cfg['right']) self.b, self.a = ss.butter(3, 2 * 1.0 / self.fs, btype='high') self.b_l, self.a_l = ss.butter(3, 2 * 20.0 / self.fs, btype='low')
def __init__(self, peer_config, mx_addresses=[('localhost', 41921)], catch_signals=True, context=ctx.get_dummy_context('DriverComm')): """ *peer_config* - parameter provider. Should respond to get_param(param_name, value) and has_param(param_name) calls. PeerConfig and PeerControl objects are suitable. *mx_addresses* - list of (host, port) pairs. Port value None means using default amplifier binary value. """ self.config = peer_config if not hasattr(self, "_mx_addresses"): # FIXME self._mx_addresses = mx_addresses if not hasattr(self, "logger"): self.logger = context['logger'] self.driver = self.run_driver( self.get_run_args((socket.gethostbyname(self._mx_addresses[0][0]), self._mx_addresses[0][1]))) self.driver_out_q = Queue() self.driver_out_thr = Thread(target=enqueue_output, args=(self.driver.stdout, self.driver_out_q)) self.driver_out_thr.daemon = True # thread dies with the program self.driver_out_thr.start() self.driver_err_q = Queue() self.driver_err_thr = Thread(target=enqueue_output, args=(self.driver.stderr, self.driver_err_q)) self.driver_err_thr.daemon = True # thread dies with the program self.driver_err_thr.start() if catch_signals: signal.signal(signal.SIGTERM, self.signal_handler()) signal.signal(signal.SIGINT, self.signal_handler())
def __init__(self, addresses,context=ctx.get_dummy_context('UgmBlinkingConnection')): self.connection = connect_client(type = peers.UGM_ENGINE, addresses=addresses) self.context = context self.blink_msg = variables_pb2.Blink()
def __init__(self, engine, ip, context=ctx.get_dummy_context('UdpServer')): """Init server and store ugm engine.""" self._context = context self._engine = engine self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind((ip, 0))
def __init__(self, configs, context=ctx.get_dummy_context('RobotEngine')): self.logger = context['logger'] self._robot = rovio.Rovio('', configs['robot_ip']) self.robot_info = int(configs['robot_info']) self._rc = rovio.RovioController(self._robot) self._rc.start()
def run(in_file, use_channels, ignore_channels, montage, montage_channels, dec_count, plot_stats=True, context=ctx.get_dummy_context('UgmBlinkingConnection')): logger = context['logger'] mgr = read_manager.ReadManager( in_file+'.obci.xml', in_file+'.obci.raw', in_file+'.obci.tag') to_frequency = int(float(mgr.get_param("sampling_frequency"))) if use_channels is None: use_channels = mgr.get_param('channels_names') if ignore_channels is not None: for i in ignore_channels: try: use_channels.remove(i) except: pass exp_info = mgr.get_tags('experimentInfo')[0]['desc'] to_signal = float(exp_info['target_time']) freqs = [int(i) for i in exp_info['all_freqs'].split(';')] data = sp.signalParser(in_file+'.obci') train_tags = data.get_train_tags(trial_separator_name='diodes', screen=True) logger.info("Run csp with: use_channels: "+str(use_channels)+" motage: "+str(montage)+" montage_channels: "+str(montage_channels)) q = csp.modCSP(in_file+'.obci', freqs, use_channels, montage, montage_channels) q.start_CSP(to_signal, to_frequency, baseline = False, filt='cheby', method = 'regular', train_tags = train_tags)#liczenie CSP time = pylab.linspace(1, to_signal, 7) t1, t2 = q.time_frequency_selection(to_frequency, train_tags, time=time, frequency_no=dec_count, plt=False) logger.info("Got times t1: "+str(t1)+ " and t2: "+str(t2)) logger.info("Set buffer time:"+str(t2)) value, mu, sigma, means, stds, out_top, out_bottom = q.count_stats(to_signal, to_frequency, train_tags, plt=plot_stats)#Liczenie statystyk logger.info("For freqs: "+str(freqs)) logger.info("Got means: "+str(means)) pairs = zip(means, freqs) pairs.sort(reverse=True) logger.info("Sorted: "+str(pairs)) best = [i[1] for i in pairs] best_means = [i[0] for i in pairs] logger.info("Best freqs: "+str(best)) logger.info("dec_count: "+str(dec_count)) logger.info("freqs: " + str(best[:dec_count])) logger.info("Finished CSP with stats:") logger.info(str(value) + " / " + str(mu) + " / " + str(sigma)) logger.info("And q:") logger.info(str(q)) d = {'value': value, 'mu': mu, 'sigma': sigma, 'q' : q, 'freqs':';'.join([str(i) for i in best[:dec_count]]), 'all_freqs':';'.join([str(i) for i in best]), 'all_means':';'.join([str(i) for i in best_means]), 'dec_count':dec_count, 'buffer':t2, 'use_channels':';'.join(use_channels), 'montage':montage, 'montage_channels':';'.join(montage_channels), 'out_top':out_top, 'out_bottom':out_bottom } return d
def __init__(self, configs, context=ctx.get_dummy_context('RobotEngine')): self.logger = context['logger'] self._robot = dron.ARDrone(configs['drone_ip'], configs['drone_speed']) self.init_signals()
def __init__(self, configs, context=ctx.get_dummy_context('MazeEngine')): self.logger = context['logger'] self._curr = 0 self._line = START_LINE self._message = INITIAL_TOOLTIP
def run(in_file, use_channels, ignore_channels, montage, montage_channels, dec_count, plot_stats=True, context=ctx.get_dummy_context('UgmBlinkingConnection')): logger = context['logger'] mgr = read_manager.ReadManager(in_file + '.obci.xml', in_file + '.obci.raw', in_file + '.obci.tag') to_frequency = int(float(mgr.get_param("sampling_frequency"))) if use_channels is None: use_channels = mgr.get_param('channels_names') if ignore_channels is not None: for i in ignore_channels: try: use_channels.remove(i) except: pass exp_info = mgr.get_tags('experimentInfo')[0]['desc'] to_signal = float(exp_info['target_time']) freqs = [int(i) for i in exp_info['all_freqs'].split(';')] data = sp.signalParser(in_file + '.obci') train_tags = data.get_train_tags(trial_separator_name='diodes', screen=True) logger.info("Run csp with: use_channels: " + str(use_channels) + " motage: " + str(montage) + " montage_channels: " + str(montage_channels)) q = csp.modCSP(in_file + '.obci', freqs, use_channels, montage, montage_channels) q.start_CSP(to_signal, to_frequency, baseline=False, filt='cheby', method='regular', train_tags=train_tags) #liczenie CSP time = pylab.linspace(1, to_signal, 7) t1, t2 = q.time_frequency_selection(to_frequency, train_tags, time=time, frequency_no=dec_count, plt=False) logger.info("Got times t1: " + str(t1) + " and t2: " + str(t2)) logger.info("Set buffer time:" + str(t2)) value, mu, sigma, means, stds, out_top, out_bottom = q.count_stats( to_signal, to_frequency, train_tags, plt=plot_stats) #Liczenie statystyk logger.info("For freqs: " + str(freqs)) logger.info("Got means: " + str(means)) pairs = zip(means, freqs) pairs.sort(reverse=True) logger.info("Sorted: " + str(pairs)) best = [i[1] for i in pairs] best_means = [i[0] for i in pairs] logger.info("Best freqs: " + str(best)) logger.info("dec_count: " + str(dec_count)) logger.info("freqs: " + str(best[:dec_count])) logger.info("Finished CSP with stats:") logger.info(str(value) + " / " + str(mu) + " / " + str(sigma)) logger.info("And q:") logger.info(str(q)) d = { 'value': value, 'mu': mu, 'sigma': sigma, 'q': q, 'freqs': ';'.join([str(i) for i in best[:dec_count]]), 'all_freqs': ';'.join([str(i) for i in best]), 'all_means': ';'.join([str(i) for i in best_means]), 'dec_count': dec_count, 'buffer': t2, 'use_channels': ';'.join(use_channels), 'montage': montage, 'montage_channels': ';'.join(montage_channels), 'out_top': out_top, 'out_bottom': out_bottom } return d