244 lines
8.7 KiB
Python
244 lines
8.7 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
|
|
- AVG gates are set-up for correct length for particular station, P2P count is set to 100 for all channels + vsum
|
|
- AMPLT-REFERENCE is set to the klystron saturation point
|
|
- feedbacks are in closed loop (both)
|
|
- you know the settling time of the feedback + 100 P2P-count + 100 Hz, if required, change it below
|
|
-
|
|
|
|
"""
|
|
|
|
#################################################################
|
|
# Parameter SECTION, change it to your RF station before run
|
|
SECTION = "SINSB02"
|
|
|
|
# for 100 Hz and P2P-count = 100 this can be at least 1.1 seconds
|
|
latency = 0.3
|
|
#################################################################
|
|
|
|
|
|
|
|
|
|
|
|
# some other parameters
|
|
|
|
|
|
|
|
|
|
|
|
# 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 + "-RSYS:SET-VSUM-PHASE")
|
|
cv_rf_amplt = PV("amplt_ref", SECTION + "-RSYS:SET-ACC-VOLT")
|
|
|
|
# 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")
|
|
|
|
# auxiliary measured variables, but not scanned
|
|
#mva_hvps = PV("HVPS" ,SECTION + "-RMOD:V-SET")
|
|
mva_hvps = PV("HVPS" ,"SINEG01-RMOD:V-SET")
|
|
|
|
# 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()
|
|
|
|
mva_hvps.initialize()
|
|
|
|
|
|
|
|
#################################################################################
|
|
# scan
|
|
|
|
hvps = mva.hvps.read()
|
|
|
|
# define current amplitude as saturation amplitude, then define three scans
|
|
amplt_sat = cv_rf_amplt.read()
|
|
amplt_m5 = 0.95 * amplt_stop
|
|
amplt_m10 = 0.9 * amplt_stop
|
|
|
|
#cv_rf_amplt.write(amplt_sat)
|
|
#time.sleep(1.0)
|
|
#scan_result_sat = 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), -170, 180, 10, latency=latency, title="Jitter Scan")
|
|
#cv_rf_amplt.write(amplt_m5)
|
|
#time.sleep(1.0)
|
|
#scan_result_m5 = 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), -170, 180, 10, latency=latency, title="Jitter Scan")
|
|
#cv_rf_amplt.write(amplt_m10)
|
|
#time.sleep(1.0)
|
|
#scan_result_m10 = 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), -170, 180, 10, latency=latency, title="Jitter Scan")
|
|
|
|
|
|
#scan_result = ascan((cv_rf_phase, cv_rf_amplt), (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), (-170.0, 0.2), (180.0, 0.3), (10.0, 0.05) , latency=latency, title="Jitter Scan", zigzag=True)
|
|
scan_result = ascan((cv_rf_amplt, 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), ( 0.2, -170.0), (0.3, 180.0), (0.05, 10.0) , latency=latency, title="Jitter Scan", zigzag=True)
|
|
|
|
|
|
|
|
#################################################################################
|
|
# 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()
|
|
|
|
mva_hvps.close()
|
|
|
|
|
|
#################################################################################
|
|
# analyze
|
|
|
|
# struct definition to hold all relevant statistics data
|
|
class statistics_data (object):
|
|
min = 0.0
|
|
mean = 0.0
|
|
max = 0.0
|
|
sigma = 0.0
|
|
|
|
# struct definition for statistics dat aof all three amplitude levels
|
|
class all_statistics_data (object):
|
|
sat = statistics_data()
|
|
m5 = statistics_data()
|
|
m10 = statistics_data()
|
|
|
|
def return_string(self):
|
|
# give results back as formatted string
|
|
ret_str = "Statistics:\tmin\tmean\tmax\tstdev"
|
|
ret_str = ret_str + "\nSaturation :\t" + str(self.sat.min)[:7] + "\t" + str(self.sat.mean)[:7] + "\t" + str(self.sat.max)[:7] + "\t" + str(self.sat.stdev)[:7]
|
|
ret_str = ret_str + "\n5% out of sat :\t" + str(self.m5.min)[:7] + "\t" + str(self.m5.mean)[:7] + "\t" + str(self.m5.max)[:7] + "\t" + str(self.m5.stdev)[:7]
|
|
ret_str = ret_str + "\n10% out of sat:\t" + str(self.m10.min)[:7] + "\t" + str(self.m10.mean)[:7] + "\t" + str(self.m10.max)[:7] + "\t" + str(self.m10.stdev)[:7]
|
|
return ret_str
|
|
|
|
|
|
|
|
def statistics_calc(data_in):
|
|
"function calculates the min/max/mean/stdev of an array"
|
|
temp = statistics_data();
|
|
temp.mean = mean (data_in)
|
|
temp.min = min (data_in)
|
|
temp.max = max (data_in)
|
|
temp.stdev = stdev(data_in)
|
|
return temp
|
|
|
|
|
|
def all_statistics_calc(data_in):
|
|
"function calculates for all three amplitudes the statistics data."
|
|
temp = all_statistics_data();
|
|
temp.m10 = statistics_calc (data_in[0:35])
|
|
temp.m5 = statistics_calc (data_in[36:71])
|
|
temp.sat = statistics_calc (data_in[72:107])
|
|
return temp
|
|
|
|
|
|
|
|
# create emtpy structs
|
|
ref_jit_amplt = all_statistics_data()
|
|
ref_jit_phase = all_statistics_data()
|
|
|
|
iqm_jit_amplt = all_statistics_data()
|
|
iqm_jit_phase = all_statistics_data()
|
|
|
|
pre_jit_amplt = all_statistics_data()
|
|
pre_jit_phase = all_statistics_data()
|
|
|
|
kly_jit_amplt = all_statistics_data()
|
|
kly_jit_phase = all_statistics_data()
|
|
|
|
|
|
# calculate statistics
|
|
ref_jit_amplt = all_statistics_calc(scan_result.getReadable(0))
|
|
ref_jit_phase = all_statistics_calc(scan_result.getReadable(1))
|
|
|
|
iqm_jit_amplt = all_statistics_calc(scan_result.getReadable(2))
|
|
iqm_jit_phase = all_statistics_calc(scan_result.getReadable(3))
|
|
|
|
pre_jit_amplt = all_statistics_calc(scan_result.getReadable(4))
|
|
pre_jit_phase = all_statistics_calc(scan_result.getReadable(5))
|
|
|
|
kly_jit_amplt = all_statistics_calc(scan_result.getReadable(6))
|
|
kly_jit_phase = all_statistics_calc(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", ref_jit_amplt)
|
|
set_attribute(path, "ref_jit_phase", ref_jit_phase)
|
|
|
|
set_attribute(path, "iqm_jit_amplt", iqm_jit_amplt)
|
|
set_attribute(path, "iqm_jit_phase", iqm_jit_phase)
|
|
|
|
set_attribute(path, "pre_jit_amplt", pre_jit_amplt)
|
|
set_attribute(path, "pre_jit_phase", pre_jit_phase)
|
|
|
|
set_attribute(path, "kly_jit_amplt", kly_jit_amplt)
|
|
set_attribute(path, "kly_jit_phase", kly_jit_phase)
|
|
|
|
set_attribute(path, "HVPS", hvps)
|
|
|
|
|
|
|
|
#################################################################################
|
|
# ELOG
|
|
|
|
msg = "HVPS command = " + str(hvps)[:2] + "V"
|
|
msg = msg + "\n---------------------------------------------------------"
|
|
msg = msg + "\nREF amplt\t" + ref_jit_amplt.return_string()
|
|
msg = msg + "\n\nREF phase\t" + ref_jit_phase.return_string()
|
|
msg = msg + "\n---------------------------------------------------------"
|
|
msg = msg + "\nIQM amplt\t" + iqm_jit_amplt.return_string()
|
|
msg = msg + "\n\nIQM phase\t" + iqm_jit_phase.return_string()
|
|
msg = msg + "\n---------------------------------------------------------"
|
|
msg = msg + "\nPRE amplt\t" + pre_jit_amplt.return_string()
|
|
msg = msg + "\n\nPRE phase\t" + pre_jit_phase.return_string()
|
|
msg = msg + "\n---------------------------------------------------------"
|
|
msg = msg + "\nKLY amplt\t" + kly_jit_amplt.return_string()
|
|
msg = msg + "\n\nKLY phase\t" + kly_jit_phase.return_string()
|
|
msg = msg + "\n---------------------------------------------------------"
|
|
|
|
print msg
|
|
|
|
# save the entry in the logbook
|
|
plot_files = get_plot_snapshots("Jitter Scan")
|
|
time.sleep(1.0)
|
|
elogllrf("Jitter Scan (HVPS="+str(hvps)[:2]+"V", msg,"Measurement", "RF Stability", SECTION, plot_files)
|
|
|
|
|
|
|