Files
sf-op/script/Undulators/K_AR_KtoTaper.py
2025-12-15 16:53:16 +01:00

38 lines
1.2 KiB
Python

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")