From df3433cb494e4ab7025d9570d4633306cafe3f8c Mon Sep 17 00:00:00 2001 From: Bernardo Carvalho Date: Fri, 11 Oct 2024 12:45:38 +0000 Subject: [PATCH] Option to use decimated MDSplus data Signed-off-by: Bernardo Carvalho --- Analysis/pyqtPlotMds.py | 47 +++++++++++++++++++++++++++------------- Startup/ketchup.py | 37 ------------------------------- Startup/pulse-ketchup.py | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 52 deletions(-) delete mode 100644 Startup/ketchup.py create mode 100755 Startup/pulse-ketchup.py diff --git a/Analysis/pyqtPlotMds.py b/Analysis/pyqtPlotMds.py index 28859d4..107be71 100755 --- a/Analysis/pyqtPlotMds.py +++ b/Analysis/pyqtPlotMds.py @@ -3,12 +3,17 @@ This script plots the MARTe2 ATCAIop samples stored in MDSplus All of the plots may be panned/scaled by dragging with the left/right mouse buttons. Right click on any plot to show a context menu. + +To change EPICS EO, WO use. e.g. +caput -a ISTTOK:central:ATCAIOP1-WO 14 0.191 0.174 -0.036 -0.044 0.183 0.126 0.020 0.140 -0.461 -0.572 0.022 -0.262 0.475 0.353 + """ import numpy as np import pyqtgraph as pg # from pyqtgraph.Qt import QtCore -from MDSplus import Tree +# from MDSplus import Tree +import MDSplus as mds import argparse app = pg.mkQApp("Plotting MARTe2 AtcaIop Data") @@ -17,10 +22,12 @@ app = pg.mkQApp("Plotting MARTe2 AtcaIop Data") # MAX_SAMPLES = 50000 ADC_CHANNELS = 14 # channels stored in ISTTOK -DECIM_RATE = 200 +ADC_DECIM_RATE = 200 -parser = argparse.ArgumentParser( - description='Script to support the QA activities') +parser = argparse.ArgumentParser(description= + """Script to plot AtcaIop MDSplus data and calc drifts + To change EPICS EO, WO use. e.g. + caput -a ISTTOK:central:ATCAIOP1-WO 14 0.191 0.174 -0.036 -0.044 0.183 0.126 0.020 0.140 -0.461 -0.572 0.022 -0.262 0.475 0.353""") # parser.add_argument('-l','--list', nargs='+', # help=' Set flag', required=True) @@ -35,6 +42,8 @@ parser.add_argument('-m', '--maxpoints', type=int, help='Max points to plot', default=50000) parser.add_argument('-e', '--averages', action='store_true', help='Calc averages') +parser.add_argument('-d', '--decimated', action='store_true', + help='Use decimated data') # parser.add_argument('-w', '--drift', action='store_true', help='Calc drifts') parser.add_argument('-z', '--zero', action='store_true', help='Zero integral Lines') @@ -45,8 +54,9 @@ mdsPulseNumber = args.shot mdsTreeName = 'rtappisttok' try: - tree = Tree(mdsTreeName, mdsPulseNumber) -except Exception: + tree = mds.Tree(mdsTreeName, mdsPulseNumber) +# except Exception: +except mds.mdsExceptions.TreeFOPENR: print(f'Failed opening {mdsTreeName} for pulse number {mdsPulseNumber:d}') exit() @@ -57,7 +67,7 @@ win.setWindowTitle('pyqtgraph example: Plotting') # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) -p1 = win.addPlot(title="ATCA-IOP ADC raw decimated") +p1 = win.addPlot(title="ATCA-IOP ADC raw data") # add plt.addLegend() BEFORE you create the curves. # mdsNode = tree.getNode("ATCAIOP1.ADC0RAW") # dataAdc = mdsNode.getData().data() @@ -75,15 +85,15 @@ for i in range(ADC_CHANNELS): meanD[i] = np.mean(dataAdc[:, 0]).astype(int) mdsNode = tree.getNode(f"ATCAIOP1.ADC{i}INT") dataAdcInt = mdsNode.getData().data() - total_samples = DECIM_RATE * len(dataAdcInt[:, 0]) + total_samples = ADC_DECIM_RATE * len(dataAdcInt[:, 0]) driftW[i] = (dataAdcInt[-1, 0] - dataAdcInt[0, 0]) / total_samples if (args.averages): - print(f"EO: {ADC_CHANNELS} ", end='') + print(f"{ADC_CHANNELS} EO: ", end='') for i in range(ADC_CHANNELS): print(f"{meanD[i]:d} ", end='') print(" ") - print(f"WO: {ADC_CHANNELS} ", end='') + print(f"{ADC_CHANNELS} WO: ", end='') for i in range(ADC_CHANNELS): print(f"{driftW[i]:0.3f} ", end='') print(" ") @@ -95,7 +105,7 @@ for i in range(start, stop): dataAdc = mdsNode.getData().data() timeData = mdsNode.getDimensionAt(0).data() y = dataAdc[:args.maxpoints, 0] - x = DECIM_RATE * np.arange(len(y)) / 2.0e6 + x = ADC_DECIM_RATE * np.arange(len(y)) / 2.0e6 p1.plot(x, y, pen=pg.mkPen(i, width=2), name=f"Ch {i+1}") # p1.setLabel('bottom', "Y Axis", units='s') @@ -108,20 +118,27 @@ stop = args.irange[1] # print("WO: ", end='') for i in range(start, stop): # mdsNode = tree.getNode(f"ATCAIOP1.ADC8INT") - mdsNode = tree.getNode(f"ATCAIOP1.ADC{i}INTD") + if args.decimated: + node = f"ATCAIOP1.ADC{i}INTD" + else: + node = f"ATCAIOP1.ADC{i}INT" + mdsNode = tree.getNode(node) try: dataAdcInt = mdsNode.getData().data() timeData = mdsNode.getDimensionAt(0).data() - total_samples = DECIM_RATE * len(dataAdcInt[:, 0]) + total_samples = len(dataAdcInt[:, 0]) y = dataAdcInt[:args.maxpoints, 0] / 2.0e6 # LSB * sec + x = np.arange(len(y)) / 2.0e6 # in sec + # if args.decimated: + total_samples *= ADC_DECIM_RATE + x *= ADC_DECIM_RATE if (args.zero): y = y - dataAdcInt[0, 0] / 2.0e6 # LSB * sec # wo = (dataAdcInt[-1, 0] - dataAdcInt[0, 0]) /total_samples # print(f"{wo:0.4f} ", end='') - x = DECIM_RATE * np.arange(len(y)) / 2.0e6 # in sec p4.plot(x, y, pen=pg.mkPen(i, width=2), name=f"Ch {i+1}") except Exception: - print(f"No data ATCAIOP1.ADC{i:d}INTD") + print(f"No data for {node}") print(" ") diff --git a/Startup/ketchup.py b/Startup/ketchup.py deleted file mode 100644 index 96d0134..0000000 --- a/Startup/ketchup.py +++ /dev/null @@ -1,37 +0,0 @@ - -#!/usr/bin/env python3 -""" -This script -""" - -from MDSplus import Tree -import argparse - - -MDSTREENAME = 'rtappisttok' - -def main(args): - mdsPulseNumber = args.shot - - try: - if(mdsPulseNumber > 0): - tree = Tree(MDSTREENAME) - tree.setCurrent(mdsPulseNumber) - #else: - tree.close() - - except: - print(f'Failed opening {MDSTREENAME} for pulse number {mdsPulseNumber:d}') - exit() - - print(f'Last Pulse for {MDSTREENAME} is {mdsPulseNumber:d}') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description = 'Script to synchronize ISTTOK shot number') - - parser.add_argument('-s', '--shot', type=int, help='Mds+ pulse Number ([1, ...])', default=100) - - args = parser.parse_args() - main(args) -# vim: set syntax=python ts=4 sw=4 sts=4 sr et diff --git a/Startup/pulse-ketchup.py b/Startup/pulse-ketchup.py new file mode 100755 index 0000000..626b2e5 --- /dev/null +++ b/Startup/pulse-ketchup.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +""" +This script resets the MDSplus pulseNumber of Tree +""" +from MDSplus import Tree +from MDSplus.mdsExceptions import TreeFOPENR +import argparse + + +MDSTREENAME = 'rtappisttok' + + +def main(args): + mdsPulseNumber = args.shot + + try: + if (mdsPulseNumber > 0): + tree = Tree(MDSTREENAME) + tree.setCurrent(mdsPulseNumber) + # else: + tree.close() + + except TreeFOPENR: + print(f'Failed opening {MDSTREENAME} for ' + f'pulse number {mdsPulseNumber:d}') + exit() + + print(f'Last Pulse for {MDSTREENAME} is {mdsPulseNumber:d}') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Script to synchronize ISTTOK shot number') + + parser.add_argument('-s', '--shot', + type=int, help='Mds+ pulse Number ([1, ...])', + default=99) + + args = parser.parse_args() + main(args) + +# vim: set syntax=python ts=4 sw=4 sts=4 sr et