def dispense(self): if self.left_trial: arena.run_command("dispense", exp.get_params()["left_feeder"], None, False) else: arena.run_command("dispense", exp.get_params()["right_feeder"], None, False)
def led_blink(num_blinks, led_duration): interval = led_duration / num_blinks / 2 def toggle_led(): arena.run_command("toggle", "Signal LED") arena.run_command("set", "Signal LED", [0]) return schedule.repeat(toggle_led, interval, repeats=num_blinks * 2)
def route_arena(): try: command = flask.request.json[0] interface = flask.request.json[1] if len(flask.request.json) > 2: args = flask.request.json[2:] else: args = None arena.run_command(command, interface, args, False) return flask.Response("ok") except Exception as e: log.exception("Exception while running arena command:") flask.abort(500, e)
def show_cue(self, left): session_state["state"] = "cue" params = exp.get_params() blink_dur = params["blink_dur_left"] if left else params[ "blink_dur_right"] arena.run_command("periodic", params["light"], [1, blink_dur], False) def stop_blink(): arena.run_command("periodic", params["light"], [0], True) self.to_feed_state() self.cancel_stop_blink = schedule.once( stop_blink, params["cue_duration"], )
def run_trial(self): if session_state["cur_trial"] == 0: return # Success if exp.get_params()["dispense_reward"]: self.log.info("Trial ended. Dispensing reward.") exp.event_logger.log( "loclearn/reward", {"stochastic_delay": self.using_stochastic_delay} ) self.log.info( f"Dispensing reward (stochastic_delay={self.using_stochastic_delay})" ) arena.run_command("dispense", "Left feeder", None, False) else: self.log.info("Trial ended.") session_state["reward_scheduled"] = False
def dispense_reward(self): if random.random() <= exp.get_params()["reward"]["dispense_prob"]: self.log.info("Trial ended. Dispensing reward.") else: self.log.info( "Trial ended. NOT dispensing reward (stochastic reward).") exp.next_trial() return rewards_count = session_state["rewards_count"] + 1 session_state["reward_scheduled"] = False feeders = exp.get_params()["reward"]["feeders"] max_reward = sum(feeders.values()) rewards_sum = 0 for interface, rewards in feeders.items(): rewards_sum += rewards if rewards_count <= rewards_sum: exp.event_logger.log( "dispensing_reward", { "num": rewards_count, "stochastic_delay": self.using_stochastic_delay, }, ) self.log.info( f"Dispensing reward #{rewards_count} from feeder {interface} (stochastic_delay={self.using_stochastic_delay})" ) arena.run_command("dispense", interface, None, False) break if rewards_count >= max_reward: session_state["out_of_rewards"] = True self.log.info("Out of rewards!") session_state["rewards_count"] = rewards_count exp.next_trial()
def on_day_end(self): arena.run_command("set", "AC Line 2", [0]) arena.run_command("set", "AC Line 1", [0]) video_system.stop_record() arena.stop_trigger() self.bbox_collector.stop()
def on_day_start(self): self.bbox_collector.start(self.on_bbox_detection) arena.start_trigger() video_system.start_record() arena.run_command("set", "AC Line 2", [1]) arena.run_command("set", "AC Line 1", [1])
def stop_blink(): arena.run_command("periodic", params["light"], [0], True) self.to_feed_state()
def start_blink(interface, period_time=None): arena.run_command("periodic", interface, [1, int(period_time)], False)
def heat_off(log): log.info("Turning heat off") arena.run_command("set", "AC Line 1", [0])
def heat_on(log): log.info("Turning heat on") arena.run_command("set", "AC Line 1", [1])
def dispatch_reward_actual(self): self.log.info("REWARD SENT") arena.run_command("dispense", "Left feeder")
def led_stimulus(self): self.stim_cancel = schedule.repeat( lambda: arena.run_command("toggle", "Signal LED"), exp.get_params()["led_duration"], 2 * exp.get_params().get("led_blinks", 1), )
def toggle_led(): arena.run_command("toggle", "Signal LED")
def stop_blink(interface): arena.run_command("periodic", interface, [0], True)
def lights_on(log): log.info("Turning lights on") arena.run_command("set", "AC Line 2", [1])
def run_trial(self): self.log.info(f"{exp.session_state['cur_trial']}: {time.time()}") arena.run_command("toggle", "Signal LED", update_value=True)
def lights_off(log): log.info("Turning lights off") arena.run_command("set", "AC Line 2", [0])