Ejemplo n.º 1
0
    def update(self, data):
        self.sweep_scatter.setData(
            np.tile(self.depths, self.sensor_config.number_of_subsweeps),
            data["sweep"].flatten(),
        )
        self.fast_scatter.setData(self.depths, data["fast"])
        self.slow_scatter.setData(self.depths, data["slow"])

        noise = data["noise"]
        self.noise_curve.setData(self.depths, noise)
        self.noise_plot.setYRange(0,
                                  self.noise_smooth_max.update(np.max(noise)))

        movement_x = data["presence_distance"]

        move_ys = data["depthwise_presence"]
        self.inter_curve.setData(self.depths, data["inter"])
        self.total_curve.setData(self.depths, move_ys)
        m = self.move_smooth_max.update(np.max(move_ys))
        m = max(m, 2 * self.processing_config.detection_threshold)
        self.move_plot.setYRange(0, m)
        self.move_depth_line.setPos(movement_x)
        self.move_depth_line.setVisible(data["presence_detected"])

        move_hist_ys = data["presence_history"]
        move_hist_xs = np.linspace(-self.history_length_s, 0,
                                   len(move_hist_ys))
        self.move_hist_curve.setData(move_hist_xs,
                                     np.minimum(move_hist_ys, OUTPUT_MAX))

        if data["presence_detected"]:
            present_text = "Presence detected at {:.0f} cm".format(movement_x *
                                                                   100)
            present_html = self.present_html_format.format(present_text)
            self.present_text_item.setHtml(present_html)

            self.present_text_item.show()
            self.not_present_text_item.hide()
        else:
            self.present_text_item.hide()
            self.not_present_text_item.show()

        brush = example_utils.pg_brush_cycler(0)
        for sector in self.sectors:
            sector.setBrush(brush)

        if data["presence_detected"]:
            index = (data["presence_distance_index"] +
                     self.sector_offset) // self.sector_size
            self.sectors[index].setBrush(example_utils.pg_brush_cycler(1))
Ejemplo n.º 2
0
    def update(self, data):
        # Data plots

        for i, ys in enumerate(data["sweep"].T):
            self.data_curves[i].setData(ys)

        # Spectral density plot

        sd = data["sd"]
        m = self.smooth_max.update(max(10, np.max(sd)))
        self.sd_plot.setYRange(0, m)
        self.sd_curve.setData(self.bin_vs * self.unit.scale, sd)

        self.sd_threshold_line.setPos(data["sd_threshold"])

        # Rolling speed plot

        vs = data["vel_history"] * self.unit.scale
        mask = ~np.isnan(vs)
        ts = -np.flip(np.arange(vs.size)) * self.dt
        bs = data["belongs_to_last_sequence"]
        brushes = [example_utils.pg_brush_cycler(int(b)) for b in bs[mask]]

        self.vel_scatter.setData(ts[mask], vs[mask], brush=brushes)

        v = data["vel"]
        if v:
            html = self.vel_html_fmt.format(v * self.unit.scale,
                                            self.unit.label)
            self.vel_text_item.setHtml(html)
            self.vel_text_item.show()

            self.vel_max_line.setPos(v * self.unit.scale)
            self.vel_max_line.show()
        else:
            self.vel_text_item.hide()
            self.vel_max_line.hide()

        # Sequence speed plot

        hs = data["sequence_vels"] * self.unit.scale
        self.bar_graph.setOpts(height=hs)

        if hs[-1] > 1e-3:
            html = self.vel_html_fmt.format(hs[-1], self.unit.label)
            self.sequences_text_item.setHtml(html)
