Files
sf-op/script/Diagnostics/BlmGainScan.py
2021-08-17 14:06:14 +02:00

98 lines
3.2 KiB
Python
Executable File

#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import ch.psi.pshell.bs.Scalar as Scalar
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
#Arguments
SAMPLES = 10
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-1-CH03-V-MM2",]
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"]
RANGE = [0.5, 1.1]
STEP_SIZE = 0.01
SETTLING_TIME = 0.5
SIMULATION = False
do_elog = True
gain_positioners = []
for i in range(len(GAINS)):
gain_positioners.append( DummyPositioner("gain " + str(i+1)) if SIMULATION else Channel(GAINS[i], alias = "gain " + str(i+1)))
attenuators = []
for i in range(len(ATTENUATORS)):
att = DiscretePositioner("Att"+str(i+1), ATTENUATORS[i])
att.initialize()
attenuators.append(att)
#Channel-based
#blm1 = ChannelDouble("blm1", "SINDI02-DBLM025:B1_LOSS"); blm1.setMonitored(True); blm1.initialize()
#blm2 = ChannelDouble("blm2", "SINDI02-DBLM085:B1_LOSS"); blm2.setMonitored(True); blm2.initialize()
#Stream creation
sensors = []
line_plots = []
st = Stream("pulse_id", dispatcher)
for i in range(len(BLMS)):
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 10, 0)
av = create_averager(blm, SAMPLES, interval = -1)
av.setMonitored(i>0)
sensors.append(av)
sensors.append(av.stdev)
sensors.append(av.samples)
line_plots.append(av.samples)
st.initialize()
st.start()
st.waitCacheChange(10000) #Wait stream be running before starting scan
"""
#Averaging
ablm1 = create_averager(blm1, SAMPLES, interval = -1)
ablm2 = create_averager(blm2, SAMPLES, interval = -1)
ablm2.setMonitored(True)
"""
#Plot setup
setup_plotting( line_plots = line_plots)
#Metadata
set_attribute("/", "Samples" , SAMPLES)
set_attribute("/", "BLM" , BLMS)
set_attribute("/", "Gain" , GAINS)
set_attribute("/", "Range" , RANGE)
set_attribute("/", "Attenuators" , ATTENUATORS)
set_attribute("/", "StepSize" , STEP_SIZE)
set_attribute("/", "SamplingTime" , SETTLING_TIME)
for att in attenuators:
set_attribute("/", att.setpoint.channelName, att.read())
try:
r=lscan(gain_positioners, sensors, [RANGE[0],] * len(gain_positioners), [RANGE[1],] * len(gain_positioners), [STEP_SIZE,] * len(gain_positioners), latency = SETTLING_TIME)
finally:
st.close()
# save the entry in the logbook
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path + "\n\n" + "Save to ELOG?", "YesNo") == "Yes":
gsa_log_msg = "Data file: " + get_exec_pars().path
gsa_log_msg = gsa_log_msg + "\nSamples = " + str(SAMPLES)
gsa_log_msg = gsa_log_msg + "\nBLM = " + str(BLMS)
gsa_log_msg = gsa_log_msg + "\nGain = " + str(GAINS)
gsa_log_msg = gsa_log_msg + "\nRange = " + str(RANGE)
gsa_log_msg = gsa_log_msg + "\nAttenuators = " + str(ATTENUATORS)
gsa_log_msg = gsa_log_msg + "\nStepSize = " + str(STEP_SIZE)
gsa_log_msg = gsa_log_msg + "\nSamplingTime = " + str(SETTLING_TIME)
plots = get_plot_snapshots()
save=[]
for i in range(len(BLMS)):
save.append(plots[3*i])
elog("Wire Scan", gsa_log_msg, save)