From 8ddc109a649899ab6a0b673908186a39c75c8f71 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 12 Dec 2018 08:37:20 +0100 Subject: GUI: add progress bar --- python/dpd/Measure.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'python/dpd/Measure.py') diff --git a/python/dpd/Measure.py b/python/dpd/Measure.py index 489c4c0..eb3c199 100644 --- a/python/dpd/Measure.py +++ b/python/dpd/Measure.py @@ -15,7 +15,7 @@ import logging class Measure: """Collect Measurement from DabMod""" - def __init__(self, config, samplerate, port, num_samples_to_request): + def __init__(self, config, samplerate : int, port : int, num_samples_to_request : int): logging.info("Instantiate Measure object") self.c = config self.samplerate = samplerate @@ -23,7 +23,7 @@ class Measure: self.port = port self.num_samples_to_request = num_samples_to_request - def _recv_exact(self, sock, num_bytes): + def _recv_exact(self, sock : socket.socket, num_bytes : int) -> bytes: """Receive an exact number of bytes from a socket. This is a wrapper around sock.recv() that can return less than the number of requested bytes. @@ -41,7 +41,7 @@ class Measure: bufs.append(b) return b''.join(bufs) - def receive_tcp(self): + def receive_tcp(self, num_samples_to_request : int): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(4) s.connect(('localhost', self.port)) @@ -49,8 +49,8 @@ class Measure: logging.debug("Send version") s.sendall(b"\x01") - logging.debug("Send request for {} samples".format(self.num_samples_to_request)) - s.sendall(struct.pack("=I", self.num_samples_to_request)) + logging.debug("Send request for {} samples".format(num_samples_to_request)) + s.sendall(struct.pack("=I", num_samples_to_request)) logging.debug("Wait for TX metadata") num_samps, tx_second, tx_pps = struct.unpack("=III", self._recv_exact(s, 12)) @@ -91,13 +91,14 @@ class Measure: return txframe, tx_ts, rxframe, rx_ts - def get_samples(self): + def get_samples(self, short=False): """Connect to ODR-DabMod, retrieve TX and RX samples, load into numpy arrays, and return a tuple (txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median) """ - txframe, tx_ts, rxframe, rx_ts = self.receive_tcp() + n_samps = int(self.num_samples_to_request / 4) if short else self.num_samples_to_request + txframe, tx_ts, rxframe, rx_ts = self.receive_tcp(n_samps) # Normalize received signal with sent signal rx_median = np.median(np.abs(rxframe)) @@ -116,6 +117,7 @@ class Measure: # The MIT License (MIT) # +# Copyright (c) 2018 Matthias P. Braendli # Copyright (c) 2017 Andreas Steger # # Permission is hereby granted, free of charge, to any person obtaining a copy -- cgit v1.2.3 From f409d342c5a314f4aa35382bbdd8daa3882172d1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 12 Dec 2018 10:56:33 +0100 Subject: Improve DPD calibration --- python/dpd/Measure.py | 20 ++++++++++++++++++++ python/dpd/RX_Agc.py | 16 ++++++++++++---- python/dpdce.py | 3 ++- 3 files changed, 34 insertions(+), 5 deletions(-) (limited to 'python/dpd/Measure.py') diff --git a/python/dpd/Measure.py b/python/dpd/Measure.py index eb3c199..e5a72c7 100644 --- a/python/dpd/Measure.py +++ b/python/dpd/Measure.py @@ -90,6 +90,26 @@ class Measure: return txframe, tx_ts, rxframe, rx_ts + def get_samples_unaligned(self, short=False): + """Connect to ODR-DabMod, retrieve TX and RX samples, load + into numpy arrays, and return a tuple + (txframe, tx_ts, rxframe, rx_ts, rx_median, tx_median) + """ + + n_samps = int(self.num_samples_to_request / 4) if short else self.num_samples_to_request + txframe, tx_ts, rxframe, rx_ts = self.receive_tcp(n_samps) + + # Normalize received signal with sent signal + rx_median = np.median(np.abs(rxframe)) + tx_median = np.median(np.abs(txframe)) + rxframe = rxframe / rx_median * tx_median + + + logging.info( + "Measurement done, tx %d %s, rx %d %s" % + (len(txframe), txframe.dtype, len(rxframe), rxframe.dtype)) + + return txframe, tx_ts, rxframe, rx_ts, rx_median, tx_median def get_samples(self, short=False): """Connect to ODR-DabMod, retrieve TX and RX samples, load diff --git a/python/dpd/RX_Agc.py b/python/dpd/RX_Agc.py index bca9643..4700e68 100644 --- a/python/dpd/RX_Agc.py +++ b/python/dpd/RX_Agc.py @@ -45,10 +45,15 @@ class Agc: self.peak_to_median = 1./c.RAGC_rx_median_target def run(self) -> Tuple[bool, str]: - self.adapt.set_rxgain(self.rxgain) + try: + self.adapt.set_rxgain(self.rxgain) + except ValueError as e: + return (False, "Setting RX gain to {} failed: {}".format(self.rxgain, e)) + time.sleep(0.5) + # Measure - txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median = self.measure.get_samples(short=True) + txframe, tx_ts, rxframe, rx_ts, rx_median, tx_median = self.measure.get_samples_unaligned(short=False) # Estimate Maximum rx_peak = self.peak_to_median * rx_median @@ -70,9 +75,12 @@ class Agc: logging.warning(w) return (False, "\n".join([measurements, w])) else: - self.adapt.set_rxgain(self.rxgain) + try: + self.adapt.set_rxgain(self.rxgain) + except ValueError as e: + return (False, "Setting RX gain to {} failed: {}".format(self.rxgain, e)) time.sleep(0.5) - return (True, measurements) + return (True, measurements) def plot_estimates(self): """Plots the estimate of for Max, Median, Mean for different diff --git a/python/dpdce.py b/python/dpdce.py index 03bc907..1ceac46 100755 --- a/python/dpdce.py +++ b/python/dpdce.py @@ -163,10 +163,11 @@ def engine_worker(): N_ITER = 5 for i in range(N_ITER): agc_success, agc_summary = agc.run() - summary = ["calibration run {}:".format(i)] + agc_summary.split("\n") + summary += ["calibration run {}:".format(i)] + agc_summary.split("\n") with lock: results['stateprogress'] = int((i + 1) * 100/N_ITER) + results['summary'] = ["Calibration ongoing:"] + summary if not agc_success: break -- cgit v1.2.3