diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-12-18 16:53:56 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-12-18 16:53:56 +0100 |
commit | 9d2c85f7a2a23fcf9ce3c842d86227afed43a153 (patch) | |
tree | fe3961130d308212047381eb23a8d2b6e2065dfe /python/dpd | |
parent | e83e1324a50055a4b972b78e26383df7ee290fee (diff) | |
download | dabmod-9d2c85f7a2a23fcf9ce3c842d86227afed43a153.tar.gz dabmod-9d2c85f7a2a23fcf9ce3c842d86227afed43a153.tar.bz2 dabmod-9d2c85f7a2a23fcf9ce3c842d86227afed43a153.zip |
GUI: Automatically iterate captures and show model plots
Diffstat (limited to 'python/dpd')
-rw-r--r-- | python/dpd/Model_AM.py | 23 | ||||
-rw-r--r-- | python/dpd/Model_PM.py | 23 | ||||
-rw-r--r-- | python/dpd/Model_Poly.py | 14 |
3 files changed, 27 insertions, 33 deletions
diff --git a/python/dpd/Model_AM.py b/python/dpd/Model_AM.py index 75b226f..b07a5a5 100644 --- a/python/dpd/Model_AM.py +++ b/python/dpd/Model_AM.py @@ -42,22 +42,18 @@ class Model_AM: """Calculates new coefficients using the measurement and the previous coefficients""" - def __init__(self, - c, - learning_rate_am=1, - plot=False): + def __init__(self, c, learning_rate_am=1): self.c = c - self.learning_rate_am = learning_rate_am - self.plot = plot + self._plot_data = None + + def plot(self, plot_location, title): + if self._plot_data is not None: + tx_dpd, rx_received, coefs_am, coefs_am_new = self._plot_data - def _plot(self, tx_dpd, rx_received, coefs_am, coefs_am_new): - if self.plot and self.c.plot_location is not None: tx_range, rx_est = calc_line(coefs_am, 0, 0.6) tx_range_new, rx_est_new = calc_line(coefs_am_new, 0, 0.6) - dt = datetime.datetime.now().isoformat() - fig_path = self.c.plot_location + "/" + dt + "_Model_AM.png" sub_rows = 1 sub_cols = 1 fig = plt.figure(figsize=(sub_cols * 6, sub_rows / 2. * 6)) @@ -76,14 +72,14 @@ class Model_AM: label="Binned Data", color="blue", s=1) - ax.set_title("Model_AM") + ax.set_title("Model_AM {}".format(title)) ax.set_xlabel("TX Amplitude") ax.set_ylabel("RX Amplitude") ax.set_xlim(-0.5, 1.5) ax.legend(loc=4) fig.tight_layout() - fig.savefig(fig_path) + fig.savefig(plot_location) plt.close(fig) def get_next_coefs(self, tx_dpd, rx_received, coefs_am): @@ -95,13 +91,14 @@ class Model_AM: coefs_am_new = coefs_am + \ self.learning_rate_am * (coefs_am_new - coefs_am) - self._plot(tx_dpd, rx_received, coefs_am, coefs_am_new) + self._plot_data = (tx_dpd, rx_received, coefs_am, coefs_am_new) return coefs_am_new # The MIT License (MIT) # # Copyright (c) 2017 Andreas Steger +# Copyright (c) 2018 Matthias P. Braendli # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/python/dpd/Model_PM.py b/python/dpd/Model_PM.py index 7b80bf3..40fa1d4 100644 --- a/python/dpd/Model_PM.py +++ b/python/dpd/Model_PM.py @@ -28,22 +28,18 @@ class Model_PM: """Calculates new coefficients using the measurement and the previous coefficients""" - def __init__(self, - c, - learning_rate_pm=1, - plot=False): + def __init__(self, c, learning_rate_pm=1): self.c = c - self.learning_rate_pm = learning_rate_pm - self.plot = plot + self._plot_data = None + + def plot(self, plot_location, title): + if self._plot_data is not None: + tx_dpd, phase_diff, coefs_pm, coefs_pm_new = self._plot_data - def _plot(self, tx_dpd, phase_diff, coefs_pm, coefs_pm_new): - if self.plot and self.c.plot_location is not None: tx_range, phase_diff_est = self.calc_line(coefs_pm, 0, 0.6) tx_range_new, phase_diff_est_new = self.calc_line(coefs_pm_new, 0, 0.6) - dt = datetime.datetime.now().isoformat() - fig_path = self.c.plot_location + "/" + dt + "_Model_PM.png" sub_rows = 1 sub_cols = 1 fig = plt.figure(figsize=(sub_cols * 6, sub_rows / 2. * 6)) @@ -62,13 +58,13 @@ class Model_PM: label="Binned Data", color="blue", s=1) - ax.set_title("Model_PM") + ax.set_title("Model_PM {}".format(title)) ax.set_xlabel("TX Amplitude") ax.set_ylabel("Phase DIff") ax.legend(loc=4) fig.tight_layout() - fig.savefig(fig_path) + fig.savefig(plot_location) plt.close(fig) def _discard_small_values(self, tx_dpd, phase_diff): @@ -97,13 +93,14 @@ class Model_PM: coefs_pm_new = self.fit_poly(tx_dpd, phase_diff) coefs_pm_new = coefs_pm + self.learning_rate_pm * (coefs_pm_new - coefs_pm) - self._plot(tx_dpd, phase_diff, coefs_pm, coefs_pm_new) + self._plot_data = (tx_dpd, phase_diff, coefs_pm, coefs_pm_new) return coefs_pm_new # The MIT License (MIT) # # Copyright (c) 2017 Andreas Steger +# Copyright (c) 2018 Matthias P. Braendli # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/python/dpd/Model_Poly.py b/python/dpd/Model_Poly.py index c8f6135..ca39492 100644 --- a/python/dpd/Model_Poly.py +++ b/python/dpd/Model_Poly.py @@ -36,20 +36,20 @@ class Poly: """Calculates new coefficients using the measurement and the previous coefficients""" - def __init__(self, - c, - learning_rate_am=1.0, - learning_rate_pm=1.0): + def __init__(self, c, learning_rate_am=1.0, learning_rate_pm=1.0): self.c = c - self.plot = c.MDL_plot self.learning_rate_am = learning_rate_am self.learning_rate_pm = learning_rate_pm self.reset_coefs() - self.model_am = Model_AM.Model_AM(c, plot=self.plot) - self.model_pm = Model_PM.Model_PM(c, plot=self.plot) + self.model_am = Model_AM.Model_AM(c) + self.model_pm = Model_PM.Model_PM(c) + + def plot(self, am_plot_location, pm_plot_location, title): + self.model_am.plot(am_plot_location, title) + self.model_pm.plot(pm_plot_location, title) def reset_coefs(self): self.coefs_am = np.zeros(5, dtype=np.float32) |