diff options
Diffstat (limited to 'gui/dpd')
-rw-r--r-- | gui/dpd/Capture.py | 30 | ||||
-rw-r--r-- | gui/dpd/__init__.py | 20 |
2 files changed, 42 insertions, 8 deletions
diff --git a/gui/dpd/Capture.py b/gui/dpd/Capture.py index de428cb..e2ac63d 100644 --- a/gui/dpd/Capture.py +++ b/gui/dpd/Capture.py @@ -29,6 +29,10 @@ import os import logging import numpy as np from scipy import signal +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import io from . import Align as sa @@ -77,10 +81,11 @@ class Capture: self.binning_n_bins = 64 # Number of bins between binning_start and binning_end self.binning_n_per_bin = 128 # Number of measurements pre bin - self.target_median = 0.01 + self.target_median = 0.05 self.median_max = self.target_median * 1.4 self.median_min = self.target_median / 1.4 + # axis 0: bins # axis 1: 0=tx, 1=rx self.accumulated_bins = [np.zeros((0, 2), dtype=np.complex64) for i in range(self.binning_n_bins)] @@ -179,6 +184,29 @@ class Capture: def bin_histogram(self): return [b.shape[0] for b in self.accumulated_bins] + def pointcloud_png(self): + fig = plt.figure() + ax = plt.subplot(1, 1, 1) + for b in self.accumulated_bins: + if b: + ax.scatter( + np.abs(b[0]), + np.abs(b[1]), + s=0.1, + color="black") + ax.set_title("Captured and Binned Samples") + ax.set_xlabel("TX Amplitude") + ax.set_ylabel("RX Amplitude") + ax.set_ylim(0, 0.8) + ax.set_xlim(0, 1.1) + ax.legend(loc=4) + fig.tight_layout() + buf = io.BytesIO() + fig.savefig(buf) + plt.close(fig) + + return buf.getvalue() + def _bin_and_accumulate(self, txframe, rxframe): """Bin the samples and extend the accumulated samples""" diff --git a/gui/dpd/__init__.py b/gui/dpd/__init__.py index 8dd0807..06d180d 100644 --- a/gui/dpd/__init__.py +++ b/gui/dpd/__init__.py @@ -47,19 +47,25 @@ class DPD: r['capture'] = self.last_capture_info return r + def pointcloud_png(self): + return self.capture.pointcloud_png() + def capture_samples(self): """Captures samples and store them in the accumulated samples, returns a dict with some info""" + result = {} try: txframe_aligned, tx_ts, tx_median, rxframe_aligned, rx_ts, rx_median = self.capture.get_samples() - self.last_capture_info['length'] = len(txframe_aligned) - self.last_capture_info['tx_median'] = float(tx_median) - self.last_capture_info['rx_median'] = float(rx_median) - self.last_capture_info['tx_ts'] = tx_ts - self.last_capture_info['rx_ts'] = rx_ts - return self.last_capture_info + result['status'] = "ok" + result['length'] = len(txframe_aligned) + result['tx_median'] = float(tx_median) + result['rx_median'] = float(rx_median) + result['tx_ts'] = tx_ts + result['rx_ts'] = rx_ts except ValueError as e: - raise ValueError("Capture failed: {}".format(e)) + result['status'] = "Capture failed: {}".format(e) + + self.last_capture_info = result # tx, rx, phase_diff, n_per_bin = extStat.extract(txframe_aligned, rxframe_aligned) # off = SA.calc_offset(txframe_aligned) |