def __init__(self, sensor_config, processing_config, session_info):
        self.processing_config = processing_config

        self.processing_config.bg.buffered_data = None
        self.processing_config.bg.error = None

        self.depths = utils.get_range_depths(sensor_config, session_info)
        num_depths = self.depths.size
        num_sensors = len(sensor_config.sensor)

        buffer_length = self.processing_config.bg_buffer_length
        self.bg_buffer = np.zeros([buffer_length, num_sensors, num_depths])

        history_length = self.processing_config.history_length
        self.history = np.zeros([history_length, num_sensors, num_depths])

        self.data_index = 0
    def __init__(self, sensor_config, processing_config, session_info):
        num_sensors = len(sensor_config.sensor)
        num_depths = utils.get_range_depths(sensor_config, session_info).size
        history_len = processing_config.history_length

        pd_config = presence_detection_sparse.get_processing_config()
        processor_class = presence_detection_sparse.Processor

        try:
            self.pd_processors = [
                processor_class(sensor_config, pd_config, session_info)
            ]
        except AssertionError:
            self.pd_processors = None

        self.data_history = np.ones([history_len, num_sensors, num_depths
                                     ]) * 2**15
        self.presence_history = np.zeros(
            [history_len, num_sensors, num_depths])
    def __init__(self, sensor_config, processing_config, session_info):
        self.processing_config = processing_config

        self.downsampling_factor = sensor_config.downsampling_factor
        self.sweeps_per_frame = sensor_config.sweeps_per_frame
        sweep_rate = session_info["sweep_rate"]
        self.depths = utils.get_range_depths(sensor_config, session_info)
        self.step_length = session_info["step_length_m"]
        self.f_res = sweep_rate / self.sweeps_per_frame
        self.fft_x_scale = 100 * self.step_length

        self.smooth_max = utils.SmoothMax(
            sweep_rate / self.sweeps_per_frame,
            tau_grow=0,
            tau_decay=0.5,
            hysteresis=0.1,
        )

        self.setup_is_done = False
Ejemplo n.º 4
0
    def __init__(self, sensor_config, processing_config, session_info):
        self.f = sensor_config.update_rate
        depths = utils.get_range_depths(sensor_config, session_info)
        self.num_depths = depths.size

        max_window_size = 2 ** ProcessingConfiguration.WINDOW_SIZE_POW_OF_2_MAX
        self.sweep_history = np.full([max_window_size, self.num_depths], np.nan)

        self.collapsed_asd = None
        self.collapsed_asd_history = None

        self.window_size = None
        self.frames_between_updates = None
        self.rolling_history_size = None

        self.tick_idx = 0
        self.last_update_tick = 0

        self.update_processing_config(processing_config)
Ejemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("filename")
    args = parser.parse_args()
    filename = args.filename

    record = recording.load(filename)

    print_record(record)

    if len(record.data.shape) == 3:  # Envelope, IQ, Power bins
        x = np.arange(len(record.data))
        y = utils.get_range_depths(record.sensor_config, record.session_info)
        z = np.abs(record.data[:, 0, :]).T

        fig, ax = plt.subplots()
        ax.pcolormesh(x, y, z)
        ax.set_xlabel("Sweep index")
        ax.set_ylabel("Depth (m)")
        fig.tight_layout()
        plt.show()
Ejemplo n.º 6
0
 def __init__(self, sensor_config, processing_config, session_info):
     self.sensor_config = sensor_config
     self.depths = utils.get_range_depths(sensor_config, session_info)
