This commit is contained in:
gobbo_a
2025-12-15 16:53:16 +01:00
parent 1fa968a960
commit 4f6a49c538
37 changed files with 1214 additions and 518 deletions
+54
View File
@@ -0,0 +1,54 @@
lat = 0.01
sample = 1000
ELECTRON_CHARGE = 1.60217663e-19
BPM1 = "SARBD02-DBPM010:Y1-RT"
BPM2 = "SARBD02-DBPM040:Y1-RT"
DISP_BPM1 = "SARBD02-DBPM010:DISPERSION-OP" #198.0 mm natural disp. Holylist
DISP_BPM2 = "SARBD02-DBPM040:DISPERSION-OP" #397.8 mm natural disp. Holylist
SFB_BEAM_DUMP = "SFB_BEAM_DUMP_AR:ONOFF1"
LASING_OFF = "Undulators/K_AR_lasing_off.py"
LASING_ON = "Undulators/K_AR_taper.py"
BUNCH_CHARGE = "SARBD02-DBPM010:Q1-AVG"
ELECTRON_ENERGY = "SARCL02-MBND100:P-READ"
ENE_BPM1 = "SARBD02-DBPM010:PULSE-ENE-OP"
ENE_BPM2 = "SARBD02-DBPM040:PULSE-ENE-OP"
ERR_BPM1 = "SARBD02-DBPM010:PULSE-ENE-ERR-OP"
ERR_BPM2 = "SARBD02-DBPM040:PULSE-ENE-ERR-OP"
y_bpm1 = ChannelDouble(BPM1, BPM1)
y_bpm2 = ChannelDouble(BPM2, BPM2)
y_bpm2.monitored = True
y_bpm1.initialize()
y_bpm2.initialize()
y_averager_bpm1 = create_averager(y_bpm1, sample, lat)
y_averager_bpm2 = create_averager(y_bpm2, sample, lat)
feedback_state_init = caget(SFB_BEAM_DUMP)
caput(SFB_BEAM_DUMP, 0)
bpm1_las_on = y_averager_bpm1.read()
bpm2_las_on = y_averager_bpm2.read()
run(LASING_OFF)
time.sleep(1.0)
bpm1_las_off = y_averager_bpm1.read()
bpm2_las_off = y_averager_bpm2.read()
run(LASING_ON)
caput(SFB_BEAM_DUMP, feedback_state_init)
y_bpm1.close()
y_bpm2.close()
bunch_charge = caget(BUNCH_CHARGE)
ene_elect = caget(ELECTRON_ENERGY)
disp1 = caget(DISP_BPM1) * 1000
disp2 = caget(DISP_BPM2) * 1000
ene_bunch = ene_elect * 1e6 * bunch_charge * 1e-12
dy_bpm1 = bpm1_las_off.mean - bpm1_las_on.mean
dy_bpm2 = bpm2_las_off.mean - bpm2_las_on.mean
pulse_energy_bpm1 = dy_bpm1 / disp1 * ene_bunch * 1000
pulse_energy_bpm2 = dy_bpm2 / disp2 * ene_bunch * 1000
dy_bpm1_stdev = bpm1_las_off.stdev + bpm1_las_on.stdev
dy_bpm2_stdev = bpm2_las_off.stdev + bpm2_las_on.stdev
pulse_energy_bpm1_stdev = dy_bpm1_stdev / disp1 * ene_bunch * 1000
pulse_energy_bpm2_stdev = dy_bpm2_stdev / disp2 * ene_bunch * 1000
print(pulse_energy_bpm1, pulse_energy_bpm1_stdev)
print(pulse_energy_bpm2, pulse_energy_bpm2_stdev)
caput(ENE_BPM1, pulse_energy_bpm1)
caput(ERR_BPM1, pulse_energy_bpm1_stdev)
caput(ENE_BPM2, pulse_energy_bpm2)
caput(ERR_BPM2, pulse_energy_bpm2_stdev)
+54
View File
@@ -0,0 +1,54 @@
lat = 0.01
sample = 1000
ELECTRON_CHARGE = 1.60217663e-19
BPM1 = "SATBD02-DBPM010:Y2-RT"
BPM2 = "SATBD02-DBPM040:Y2-RT"
DISP_BPM1 = "SATBD02-DBPM010:DISPERSION-OP" #198.0 mm natural disp. Holylist
DISP_BPM2 = "SATBD02-DBPM040:DISPERSION-OP" #397.8 mm natural disp. Holylist
SFB_BEAM_DUMP = "SFB_BEAM_DUMP_AT:ONOFF1"
LASING_OFF = "Undulators/K_AT_lasing_off.py"
LASING_ON = "Undulators/K_AT_taper.py"
BUNCH_CHARGE = "SATBD02-DBPM010:Q2-AVG"
ELECTRON_ENERGY = "SATCB01:ENE-FILT-OP"
ENE_BPM1 = "SATBD02-DBPM010:PULSE-ENE-OP"
ENE_BPM2 = "SATBD02-DBPM040:PULSE-ENE-OP"
ERR_BPM1 = "SATBD02-DBPM010:PULSE-ENE-ERR-OP"
ERR_BPM2 = "SATBD02-DBPM040:PULSE-ENE-ERR-OP"
y_bpm1 = ChannelDouble(BPM1, BPM1)
y_bpm2 = ChannelDouble(BPM2, BPM2)
y_bpm2.monitored = True
y_bpm1.initialize()
y_bpm2.initialize()
y_averager_bpm1 = create_averager(y_bpm1, sample, lat)
y_averager_bpm2 = create_averager(y_bpm2, sample, lat)
feedback_state_init = caget(SFB_BEAM_DUMP)
caput(SFB_BEAM_DUMP, 0)
bpm1_las_on = y_averager_bpm1.read()
bpm2_las_on = y_averager_bpm2.read()
run(LASING_OFF)
time.sleep(1.0)
bpm1_las_off = y_averager_bpm1.read()
bpm2_las_off = y_averager_bpm2.read()
run(LASING_ON)
caput(SFB_BEAM_DUMP, feedback_state_init)
y_bpm1.close()
y_bpm2.close()
bunch_charge = caget(BUNCH_CHARGE)
ene_elect = caget(ELECTRON_ENERGY)
disp1 = caget(DISP_BPM1) * 1000
disp2 = caget(DISP_BPM2) * 1000
ene_bunch = ene_elect * 1e6 * bunch_charge * 1e-12
dy_bpm1 = bpm1_las_off.mean - bpm1_las_on.mean
dy_bpm2 = bpm2_las_off.mean - bpm2_las_on.mean
pulse_energy_bpm1 = dy_bpm1 / disp1 * ene_bunch * 1000
pulse_energy_bpm2 = dy_bpm2 / disp2 * ene_bunch * 1000
dy_bpm1_stdev = bpm1_las_off.stdev + bpm1_las_on.stdev
dy_bpm2_stdev = bpm2_las_off.stdev + bpm2_las_on.stdev
pulse_energy_bpm1_stdev = dy_bpm1_stdev / disp1 * ene_bunch * 1000
pulse_energy_bpm2_stdev = dy_bpm2_stdev / disp2 * ene_bunch * 1000
print(pulse_energy_bpm1, pulse_energy_bpm1_stdev)
print(pulse_energy_bpm2, pulse_energy_bpm2_stdev)
caput(ENE_BPM1, pulse_energy_bpm1)
caput(ERR_BPM1, pulse_energy_bpm1_stdev)
caput(ENE_BPM2, pulse_energy_bpm2)
caput(ERR_BPM2, pulse_energy_bpm2_stdev)
+37
View File
@@ -0,0 +1,37 @@
import_py("CPython/k_fit", "k_fit")
undlist = ("SARUN03","SARUN04","SARUN05","SARUN06","SARUN07","SARUN08","SARUN09",
"SARUN10","SARUN11","SARUN12","SARUN13","SARUN14","SARUN15")
arr_k_total = []
for und in undlist:
arr_k_total.append(caget(und + "-UIND030:K_UND_SET"))
i = 0
while abs(arr_k_total[i] - arr_k_total[i + 1]) > 0.05:
i = i + 1
lin_start = i
lin_fit, qua_fit, qua_start_fit = k_fit(arr_k_total[lin_start:])
lin = int(round(lin_fit / 1e-6))
qua = int(round(qua_fit / 1e-6))
lin_start = int(lin_start)
lin_stop = len(arr_k_total) - 1
qua_start = int(qua_start_fit)
qua_stop = len(arr_k_total) - 1
caput("SARUN:TAPER-LIN", lin)
caput("SARUN:TAPER-QUA", qua)
caput("SARUN:TAPER-LIN-START", lin_start)
caput("SARUN:TAPER-LIN-STOP", lin_stop)
caput("SARUN:TAPER-QUA-START", qua_start)
caput("SARUN:TAPER-QUA-STOP", qua_stop)
u, i, j = 0, 0, 0
for und in undlist:
K_taper = lin_fit * i + qua_fit * j**2
k_total = arr_k_total[u]
K_set = k_total - K_taper
caputq(und + "-UIND030:K_TAPER_SET", K_taper)
caputq(und + "-UIND030:K_SET", K_set)
if lin_start <= u <= lin_stop: i = i + 1
if qua_start <= u <= qua_stop: j = j + 1
u = u + 1
set_return("Success")
+3 -3
View File
@@ -4,12 +4,12 @@ undlist = ("SARUN03","SARUN04","SARUN05","SARUN06","SARUN07","SARUN08","SARUN09"
i = 0
amp = 0.10
for und in undlist:
rand = random() * 0.7 + 0.3
rand = random() * 0.7 + 0.3 # 0.3<rand<1.0
K_taper = (-1)**i * amp * rand
i = i + 1
K = caget(und + "-UIND030:K_SET")
K_min = caget(und + "-UIND030:K_SET.DRVL")
K_max = caget(und + "-UIND030:K_SET.DRVH")
K_min = caget(und + "-UIND030:K_UND_SET.LOW")
K_max = caget(und + "-UIND030:K_UND_SET.HIGH")
if K + K_taper > K_max:
K_taper = -K_taper
if K + K_taper < K_min:
-1
View File
@@ -1,4 +1,3 @@
print "ENTER"
taper_lin = caget("SARUN:TAPER-LIN") * 1e-6
taper_qua = caget("SARUN:TAPER-QUA") * 1e-6
taper_lin_start = caget("SARUN:TAPER-LIN-START.RVAL")
+37
View File
@@ -0,0 +1,37 @@
import_py("CPython/k_fit", "k_fit")
undlist = ("SATUN06","SATUN07","SATUN08","SATUN09","SATUN10","SATUN11","SATUN12","SATUN13",
"SATUN15","SATUN16","SATUN17","SATUN18","SATUN19","SATUN20","SATUN21","SATUN22")
arr_k_total = []
for und in undlist:
arr_k_total.append(caget(und + "-UIND030:K_UND_SET"))
i = 0
while abs(arr_k_total[i] - arr_k_total[i + 1]) > 0.05:
i = i + 1
lin_start = i
lin_fit, qua_fit, qua_start_fit = k_fit(arr_k_total[lin_start:])
lin = int(round(lin_fit / 1e-6))
qua = int(round(qua_fit / 1e-6))
lin_start = int(lin_start)
lin_stop = len(arr_k_total) - 1
qua_start = int(qua_start_fit)
qua_stop = len(arr_k_total) - 1
caput("SATUN:TAPER-LIN", lin)
caput("SATUN:TAPER-QUA", qua)
caput("SATUN:TAPER-LIN-START", lin_start)
caput("SATUN:TAPER-LIN-STOP", lin_stop)
caput("SATUN:TAPER-QUA-START", qua_start)
caput("SATUN:TAPER-QUA-STOP", qua_stop)
u, i, j = 0, 0, 0
for und in undlist:
K_taper = lin_fit * i + qua_fit * j**2
k_total = arr_k_total[u]
K_set = k_total - K_taper
caputq(und + "-UIND030:K_TAPER_SET", K_taper)
caputq(und + "-UIND030:K_SET", K_set)
if lin_start <= u <= lin_stop: i = i + 1
if qua_start <= u <= qua_stop: j = j + 1
u = u + 1
set_return("Success")
+2 -2
View File
@@ -8,8 +8,8 @@ for und in undlist:
K_taper = (-1)**i * 0.25 + random() * 0.050 - 0.025
i = i + 1
K = caget(und + "-UIND030:K_SET")
K_min = caget(und + "-UIND030:K_SET.DRVL")
K_max = caget(und + "-UIND030:K_SET.DRVH")
K_min = caget(und + "-UIND030:K_UND_SET.LOW")
K_max = caget(und + "-UIND030:K_UND_SET.HIGH")
if K + K_taper > K_max:
K_taper = K_max - K - random() * 0.025
if K + K_taper < K_min:
+2 -2
View File
@@ -8,8 +8,8 @@ for und in undlist:
K_taper = (-1)**i * 0.25 + random() * 0.050 - 0.025
i = i + 1
K = caget(und + "-UIND030:K_SET")
K_min = caget(und + "-UIND030:K_SET.DRVL")
K_max = caget(und + "-UIND030:K_SET.DRVH")
K_min = caget(und + "-UIND030:K_UND_SET.LOW")
K_max = caget(und + "-UIND030:K_UND_SET.HIGH")
if K + K_taper > K_max:
K_taper = K_max - K - random() * 0.025
if K + K_taper < K_min:
+2 -2
View File
@@ -10,8 +10,8 @@ for und in undlist:
K_taper = (-1)**i * amp * rand
i = i + 1
K = caget(und + "-UIND030:K_SET")
K_min = caget(und + "-UIND030:K_SET.DRVL")
K_max = caget(und + "-UIND030:K_SET.DRVH")
K_min = caget(und + "-UIND030:K_UND_SET.LOW")
K_max = caget(und + "-UIND030:K_UND_SET.HIGH")
if K + K_taper > K_max:
K_taper = -K_taper
if K + K_taper < K_min:
+4
View File
@@ -8,6 +8,10 @@ taper_qua_stop = caget("SATUN:TAPER-QUA-STOP.RVAL")
undlist = ("SATUN06","SATUN07","SATUN08","SATUN09","SATUN10","SATUN11","SATUN12","SATUN13",
"SATUN15","SATUN16","SATUN17","SATUN18","SATUN19","SATUN20","SATUN21","SATUN22")
screen_pos = caget("SATBD01-DSCR120:GET_SCREEN1_POS")
if screen_pos != "Out of beam":
caput("SATBD01-DSCR120:SET_SCREEN1_POS", 0)
u = 0
i, j = 0, 0
for und in undlist:
+4
View File
@@ -8,6 +8,10 @@ taper_qua_stop = caget("SATUN:TAPER-QUA-STOP.RVAL")
undlist = ("SATUN06","SATUN07","SATUN08","SATUN09","SATUN10","SATUN11","SATUN12","SATUN13",
"SATUN15","SATUN16","SATUN17","SATUN18","SATUN19","SATUN20","SATUN21","SATUN22")
screen_pos = caget("SATBD01-DSCR120:GET_SCREEN1_POS")
if screen_pos != "Out of beam":
caput("SATBD01-DSCR120:SET_SCREEN1_POS", 0)
u = 0
i, j = 0, 0
for und in undlist:
+4
View File
@@ -8,6 +8,10 @@ taper_qua_stop = caget("SATUN:TAPER-QUA-STOP.RVAL")
undlist = ("SATUN06","SATUN07","SATUN08","SATUN09","SATUN10","SATUN11","SATUN12","SATUN13",
"SATUN15","SATUN16","SATUN17","SATUN18","SATUN19","SATUN20","SATUN21","SATUN22")
screen_pos = caget("SATBD01-DSCR120:GET_SCREEN1_POS")
if screen_pos != "Out of beam":
caput("SATBD01-DSCR120:SET_SCREEN1_POS", 0)
u = 0
i, j = 0, 0
for und in undlist:
+109 -42
View File
@@ -1,42 +1,36 @@
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import_py("CPython/hfitoff", "hfitoff")
import_py("CPython/extremum", "extremum")
dry_run = False
do_elog = False
do_elog = True
#und = "SARUN15"
#scan = "AR_K"
if get_exec_pars().args: # args is set by callin process (Qt panel)
und = args[0]
scan = args[1]
if dry_run:
und = "STEST01"
scan = "AR_PHI"
if scan == "AR_K" or scan == "AT_K":
x_channel = und + "-UIND030:K_SET"
message_channel = und + ":K-SCAN-MESSAGE"
x0 = caget(x_channel)
start = x0 - 0.005
end = x0 + 0.005
step = 10
lat = 0.1
nb = 90
if scan == "AR_PHI" or scan == "AT_PHI":
message_channel = und + ":PHI-SCAN-MESSAGE"
start = -180
end = 180
step = 12
lat = 0.1
nb = 90
if scan == "AR_K":
x_ok_channel = und + "-UPHS060:GAP-POS-OK" # UPHS is slower
gd_state_init = {}
if scan == "AR_K":
gd_state_init["SARFE10-PBPG050:ENERGY-SELECT"] = caget("SARFE10-PBPG050:ENERGY-SELECT")
gd_state_init["SARFE10-PBPG050:ENERGY"] = caget("SARFE10-PBPG050:ENERGY")
machine_ene = caget("SARUN:FELPHOTENE")
caput("SARFE10-PBPG050:ENERGY", machine_ene * 1000)
caput("SARFE10-PBPG050:ENERGY-SELECT", "USER")
x_channel = und + "-UIND030:K_SET" # use UPHS for pos ok -> UPHS slower (exception for SARUN15)
x_ok_channel = und + "-UPHS060:GAP-POS-OK" if und is not "SARUN15" else "SARUN15-UIND030:GAP-POS-OK"
y_channel = "SARFE10-PBIG050-EVR0:CALCI"
elif scan == "AT_K":
gd_state_init["SATFE10-PEPG046:ENERGY-SELECT"] = caget("SATFE10-PEPG046:ENERGY-SELECT")
gd_state_init["SATFE10-PEPG046:ENERGY"] = caget("SATFE10-PEPG046:ENERGY")
machine_ene = caget("SATUN:FELPHOTENE")
caput("SATFE10-PEPG046:ENERGY", machine_ene * 1000)
caput("SATFE10-PEPG046:ENERGY-SELECT", "USER")
x_channel = und + "-UIND030:K_SET"
x_ok_channel = und + "-UIND030:RADIAL-POS-OK"
y_channel = "SATFE10-PEPG046-EVR0:CALCI"
elif scan == "AR_PHI":
@@ -47,11 +41,30 @@ elif scan == "AT_PHI":
x_channel = und + "-UDLY060:PH-SHIFT-OP"
x_ok_channel = und + "-UDLY060:GAP-COMP-OP"
y_channel = "SATFE10-PEPG046-EVR0:CALCI"
if und == "STEST01" and scan == "AR_K":
y_channel = "STEST01:K-CALCI"
if und == "STEST01" and scan == "AR_PHI":
y_channel = "STEST01:PHI-CALCI"
if scan == "AR_K" or scan == "AT_K":
message_channel = und + ":K-SCAN-MESSAGE"
x0 = caget(x_channel)
start = x0 - 0.005
end = x0 + 0.005
step = 10
lat = 0.02
nb = 150
if scan == "AR_PHI" or scan == "AT_PHI":
message_channel = und + ":PHI-SCAN-MESSAGE"
start = -180
end = 180
step = 12
lat = 0.02
nb = 150
if scan == "AR_K" or scan == "AR_PHI":
gd_state_init["SARFE10-PBPG050:HAMP-X-HVS-STATUS"] = caget("SARFE10-PBPG050:HAMP-X-HVS-STATUS")
gd_state_init["SARFE10-PBPG050:HAMP-Y-HVS-STATUS"] = caget("SARFE10-PBPG050:HAMP-Y-HVS-STATUS")
caput("SARFE10-PBPG050:HAMP-X-HVS-STATUS", "OFF")
caput("SARFE10-PBPG050:HAMP-Y-HVS-STATUS", "OFF")
x_val = ChannelDouble(x_channel, x_channel)
x_val.initialize()
@@ -60,37 +73,56 @@ y_val.initialize()
x_val0 = x_val.read()
y_averager = create_averager(y_val, nb, lat)
#check mover position
# pause scan when beam is down
def is_beam_ok():
mps_ma = int(caget("SIN-EMED-DTSA001:LEVEL1_MA.RVAL"))
mps_ar = int(caget("SIN-EMED-DTSA002:LEVEL1_AR.RVAL"))
mps_at = int(caget("SIN-EMED-DTSA003:LEVEL1_AT.RVAL"))
beam_ok = (mps_ma + mps_ar + mps_at == 3)
return beam_ok
def wait_beam():
if not is_beam_ok():
print("Waiting for beam...")
while not is_beam_ok():
time.sleep(0.5)
print("Beam ok")
# check mover position and wait for beam
def before():
time.sleep(1.0)
timeout = 10.0
timeout = 15.0
start_time = time.time()
while (True):
mover_status = caget(x_ok_channel)
print(mover_status)
if mover_status=="OK" or mover_status=="True":
break
if time.time() - start_time > timeout:
raise Exception("mover timeout")
wait_beam()
#update the plot dynamically
# check for beam and update the plot dynamically
arr_x, arr_y = [],[]
def after(rec):
arr_x.append(rec.positions[0])
arr_y.append(rec.readables[0].mean)
caput("SF-SCAN-GLOBAL:X-ARRAY", to_array(arr_x, 'd'))
caput("SF-SCAN-GLOBAL:Y-ARRAY", to_array(arr_y, 'd'))
if not is_beam_ok():
print("Beam is down, invalidating record...")
rec.invalidate()
arr_x.append(rec.positions[0])
arr_y.append(rec.readables[0].mean)
caput("SF-SCAN-GLOBAL:X-ARRAY", to_array(arr_x, 'd'))
caput("SF-SCAN-GLOBAL:Y-ARRAY", to_array(arr_y, 'd'))
#scan and plot
# scan and plot
try:
caput("SF-SCAN-GLOBAL:FIT-X-ARRAY", to_array([0.0], 'd'))
caput("SF-SCAN-GLOBAL:FIT-Y-ARRAY", to_array([0.0], 'd'))
x_val.write(start)
time.sleep(5.0)
caput(message_channel, "scanning ")
caput(message_channel, "scanning...")
caput("SF-SCAN-GLOBAL:FIT-X-ARRAY", to_array([0.0], 'd'))
caput("SF-SCAN-GLOBAL:FIT-Y-ARRAY", to_array([0.0], 'd'))
r = lscan(x_val, y_averager, start, end, step, latency=lat, before_read = before, after_read = after)
x_array = r.getPositions(0)
y_array = energy = [val.mean for val in r.getReadable(0)]
y_array = [val.mean for val in r.getReadable(0)]
y_array_error_mean = mean([val.stdev for val in r.getReadable(0)])
caput("SF-SCAN-GLOBAL:X-ARRAY", to_array(x_array, 'd'))
caput("SF-SCAN-GLOBAL:Y-ARRAY", to_array(y_array, 'd'))
try:
@@ -98,6 +130,10 @@ try:
x_max, y_max, fit_x, fit_y, R2 = extremum(x_array, y_array)
if scan == "AR_PHI" or scan == "AT_PHI":
fit_amplitude, fit_x_deg, fit_offset, x_max, fit_x, fit_y = hfitoff(y_array, x_array)
while x_max < -180:
x_max = x_max + 360
while x_max > 180:
x_max = x_max - 360
except:
raise Exception("Fit failure")
plt = plot(None, name="param scan")[0]
@@ -111,11 +147,42 @@ try:
caput(und + ":SCAN-CREST", x_max)
caput("SF-SCAN-GLOBAL:FIT-X-ARRAY", fit_x)
caput("SF-SCAN-GLOBAL:FIT-Y-ARRAY", fit_y)
signal_amplitude = max(fit_y) - min(fit_y)
signal_to_noise = signal_amplitude / y_array_error_mean if y_array_error_mean != 0 else 0
now = str(caget("SF-TIME:FULL-DATE"))
now = now[:16] if now[0].isdigit() else ""
message = now
if scan == "AR_K" or scan == "AT_K":
caput(message_channel, "on-crest: " + ("%.4f" % x_max))
message = message + (" %.4f" % x_max)
if scan == "AR_PHI" or scan == "AT_PHI":
caput(message_channel, "on-crest: " + ("%.1f" % x_max))
message = message + (" %.1f deg" % x_max)
message = message + " (snr: " + ("%.2f)" % signal_to_noise)
caput(message_channel, message)
finally:
if scan == "AR_K":
caput("SARFE10-PBPG050:ENERGY", gd_state_init["SARFE10-PBPG050:ENERGY"])
caput("SARFE10-PBPG050:ENERGY-SELECT", gd_state_init["SARFE10-PBPG050:ENERGY-SELECT"])
if scan == "AT_K":
caput("SATFE10-PEPG046:ENERGY", gd_state_init["SATFE10-PEPG046:ENERGY"])
caput("SATFE10-PEPG046:ENERGY-SELECT", gd_state_init["SATFE10-PEPG046:ENERGY-SELECT"])
if scan == "AR_K" or scan == "AR_PHI":
caput("SARFE10-PBPG050:HAMP-X-HVS-STATUS", gd_state_init["SARFE10-PBPG050:HAMP-X-HVS-STATUS"])
caput("SARFE10-PBPG050:HAMP-Y-HVS-STATUS", gd_state_init["SARFE10-PBPG050:HAMP-Y-HVS-STATUS"])
x_val.write(x_val0)
x_val.close()
y_val.close()
# Elog entry
if do_elog:
title = "Undulator scan " + und
log_msg = "Data file: " + get_exec_pars().path + "\n"
if scan == "AR_K" or scan == "AT_K":
log_msg = log_msg + "On-crest K: %0.4f" % x_max + "\n"
if scan == "AR_PHI" or scan == "AT_PHI":
log_msg = log_msg + "On-crest phase: %0.1f" % x_max + " deg\n"
log_msg = log_msg + "Scan quality: %0.2f" % signal_to_noise
attachments = get_plot_snapshots(size=(600,400))
elog(title, log_msg, attachments)
set_return([x_max, signal_to_noise])
+40 -8
View File
@@ -1,9 +1,41 @@
und_table = ["SARUN03", "SARUN04", "SARUN05", "SARUN06", "SARUN07",
"SARUN08", "SARUN09", "SARUN10", "SARUN11", "SARUN12",
"SARUN13", "SARUN13", "SARUN13", "STEST01"]
und_table = ["SARUN03", "SARUN04", "SARUN05", "SARUN06", "SARUN07",
"SARUN08", "SARUN09", "SARUN10", "SARUN11", "SARUN12",
"SARUN13", "SARUN14", "SARUN15", "STEST01", "SATUN06",
"SATUN07", "SATUN08", "SATUN09", "SATUN10", "SATUN11",
"SATUN12", "SATUN13", "SATUN15", "SATUN16", "SATUN17",
"SATUN18", "SATUN19", "SATUN20", "SATUN21", "SATUN22"]
psh_table = ["SARUN03", "SARUN04", "SARUN05", "SARUN06", "SARUN07",
"SARUN08", "SARUN09", "SARUN10", "SARUN11", "SARUN12",
"SARUN13", "SARUN14", "STEST01", "SATUN06",
"SATUN07", "SATUN08", "SATUN09", "SATUN10", "SATUN11",
"SATUN12", "SATUN13", "SATUN15", "SATUN16", "SATUN17",
"SATUN18", "SATUN19", "SATUN20", "SATUN21"]
snr_threshold = caget("SF-SCAN-GLOBAL:SNR-THR")
for und in und_table:
req = caget(und + "-RSYS:PHASE-SCAN-REQUIRED")
if req == "True":
run("Undulators/und_scan.py")
caput(und + ":PHASE-SCAN-REQUIRED", 0)
und_scan_global_state.assertReady()
und_scan_global_state = State.Busy
und_scan_global_result = None
try:
for und in und_table:
req = caget(und + ":K-SCAN-REQUIRED")
if req == "True":
scan = "AT_K" if und.startswith("SAT") else "AR_K"
[max_val, snr] = run("Undulators/und_scan.py")
if snr > snr_threshold:
run("Undulators/und_scan_set.py")
caput(und + ":K-SCAN-REQUIRED", 0)
for und in psh_table:
req = caget(und + ":PHI-SCAN-REQUIRED")
if req == "True":
scan = "AT_PHI" if und.startswith("SAT") else "AR_PHI"
[max_val, snr] = run("Undulators/und_scan.py")
if snr > snr_threshold:
run("Undulators/und_scan_set.py")
caput(und + ":PHI-SCAN-REQUIRED", 0)
set_return('Success')
und_scan_global_result = "Ok"
except:
und_scan_global_result = str(sys.exc_info()[1])
finally:
und_scan_global_state = State.Ready
+3 -1
View File
@@ -1,7 +1,7 @@
if get_exec_pars().args: # args is set by callin process (Qt panel)
und = args[0]
scan = args[1]
if scan == "AR_K":
set_channel = und + "-UIND030:K_SET"
elif scan == "AR_PHI":
@@ -14,3 +14,5 @@ elif scan == "AT_PHI":
set_value = caget(und + ":SCAN-CREST")
caput(set_channel, set_value)
set_return([set_channel, set_value])