ScreenPanel
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import ch.psi.pshell.imaging.Data as Data
|
||||
|
||||
d = load_data("2017/06/16/20170616_122305_snapshot.h5|/data")
|
||||
atts = get_attributes("2017/06/16/20170616_122305_snapshot.h5|/data")
|
||||
data = Data(d)
|
||||
iv = data.integrateVertically(False)
|
||||
ih = data.integrateHorizontally(False)
|
||||
xp = atts["x_profile"]
|
||||
yp = atts["y_profile"]
|
||||
p1, p2 = plot([xp, yp], ["X profile", "Y profile"])
|
||||
p1.addSeries(LinePlotSeries("d"))
|
||||
p2.addSeries(LinePlotSeries("d"))
|
||||
p1.getSeries(1).setData(iv)
|
||||
p2.getSeries(1).setData(ih)
|
||||
@@ -0,0 +1,33 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
|
||||
|
||||
dispatcher.config.disableCompression = False
|
||||
set_exec_pars(persist = False)
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 5
|
||||
BLMS = ["SINDI02-DBLM025", ] #"SINDI02-DBLM085", "S10DI01-DBLM045"]
|
||||
|
||||
|
||||
sensors = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
#st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
|
||||
for i in range(len(BLMS)):
|
||||
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 0)
|
||||
av = create_averager(blm, SAMPLES, interval = -1)
|
||||
av.setMonitored(i>0)
|
||||
sensors.append(av)
|
||||
sensors.append(av.stdev)
|
||||
sensors.append(av.samples)
|
||||
bpmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
|
||||
sensors.append(bpmw)
|
||||
|
||||
|
||||
st.initialize()
|
||||
st.start()
|
||||
if not st.waitCacheChange(3000): #Wait stream be running before starting scan
|
||||
raise Exception("Stream timeout")
|
||||
|
||||
bscan(st, 10)
|
||||
@@ -0,0 +1,25 @@
|
||||
rsys = "SINSB01-RSYS"
|
||||
bpm = "SINLH02-DBPM210"
|
||||
phi1 = -175.0
|
||||
phi2 = 180.0
|
||||
dphi = 5.0
|
||||
|
||||
def laser_on():
|
||||
caput("SIN-CVME-TIMAST-TMA:LaserDelayControl", 0)
|
||||
def laser_off():
|
||||
caput("SIN-CVME-TIMAST-TMA:LaserDelayControl", 1)
|
||||
|
||||
phi_set = Channel(rsys + ":SET-VSUM-PHASE")
|
||||
phi_get = Channel(rsys + ":GET-VSUM-PHASE")
|
||||
amp_get = Channel(rsys + ":GET-VSUM-AMPLT")
|
||||
bpm_x = Channel(bpm + ":X1")
|
||||
|
||||
r = lscan(phi_set, [phi_get, amp_get, bpm_x], phi1, phi2, dphi, 0.5, before_read = laser_on(), after_read = laser_off())
|
||||
|
||||
plot(r.getReadable(2), xdata = r.getReadable(0), title = "Phase scan")
|
||||
|
||||
(amplitude, angular_frequency, phase, ok, maximum, fit_x, fit_y) = hfit(r.getReadable(2), xdata = r.getReadable(0))
|
||||
|
||||
caput(rsys + ":SET-ON-CREST-VSUM-PHASE", maximum)
|
||||
|
||||
set_return(r.print())
|
||||
@@ -0,0 +1,51 @@
|
||||
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
start = 20.0
|
||||
stop = 140.0
|
||||
step = 5.0
|
||||
nb = 2
|
||||
lat = 0.100
|
||||
else:
|
||||
start = args[0]
|
||||
stop = args[1]
|
||||
step = args[2]
|
||||
nb = int(args[3])
|
||||
lat = args[4]
|
||||
|
||||
bph = ControlledVariable("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
|
||||
bph.config.minValue =-180.0
|
||||
bph.config.maxValue = 360.0
|
||||
bph.config.precision = 3
|
||||
bph.config.resolution = 1.0
|
||||
bph.config.save()
|
||||
bph.initialize()
|
||||
rph = Channel("SINEG01-RSYS:SET-VSUM-PHASE-SIM", type = 'd', alias = 'RF phase')
|
||||
q = Channel("SINEG01-DICT215:B1_CHARGE-SIM", type = 'd', alias = 'ICT-Q')
|
||||
|
||||
rph0 = rph.read()
|
||||
|
||||
try:
|
||||
q_averager = create_averager(q, nb, 0.100)
|
||||
rph_averager = create_averager(rph, nb, 0.100)
|
||||
r = lscan(bph, (rph_averager, q_averager), start, stop, step, latency=lat)
|
||||
beamphase = r.getPositions(0)
|
||||
rfphase = [val.mean for val in r.getReadable(0)]
|
||||
rfphaserms = [val.stdev for val in r.getReadable(0)]
|
||||
charge = [val.mean for val in r.getReadable(1)]
|
||||
chargerms = [val.stdev for val in r.getReadable(1)]
|
||||
finally:
|
||||
rph.write(rph0)
|
||||
bph.close()
|
||||
rph.close()
|
||||
q.close()
|
||||
|
||||
#Setting the return value
|
||||
index_max = charge.index(max(charge))
|
||||
bph_ref = beamphase[index_max] - 80
|
||||
rph_ref = rfphase[index_max] - 80
|
||||
|
||||
print bph_ref
|
||||
print rph_ref
|
||||
|
||||
set_return(bph_ref, rph_ref)
|
||||
@@ -0,0 +1,100 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
|
||||
|
||||
|
||||
dispatcher.config.disableCompression = True
|
||||
#set_exec_pars(persist = False)
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 2
|
||||
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-2-CH03-V-MM","S10DI01-DBLM113:M06-1-CH03-V-MM"]
|
||||
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
|
||||
BLMW = ["SINDI02-DBLM025:LOSS_SIGNAL_RAW", "SINDI02-DBLM085:LOSS_SIGNAL_RAW", "S10DI01-DBLM045:LOSS_SIGNAL_RAW"]
|
||||
BPMS = ["SINDI01-DBPM060:Q1", "SINDI02-DBPM010:Q1"]
|
||||
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"]
|
||||
ATT_SP = 0 #3,6,9,12,15
|
||||
RANGE = [0.5, 1.1]
|
||||
STEP_SIZE = 0.1
|
||||
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
|
||||
class ListenerBpmw (DeviceListener):
|
||||
def onValueChanged(self, device, value, former):
|
||||
if sampling and (get_exec_pars().scan is not None):
|
||||
path = get_exec_pars().group + "rec " + str(get_exec_pars().scan.recordIndex) + "/" + device.name
|
||||
if "Exception" in get_attributes(path).keys(): #If file does not exist
|
||||
create_dataset(path, 'd', False, (0, len(value)))
|
||||
append_dataset(path,value)
|
||||
|
||||
sampling = False
|
||||
|
||||
def before():
|
||||
global sampling
|
||||
sampling = True
|
||||
|
||||
def after():
|
||||
global sampling
|
||||
sampling = False
|
||||
|
||||
|
||||
sensors = []
|
||||
line_plots = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
|
||||
for i in range(len(BLMS)):
|
||||
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 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)
|
||||
bpmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
|
||||
#sensors.append(bpmw)
|
||||
bpmw.addListener(ListenerBpmw())
|
||||
|
||||
|
||||
#st.initialize()
|
||||
#st.start()
|
||||
#st.waitCacheChange(10000) #Wait stream be running before starting scan
|
||||
|
||||
|
||||
for i in range(len(BPMS)):
|
||||
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
|
||||
av1 = create_averager(bpm, SAMPLES, interval = -1)
|
||||
av1.setMonitored(i>0 or (len(BLMS) > 0))
|
||||
sensors.append(av1)
|
||||
sensors.append(av1.stdev)
|
||||
sensors.append(av1.samples)
|
||||
line_plots.append(av1.samples)
|
||||
|
||||
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
|
||||
try:
|
||||
st.initialize()
|
||||
st.start()
|
||||
if not st.waitCacheChange(10000): #Wait stream be running before starting scan
|
||||
raise Exception("Stream timeout")
|
||||
|
||||
tscan(sensors, 5, 0.5, before_read=before, after_read=after)
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
knob = Channel("SARUN20-MCRX080:I-SET")
|
||||
sensor1 = Channel("SINEG01-DICT215:B1_CHARGE")
|
||||
sensor2 = Channel("S10DI01-DICT025:B1_CHARGE")
|
||||
|
||||
start = -1.0
|
||||
stop = 1.0
|
||||
nstep = 10
|
||||
lat = 0.5
|
||||
|
||||
r = lscan(knob, (sensor1, sensor2), start, stop, nstep, lat)
|
||||
|
||||
plot(r.getReadable(0), name = 'plotname', xdata = r.getReadable(1))
|
||||
@@ -0,0 +1,11 @@
|
||||
knob = Channel("SARUN20-MCRX080:I-SET")
|
||||
sensor1 = Channel("SINEG01-DICT215:B1_CHARGE")
|
||||
sensor2 = Channel("S10DI01-DICT025:B1_CHARGE")
|
||||
|
||||
start = -0.5
|
||||
stop = 0.5
|
||||
nstep = 10
|
||||
lat = 0.5
|
||||
|
||||
av = create_averager(sensor1, 10, 0.1)
|
||||
lscan(knob, (av, sensor2), start, stop, nstep, lat)
|
||||
@@ -0,0 +1,4 @@
|
||||
data = tscan(Channel('SINEG01-DICT215:B1_CHARGE'), 100, 0.1)
|
||||
samples = data.getReadable(0)
|
||||
print "mean=", mean(samples)
|
||||
print "stdev=", stdev (samples)
|
||||
@@ -0,0 +1,112 @@
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
|
||||
dry_run = True
|
||||
do_elog = False
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
station = "STEST01"
|
||||
bpm_ch = "SINBC02-DBPM140"
|
||||
else:
|
||||
station = args[0]
|
||||
bpm_ch = args[1]
|
||||
|
||||
start = caget(station + "-RSYS:SET-SCAN-START")
|
||||
stop = caget(station + "-RSYS:SET-SCAN-STOP")
|
||||
step = caget(station + "-RSYS:SET-SCAN-STEP")
|
||||
lat = caget(station + "-RSYS:SET-SCAN-WAIT-TIME")
|
||||
nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
|
||||
disp = caget(bpm_ch + ":DISPERSION")
|
||||
energy0 = caget(bpm_ch + ":ENERGY")
|
||||
|
||||
phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
|
||||
phase.config.minValue =-180.0
|
||||
phase.config.maxValue = 180.0
|
||||
phase.config.precision = 3
|
||||
phase.config.rotation = True
|
||||
phase.config.resolution = 0.5
|
||||
phase.initialize()
|
||||
V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT")
|
||||
P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER")
|
||||
if dry_run:
|
||||
x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU")
|
||||
else:
|
||||
x = ChannelDouble("BPM-X", bpm_ch + ":X1")
|
||||
V.initialize()
|
||||
P.initialize()
|
||||
x.initialize()
|
||||
|
||||
phase0 = phase.read()
|
||||
|
||||
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
|
||||
caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
|
||||
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", float('nan'))
|
||||
caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", float('nan'))
|
||||
caput(station + "-RSYS:GET-ONCREST-E-GAIN", float('nan'))
|
||||
caput(station + "-RSYS:GET-ONCREST-KLY-POWER", float('nan'))
|
||||
|
||||
#update the plot dynamically
|
||||
arr_phase,arr_energy = [],[]
|
||||
def after(rec):
|
||||
global disp, energy0
|
||||
arr_phase.append(rec.positions[0])
|
||||
arr_energy.append(energy0 * (1 + rec.values[0].mean / 1000.0 / disp))
|
||||
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd'))
|
||||
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
|
||||
|
||||
try:
|
||||
x_averager = create_averager(x, nb, 0.100)
|
||||
r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after)
|
||||
rf_phase = r.getPositions(0)
|
||||
energy = [energy0 * (1 + val.mean / 1000.0 / disp) for val in r.getReadable(0)]
|
||||
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(energy, 'd'))
|
||||
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d'))
|
||||
try:
|
||||
run("CPython/wrapper")
|
||||
(fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(energy , rf_phase)
|
||||
except:
|
||||
raise Exception("Fit failure")
|
||||
plot([energy, fit_y], ["data", "fit"], [rf_phase, fit_x])
|
||||
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", ph_crest)
|
||||
caput(station + "-RSYS:GET-ONCREST-E-GAIN", fit_amplitude)
|
||||
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", fit_x)
|
||||
caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", fit_y)
|
||||
phase_min, phase_max = min(rf_phase), max(rf_phase)
|
||||
if not (phase_min <= ph_crest <= phase_max):
|
||||
raise Exception("On-crest phase outside scan range")
|
||||
phase.write(ph_crest)
|
||||
time.sleep(lat)
|
||||
Ampl = V.read()
|
||||
Power = P.read()
|
||||
caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", Ampl)
|
||||
caput(station + "-RSYS:GET-ONCREST-KLY-POWER", Power)
|
||||
finally:
|
||||
phase.write(phase0)
|
||||
phase.close()
|
||||
V.close()
|
||||
P.close()
|
||||
x.close()
|
||||
|
||||
phase_offset = 90 - ph_crest
|
||||
amplitude_scale = fit_amplitude / Ampl
|
||||
power_scale = Power / math.pow(Ampl,2)
|
||||
|
||||
caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
|
||||
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
|
||||
caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
|
||||
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
title = "Phase scan" + station
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n"
|
||||
log_msg = log_msg + "Energy Gain: %0.3f" % energy_gain + "MeV\n"
|
||||
log_msg = log_msg + "Phase Offset: %0.2f" % phase_offset + "deg\n"
|
||||
log_msg = log_msg + "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n"
|
||||
log_msg = log_msg + "Power Scale: %0.3f" % power_scale + "MW/MV^2"
|
||||
attachments = []
|
||||
if plt is not None:
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanPlot.png")
|
||||
plt.saveSnapshot(file_name, "png")
|
||||
attachments = [file_name,]
|
||||
elog(title, log_msg, attachments)
|
||||
@@ -0,0 +1 @@
|
||||
lscan(Channel('SINBC01-MCRX070:I-SET'), Channel('SINBC01-DBPM100:X1'), -0.5,0.5,101,latency=0.5)
|
||||
@@ -0,0 +1,9 @@
|
||||
x = Channel("SINBC02-DBPM140:X1-SIMU", type = 'd', alias='BPM-X')
|
||||
xb = create_averager(x, 5, 0.100)
|
||||
print 'xb =', xb
|
||||
print 'xb.min =', xb.min
|
||||
print 'xb.max =', xb.max
|
||||
print 'xb.mean =', xb.mean
|
||||
print 'xb.stdev =', xb.stdev
|
||||
print 'xb.variance =', xb.variance
|
||||
x.close()
|
||||
@@ -0,0 +1,12 @@
|
||||
y = [ -1.36633487e+01, -1.13808691e+01, -8.92628692e+00, -6.53052299e+00, \
|
||||
-5.26897045e+00, -5.75429171e+00, -1.75746114e+00, -1.39318500e-01, \
|
||||
-1.04863080e+00, 1.46985567e-02, 1.04432984e+00, 1.14839620e+00, \
|
||||
-1.45837648e+00, -2.62571957e+00, -4.64780802e+00, -4.02915206e+00, \
|
||||
-6.94357281e+00, -1.02403468e+01, -1.30960565e+01, -1.55355021e+01]
|
||||
x = [ 50.0, 51.05263158, 52.10526316, 53.15789474, 54.21052632, \
|
||||
55.26315789, 56.31578947, 57.36842105, 58.42105263, 59.47368421, \
|
||||
60.52631579, 61.57894737, 62.63157895, 63.68421053, 64.73684211, \
|
||||
65.78947368, 66.84210526, 67.89473684, 68.94736842, 70. ]
|
||||
|
||||
r = hfitoff(y, x)
|
||||
plot([y,r[5]], ["data", "fit"], [x, r[4]])
|
||||
@@ -0,0 +1,13 @@
|
||||
y = [ -1.36633487e+01, 1.13808691e+01, -8.92628692e+00, 6.53052299e+00, \
|
||||
-5.26897045e+00, 5.75429171e+00, -1.75746114e+00, 1.39318500e-01, \
|
||||
-1.04863080e+00, 1.46985567e-02, -1.04432984e+00, 1.14839620e+00, \
|
||||
-1.45837648e+00, 2.62571957e+00, -4.64780802e+00, 4.02915206e+00, \
|
||||
-6.94357281e+00, 1.02403468e+01, -1.30960565e+01, 1.55355021e+01]
|
||||
x = [ 50.0, 51.05263158, 52.10526316, 53.15789474, 54.21052632, \
|
||||
55.26315789, 56.31578947, 57.36842105, 58.42105263, 59.47368421, \
|
||||
60.52631579, 61.57894737, 62.63157895, 63.68421053, 64.73684211, \
|
||||
65.78947368, 66.84210526, 67.89473684, 68.94736842, 70. ]
|
||||
|
||||
r = hfitoff(y, x)
|
||||
#plot([y,r[5]], ["data", "fit"], [x, r[4]])
|
||||
plot([y,r[5]], [x, r[4]])
|
||||
Reference in New Issue
Block a user