Ejemplo n.º 7
0
def main():
    args = utils.ExampleArgumentParser(num_sens=1).parse_args()
    utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or utils.autodetect_serial_port()
        client = UARTClient(port)

    config = configs.IQServiceConfig()
    config.sensor = args.sensors
    config.update_rate = 10

    session_info = client.setup_session(config)
    depths = utils.get_range_depths(config, session_info)

    amplitude_y_max = 1000

    fig, (amplitude_ax, phase_ax) = plt.subplots(2)
    fig.set_size_inches(8, 6)
    fig.canvas.set_window_title("Acconeer matplotlib example")

    for ax in [amplitude_ax, phase_ax]:
        ax.set_xlabel("Depth (m)")
        ax.set_xlim(config.range_interval)
        ax.grid(True)

    amplitude_ax.set_ylabel("Amplitude")
    amplitude_ax.set_ylim(0, 1.1 * amplitude_y_max)
    phase_ax.set_ylabel("Phase")
    utils.mpl_setup_yaxis_for_phase(phase_ax)

    amplitude_line = amplitude_ax.plot(depths, np.zeros_like(depths))[0]
    phase_line = phase_ax.plot(depths, np.zeros_like(depths))[0]

    fig.tight_layout()
    plt.ion()
    plt.show()

    interrupt_handler = utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    client.start_session()

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        amplitude = np.abs(data)
        phase = np.angle(data)

        max_amplitude = np.max(amplitude)
        if max_amplitude > amplitude_y_max:
            amplitude_y_max = max_amplitude
            amplitude_ax.set_ylim(0, 1.1 * max_amplitude)

        amplitude_line.set_ydata(amplitude)
        phase_line.set_ydata(phase)

        if not plt.fignum_exists(1):  # Simple way to check if plot is closed
            break

        fig.canvas.flush_events()

    print("Disconnecting...")
    plt.close()
    client.disconnect()
    def process(self, sweep):
        mode = self.sensor_config.mode

        if self.sweep == 0:
            self.x_mm = utils.get_range_depths(self.sensor_config, self.session_info) * 1000
            if mode == Mode.SPARSE:
                self.num_sensors, point_repeats, self.data_len = sweep.shape
                self.hist_env = np.zeros((self.num_sensors, self.data_len, self.image_buffer))
            else:
                self.data_len = sweep.size
                self.num_sensors = 1
                if len(sweep.shape) > 1:
                    self.num_sensors, self.data_len = sweep.shape
                self.hist_env = np.zeros(
                    (self.num_sensors, self.data_len, self.image_buffer)
                )

        sweep_data = sweep.copy()

        env = None
        if mode == Mode.SPARSE:
            env = sweep.mean(axis=1)
        else:
            env = np.abs(sweep_data)

        for s in range(self.num_sensors):
            self.hist_env[s, :, :] = np.roll(self.hist_env[s, :, :], 1, axis=1)
            self.hist_env[s, :, 0] = env[s, :]

        plot_data = {
            "sweep_data": sweep_data,
            "env_ampl": env,
            "hist_env": self.hist_env,
            "sensor_config": self.sensor_config,
            "x_mm": self.x_mm,
            "sweep": self.sweep,
            "num_sensors": self.num_sensors,
            "ml_plotting": True,
            "ml_frame_data": None,
            "prediction": None,
            "prediction_hist": None,
            "session_info": self.session_info,
        }

        plot_data["ml_frame_data"] = self.feature_process.feature_extraction(plot_data)

        feature_map = plot_data["ml_frame_data"]["current_frame"]["feature_map"]
        complete = plot_data["ml_frame_data"]["current_frame"]["frame_complete"]
        if complete and self.evaluate and feature_map is not None:
            if plot_data["ml_frame_data"]["frame_info"].get("time_series", 1) > 1:
                feature_map = ml_helper.convert_time_series(
                    plot_data["ml_frame_data"]["current_frame"]["feature_map"],
                    plot_data["ml_frame_data"]["frame_info"]
                )
            try:
                plot_data["prediction"] = self.evaluate(feature_map)
            except Exception as e:
                print(e)
                plot_data["ml_frame_data"]["current_frame"]["frame_complete"] = False
                return plot_data

            prediction_label = plot_data["prediction"]["prediction"]
            plot_data["ml_frame_data"]["frame_list"][-1]["label"] = prediction_label

            if self.prediction_hist is None:
                self.prediction_hist = np.zeros((plot_data["prediction"]["number_labels"],
                                                 self.hist_len))
            predictions = plot_data["prediction"]["label_predictions"]
            self.prediction_hist = np.roll(self.prediction_hist, 1, axis=1)
            for key in predictions:
                pred, idx = predictions[key]
                self.prediction_hist[idx, 0] = pred
            plot_data["prediction_hist"] = self.prediction_hist

        self.sweep += 1

        return plot_data
Ejemplo n.º 9
0
 def __init__(self, sensor_config, processing_config, session_info):
     self.depths = utils.get_range_depths(sensor_config, session_info)
     self.smooth_max = utils.SmoothMax(sensor_config.update_rate)