def testInitRewardAmount(self): out = adaptive.init_reward_amount(self.sph) self.assertTrue(out == 3.0) sph = self.sph.copy() # Test return previous reward amount sph["LAST_TRIAL_DATA"] = {"trial_num": 199, "reward_amount": 999} sph["LAST_SETTINGS_DATA"] = {} out = adaptive.init_reward_amount(sph) self.assertTrue(out == 999) # Test return reduction of amount sph["LAST_TRIAL_DATA"] = {"trial_num": 200, "reward_amount": 999} out = adaptive.init_reward_amount(sph) self.assertTrue(out == 999 - sph.AR_STEP)
def __init__(self, task_settings, user_settings, debug=False, fmake=True): self.DEBUG = debug make = False if not fmake else ['video'] # ===================================================================== # IMPORT task_settings, user_settings, and SessionPathCreator params # ===================================================================== ts = { i: task_settings.__dict__[i] for i in [x for x in dir(task_settings) if '__' not in x] } self.__dict__.update(ts) us = { i: user_settings.__dict__[i] for i in [x for x in dir(user_settings) if '__' not in x] } self.__dict__.update(us) self = iotasks.deserialize_pybpod_user_settings(self) spc = SessionPathCreator(self.PYBPOD_SUBJECTS[0], protocol=self.PYBPOD_PROTOCOL, make=make) self.__dict__.update(spc.__dict__) # ===================================================================== # SUBJECT # ===================================================================== self.SUBJECT_WEIGHT = user.ask_subject_weight(self.PYBPOD_SUBJECTS[0]) self.SUBJECT_DISENGAGED_TRIGGERED = False self.SUBJECT_DISENGAGED_TRIALNUM = None # ===================================================================== # OSC CLIENT # ===================================================================== self.OSC_CLIENT_PORT = 7110 self.OSC_CLIENT_IP = '127.0.0.1' self.OSC_CLIENT = udp_client.SimpleUDPClient(self.OSC_CLIENT_IP, self.OSC_CLIENT_PORT) # ===================================================================== # PREVIOUS DATA FILES # ===================================================================== self.LAST_TRIAL_DATA = iotasks.load_data(self.PREVIOUS_SESSION_PATH) self.LAST_SETTINGS_DATA = iotasks.load_settings( self.PREVIOUS_SESSION_PATH) # ===================================================================== # ADAPTIVE STUFF # ===================================================================== self.AR_MIN_VALUE = 1.5 if 'Sucrose' in self.REWARD_TYPE else 2.0 self.REWARD_AMOUNT = adaptive.init_reward_amount(self) self.CALIB_FUNC = None if self.AUTOMATIC_CALIBRATION: self.CALIB_FUNC = adaptive.init_calib_func() self.CALIB_FUNC_RANGE = adaptive.init_calib_func_range() self.REWARD_VALVE_TIME = adaptive.init_reward_valve_time(self) self.STIM_GAIN = adaptive.init_stim_gain(self) self.IMPULSIVE_CONTROL = 'OFF' self = adaptive.impulsive_control(self) # ===================================================================== # frame2TTL # ===================================================================== self.F2TTL_GET_AND_SET_THRESHOLDS = frame2TTL.get_and_set_thresholds() # ===================================================================== # ROTARY ENCODER # ===================================================================== self.ALL_THRESHOLDS = (self.STIM_POSITIONS + self.QUIESCENCE_THRESHOLDS) self.ROTARY_ENCODER = MyRotaryEncoder( self.ALL_THRESHOLDS, self.STIM_GAIN, self.PARAMS['COM_ROTARY_ENCODER']) # ===================================================================== # SOUNDS # ===================================================================== self.SOFT_SOUND = None if 'ephys' in self._BOARD else self.SOFT_SOUND self.SOUND_SAMPLE_FREQ = sound.sound_sample_freq(self.SOFT_SOUND) self.WHITE_NOISE_DURATION = float(self.WHITE_NOISE_DURATION) self.WHITE_NOISE_AMPLITUDE = float(self.WHITE_NOISE_AMPLITUDE) self.GO_TONE_DURATION = float(self.GO_TONE_DURATION) self.GO_TONE_FREQUENCY = int(self.GO_TONE_FREQUENCY) self.GO_TONE_AMPLITUDE = float(self.GO_TONE_AMPLITUDE) self.SD = sound.configure_sounddevice( output=self.SOFT_SOUND, samplerate=self.SOUND_SAMPLE_FREQ) # Create sounds and output actions of state machine self.SOUND_BOARD_BPOD_PORT = 'Serial3' self.GO_TONE = None self.WHITE_NOISE = None self.GO_TONE_IDX = 2 self.WHITE_NOISE_IDX = 3 self = sound.init_sounds(self) # sets GO_TONE and WHITE_NOISE if self.SOFT_SOUND is None: sound.configure_sound_card( sounds=[self.GO_TONE, self.WHITE_NOISE], indexes=[self.GO_TONE_IDX, self.WHITE_NOISE_IDX], sample_rate=self.SOUND_SAMPLE_FREQ) self.OUT_STOP_SOUND = ('SoftCode', 0) if self.SOFT_SOUND else ('Serial3', ord('X')) self.OUT_TONE = ('SoftCode', 1) if self.SOFT_SOUND else ('Serial3', 6) self.OUT_NOISE = ('SoftCode', 2) if self.SOFT_SOUND else ('Serial3', 7) # ===================================================================== # RUN VISUAL STIM # ===================================================================== bonsai.start_visual_stim(self) # ===================================================================== # SAVE SETTINGS FILE AND TASK CODE # ===================================================================== if not self.DEBUG: iotasks.save_session_settings(self) iotasks.copy_task_code(self) iotasks.save_task_code(self) iotasks.copy_video_code(self) iotasks.save_video_code(self) self.bpod_lights(0) self.display_logs()