diff options
Diffstat (limited to 'python/dpdce.py')
-rwxr-xr-x | python/dpdce.py | 100 |
1 files changed, 93 insertions, 7 deletions
diff --git a/python/dpdce.py b/python/dpdce.py index 379f3d0..a9ed140 100755 --- a/python/dpdce.py +++ b/python/dpdce.py @@ -43,7 +43,8 @@ rc_port = config.getint('rc_port') samplerate = config.getint('samplerate') samps = config.getint('samps') coef_file = config['coef_file'] -log_folder = config['log_folder'] +logs_directory = config['logs_directory'] +plot_directory = config['plot_directory'] import logging import datetime @@ -52,7 +53,7 @@ save_logs = False # Simple usage scenarios don't need to clutter /tmp if save_logs: - dt = datetime.datetime.now().isoformat() + dt = datetime.datetime.utcnow().isoformat() logging_path = '/tmp/dpd_{}'.format(dt).replace('.', '_').replace(':', '-') print("Logs and plots written to {}".format(logging_path)) os.makedirs(logging_path) @@ -71,7 +72,7 @@ if save_logs: # add the handler to the root logger logging.getLogger('').addHandler(console) else: - dt = datetime.datetime.now().isoformat() + dt = datetime.datetime.utcnow().isoformat() logging.basicConfig(format='%(asctime)s - %(module)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO) @@ -83,6 +84,7 @@ import socket from lib import yamlrpc import numpy as np import traceback +import os.path from threading import Thread, Lock from queue import Queue from dpd.Model import Poly @@ -96,13 +98,14 @@ from dpd.GlobalConfig import GlobalConfig from dpd.MER import MER from dpd.Measure_Shoulders import Measure_Shoulders -c = GlobalConfig(samplerate, logging_path) +plot_path = os.path.realpath(plot_directory) + +c = GlobalConfig(samplerate, plot_path) symbol_align = Symbol_align(c) mer = MER(c) meas_shoulders = Measure_Shoulders(c) meas = Measure(c, samplerate, dpd_port, samps) -extStat = ExtractStatistic(c) -adapt = Adapt(rc_port, coef_file, logging_path) +adapt = Adapt(rc_port, coef_file, plot_path) model = Poly(c) @@ -134,7 +137,11 @@ settings = { 'digital_gain': digital_gain, 'dpddata': dpddata, } +internal_data = { + 'n_runs': 0, + } results = { + 'statplot': None, 'tx_median': 0, 'rx_median': 0, 'state': 'Idle', @@ -148,6 +155,7 @@ command_queue = Queue(maxsize=1) agc = Agc(meas, adapt, c) def engine_worker(): + extStat = ExtractStatistic(c) try: while True: cmd = command_queue.get() @@ -180,8 +188,86 @@ def engine_worker(): results['tx_median'] = float(tx_median) results['rx_median'] = float(rx_median) results['state'] = 'Idle' - results['stateprogress'] = 0 + results['stateprogress'] = 100 results['summary'] = ["Calibration was done:"] + summary + elif cmd == "reset": + with lock: + internal_data['n_runs'] = 0 + results['state'] = 'Idle' + results['stateprogress'] = 0 + results['summary'] = ["Reset"] + extStat = ExtractStatistic(c) + elif cmd == "trigger_run": + with lock: + results['state'] = 'Capture + Model' + results['stateprogress'] = 0 + n_runs = internal_data['n_runs'] + + # Get Samples and check gain + txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median = meas.get_samples() + # TODO Check TX median + + with lock: + results['stateprogress'] = 20 + results['summary'] = ["Captured {} samples".format(len(txframe_aligned)), + "TX/RX median: {} / {}".format(tx_median, rx_median)] + + # Extract usable data from measurement + tx, rx, phase_diff, n_per_bin = extStat.extract(txframe_aligned, rxframe_aligned) + + time = datetime.datetime.utcnow() + + plot_file = "stats_{}.png".format(time.strftime("%s")) + extStat.plot(os.path.join(plot_path, plot_file), time.strftime("%Y-%m-%dT%H%M%S")) + + with lock: + results['statplot'] = "dpd/" + plot_file + results['stateprogress'] = 30 + results['summary'] += ["Extracted Statistics".format(tx_median, rx_median)] + + n_meas = Heuristics.get_n_meas(n_runs) + if extStat.n_meas >= n_meas: # Use as many measurements nr of runs + if any(x is None for x in [tx, rx, phase_diff]): + with lock: + results['summary'] += ["Error! No data to calculate model"] + results['state'] = 'Idle' + results['stateprogress'] = 0 + else: + with lock: + results['state'] = 'Capture + Model' + results['stateprogress'] = 40 + results['summary'] += ["Training model"] + + model.train(tx, rx, phase_diff, lr=Heuristics.get_learning_rate(n_runs)) + + with lock: + results['state'] = 'Capture + Model' + results['stateprogress'] = 60 + results['summary'] += ["Getting DPD data"] + + dpddata = model.get_dpd_data() + with lock: + internal_data['dpddata'] = dpddata + internal_data['n_runs'] = 0 + + results['state'] = 'Capture + Model' + results['stateprogress'] = 80 + results['summary'] += ["Reset statistics"] + + extStat = ExtractStatistic(c) + + with lock: + results['state'] = 'Idle' + results['stateprogress'] = 100 + results['summary'] += ["New DPD coefficients calculated"] + + with lock: + internal_data['n_runs'] += 1 + else: + with lock: + results['state'] = 'Idle' + results['stateprogress'] = 100 + results['summary'] += ["More data required to train model"] finally: with lock: |