Ejemplo n.º 3
0
    def setup(self, win):
        win.setWindowTitle("Acconeer presence detection example")

        dashed_pen = pg.mkPen("k", width=2.5, style=QtCore.Qt.DashLine)

        if self.processing_config["show_sweep"]["value"]:
            data_plot = win.addPlot(
                title="Sweep (blue), fast (orange), and slow (green)")
            data_plot.showGrid(x=True, y=True)
            data_plot.setLabel("bottom", "Depth (m)")
            data_plot.setYRange(-2**15, 2**15)
            self.sweep_scatter = pg.ScatterPlotItem(
                size=10,
                brush=example_utils.pg_brush_cycler(0),
            )
            self.fast_scatter = pg.ScatterPlotItem(
                size=10,
                brush=example_utils.pg_brush_cycler(1),
            )
            self.slow_scatter = pg.ScatterPlotItem(
                size=10,
                brush=example_utils.pg_brush_cycler(2),
            )
            data_plot.addItem(self.sweep_scatter)
            data_plot.addItem(self.fast_scatter)
            data_plot.addItem(self.slow_scatter)

            win.nextRow()

        if self.processing_config["show_noise"]["value"]:
            self.noise_plot = win.addPlot(title="Noise")
            self.noise_plot.showGrid(x=True, y=True)
            self.noise_plot.setLabel("bottom", "Depth (m)")
            self.noise_curve = self.noise_plot.plot(
                pen=example_utils.pg_pen_cycler())
            self.noise_smooth_max = example_utils.SmoothMax(
                self.sensor_config.sweep_rate)

            win.nextRow()

        if self.processing_config["show_depthwise_output"]["value"]:
            self.move_plot = win.addPlot(title="Depthwise presence")
            self.move_plot.showGrid(x=True, y=True)
            self.move_plot.setLabel("bottom", "Depth (m)")
            self.move_curve = self.move_plot.plot(
                pen=example_utils.pg_pen_cycler())
            self.move_smooth_max = example_utils.SmoothMax(
                self.sensor_config.sweep_rate,
                tau_decay=1.0,
            )

            self.move_depth_line = pg.InfiniteLine(pen=dashed_pen)
            self.move_depth_line.hide()
            self.move_plot.addItem(self.move_depth_line)
            limit_line = pg.InfiniteLine(self.movement_limit,
                                         angle=0,
                                         pen=dashed_pen)
            self.move_plot.addItem(limit_line)

            win.nextRow()

        move_hist_plot = win.addPlot(title="Presence history")
        move_hist_plot.showGrid(x=True, y=True)
        move_hist_plot.setLabel("bottom", "Time (s)")
        move_hist_plot.setXRange(-HISTORY_LENGTH_S, 0)
        move_hist_plot.setYRange(0, OUTPUT_MAX)
        self.move_hist_curve = move_hist_plot.plot(
            pen=example_utils.pg_pen_cycler())
        limit_line = pg.InfiniteLine(self.movement_limit,
                                     angle=0,
                                     pen=dashed_pen)
        move_hist_plot.addItem(limit_line)

        self.present_html_format = '<div style="text-align: center">' \
                                   '<span style="color: #FFFFFF;font-size:16pt;">' \
                                   '{}</span></div>'
        present_html = self.present_html_format.format("Presence detected!")
        not_present_html = '<div style="text-align: center">' \
                           '<span style="color: #FFFFFF;font-size:16pt;">' \
                           '{}</span></div>'.format("No presence detected")
        self.present_text_item = pg.TextItem(
            html=present_html,
            fill=pg.mkColor(255, 140, 0),
            anchor=(0.5, 0),
        )
        self.not_present_text_item = pg.TextItem(
            html=not_present_html,
            fill=pg.mkColor("b"),
            anchor=(0.5, 0),
        )
        self.present_text_item.setPos(-2.5, 0.95 * OUTPUT_MAX)
        self.not_present_text_item.setPos(-2.5, 0.95 * OUTPUT_MAX)
        move_hist_plot.addItem(self.present_text_item)
        move_hist_plot.addItem(self.not_present_text_item)
        self.present_text_item.hide()
