def response_main(self): response_start = dt.datetime.now() while True: elapsed_time = (dt.datetime.now() - self.this_trial.time).total_seconds() response_time = elapsed_time - self.this_trial.stimulus_event.time if response_time > self.this_trial.annotations['max_wait']: self.panel.speaker.stop() self.this_trial.response = 'none' self.log.info('no response') return for port_name, port in self.response_ports.items(): if port.status(): self.this_trial.rt = (dt.datetime.now() - response_start).total_seconds() self.panel.speaker.stop() self.this_trial.response = port_name self.summary['responses'] += 1 response_event = utils.Event( name=port_name, label='peck', time=elapsed_time, ) self.this_trial.events.append(response_event) self.log.info('response: %s' % (self.this_trial.response)) return utils.wait(.015)
def stimulus_main(self): ## 1. present cue if 'cue' in self.this_trial.annotations: cue = self.this_trial.annotations["cue"] self.log.debug("cue light turning on") cue_start = dt.datetime.now() if cue == "red": self.panel.cue.red() elif cue == "green": self.panel.cue.green() elif cue == "blue": self.panel.cue.blue() utils.wait(self.parameters["cue_duration"]) self.panel.cue.off() cue_dur = (dt.datetime.now() - cue_start).total_seconds() cue_time = (cue_start - self.this_trial.time).total_seconds() cue_event = utils.Event( time=cue_time, duration=cue_dur, label='cue', name=cue, ) self.this_trial.events.append(cue_event) utils.wait(self.parameters["cuetostim_wait"]) ## 2. play stimulus stim_start = dt.datetime.now() self.this_trial.stimulus_event.time = ( stim_start - self.this_trial.time).total_seconds() self.panel.speaker.play() # already queued in stimulus_pre()
def callback(self): # callback exists in self.panel.speaker.interface for class_, port in self.class_assoc.items(): if port.status(): self.this_trial.response = class_ self.this_trial.rt = (dt.datetime.now() - self.stim_start).total_seconds() self.summary['responses'] += 1 response_event = utils.Event( name=self.parameters['classes'][class_]['component'], label='peck', time=self.this_trial.rt, ) self.this_trial.events.append(response_event) self.log.info('response: %s' % (self.this_trial.response)) if class_ == self.this_trial.class_: self.this_trial.correct = True else: self.this_trial.incorrect = True return
def stimulus_pre(self): # wait for bird to peck self.log.debug("presenting stimulus %s" % self.this_trial.stimulus) self.log.debug("from file %s" % self.this_trial.stimulus_event.file_origin) self.panel.speaker.queue(self.this_trial.stimulus_event.file_origin) self.log.debug('waiting for peck...') self.panel.center.on() trial_time = None while trial_time is None: if self.check_session_schedule() == False: self.panel.center.off() self.panel.speaker.stop() self.update_adaptive_queue(presented=False) raise EndSession else: trial_time = self.panel.center.poll(timeout=60.0) self.this_trial.time = trial_time self.panel.center.off() self.this_trial.events.append( utils.Event( name='center', label='peck', time=0.0, )) # record trial initiation self.summary['trials'] += 1 self.summary['last_trial_time'] = self.this_trial.time.ctime() self.log.info("trial started at %s" % self.this_trial.time.ctime())
def stimulus_pre(self): """ Prepares stimuli to be presented ADDED: turn on peck ports """ # wait for bird to peck self.log.debug("presenting stimulus %s" % self.this_trial.stimulus) self.log.debug("from file %s" % self.this_trial.stimulus_event.file_origin) self.log.debug('waiting for peck...') self.panel.center.on() trial_time = None #print(self.check_session_schedule()) while trial_time is None: if self.check_session_schedule() == False: self.panel.center.off() self.panel.speaker.stop() self.update_adaptive_queue(presented=False) raise EndSession else: trial_time = self.panel.center.poll(timeout=60.0) self.this_trial.time = trial_time self.this_trial.sequence = self.this_trial.annotations[ 'seq'] #self.sequences[self.this_trial.index] self.this_trial.order = self.this_trial.annotations[ 'order'] #self.trial_order_list[self.this_trial.index] self.this_trial.syll_time_lens = self.this_trial.annotations[ 'syll_time_lens'] #self.trial_order_list[self.this_trial.index] #print(vars(self.this_trial)) #print(self.this_trial.sequence) #print(self.this_trial.index) #print('stim_name: ' + ''.join([self.parameters["num_to_char"][str(i)] for i in self.this_trial.annotations['stim_name'].split('-')])) #print('sequence: ' + ''.join([self.parameters["num_to_char"][str(num)] for num in self.this_trial.sequence])) self.log.info('sequence: ' + ''.join([ self.parameters["num_to_char"][str(num)] for num in self.this_trial.sequence ])) #print(breakme) self.panel.center.off() self.this_trial.events.append( utils.Event( name='center', label='peck', time=0.0, )) # record trial initiation self.summary['trials'] += 1 self.summary['last_trial_time'] = self.this_trial.time.ctime() self.log.info("trial started at %s" % self.this_trial.time.ctime())