def setup(self, fig): self.axs = { "amplitude": fig.add_subplot(2, 1, 1), "phase": fig.add_subplot(2, 1, 2), } for ax in self.axs.values(): ax.grid(True) ax.set_xlabel("Depth (m)") ax.set_xlim(self.interval) self.axs["amplitude"].set_title("Amplitude") self.axs["amplitude"].set_ylim(0, 0.5) self.axs["phase"].set_title("Phase") example_utils.mpl_setup_yaxis_for_phase(self.axs["phase"]) fig.canvas.set_window_title("Acconeer IQ data example") fig.set_size_inches(10, 7) fig.tight_layout()
def setup(self, fig): gs = GridSpec(2, 3) self.axs = { "abs": fig.add_subplot(gs[0, 0]), "arg": fig.add_subplot(gs[1, 0]), "iq": fig.add_subplot(gs[1, 1]), "hist_pos": fig.add_subplot(gs[0, 1:]), "hist_pos_zoom": fig.add_subplot(gs[1, 2]), } max_ampl = 0.5 self.axs["abs"].set_ylim(0, max_ampl) self.axs["hist_pos"].set_ylim(-5, 5) self.axs["hist_pos_zoom"].set_ylim(-0.5, 0.5) self.axs["iq"].set_xlim(-max_ampl, max_ampl) self.axs["iq"].set_ylim(-max_ampl, max_ampl) example_utils.mpl_setup_yaxis_for_phase(self.axs["arg"]) self.axs["abs"].set_ylabel("Amplitude") self.axs["arg"].set_ylabel("Phase") self.axs["iq"].set_xlabel("Real part at line") self.axs["iq"].set_ylabel("Imaginary part at line") for k in ["hist_pos", "hist_pos_zoom"]: ax = self.axs[k] ax.set_xlabel("Time (s)") ax.set_ylabel("Tracking (mm)") for k in ["abs", "arg"]: ax = self.axs[k] ax.set_xlim(*self.interval) ax.set_xlabel("Depth (m)") for ax in self.axs.values(): ax.grid(True) fig.canvas.set_window_title("Acconeer phase tracking example") fig.set_size_inches(10, 7) fig.tight_layout()
def main(): args = example_utils.ExampleArgumentParser(num_sens=1).parse_args() example_utils.config_logging(args) if args.socket_addr: client = JSONClient(args.socket_addr) elif args.spi: client = RegSPIClient() else: port = args.serial_port or example_utils.autodetect_serial_port() client = RegClient(port) config = configs.IQServiceConfig() config.sensor = args.sensors config.range_interval = [0.2, 0.6] config.sweep_rate = 10 config.gain = 0.6 info = client.setup_session(config) num_points = info["data_length"] amplitude_y_max = 0.3 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") example_utils.mpl_setup_yaxis_for_phase(phase_ax) xs = np.linspace(*config.range_interval, num_points) amplitude_line = amplitude_ax.plot(xs, np.zeros_like(xs))[0] phase_line = phase_ax.plot(xs, np.zeros_like(xs))[0] fig.tight_layout() plt.ion() plt.show() interrupt_handler = example_utils.ExampleInterruptHandler() print("Press Ctrl-C to end session") client.start_streaming() while not interrupt_handler.got_signal: info, sweep = client.get_next() amplitude = np.abs(sweep) phase = np.angle(sweep) 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 main(): args = example_utils.ExampleArgumentParser(num_sens=1).parse_args() example_utils.config_logging(args) if args.socket_addr: client = JSONClient(args.socket_addr) else: port = args.serial_port or example_utils.autodetect_serial_port() client = RegClient(port) config = base_config() config.sensor = args.sensors info = client.setup_session(config) num_points = info["data_length"] # Setup plot window for amplitude and phase filled with zeros. amplitude_y_max = 1 fig, (amplitude_ax, phase_ax1) = plt.subplots(2) fig.set_size_inches(12, 6) fig.canvas.set_window_title("Annotate test") fig, (ny_ax2) = plt.subplots(1) fig.set_size_inches(8, 5) fig.canvas.set_window_title("test två fönster") for ax in [amplitude_ax]: ax.set_xlabel("Depth (m)") ax.set_xlim(config.range_interval) ax.grid(True) for ax1 in [phase_ax1]: ax1.set_xlabel("Depth(m)") ax1.set_xlim(config.range_interval) ax1.grid(True) for ax2 in [ny_ax2]: ax2.set_xlabel("Depth (m)") ax2.set_xlim(config.range_interval) ax2.grid(True) amplitude_ax.set_ylabel("Amplitude") amplitude_ax.set_ylim(0, 1.0 * amplitude_y_max) phase_ax1.set_ylabel("Phase") example_utils.mpl_setup_yaxis_for_phase(phase_ax1) ny_ax2.set_ylim(-1, 1) xs = np.linspace(*config.range_interval, num_points) amplitude_line = amplitude_ax.plot(xs, np.zeros_like(xs))[0] phase_line = phase_ax1.plot(xs, np.zeros_like(xs))[0] ny_line = ny_ax2.plot(xs, np.zeros_like(xs))[0] fig.tight_layout() plt.ion() plt.show() # Setup box for annotation with maximum bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72) arrowprops = dict(arrowstyle="->", connectionstyle="angle,angleA=0,angleB=90") kw = dict(xycoords='data', textcoords="axes fraction", arrowprops=arrowprops, bbox=bbox_props, ha="right", va="top") interrupt_handler = example_utils.ExampleInterruptHandler() print("Press Ctrl-C to end session") client.start_streaming() while not interrupt_handler.got_signal: # for i in range(0, 1): # Get new sensor data info, sweep = client.get_next() amplitude = np.abs(sweep) phase = np.angle(sweep) # Update annotation with the new amplitude and position ymax = amplitude.max() xmax = config.range_interval[0] + (config.range_interval[1] - config.range_interval[0]) * \ (np.argmax(amplitude)/num_points) text = "x={:.2f}, y={:.2f}".format(xmax, ymax) annotate = ax.annotate(text, xy=(xmax, ymax), xytext=(0.96, 0.96), **kw) vline_ax0 = ax.axvline(x=xmax, ymin=0, ymax=ymax, linewidth=2, color='k') vline_ax1 = ax1.axvline(x=xmax, ymin=-np.pi, ymax=np.pi, linewidth=2, color='k') # update plot with new sensor data 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() annotate.remove() vline_ax0.remove() vline_ax1.remove() print("Disconnecting...") plt.close() client.disconnect()