コード例 #1
0
 def stop_experiment(self):
     """
     Stop the experiment and reset the timer
     """
     self.experiment_finished = True
     print("Experiment completed!")
     self._exp_timer.reset()
     # don't forget to stop the laser for safety!
     laser_switch(False)
コード例 #2
0
    def check_skeleton(self, frame, skeleton):
        """
        Checking each passed animal skeleton for a pre-defined set of conditions
        Outputting the visual representation, if exist
        Advancing trials according to inherent logic of an experiment
        :param frame: frame, on which animal skeleton was found
        :param skeleton: skeleton, consisting of multiple joints of an animal
        """
        self.check_exp_timer()  # checking if experiment is still on

        if not self.experiment_finished:
            result, response = self._trigger.check_skeleton(skeleton=skeleton)
            plot_triggers_response(frame, response)
            if result:
                laser_switch(True)
                self._event_count += 1
                print(self._event_count)
                print("Light on")

            else:
                laser_switch(False)
                print("Light off")

            return result, response
コード例 #3
0
    def check_skeleton(self, frame, skeleton):

        if self._experiment_timer.check_timer():
            if self._total_time >= self._max_total_time:
                # check if total time to stimulate per experiment is reached
                print("Ending experiment, total event time ran out")
                self.stop_experiment()
            else:
                # if not continue
                if not self._intertrial_timer.check_timer():
                    # check if there is an intertrial time running right now, if not continue
                    # check if the headdirection angle is within limits
                    _, angle_point = angle_between_vectors(
                        *skeleton["neck"], *skeleton["nose"], *self._point)
                    if self._start_angle <= angle_point <= self._end_angle:
                        if not self._event:
                            # if a stimulation event wasn't started already, start one
                            print("Starting Stimulation")
                            self._event = True
                            # and activate the laser, start the timer and reset the intertrial timer
                            laser_switch(True)
                            self._event_start = time.time()
                            self._intertrial_timer.reset()
                        else:
                            if time.time(
                            ) - self._event_start <= self._max_trial_time:
                                # if the total event time has not reached the maximum time per event
                                # self._trial_time = time.time() - self._event_start
                                pass
                            else:
                                # if the maximum event time was reached, reset the event,
                                # turn off the laser and start intertrial time
                                print(
                                    "Ending Stimulation, Stimulation time ran out"
                                )
                                self._event = False
                                # laser_toggle(False)
                                laser_switch(False)
                                # self._trial_time = time.time() - self._event_start
                                trial_time = time.time() - self._event_start
                                self._total_time += trial_time
                                self._results.append(trial_time)
                                print("Stimulation duration", trial_time)
                                self._intertrial_timer.start()
                    else:
                        # if the headdirection is not within the parameters
                        if self._event:
                            # but the stimulation is still going
                            if time.time(
                            ) - self._event_start < self._min_trial_time:
                                # check if the minimum event time was not reached, then pass
                                pass
                            else:
                                # if minumum event time has been reached, reset the event,
                                # turn of the laser and start intertrial time
                                print("Ending Stimulation, angle not in range")
                                self._event = False
                                # laser_toggle(False)
                                laser_switch(False)
                                # self._trial_time = time.time() - self._event_start
                                trial_time = time.time() - self._event_start
                                self._total_time += trial_time
                                self._results.append(trial_time)
                                print("Stimulation duration", trial_time)
                                self._intertrial_timer.start()
        else:
            # if maximum experiment time was reached, stop experiment
            print("Ending experiment, timer ran out")
            self.stop_experiment()

        return self._event