Files
sf-rf/script/jitter_scan.py
2016-06-29 08:29:34 +02:00

129 lines
4.1 KiB
Python

"""
File: jitter_scan.py
Author: KR84
Copyright PSI LLRF, 2016
Purpose Record RF system jitters and store / archive data
Preconditions RF station is running
"""
#################################################################
# Parameter SECTION, change it to your RF station before run
SECTION = "SINSB02"
#################################################################
# some other parameters
# for 100 Hz and P2P-count = 100 this can be 1.1 seconds
latency = 0.3
start = -170.0
stop = 180.0
step = 10.0
print "SECTION = ", SECTION
print "Start = ", start
print "Stop = ", stop
print "Step = ", step
# re-define filename, such that the SECTION is also in the filename
set_context(path = "{data}/{year}_{month}/{date}/{date}_{time}_" + str(SECTION) + "_{name}")
# define all PVs
import ch.psi.pshell.epics.ProcessVariable as PV
# controlled variabales
cv_rf_phase = PV("phase_ref", SECTION + "-RLLE-DSP:PHASE-REFERENCE")
cv_rf_amplt = PV("amplt_ref", SECTION + "-RLLE-DSP:AMPLT-REFERENCE")
# measured variables
mv_ref_jit_amplt = PV("REF_amplt_jit" ,SECTION + "-RLLE-REF10:SIG-AMPLT-JIT-P2P-REL")
mv_ref_jit_phase = PV("REF_phase_jit" ,SECTION + "-RLLE-REF10:SIG-PHASE-JIT-P2P")
mv_iqm_jit_amplt = PV("IQM_amplt_jit" ,SECTION + "-RIQM-DCP10:FOR-AMPLT-JIT-P2P-REL")
mv_iqm_jit_phase = PV("IQM_phase_jit" ,SECTION + "-RIQM-DCP10:FOR-PHASE-JIT-P2P")
mv_pre_jit_amplt = PV("PRE_amplt_jit" ,SECTION + "-RPRE-DCP10:FOR-AMPLT-JIT-P2P-REL")
mv_pre_jit_phase = PV("PRE_phase_jit" ,SECTION + "-RPRE-DCP10:FOR-PHASE-JIT-P2P")
mv_kly_jit_amplt = PV("KLY_amplt_jit" ,SECTION + "-RKLY-DCP10:FOR-AMPLT-JIT-P2P-REL")
mv_kly_jit_phase = PV("KLY_phase_jit" ,SECTION + "-RKLY-DCP10:FOR-PHASE-JIT-P2P")
# initialize all PVs
cv_rf_phase.initialize()
cv_rf_amplt.initialize()
mv_ref_jit_amplt.initialize()
mv_ref_jit_phase.initialize()
mv_iqm_jit_amplt.initialize()
mv_iqm_jit_phase.initialize()
mv_pre_jit_amplt.initialize()
mv_pre_jit_phase.initialize()
mv_kly_jit_amplt.initialize()
mv_kly_jit_phase.initialize()
scan_result = lscan(cv_rf_phase, (mv_ref_jit_amplt,mv_ref_jit_phase,mv_iqm_jit_amplt,mv_iqm_jit_phase,mv_pre_jit_amplt,mv_pre_jit_phase,mv_kly_jit_amplt,mv_kly_jit_phase), start, stop, step , latency=latency, title="Jitter Scan")
# close all PVs
cv_rf_phase.close()
cv_rf_amplt.close()
mv_ref_jit_amplt.close()
mv_ref_jit_phase.close()
mv_iqm_jit_amplt.close()
mv_iqm_jit_phase.close()
mv_pre_jit_amplt.close()
mv_pre_jit_phase.close()
mv_kly_jit_amplt.close()
mv_kly_jit_phase.close()
# analyze
ref_jit_amplt_mean = mean(scan_result.getReadable(0))
ref_jit_phase_mean = mean(scan_result.getReadable(1))
iqm_jit_amplt_mean = mean(scan_result.getReadable(2))
iqm_jit_phase_mean = mean(scan_result.getReadable(3))
pre_jit_amplt_mean = mean(scan_result.getReadable(4))
pre_jit_phase_mean = mean(scan_result.getReadable(5))
kly_jit_amplt_mean = mean(scan_result.getReadable(6))
kly_jit_phase_mean = mean(scan_result.getReadable(7))
#Setting attributes to the scan group
path = get_context().group
set_attribute(path, "SECTION", SECTION)
set_attribute(path, "ref_jit_amplt_mean", ref_jit_amplt_mean)
set_attribute(path, "ref_jit_phase_mean", ref_jit_phase_mean)
set_attribute(path, "iqm_jit_amplt_mean", iqm_jit_amplt_mean)
set_attribute(path, "iqm_jit_phase_mean", iqm_jit_phase_mean)
set_attribute(path, "pre_jit_amplt_mean", pre_jit_amplt_mean)
set_attribute(path, "pre_jit_phase_mean", pre_jit_phase_mean)
set_attribute(path, "kly_jit_amplt_mean", kly_jit_amplt_mean)
set_attribute(path, "kly_jit_phase_mean", kly_jit_phase_mean)
# ELOG
msg = scan_result.print("\t")
msg = msg + "\nMean:\nREF amplt\t" + str(ref_jit_amplt_mean)[:5] + "\nREF phase\t" + str(ref_jit_phase_mean)[:5] + "\n\nIQM amplt\t" + str(iqm_jit_amplt_mean)[:5] + "\nIQM phase\t" + str(iqm_jit_phase_mean)[:5] + "\n\nPRE amplt\t" + str(pre_jit_amplt_mean)[:5] + "\npre phase\t" + str(pre_jit_phase_mean)[:5] + "\n\nKLY amplt\t" + str(kly_jit_amplt_mean)[:5] + "\nkly phase\t" + str(kly_jit_phase_mean)[:5]
msg = msg + "\n\nFile: " + get_context().path
print msg
elogllrf("Jitter Scan", msg,"Measurement", "RF Stability", SECTION, get_plot_snapshots())
# save the entry in the logbook