Ejemplo n.º 1
0
    def _process(self, im, image_scale: Param(0.5, (0.05, 1.0)),
                 filter_size: Param(2, (0, 15)), color_invert: Param(True),
                 clip: Param(140, (0, 255)), **extraparams):
        """Optionally resizes, smooths and inverts the image

        :param im:
        :param state:
        :param filter_size:
        :param image_scale:
        :param color_invert:
        :return:
        """
        if image_scale != 1:
            im = cv2.resize(im,
                            None,
                            fx=image_scale,
                            fy=image_scale,
                            interpolation=cv2.INTER_AREA)
        if filter_size > 0:
            im = cv2.boxFilter(im, -1, (filter_size, filter_size))
        if color_invert:
            im = 255 - im
        if clip > 0:
            im = np.maximum(im, clip) - clip

        if self.set_diagnostic == "filtered":
            self.diagnostic_image = im

        return NodeOutput([], im)
Ejemplo n.º 2
0
 def __init__(self, **kwargs):
     super().__init__(name="video_params", **kwargs)
     self.framerate = Param(
         100.0, limits=(10, 700), unit="Hz", desc="Framerate (Hz)"
     )
     self.offset = Param(50)
     self.paused = Param(False)
Ejemplo n.º 3
0
 def __init__(self):
     super().__init__()
     # Here we define these attributes as Param s. This will automatically
     #  build a control for them and make them modifiable live from the
     # interface.
     self.period_sec = Param(10.0, limits=(0.2, None))
     self.flash_duration = Param(1.0, limits=(0.0, None))
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, name="general/animal", **kwargs)
     self.species = Param("")
     self.age = Param("")
     self.id = Param("0")
     self.comments = Param("", desc="Comments on the animal or experiment")
     self.genotype = Param("WT")
Ejemplo n.º 5
0
 def __init__(self):
     super().__init__()
     self.n_trials = Param(120, (0, 2400))
     self.stim_on_duration = Param(10, (0, 30))
     self.stim_off_duration = Param(10, (0, 30))
     self.center_offset = Param(0, (-100, 100))
     self.brightness = Param(255, (0, 255))
Ejemplo n.º 6
0
    def __init__(self):
        super().__init__()

        self.inter_stim_pause = Param(20.0)
        self.grating_vel = Param(10.0)
        self.grating_duration = Param(10.0)
        self.grating_cycle = Param(10.0)
Ejemplo n.º 7
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.º 8
0
 def __init__(self):
     super().__init__()
     self.name = "scanning/planar_scanning"
     self.lateral_range = Param((0, 0.5), (-2, 2))
     self.lateral_frequency = Param(500.0, (10, 1000), unit="Hz")
     self.frontal_range = Param((0, 0.5), (-2, 2))
     self.frontal_frequency = Param(500.0, (10, 1000), unit="Hz")
Ejemplo n.º 9
0
    def __init__(self):
        super().__init__()

        self.inter_stim_pause = Param(10)
        self.grating_vel = Param(10.0)
        self.grating_duration = Param(30)
        self.grating_cycle = Param(10)
        self.target_vel = Param(-15.0, limits=(-50, 20))
Ejemplo n.º 10
0
    def __init__(self):
        super().__init__()

        self.t_pre = Param(5.)  # time of still gratings before they move
        self.t_move = Param(5.)  # time of gratings movement
        self.grating_vel = Param(-10.)  # gratings velocity
        self.grating_period = Param(10)  # grating spatial period
        self.grating_angle_deg = Param(90.)  # grating orientation
Ejemplo n.º 11
0
 def __init__(self):
     super().__init__()
     self.name = "experiment_settings"
     self.save_dir = Param(conf["default_paths"]["data"], gui=False)
     self.notification_email = Param("")
     self.overwrite_save_folder = Param(0, (0, 1),
                                        gui=False,
                                        loadable=False)
Ejemplo n.º 12
0
 def __init__(self):
     super().__init__(self)
     self.name = "scanning/volumetric_recording"
     self.piezo_scan_range = Param((180.0, 220.0), (0.0, 400.0), unit="um")
     self.frequency = Param(3.0, (0.1, 100), unit="volumes/s (Hz)")
     self.n_planes = Param(4, (2, 100))
     self.n_skip_start = Param(0, (0, 20))
     self.n_skip_end = Param(0, (0, 20))
