Example #1
0
    def trial_completed(self, behavior_data):
        """Update outcome variables using bpod.session.current_trial
        Check trial for state entries, first value of first tuple"""
        # Update elapsed_time
        self.elapsed_time = datetime.datetime.now() - self.init_datetime
        self.behavior_data = behavior_data
        correct = ~np.isnan(
            self.behavior_data['States timestamps']['correct'][0][0])
        error = ~np.isnan(
            self.behavior_data['States timestamps']['error'][0][0])
        no_go = ~np.isnan(
            self.behavior_data['States timestamps']['no_go'][0][0])
        assert correct or error or no_go
        # Add trial's response time to the buffer
        self.response_time = misc.get_trial_rt(self.behavior_data)
        self.response_time_buffer.append(self.response_time)
        # Update response buffer -1 for left, 0 for nogo, and 1 for rightward
        if (correct and self.position < 0) or (error and self.position > 0):
            self.response_side_buffer.append(1)
        elif (correct and self.position > 0) or (error and self.position < 0):
            self.response_side_buffer.append(-1)
        elif no_go:
            self.response_side_buffer.append(0)
        # Update the trial_correct variable + buffer
        self.trial_correct = bool(correct)
        self.trial_correct_buffer.append(self.trial_correct)
        # Increment the trial correct counter
        self.ntrials_correct += self.trial_correct
        # Update the water delivered
        if self.trial_correct:
            self.water_delivered += self.reward_amount

        # SAVE TRIAL DATA
        params = self.__dict__.copy()
        params.update({'behavior_data': behavior_data})
        # Convert to str all non serializable params
        params['data_file'] = str(params['data_file'])
        params['osc_client'] = 'osc_client_pointer'
        params['init_datetime'] = params['init_datetime'].isoformat()
        params['elapsed_time'] = str(params['elapsed_time'])
        params['position'] = int(params['position'])
        # Delete buffered data
        params['stim_probability_left_buffer'] = ''
        params['position_buffer'] = ''
        params['contrast_buffer'] = ''
        params['signed_contrast_buffer'] = ''
        params['response_time_buffer'] = ''
        params['response_side_buffer'] = ''
        params['trial_correct_buffer'] = ''
        # Dump and save
        out = json.dumps(params, cls=ComplexEncoder)
        self.data_file.write(out)
        self.data_file.write('\n')
        self.data_file.close()
        # If more than 42 trials save transfer_me.flag
        if self.trial_num == 42:
            misc.create_flags(self.data_file_path, self.poop_count)

        return self
Example #2
0
 def trial_completed(self, behavior_data):
     """Update outcome variables using bpod.session.current_trial
     Check trial for state entries, first value of first tuple"""
     # Update elapsed_time
     self.elapsed_time = datetime.datetime.now() - self.init_datetime
     correct_rewarded = ~np.isnan(self.behavior_data['States timestamps']
                                  ['correct']['rewarded'][0][0])
     correct_unrewarded = ~np.isnan(  #added vy alex
         self.behavior_data['States timestamps']['correct']['unrewarded'][0]
         [0])  ####
     error = ~np.isnan(
         self.behavior_data['States timestamps']['error'][0][0])
     no_go = ~np.isnan(
         self.behavior_data['States timestamps']['no_go'][0][0])
     assert correct_rewarded or correct_unrewarded or error or no_go  ####
     # Add trial's response time to the buffer
     self.response_time_buffer.append(misc.get_trial_rt(behavior_data))
     # Update the trial_correct variable
     self.trial_correct_rewarded = bool(correct_rewarded)  ####
     self.trial_correct_unrewarded = bool(correct_unrewarded)  ####
     # Increment the trial correct counter
     self.ntrials_correct_unrewarded += self.trial_correct_unrewarded  ####
     self.ntrials_correct_rewarded += self.trial_correct_rewarded  ####
     # Update the water delivered
     if self.trial_correct_rewarded:  ####
         self.water_delivered += self.reward_amount  ####
     # SAVE TRIAL DATA
     params = self.__dict__.copy()
     params.update({'behavior_data': behavior_data})
     # Convert to str all non serializable params
     params['data_file'] = str(params['data_file'])
     params['osc_client'] = 'osc_client_pointer'
     params['init_datetime'] = params['init_datetime'].isoformat()
     params['elapsed_time'] = str(params['elapsed_time'])
     params['position'] = int(params['position'])
     # Dump and save
     out = json.dumps(params, cls=ComplexEncoder)
     self.data_file.write(out)
     self.data_file.write('\n')
     self.data_file.close()
     # If more than 42 trials save transfer_me.flag
     if self.trial_num == 42:
         misc.create_flags(self.data_file_path, self.poop_count)
     return json.loads(out)
Example #3
0
    def trial_completed(self, behavior_data):
        """Update outcome variables using bpod.session.current_trial
        Check trial for state entries, first value of first tuple """
        # Update elapsed_time
        self.elapsed_time = datetime.datetime.now() - self.init_datetime
        # SAVE TRIAL DATA
        params = self.__dict__.copy()
        params.update({'behavior_data': behavior_data})
        # open data_file is not serializable, convert to str
        params['data_file'] = str(params['data_file'])
        params['osc_client'] = 'osc_client_pointer'
        params['init_datetime'] = params['init_datetime'].isoformat()
        params['elapsed_time'] = str(params['elapsed_time'])

        out = json.dumps(params, cls=ComplexEncoder)
        self.data_file.write(out)
        self.data_file.write('\n')
        self.data_file.close()
        # If more than 42 trials save transfer_me.flag
        if self.trial_num == 42:
            misc.create_flags(self.data_file_path, self.poop_count)

        return json.loads(out)