def route_video_record(cmd):
        if cmd == "start":
            video_system.start_record()
        elif cmd == "stop":
            video_system.stop_record()

        return flask.Response("ok")
    def run(self, params):
        # resetting init values
        self.in_trial = False
        self.got_detection = False
        self.time = 0.0
        self.cancel_trials = None
        self.cancel_logic_trial = None
        self.prev_det = None
        self.prev_trial_detection = False
        self.stim_cancel = None
        self.consq_end = False

        self.data_dir = session_state["data_dir"]
        self.cur_trial = params["$num_trials"]
        self.consecutive = params["consecutive"]
        # determining the experiment type
        self.ex_type = ("consecutive" if self.consecutive else
                        ("continuous" if params["continuous"] else "regular"))
        # logging yolo detections
        self.yolo_log = data_log.QueuedDataLogger(
            columns=[
                ("time", "timestamptz not null"),
                ("x1", "double precision"),
                ("y1", "double precision"),
                ("x2", "double precision"),
                ("y2", "double precision"),
                ("confidence", "double precision"),
            ],
            csv_path=session_state["data_dir"] / "head_bbox.csv",
            table_name="bbox_position",
        )
        self.yolo_log.start()

        # detecting Aruco squares within arena
        self.detectAruco()

        if params["record_all"]:  # record start at init
            video_system.start_record()

        if not self.consecutive:  # no need to schedule next trials if consecutive
            self.cancel_trials = schedule.repeat(
                self.period_call,
                params.get("exp_interval", 100),
                params.get("num_of_exp", 1) - 1,
            )  # schedule the next trials

        # starting image observers
        yolo = exp.image_observers["head_bbox"]
        yolo.on_detection = self.on_yolo_detection
        yolo.start_observing()
        self.log.info("Start Observing")

        monitor.change_color("white")
Example #3
0
    def run(self):
        self.rng = np.random.default_rng()

        self.left_feeding_pos = None
        self.right_feeding_pos = None

        params = exp.get_params()

        for a in self.aruco_markers:
            if a["id"] == params["left_aruco_id"]:
                self.left_feeding_pos = a["center"]
            elif a["id"] == params["right_aruco_id"]:
                self.right_feeding_pos = a["center"]

        if self.left_feeding_pos is None or self.right_feeding_pos is None:
            raise ValueError(
                "Could not find left and/or right feeding positions")
        else:
            self.log.info(f"Left feeding position: {self.left_feeding_pos}")
            self.log.info(f"Right feeding position: {self.right_feeding_pos}")

        self.radius = params["feeding_radius"]

        if self.aruco_img is not None:
            img = np.copy(self.aruco_img)
        else:
            img, _ = image_sources[params["image_source_id"]].get_image()

        for a in self.aruco_markers:
            img = cv.circle(
                img,
                tuple(a["center"]),
                radius=self.radius,
                color=(0, 255, 0),
                thickness=5,
            )

        now_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
        area_image_path = session_state[
            "data_dir"] / f"feeding_areas_{now_str}.jpg"
        self.log.info(f"Saving feeding areas image to {area_image_path}")
        cv.imwrite(str(area_image_path), img)

        if params["record_video"]:
            video_system.start_record()

        self.bbox_collector.run(self.on_bbox_detection)
        self.shaping_mode = params["shaping_mode"]
        session_state["state"] = "idle"
    def run(self):
        self.find_reinforced_location()
        self.bbox_collector.run(self.on_bbox_detection)
        session_state["is_in_area"] = False
        self.in_out_time = None
        session_state.add_callback("is_in_area", self.is_in_area_changed)
        session_state["cooldown"] = False
        session_state["reward_scheduled"] = False
        self.cancel_cooldown = None
        self.cancel_reward_delay = None
        self.cancel_blink = None
        self.using_stochastic_delay = None

        if exp.get_params()["record_video"]:
            video_system.start_record()
Example #5
0
    def run_trial(self):
        if exp.get_params()["record_video"]:
            video_system.start_record()

        if exp.get_params()["media_url"] is not None:
            schedule.once(
                lambda: mqtt.client.publish_json(
                    "event/command/init_media", {"url": exp.get_params()["media_url"]}
                ),
                exp.get_params()["start_delay"],
            )

        else:
            schedule.once(
                lambda: mqtt.client.publish_json(
                    "event/command/init_bugs", exp.get_params()
                ),
                exp.get_params()["start_delay"],
            )
    def run(self):
        self.paths = list(
            Path(exp.get_params()["stimuli_path"]).rglob("*.jpg")) + list(
                Path(exp.get_params()["stimuli_path"]).rglob("*.JPG"))

        random.shuffle(self.paths)
        exp.session_state["image_list"] = self.paths

        self.log.info(f"Loaded {len(self.paths)} images.")

        intervals = [exp.get_params()["preseq_delay"]] + [
            exp.get_params()["stimuli_duration"],
            exp.get_params()["interstimuli_duration"],
        ] * len(self.paths)

        self.cur_index = 0
        self.clear(exp.get_params()["interstimuli_color"])

        self.cancel_sequence = schedule.sequence(self.display_stimuli,
                                                 intervals)
        video_system.start_record()
    def run_trial(self, params):

        self.in_trial = True

        if (params.get("record_exp", True)
                and not params["record_all"]):  # recording trials only
            video_system.start_record()

        self.log.info("Trial " + str(params["$num_trials"] - self.cur_trial) +
                      " started " + str(datetime.datetime.now()))

        if not self.consecutive:
            self.stim()  # present stimulus at trials start
            # giving a reward if bypass_detection enabled
            if params["bypass_detection"] and params["reward_detections"]:
                self.dispatch_reward()
                self.end_logic_trial()
            else:  # scheduling the logical end of trial
                self.cancel_logic_trial = schedule.once(
                    self.end_logic_trial, params["trial_length"])

        self.log.info("run trial procedure finished")
 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 start_record(log):
    log.info("Starting video recording.")
    video_system.start_record()
Example #10
0
 def run(self):
     monitor.set_color(exp.get_params()["background_color"])
     if exp.get_params()["record_video"]:
         video_system.start_record()
Example #11
0
    def run(self):
        self.cur_trial = exp.get_params()["$num_trials"]

        if exp.get_params()["record_exp"]:  # record start at init
            video_system.start_record()