Ejemplo n.º 13
0
 def __init__(self, **kwargs):
     super().__init__(name="a/gino", **kwargs)
     self.random = 5
     self.a = Param(1)
     self.b = Param(2.0)
     self.c = Param(5)
     self.a_list = Param("a", ["a", "b", "c"])
     self.sig_param_changed.connect(self.update_param)
Ejemplo n.º 14
0
    def detect(
        self,
        im,
        tail_start: Param((0, 0), gui=False),
        n_segments: Param(7),
        tail_length: Param((1, 1), gui=False),
        **extraparams
    ):
        """Tail tracing based on min (or max) detection on arches. Wraps
        _tail_trace_core_ls. Speed testing: 20 us for a 514x640 image without
        smoothing, 300 us with smoothing.

        Parameters
        ----------
        img :
            input image
        tail_start :
            tail starting point (x, y) (Default value = (0)
        tail_length :
            tail length (Default value = (1)
        n_segments :
            number of segments (Default value = 7)
        dark_tail :
            True for inverting image colors (Default value = False)
        im :

        0) :

        1) :

        image_scale :
             (Default value = 1)

        Returns
        -------

        """
        start_y, start_x = tail_start
        tail_length_y, tail_length_x = tail_length

        scale = im.shape[0]

        # Calculate tail length:
        length_tail = np.sqrt(tail_length_x**2 + tail_length_y**2) * scale

        # Initial displacements in x and y:
        disp_x = tail_length_x * scale / n_segments
        disp_y = tail_length_y * scale / n_segments

        start_x *= scale
        start_y *= scale

        # Use jitted function for the actual calculation:
        angle_list = _tail_trace_core_ls(
            im, start_x, start_y, disp_x, disp_y, n_segments, length_tail
        )

        return angle_list
Ejemplo n.º 15
0
 def __init__(self):
     super().__init__()
     self.name = "recording"
     self.n_planes = Param(1, (1, 500))
     self.dz = Param(1.0, (0.1, 20.0), unit="um")
     self.save_dir = Param(r"C:\Users\portugueslab\Desktop\test\python",
                           gui=False)
     self.notification_email = Param("None")
     self.notify_every_n_planes = Param(3, (1, 1000))
Ejemplo n.º 16
0
 def __init__(self):
     super().__init__()
     self.name = "camera/parameters"
     self.exposure_time = Param(conf["camera"]["default_exposure"],
                                (1, 1000),
                                unit="ms")
     self.binning = Param(conf["camera"]["default_binning"], [1, 2, 4])
     self.roi = Param(
         roi_size, gui=False
     )  # order of params here is [hpos, vpos, hsize, vsize,]; h: horizontal, v: vertical
Ejemplo n.º 17
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.º 18
0
 def __init__(self, **kwargs):
     super().__init__(name="camera_params", **kwargs)
     self.exposure = Param(1.,
                           limits=(0.1, 50),
                           unit="ms",
                           desc="Exposure (ms)")
     self.framerate = Param(150.,
                            limits=(10, 700),
                            unit=" Hz",
                            desc="Framerate (Hz)")
     self.gain = Param(1.,
                       limits=(0.1, 12),
                       desc="Camera amplification gain")
     self.ring_buffer_length = Param(
         300, (1, 2000),
         desc="Rolling buffer that saves the last items",
         gui=False)
     self.paused = Param(False)
     self.replay = Param(True, desc="Replaying", gui=False)
     self.replay_fps = Param(
         15,
         (0, 500),
         desc=
         "If bigger than 0, the rolling buffer will be replayed at the given framerate",
     )
     self.replay_limits = Param((0, 600), gui=False)
