Loading csp-lmc-mid/charts/csp-lmc-mid/charts/csp-proto/values.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ csplmc: image: registry: nexus.engageska-portugal.pt/ska-docker image: mid-csp-lmc tag: 0.6.7-e2efb2f tag: 0.6.8-6ec0c11 pullPolicy: IfNotPresent deviceServers: Loading csp-lmc-mid/tools/adr8_plot.py 0 → 100644 +106 −0 Original line number Diff line number Diff line from threading import Thread import tango import time import collections import matplotlib.pyplot as plt import matplotlib.animation as animation #import struct from tango import EventType class attributePlot: def __init__(self, plotLength = 100, device='mid_csp/elt/subarray_01'): self.plotMaxLength = plotLength self.data = collections.deque([0] * plotLength, maxlen=plotLength) self.plotTimer = 0 self.previousTimer = 0 self.proxy = 0 self.thread = None self.isRun = True self.device = device try: self.proxy = tango.DeviceProxy("mid_csp/elt/subarray_01") print('Connected to device {}'.format(device)) except: print("Failed to connect to device {}".format(device) ) def readAttributeStart(self): if self.proxy: self.proxy.subscribe_event("obsState", tango.EventType.CHANGE_EVENT, self.attributes_change_evt_cb, stateless=False) if self.thread == None: self.thread = Thread(target=self.backgroundThread) self.thread.start() def getAttributeData(self, frame, lines, lineValueText, lineLabel, timeText): currentTimer = time.perf_counter() self.plotTimer = int((currentTimer - self.previousTimer) * 1000) # the first reading will be erroneous self.previousTimer = currentTimer timeText.set_text('Plot Interval = ' + str(self.plotTimer) + 'ms') self.data.append(self.obs_state) # we get the latest data point and append it to our array lines.set_data(range(self.plotMaxLength), self.data) lineValueText.set_text('[' + lineLabel + '] = ' + str(self.obs_state)) def backgroundThread(self): # retrieve data time.sleep(0.2) # give some buffer time for retrieving data while (self.isRun): time.sleep(0.05) def attributes_change_evt_cb(self, evt): dev_name = evt.device.dev_name() if not evt.err: try: if evt.attr_value.name.lower() == "obsstate": self.obs_state = evt.attr_value.value self.data.append(self.obs_state) # we get the latest data point and append it to our array self.data.append(self.obs_state) # we get the latest data point and append it to our array print("Received event on {}/{}: {}".format(dev_name, str(evt.attr_value.name), str(evt.attr_value.value))) except tango.DevFailed as df: self.logger.error(str(df.args[0].desc)) except Exception as except_occurred: self.logger.error(str(except_occurred)) else: for item in evt.errors: if item.reason == "API_EventTimeout": print("API_EventTimeout") def close(self): self.isRun = False self.thread.join() print('Disconnected...') def main(): maxPlotLength = 100 s = attributePlot(maxPlotLength, 'mid_csp/elt/subarray_01') # initializes all required variables s.readAttributeStart() # starts background thread # plotting starts below pltInterval = 100 # Period at which the plot animation updates [ms] xmin = 0 xmax = maxPlotLength ymin = -1 ymax = 12 fig = plt.figure("MID CSP Subarray ADR-8 transitions") ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax )) ax.set_title('obsState real-time graph') ax.set_xlabel("time") ax.set_ylabel("obsState") plt.yticks(range(11), ('EMPTY', 'RESOURCING', 'IDLE', 'CONFIGURING', 'READY', 'SCANNING', 'ABORTING', 'ABORTED', 'RESETTING', 'FAULT', 'RESTARTING')) lineLabel = 'obsState' timeText = ax.text(0.50, 0.95, '', transform=ax.transAxes) lines = ax.plot([], [], label=lineLabel)[0] lineValueText = ax.text(0.50, 0.90, '', transform=ax.transAxes) anim = animation.FuncAnimation(fig, s.getAttributeData, fargs=(lines, lineValueText, lineLabel, timeText), interval=pltInterval) # fargs has to be a tuple plt.legend(loc="upper left") plt.show() s.close() if __name__ == '__main__': main() Loading
csp-lmc-mid/charts/csp-lmc-mid/charts/csp-proto/values.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ csplmc: image: registry: nexus.engageska-portugal.pt/ska-docker image: mid-csp-lmc tag: 0.6.7-e2efb2f tag: 0.6.8-6ec0c11 pullPolicy: IfNotPresent deviceServers: Loading
csp-lmc-mid/tools/adr8_plot.py 0 → 100644 +106 −0 Original line number Diff line number Diff line from threading import Thread import tango import time import collections import matplotlib.pyplot as plt import matplotlib.animation as animation #import struct from tango import EventType class attributePlot: def __init__(self, plotLength = 100, device='mid_csp/elt/subarray_01'): self.plotMaxLength = plotLength self.data = collections.deque([0] * plotLength, maxlen=plotLength) self.plotTimer = 0 self.previousTimer = 0 self.proxy = 0 self.thread = None self.isRun = True self.device = device try: self.proxy = tango.DeviceProxy("mid_csp/elt/subarray_01") print('Connected to device {}'.format(device)) except: print("Failed to connect to device {}".format(device) ) def readAttributeStart(self): if self.proxy: self.proxy.subscribe_event("obsState", tango.EventType.CHANGE_EVENT, self.attributes_change_evt_cb, stateless=False) if self.thread == None: self.thread = Thread(target=self.backgroundThread) self.thread.start() def getAttributeData(self, frame, lines, lineValueText, lineLabel, timeText): currentTimer = time.perf_counter() self.plotTimer = int((currentTimer - self.previousTimer) * 1000) # the first reading will be erroneous self.previousTimer = currentTimer timeText.set_text('Plot Interval = ' + str(self.plotTimer) + 'ms') self.data.append(self.obs_state) # we get the latest data point and append it to our array lines.set_data(range(self.plotMaxLength), self.data) lineValueText.set_text('[' + lineLabel + '] = ' + str(self.obs_state)) def backgroundThread(self): # retrieve data time.sleep(0.2) # give some buffer time for retrieving data while (self.isRun): time.sleep(0.05) def attributes_change_evt_cb(self, evt): dev_name = evt.device.dev_name() if not evt.err: try: if evt.attr_value.name.lower() == "obsstate": self.obs_state = evt.attr_value.value self.data.append(self.obs_state) # we get the latest data point and append it to our array self.data.append(self.obs_state) # we get the latest data point and append it to our array print("Received event on {}/{}: {}".format(dev_name, str(evt.attr_value.name), str(evt.attr_value.value))) except tango.DevFailed as df: self.logger.error(str(df.args[0].desc)) except Exception as except_occurred: self.logger.error(str(except_occurred)) else: for item in evt.errors: if item.reason == "API_EventTimeout": print("API_EventTimeout") def close(self): self.isRun = False self.thread.join() print('Disconnected...') def main(): maxPlotLength = 100 s = attributePlot(maxPlotLength, 'mid_csp/elt/subarray_01') # initializes all required variables s.readAttributeStart() # starts background thread # plotting starts below pltInterval = 100 # Period at which the plot animation updates [ms] xmin = 0 xmax = maxPlotLength ymin = -1 ymax = 12 fig = plt.figure("MID CSP Subarray ADR-8 transitions") ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax )) ax.set_title('obsState real-time graph') ax.set_xlabel("time") ax.set_ylabel("obsState") plt.yticks(range(11), ('EMPTY', 'RESOURCING', 'IDLE', 'CONFIGURING', 'READY', 'SCANNING', 'ABORTING', 'ABORTED', 'RESETTING', 'FAULT', 'RESTARTING')) lineLabel = 'obsState' timeText = ax.text(0.50, 0.95, '', transform=ax.transAxes) lines = ax.plot([], [], label=lineLabel)[0] lineValueText = ax.text(0.50, 0.90, '', transform=ax.transAxes) anim = animation.FuncAnimation(fig, s.getAttributeData, fargs=(lines, lineValueText, lineLabel, timeText), interval=pltInterval) # fargs has to be a tuple plt.legend(loc="upper left") plt.show() s.close() if __name__ == '__main__': main()