Esempio n. 1
0
 def next_trial(self):
     # First trial exception
     if self.trial_num == 0:
         self.trial_num += 1
         # Send next trial info to Bonsai
         bonsai.send_current_trial_info(self)
         return
     self.data_file = str(self.data_file)
     # Increment trial number
     self.trial_num += 1
     # Update contrast
     self.contrast = random.choice(self.contrast_set)
     # Update stimulus phase
     self.stim_phase = random.uniform(0, math.pi)
     # Update position
     self.position = random.choice(self.position_set)
     # Update delay to stimulus center
     self.delay_to_stim_center = np.random.normal(
         self.delay_to_stim_center_mean, 2)
     # Update water delivered
     self.water_delivered += self.reward_amount
     # Open the data file to append the next trial
     self.data_file = open(self.data_file_path, 'a')
     # Send next trial info to Bonsai
     bonsai.send_current_trial_info(self)
Esempio n. 2
0
    def next_trial(self):
        # First trial exception
        if self.trial_num == 0:
            self.trial_num += 1
            # Send next trial info to Bonsai
            bonsai.send_current_trial_info(self)
            return
        self.data_file = str(self.data_file)
        # update + next contrast: update buffers/counters + get next contrast
        # This has to happen before self.contrast is pointing to next trials
        self.contrast.next_trial(self.position)  # still prev_position

        # Increment trial number
        self.trial_num += 1
        # Update quiescent period
        self.quiescent_period = self.quiescent_period_base + misc.texp()
        # Update stimulus phase
        self.stim_phase = random.uniform(0, math.pi)
        # Update contrast
        self._next_contrast()
        # Update position
        self.position, self.stim_probability_left = self._next_position()
        # Update signed_contrast and buffer (AFTER position update)
        self.signed_contrast = self.contrast.value * np.sign(self.position)
        self.signed_contrast_buffer.append(self.signed_contrast)
        # Update state machine events
        self.event_error = self.threshold_events_dict[self.position]
        self.event_reward = self.threshold_events_dict[-self.position]
        # Reset outcome variables for next trial
        self.trial_correct = None
        # Open the data file to append the next trial
        self.data_file = open(self.data_file_path, 'a')
        # Send next trial info to Bonsai
        bonsai.send_current_trial_info(self)
Esempio n. 3
0
 def next_trial(self):
     # First trial exception
     if self.trial_num == 0:
         self.trial_num += 1
         self.block_num += 1
         self.block_rew_num += 1
         self.block_trial_num += 1
         # Send next trial info to Bonsai
         bonsai.send_current_trial_info(self)
         return
     self.data_file = str(self.data_file)
     # Increment trial number
     self.trial_num += 1
     # Update quiescent period
     self.quiescent_period = self.quiescent_period_base + misc.texp()
     # Update stimulus phase
     self.stim_phase = random.uniform(0, math.pi)
     # Update block
     self = blocks.update_block_params(self)
     # Update stim probability left
     self.stim_probability_left = blocks.update_probability_left(self)
     # Update position
     self.position = blocks.draw_position(self.position_set,
                                          self.stim_probability_left)
     # Update contrast
     self.contrast = misc.draw_contrast(
         self.contrast_set, prob_type=self.contrast_set_probability_type)
     self.signed_contrast = self.contrast * np.sign(self.position)
     # Update state machine events
     self.event_error = self.threshold_events_dict[self.position]
     self.event_correct = self.threshold_events_dict[
         -self.position]  # need to check this
     self.rewarded = blocks_rew.draw_reward(
         self.position, self.rew_set, self.rew_probability_left
     )  #### @alejandro This determines whether an event is rewarded
     # Reset outcome variables for next trial
     self.trial_correct_rewarded = None  ####
     self.trial_correct_unrewarded = None  ####
     # Open the data file to append the next trial
     self.data_file = open(self.data_file_path, 'a')
     # Send next trial info to Bonsai
     bonsai.send_current_trial_info(self)
     #Update opto_variables
     self.opto_trial = optobpod.opto_switch(self.opto_on, self.opto_freq)
Esempio n. 4
0
 def next_trial(self):
     # First trial exception
     if self.trial_num == 0:
         self.trial_num += 1
         self.block_num += 1
         self.block_trial_num += 1
         # Send next trial info to Bonsai
         bonsai.send_current_trial_info(self)
         return
     self.data_file = str(self.data_file)
     # Increment trial number
     self.trial_num += 1
     # Update quiescent period
     self.quiescent_period = self.quiescent_period_buffer[self.trial_num -
                                                          1]
     # Update stimulus phase
     self.stim_phase = self.stim_phase_buffer[self.trial_num - 1]
     # Update block
     self.block_trial_num += 1
     if self.block_trial_num > self.block_len:
         self.block_num += 1
         self.block_trial_num = 1
         self.block_len = self.len_blocks_buffer[self.block_num - 1]
     # Update stim probability left + buffer
     self.stim_probability_left = blocks.calc_probability_left(self)
     self.stim_probability_left_buffer.append(self.stim_probability_left)
     # Update position + buffer
     self.position = int(self.position_buffer[self.trial_num - 1])
     # Update contrast + buffer
     self.contrast = self.contrast_buffer[self.trial_num - 1]
     # Update signed_contrast + buffer (AFTER position update)
     self.signed_contrast = self.contrast * np.sign(self.position)
     self.signed_contrast_buffer.append(self.signed_contrast)
     # Update state machine events
     self.event_error = self.threshold_events_dict[self.position]
     self.event_reward = self.threshold_events_dict[-self.position]
     # Reset outcome variables for next trial
     self.trial_correct = None
     # Open the data file to append the next trial
     self.data_file = open(self.data_file_path, 'a')
     # Send next trial info to Bonsai
     bonsai.send_current_trial_info(self)
Esempio n. 5
0
 def next_trial(self):
     # First trial exception
     if self.trial_num == 0:
         self.trial_num += 1
         self.block_num += 1
         self.block_trial_num += 1
         # Send next trial info to Bonsai
         bonsai.send_current_trial_info(self)
         return
     self.data_file = str(self.data_file)
     # Increment trial number
     self.trial_num += 1
     # Update quiescent period
     self.quiescent_period = self.quiescent_period_base + misc.texp()
     # Update stimulus phase
     self.stim_phase = random.uniform(0, math.pi)
     # Update block
     self = blocks.update_block_params(self)
     # Update stim probability left + buffer
     self.stim_probability_left = blocks.update_probability_left(self)
     self.stim_probability_left_buffer.append(self.stim_probability_left)
     # Update position + buffer
     self.position = blocks.draw_position(self.position_set,
                                          self.stim_probability_left)
     self.position_buffer.append(self.position)
     # Update contrast + buffer
     self.contrast = misc.draw_contrast(
         self.contrast_set, prob_type=self.contrast_set_probability_type)
     self.contrast_buffer.append(self.contrast)
     # Update signed_contrast + buffer (AFTER position update)
     self.signed_contrast = self.contrast * np.sign(self.position)
     self.signed_contrast_buffer.append(self.signed_contrast)
     # Update state machine events
     self.event_error = self.threshold_events_dict[self.position]
     self.event_reward = self.threshold_events_dict[-self.position]
     # Reset outcome variables for next trial
     self.trial_correct = None
     # Open the data file to append the next trial
     self.data_file = open(self.data_file_path, 'a')
     # Send next trial info to Bonsai
     bonsai.send_current_trial_info(self)