Ejemplo n.º 4
0
    def setup(self, win):
        win.setWindowTitle("Acconeer presence detection example")
        win.setAntialiasing(True)

        self.limit_lines = []
        dashed_pen = pg.mkPen("k", width=2.5, style=QtCore.Qt.DashLine)

        # Data plot

        self.data_plot = win.addPlot(
            row=0,
            col=0,
            title="Frame (blue), fast (orange), and slow (green)",
        )
        self.data_plot.showGrid(x=True, y=True)
        self.data_plot.setLabel("bottom", "Depth (m)")
        self.data_plot.setLabel("left", "Amplitude")
        self.data_plot.setYRange(-2**15, 2**15)
        self.sweep_scatter = pg.ScatterPlotItem(
            size=10,
            brush=example_utils.pg_brush_cycler(0),
        )
        self.fast_scatter = pg.ScatterPlotItem(
            size=10,
            brush=example_utils.pg_brush_cycler(1),
        )
        self.slow_scatter = pg.ScatterPlotItem(
            size=10,
            brush=example_utils.pg_brush_cycler(2),
        )
        self.data_plot.addItem(self.sweep_scatter)
        self.data_plot.addItem(self.fast_scatter)
        self.data_plot.addItem(self.slow_scatter)

        # Noise estimation plot

        self.noise_plot = win.addPlot(
            row=1,
            col=0,
            title="Noise",
        )
        self.noise_plot.showGrid(x=True, y=True)
        self.noise_plot.setLabel("bottom", "Depth (m)")
        self.noise_plot.setLabel("left", "Amplitude")
        self.noise_curve = self.noise_plot.plot(
            pen=example_utils.pg_pen_cycler())
        self.noise_smooth_max = example_utils.SmoothMax(
            self.sensor_config.sweep_rate)

        # Depthwise presence plot

        self.move_plot = win.addPlot(
            row=2,
            col=0,
            title="Depthwise presence",
        )
        self.move_plot.showGrid(x=True, y=True)
        self.move_plot.setLabel("bottom", "Depth (m)")
        self.move_plot.setLabel("left", "Norm. ampl.")
        zero_curve = self.move_plot.plot(self.depths,
                                         np.zeros_like(self.depths))
        self.inter_curve = self.move_plot.plot()
        self.total_curve = self.move_plot.plot()
        self.move_smooth_max = example_utils.SmoothMax(
            self.sensor_config.sweep_rate,
            tau_decay=1.0,
            tau_grow=0.25,
        )

        self.move_depth_line = pg.InfiniteLine(pen=pg.mkPen("k", width=1.5))
        self.move_depth_line.hide()
        self.move_plot.addItem(self.move_depth_line)
        limit_line = pg.InfiniteLine(angle=0, pen=dashed_pen)
        self.move_plot.addItem(limit_line)
        self.limit_lines.append(limit_line)

        fbi = pg.FillBetweenItem(
            zero_curve,
            self.inter_curve,
            brush=example_utils.pg_brush_cycler(0),
        )
        self.move_plot.addItem(fbi)

        fbi = pg.FillBetweenItem(
            self.inter_curve,
            self.total_curve,
            brush=example_utils.pg_brush_cycler(1),
        )
        self.move_plot.addItem(fbi)

        # Presence history plot

        self.move_hist_plot = pg.PlotItem(title="Presence history")
        self.move_hist_plot.showGrid(x=True, y=True)
        self.move_hist_plot.setLabel("bottom", "Time (s)")
        self.move_hist_plot.setLabel(
            "left", "Score (limited to {})".format(OUTPUT_MAX))
        self.move_hist_plot.setXRange(-self.history_length_s, 0)
        self.move_hist_plot.setYRange(0, OUTPUT_MAX)
        self.move_hist_curve = self.move_hist_plot.plot(
            pen=example_utils.pg_pen_cycler())
        limit_line = pg.InfiniteLine(angle=0, pen=dashed_pen)
        self.move_hist_plot.addItem(limit_line)
        self.limit_lines.append(limit_line)

        self.present_html_format = '<div style="text-align: center">' \
                                   '<span style="color: #FFFFFF;font-size:15pt;">' \
                                   '{}</span></div>'
        not_present_html = '<div style="text-align: center">' \
                           '<span style="color: #FFFFFF;font-size:15pt;">' \
                           '{}</span></div>'.format("No presence detected")
        self.present_text_item = pg.TextItem(
            fill=pg.mkColor(0xff, 0x7f, 0x0e, 200),
            anchor=(0.5, 0),
        )
        self.not_present_text_item = pg.TextItem(
            html=not_present_html,
            fill=pg.mkColor(0x1f, 0x77, 0xb4, 180),
            anchor=(0.5, 0),
        )

        pos = (-self.history_length_s / 2, 0.95 * OUTPUT_MAX)
        self.present_text_item.setPos(*pos)
        self.not_present_text_item.setPos(*pos)
        self.move_hist_plot.addItem(self.present_text_item)
        self.move_hist_plot.addItem(self.not_present_text_item)
        self.present_text_item.hide()

        # Sector plot

        self.sector_plot = pg.PlotItem()
        self.sector_plot.setAspectLocked()
        self.sector_plot.hideAxis("left")
        self.sector_plot.hideAxis("bottom")
        self.sectors = []

        pen = pg.mkPen("k", width=1)
        span_deg = 25
        for r in np.flip(np.arange(self.num_sectors) + 1):
            sector = pg.QtGui.QGraphicsEllipseItem(-r, -r, r * 2, r * 2)
            sector.setStartAngle(-16 * span_deg)
            sector.setSpanAngle(16 * span_deg * 2)
            sector.setPen(pen)
            self.sector_plot.addItem(sector)
            self.sectors.append(sector)

        self.sectors.reverse()

        sublayout = win.addLayout(row=3, col=0)
        sublayout.layout.setColumnStretchFactor(0, 2)
        sublayout.addItem(self.move_hist_plot, col=0)
        sublayout.addItem(self.sector_plot, col=1)

        self.setup_is_done = True
        self.update_processing_config()