Ejemplo n.º 1
0
    def setup(self, tree=None):
        """ Due to multiprocessing limitations, the setup is
        run separately from the constructor

        """
        diag_images = []
        for node in PreOrderIter(self.root):
            node.setup()
            if node._params is not None:
                self.all_params[node.strpath] = node._params
                if tree is not None:
                    tree.add(node._params)
                self.node_dict[node.strpath] = node
            diag_images.extend((node.strpath + "/" + imname
                                for imname in node.diagnostic_image_options))
        self.all_params["diagnostics"] = Parametrized(
            name="tracking/diagnostics",
            params=dict(image=Param("unprocessed", ["unprocessed"] +
                                    diag_images)),
            tree=tree,
        )
        self.all_params["reset"] = Parametrized(
            name="tracking/reset",
            params=dict(reset=Param(False, gui="button")),
            tree=tree,
        )
Ejemplo n.º 2
0
 def __init__(self):
     super().__init__()
     # self.add_params(dark_tail=False)
     self.params = Parametrized(name="tracking/tail_angles", params=self.detect)
     self.accumulator_headers = ["tail_sum"] + [
         "theta_{:02}".format(i) for i in range(self.params.n_segments)
     ]
Ejemplo n.º 3
0
    def testFunc(self):
        def paramfunc(x: Param(0.5), y: Param("ABCDF")):
            return x, y

        p = Parametrized(params=paramfunc)
        assert p.x == 0.5
        assert p.y == "ABCDF"
Ejemplo n.º 4
0
    def __init__(self,
                 acc: QueueDataAccumulator,
                 i_fish=0,
                 n_bouts=10,
                 n_save_max=300):
        super().__init__()
        self.title = "Bout shape"
        self.acc = acc
        self.bouts = deque()
        self.i_fish = i_fish
        self.processed_index = 0
        self.detection_params = Parametrized(params=dict(
            threshold=Param(0.2, (0.01, 5.0)),
            n_without_crossing=Param(5, (0, 10)),
            pad_before=Param(5, (0, 20)),
            pad_after=Param(5, (0, 20)),
            min_bout_len=Param(1, (1, 30)),
        ))
        self.n_bouts = n_bouts
        self.old_coords = None
        self.i_curve = 0
        self.n_save_max = n_save_max

        self.setLayout(QVBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.btn_editparam = QPushButton("Detection parameters")
        self.btn_editparam.clicked.connect(self.edit_params)
        self.layout().addWidget(self.btn_editparam)
        self.wnd_params = None

        self.vmax = 0
        self.lbl_vmax = QLabel()
        self.layout().addWidget(self.lbl_vmax)

        self.display_widget = pg.GraphicsLayoutWidget()
        self.layout().addWidget(self.display_widget)
        self.vb_display = pg.ViewBox()
        self.vb_display.setAspectLocked(True, 1)
        self.vb_display.setRange(xRange=[-1, 5], disableAutoRange=True)
        self.vb_display.invertY(True)
        self.display_widget.addItem(self.vb_display)

        self.bout_curves = [
            pg.PlotCurveItem(connect="finite") for _ in range(self.n_bouts)
        ]

        self.colors = np.zeros(self.n_bouts)
        self.decay_constant = 0.99

        self.bout_coords = None
        self.bout_state = BoutState(0, 0.0, 0, 0, 0)

        for c in self.bout_curves:
            self.vb_display.addItem(c)
Ejemplo n.º 5
0
    def __init__(
        self,
        app=None,
        protocol=None,
        dir_save=None,
        dir_assets="",
        instance_number=-1,
        database=None,
        metadata_general=None,
        metadata_animal=None,
        loop_protocol=False,
        arduino_config=None,
        log_format="csv",
        trigger_duration_queue=None,
        scope_triggering=None,
        offline=False,
        **kwargs
    ):
        self.arguments = locals()
        super().__init__()

        self.app = app
        self.protocol = protocol

        self.arduino_config = arduino_config

        # If there's a trigger, reference its queue to pass the duration:
        self.trigger = scope_triggering
        if scope_triggering is not None:
            self.trigger_duration_queue = scope_triggering.duration_queue
        self.offline = offline

        self.asset_dir = dir_assets

        if dir_save is None:
            dir_save = tempfile.gettempdir()
        self.base_dir = dir_save
        self.database = database
        self.use_db = True if database else False
        self.log_format = log_format
        self.loop_protocol = loop_protocol

        self.dc = DataCollector(
            folder_path=self.base_dir, instance_number=instance_number
        )

        self.window_main = None
        self.scope_config = None
        self.arduino_board = None
        self.abort = False

        self.logger = logging.getLogger()
        self.logger.setLevel("INFO")

        # We will collect data only of a directory for saving is specified:
        # Conditional, in case metadata are generated and passed from the
        # configuration file:
        if metadata_general is None:
            self.metadata = GeneralMetadata(tree=self.dc)
        else:
            self.metadata = metadata_general(tree=self.dc)

        if metadata_animal is None:
            self.metadata_animal = AnimalMetadata(tree=self.dc)
        else:
            self.metadata_animal = metadata_animal(tree=self.dc)

        # This is done to save GUI configuration:
        self.gui_params = Parametrized(
            "gui", tree=self.dc, params=dict(geometry=Param(""), window_state=Param(""))
        )

        self.dc.add(self.protocol)

        self.protocol_runner = ProtocolRunner(experiment=self)

        # assign signals from protocol_runner to be used externally:
        self.sig_protocol_finished = self.protocol_runner.sig_protocol_finished
        self.sig_protocol_started = self.protocol_runner.sig_protocol_started

        self.protocol_runner.sig_protocol_finished.connect(self.end_protocol)

        self.i_run = 0
        self.current_timestamp = datetime.datetime.now()

        self.gui_timer = QTimer()
        self.gui_timer.setSingleShot(False)

        self.t0 = datetime.datetime.now()

        self.animal_id = None
        self.session_id = None
Ejemplo n.º 6
0
 def setup(self):
     self._params = Parametrized(params=self._process,
                                 name="tracking+" + self.name)