From 1c0df7c8242b4796801b97f5fc464cf3fab611c6 Mon Sep 17 00:00:00 2001 From: Bernardo Carvalho Date: Fri, 23 May 2025 17:52:39 +0100 Subject: [PATCH] Added script to update MDS tree Signed-off-by: Bernardo Carvalho --- Analysis/epics-env.sh | 10 ++++++ Analysis/saveEoWo2MDSplus.py | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Analysis/epics-env.sh create mode 100644 Analysis/saveEoWo2MDSplus.py diff --git a/Analysis/epics-env.sh b/Analysis/epics-env.sh new file mode 100644 index 0000000..066d96c --- /dev/null +++ b/Analysis/epics-env.sh @@ -0,0 +1,10 @@ +# Epics stuff +EPICS_BASE=/opt/epics/epics-base +EPICS_HOST_ARCH=`${EPICS_BASE}/startup/EpicsHostArch` +EPICS_BASE_BIN=${EPICS_BASE}/bin/${EPICS_HOST_ARCH} +export PATH=${EPICS_BASE_BIN}:${PATH} + +#export EPICS_CA_ADDR_LIST="10.10.136.177" +export EPICS_CA_AUTO_ADDR_LIST="NO" +export EPICS_CA_ADDR_LIST="192.168.1.110" + diff --git a/Analysis/saveEoWo2MDSplus.py b/Analysis/saveEoWo2MDSplus.py new file mode 100644 index 0000000..e60ef77 --- /dev/null +++ b/Analysis/saveEoWo2MDSplus.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +""" +This script update a MDSplus Tree with the epics EO/WO offsets + +First use: + export EPICS_CA_AUTO_ADDR_LIST="NO" + export EPICS_CA_ADDR_LIST="192.168.1.110" +""" +import numpy as np + +import mdsthin +from epics import caget +import argparse + +ADC_CHANNELS = 12 # channels stored in ISTTOK +MDSTREENAME = 'isttokmarte' + +EOPV = 'ISTTOK:central:ATCAIOP1-EO' +EO_NODE = '\\TOP.HARDWARE.ATCA_2.IOP_9.CHANNEL_{}.EO_OFFSET' +WOPV = 'ISTTOK:central:ATCAIOP1-WO' +WO_NODE = '\\TOP.HARDWARE.ATCA_2.IOP_9.CHANNEL_{}.WO_OFFSET' +# Connect over SSH +c = mdsthin.Connection('ssh://oper@atca-marte2') + + +def saveEoWo(args): + mdsPulseNumber = args.shot + try: + if (mdsPulseNumber > 0): + c.openTree(MDSTREENAME, mdsPulseNumber) + else: + # Open the current shot + c.openTree(MDSTREENAME, 0) + + except Exception: + print(f'Failed opening {MDSTREENAME} for pulse number ' + + f'{mdsPulseNumber:d}') + exit() + print(f'Opening Tree {MDSTREENAME} for pulse {mdsPulseNumber:d}') + eo = caget(EOPV) + wo = caget(WOPV) + for i, e in enumerate(eo): + # Read individual nodes + y = c.get(EO_NODE.format(i)).data() + print(f" i: {i}, {e}, m: {y}") + # Using an explicit MDSplus type + c.put(EO_NODE.format(i), '$', mdsthin.Int32(e)) + + for i, w in enumerate(wo): + y = c.get(WO_NODE.format(i)).data() + print(f" i: {i}, {w}, m: {y}") + c.put(WO_NODE.format(i), '$', mdsthin.Float32(w)) + # print(wo) + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Script to update a MDSplus Tree with the epics EO/WO') + + parser.add_argument('-s', '--shot', + type=int, help='Mds+ pulse Number ([1, ...])', + default=52739) + # parser.add_argument('-e', '--averages', action='store_true', help='Calc averages') +# parser.add_argument('-w', '--drift', action='store_true', help='Calc drifts') + + args = parser.parse_args() + saveEoWo(args)