Ejemplo n.º 19
0
    def __init__(self, **kwargs):
        # We will define all metadata as Parameters.
        super().__init__(**kwargs)

        # String parameter. Setting the loadable flag to false prevent this
        # parameter to be restored frin the stytra_last_config file, and the
        # editable to false to make it not changable in the interface:
        self.species = Param("Kraken kraken", loadable=False, editable=False)
        # String parameter with a default and a description.
        # The description appears hovering with mouse.
        self.location = Param("North Atlantic",
                              desc="Approximate location of the sightening")
        # Drop down menu, for multiple choices:
        self.diet = Param("Humans", ["Humans", "Ships", "Unknown"])
        # Redefine age with units:
        self.age = Param(500, limits=(1, 10000), unit="years")
        # A simple integer, with limits:
        self.n_tentacles = Param(8, limits=(1, 200))
        # An integer with inferior boundary only (no upper limit for the terror):
        self.n_casualties = Param(8, limits=(1, None))
        # A simple float, with limits and measure units:
        self.dimensions = Param(8.0, limits=(0.5, 100), unit="m")

        # Some parameters are already defined in the AnimalMetadata class
        # (species, genotype, comments, id). Here we overwrite them:
        self.id = Param("")
Ejemplo n.º 20
0
    def _process(self, im, learning_rate: Param(0.04, (0.0, 1.0)),
                 learn_every: Param(400, (1, 10000))):
        messages = []
        if self.background_image is None:
            self.background_image = im.astype(np.float32)
            messages.append("I:New backgorund image set")
        elif self.i == 0:
            self.background_image[:, :] = im.astype(np.float32) * np.float32(
                learning_rate) + self.background_image * np.float32(
                    1 - learning_rate)

        self.i = (self.i + 1) % learn_every

        return NodeOutput(messages, negdif(self.background_image, im))
Ejemplo n.º 21
0
 def __init__(self):
     super().__init__()
     self.name = "scanning"
     self.aspect_ratio = Param(1.0, (0.2, 5.0))
     self.voltage = Param(3.0, (0.2, 4.0))
     self.framerate = Param(2.0, (0.1, 10.0))
     self.reset_shutter = Param(False)
     self.binning = Param(10, (1, 50))
     self.output_rate_khz = Param(400, (50, 2000))
     self.laser_power = Param(10.0, (0, 100))
     self.n_turn = Param(10, (0, 100))
     self.n_extra_init = Param(100, (0, 100))
Ejemplo n.º 22
0
 def __init__(self):
     super().__init__()
     self.name = "general/scanning_state"
     self.scanning_state = Param(
         "Paused",
         ["Paused", "Calibration", "Planar", "Volume"],
     )
Ejemplo n.º 23
0
def grow_rois(
    stack,
    corr_map,
    init_corr_thresh: Param(0.15, (0.01, 0.95)) = 0.15,
    corr_thresh_inc_dist: Param(1.0, (0.5, 15)) = 1,
    final_corr_threshold: Param(0.0, (0, 0.95)) = 0,
    max_radius: Param(10, (2, 100)) = 10,
    min_area: Param(1, (1, 50)) = 1,
    max_labels: Param(100, (10, 20000)) = 100,
    max_investigate: Param(2000, (100, 30000)) = 2000,
    across_planes: Param(True) = True,
    voxel_size=(1, 1, 1),
) -> np.ndarray:
    """Find ROIs by taking local maxima of correlation maps and growing ROIs
     around them

    :param corr_map: input correlation map
    :param init_corr_thresh: the threshold of correlation that gets added to
        the roi, grows linearly until corr_thresh_inc_dist
    :param corr_thresh_inc_dist: the distance until which the correlation
        threshold increases, in voxels if voxel_size is not specified, otherwise
        in um
     :param final_corr_threshold: the correlation threshold reached over
        corr_threshold_steps
    :param max_radius: the maximum radius of a ROIs, so that they are
        roughly circular
    :param min_area: the minimum area of a ROI
    :param max_labels: the maximal number of ROIs to search for
        (if not across planes, in one plane)
    :param max_investigate: the maximum number of potential ROIs to investigate
        per slice or volume part (as small ROIs are discarded)

    :param across_planes: True to grow ROIs across planes
    :param voxel_size: (optional, size of voxels in mm)


    :return: stack ROIs labeled
    """

    # if we get the video or the correlation map of the wrong shape,
    #  expand it so that the algorithm still works
    stack = to_4d(stack)
    corr_map = to_3d(corr_map)

    return _jit_flood(
        stack,
        corr_map,
        init_corr_thresh,
        max_labels,
        final_corr_threshold,
        max_radius,
        corr_thresh_inc_dist,
        max_investigate,
        min_area,
        across_planes,
        voxel_size,
    )
