From 08146cf084bdd6d4ce900d3adfcfe951acc95cef Mon Sep 17 00:00:00 2001
From: Tammo Jan Dijkema <T.J.Dijkema@gmail.com>
Date: Wed, 17 Jan 2024 15:50:18 +0100
Subject: [PATCH] Automatic title

---
 makedata.py   |  2 +-
 power_plot.py | 23 ++++++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/makedata.py b/makedata.py
index aea1fe8..b4b194e 100755
--- a/makedata.py
+++ b/makedata.py
@@ -14,5 +14,5 @@ with open("doppler.txt", "r") as f:
             print(line, end='', flush=True)
         else:
             print(line, end='', flush=True)
-            if a > 1000:
+            if a > 500:
                 sleep(1)
diff --git a/power_plot.py b/power_plot.py
index 200315b..8b606b0 100755
--- a/power_plot.py
+++ b/power_plot.py
@@ -39,17 +39,17 @@ last_seconds = 10 * 60
 class PowerPlot:
     """A power plot with two time scales"""
 
-    def __init__(self, fig):
+    def __init__(self, fig, yname):
         self.fig = fig
         self.ax = fig.add_subplot()
         self.ax.set_xlabel("Time (UTC)")
-        self.ax.set_ylabel("Frequency")
+        self.ax.set_ylabel(yname)
         self.ax.xaxis_date()
         self.min, self.max = None, None
         self.ax.xaxis.set_major_formatter(
             FuncFormatter(lambda x, pos: f"{num2date(x):%H:%M}")
         )
-        fig.suptitle(f"Maximum frequency", fontsize=16)
+        fig.suptitle(yname, fontsize=16)
         fig.tight_layout()
         (self.totalplot,) = self.ax.plot([], [], ".", color="blue")
         (self.totalplothighlight,) = self.ax.plot(
@@ -95,26 +95,30 @@ class MyToolbar(NavigationToolbar):
 class PowerPlotMainWindow(QMainWindow):
     """QT Application that reads data from stdin, plots in a PowerPlot"""
 
-    def __init__(self):
+    def __init__(self, col_num=1):
         super().__init__()
         self.setStyleSheet("background-color: white;")
         self.autoscale_x = True
         self.autoscale_y = True
+        self.col_num = col_num
         self.setWindowTitle("Dwingeloo Radio Telescope")
         self.setGeometry(100, 100, 800, 600)
 
         central_widget = QWidget(self)
         layout = QVBoxLayout(central_widget)
 
-        # Get metadata
+        # Get metadata and ignore it
         header_lines = []
         while True:
             line = sys.stdin.readline()
             header_lines.append(line)
             if line[0] != "#":
-                column_names = line.split()
+                column_names = [name.strip() for name in line.split()]
                 break
 
+        yname = column_names[self.col_num]
+        yname = yname.rstrip(",").capitalize()
+
         line = sys.stdin.readline()
         values = line.split(",")
         first_time = datetime.utcfromtimestamp(float(values[0]))
@@ -125,7 +129,7 @@ class PowerPlotMainWindow(QMainWindow):
 
         self.min_range = np.arange(-last_seconds, 1, 1)
 
-        self.data = np.array([float(values[1])])
+        self.data = np.array([float(values[self.col_num])])
 
         self.start_time = first_time
         self.stop_time = first_time + timedelta(hours=2)
@@ -149,7 +153,7 @@ class PowerPlotMainWindow(QMainWindow):
 
         # fig.canvas.manager.set_window_title("Dwingeloo Radio Telescope")
 
-        self.powerplot = PowerPlot(fig)
+        self.powerplot = PowerPlot(fig, yname)
 
         self.read_stdin()
         self.stdin_notifier = QSocketNotifier(
@@ -166,7 +170,7 @@ class PowerPlotMainWindow(QMainWindow):
             self.output_counter += 1
             values = line.split(",")
             time_now = float(values[0])
-            power_now = float(values[1])
+            power_now = float(values[self.col_num])
 
             self.time_dt = np.append(
                 self.time_dt, date2num(datetime.utcfromtimestamp(time_now))
@@ -210,4 +214,5 @@ if __name__ == "__main__":
     main_window = PowerPlotMainWindow()
     main_window.show()
     signal.signal(signal.SIGINT, handle_interrupt_signal)
+
     sys.exit(app.exec_())
-- 
GitLab