Ejemplo n.º 24
0
 def _process(self, input, a: Param(1), set_diagnostic=None):
     if self._output_type is None:
         self._output_type = namedtuple("o", "inp par")
     else:
         self._output_type_changed = False
     if self.set_diagnostic:
         self.diagnostic_image = "img"
     return NodeOutput([], self._output_type(par=a, inp=input))
Ejemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.an_int = Param(1)
     self.a_float = Param(1.0, (-1.0, 10.0))
     self.a_str = Param("strstr")
     self.a_folder = Param("", gui="folder")
     self.a_list = Param("a", ["a", "b", "c"], editable=False)
     self.a_bool = Param(False, editable=False)
     self.a_range = Param((0.5, 1.5), (0.0, 2.0))
     self.a_different_bool = Param(True, gui=False)
Ejemplo n.º 26
0
    def _process(self, im, wnd_pos: Param((129, 20), gui=False),
                 threshold: Param(56, limits=(1, 254)), wnd_dim: Param(
                     (14, 22), gui=False), **extraparams):
        """

        Parameters
        ----------
        im :
            image (numpy array);
        win_pos :
            position of the window on the eyes (x, y);
        win_dim :
            dimension of the window on the eyes (w, h);
        threshold :
            threshold for ellipse fitting (int).

        Returns
        -------

        """
        message = ""
        PAD = 0

        cropped = _pad(
            (im[wnd_pos[1]:wnd_pos[1] + wnd_dim[1], wnd_pos[0]:wnd_pos[0] +
                wnd_dim[0], ] < threshold).view(dtype=np.uint8).copy(),
            padding=PAD,
            val=255,
        )

        # try:
        e = _fit_ellipse(cropped)

        if self.set_diagnostic == "thresholded":
            self.diagnostic_image = (im < threshold).view(dtype=np.uint8)

        if e is False:
            e = (np.nan, ) * 10
            message = "E: eyes not detected!"
        else:
            e = (e[0][0][::-1] + e[0][1][::-1] + (-e[0][2], ) + e[1][0][::-1] +
                 e[1][1][::-1] + (-e[1][2], ))
        return NodeOutput([
            message,
        ], self._output_type(*e))
Ejemplo n.º 27
0
    def __init__(self):
        super().__init__()

        self.inter_stim_pause = Param(10.0)
        self.theta_amp = Param(np.pi / 2)
        self.windmill_freq = Param(0.2)
        self.stim_duration = Param(20.0)
        self.wave_shape = Param(value="sinusoidal", limits=["square", "sinusoidal"])
        self.n_arms_min = Param(10)
        self.n_arms_max = Param(60)
        self.n_arms_steps = Param(5)
Ejemplo n.º 28
0
    def __init__(self):
        super().__init__()

        # It is convenient for a protocol to be parametrized, so
        # we name the parameters we might want to change,
        # along with specifying the the default values.
        # This automatically creates a GUI to change them
        # (more elaborate ways of adding parameters are supported,
        # see the documentation of lightparam)

        # if you are not interested in parametrizing your
        # protocol the the whole __init__ definition
        # can be skipped

        self.n_looms = Param(10, limits=(0, 1000))
        self.max_loom_size = Param(60, limits=(0, 100))
        self.max_loom_duration = Param(5, limits=(0, 100))
        self.x_pos_pix = Param(10, limits=(0, 2000))
        self.y_pos_pix = Param(10, limits=(0, 2000))
Ejemplo n.º 29
0
    def __init__(self):
        super().__init__()

        self.inter_stim_pause = Param(20.0)
        self.grating_vel = Param(10.0)
        self.grating_duration = Param(10.0)
        self.grating_cycle = Param(10)
        self.low_gain = Param(0.5)
        self.high_gain = Param(1.5)
        self.protocol_reps = Param(6)
 def __init__(self):
     super().__init__()
     self.velocity = Param(5.5, (0, 40))
     self.max_coherent_for = Param(0.4, (0, 10))
     self.dot_density = Param(0.113, (0.01, 1.0))
     self.stimulus_duration = Param(20, (1, 100))
     self.theta = Param(90, (-180, 180))
     self.dot_radius = Param(0.6, (0, 1))