Startup
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
#Tool to align the laser on the cathode.
|
||||
# S. Bettoni, A. Gobbo, D. Voulot
|
||||
#10/05/2016
|
||||
|
||||
|
||||
#Procedure:
|
||||
#I switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
||||
#I change the current of the gun soleoid
|
||||
#I look at the centroid position (BPM or screen) downstream of the gun.
|
||||
|
||||
#TO BE PUT THE SIGNAL I-READ IN THE DEVICE DEFINITION GUN SOLENOID
|
||||
|
||||
#caput("shutter:state", Closed)
|
||||
|
||||
start_I = 0.001 #20
|
||||
end_I = 0.005 #150
|
||||
step_I = 0.0001 #1
|
||||
|
||||
#Scan using the screen
|
||||
r = lscan(gun_sol_current, [center_x, center_y], start_I, end_I, step_I, latency = 0.2)
|
||||
#Scan using the BPM
|
||||
#r = lscan(gun_sol_current, bpm_1_down_gun, start_I, end_I, step_I, latency = 0.2)
|
||||
|
||||
#I take the result of the scan and I do the plots
|
||||
x = r.getReadable(0)
|
||||
y = r.getReadable(1)
|
||||
plot(y, xdata=x, title = "CM")
|
||||
|
||||
|
||||
|
||||
|
||||
#I save the entry in the logbook
|
||||
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
# Tool to align the solenoid on the gun.
|
||||
# S. Bettoni, A. Gobbo, D. Voulot
|
||||
# 06/06/2016
|
||||
|
||||
|
||||
# Procedure:
|
||||
# switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
||||
# change the current of the gun soleoid
|
||||
# look at the centroid position (BPM or screen) downstream of the gun.
|
||||
|
||||
I_set = Channel("SINEG01-MSOL130:I-SET", alias = "I_set");
|
||||
I_get = Channel("SINEG01-MSOL130:I-READ", alias = "I_get")
|
||||
# cam_x, cam_y = ... # some camtool command / channel?
|
||||
bpm_x = Channel("SINEG01-DBPM340:X1")
|
||||
bpm_y = Channel("SINEG01-DBPM340:Y1")
|
||||
|
||||
cam_x = Channel("SINEG01-DSCR190:profile.X_stats.com", alias = "cam_x")
|
||||
cam_y = Channel("SINEG01-DSCR190:profile.Y_stats.com", alias = "cam_y")
|
||||
cam_raw_data = Channel("SINEG01-DSCR190:data")
|
||||
|
||||
|
||||
class CameraImage(ReadableMatrix):
|
||||
def read(self):
|
||||
raw = cam_raw_data.read()
|
||||
ret = []
|
||||
for i in range (self.getHeight()):
|
||||
ret.append(raw[i*self.getWidth() : (i+1)*self.getWidth()])
|
||||
return ret
|
||||
|
||||
def getWidth(self):
|
||||
return 640
|
||||
|
||||
def getHeight(self):
|
||||
return 480
|
||||
|
||||
cam_img = CameraImage()
|
||||
|
||||
|
||||
def ccr(mag):
|
||||
n = 1
|
||||
while n > 0:
|
||||
sleep(0.5)
|
||||
n = caget(mag + ":I-COMP")
|
||||
def laser_on():
|
||||
caput("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", 0)
|
||||
|
||||
def laser_off():
|
||||
caput("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", 1)
|
||||
|
||||
|
||||
def run_pipeline():
|
||||
caput("camtool...:start")
|
||||
|
||||
while !caget("camtool...:done"):
|
||||
sleep(0.1)
|
||||
|
||||
caget("camtool....:data")
|
||||
#caget("camtool....:X_stats.com")
|
||||
#caget("camtool....:X_stats.com")
|
||||
|
||||
|
||||
I1 = 20.0
|
||||
I2 = 150.0
|
||||
dI = 1.0
|
||||
settling_time = 0.0
|
||||
|
||||
# Switch off magnets
|
||||
mag = [ "SINEG01-MCRX120","SINEG01-MCRY120",
|
||||
"SINEG01-MQUA140",
|
||||
"SINEG01-MQUA150",
|
||||
"SINEG01-MCRX160","SINEG01-MCRY160",
|
||||
"SINEG01-MCRX180","SINEG01-MCRY180",
|
||||
"SINEG01-MCRX200","SINEG01-MCRY200",
|
||||
"SINEG01-MCRX220","SINEG01-MCRY220",
|
||||
"SINEG01-MQUA310",
|
||||
"SINEG01-MQUA320" ]
|
||||
for m in mag:
|
||||
caput(m + ":I-SET", 0.0)
|
||||
#for m in mag:
|
||||
# ccr(m)
|
||||
|
||||
laser_on()
|
||||
# Scan using the screen
|
||||
#r = lscan(I_set, [I_read, cam_x, cam_y], I1, I2, dI, 1.0, passes = 2, zigzag = True)
|
||||
# Scan using the BPM
|
||||
try:
|
||||
#r = lscan(I_set, [I_get, cam_x, cam_y], I1, I2, dI, 1.0, before_read = ccr)
|
||||
r = lscan(I_set, [I_get, cam_x, cam_y, cam_img], I1, I2, dI, settling_time)
|
||||
finally:
|
||||
laser_off()
|
||||
|
||||
# take the result of the scan and do the plots
|
||||
p = plot(r.getReadable(2), xdata=r.getReadable(1), title = "Centroid excursion")[0]
|
||||
|
||||
# save the entry in the logbook
|
||||
msg = str(r)
|
||||
msg = msg + "\nFile: " + get_context().path
|
||||
#msg = msg + "\n\n" + r.print()
|
||||
#elog("Gun solenoid current scan", msg , get_plot_snapshots())
|
||||
@@ -1,37 +0,0 @@
|
||||
#Tool to align the laser on the cathode.
|
||||
# S. Bettoni, A. Gobbo, D. Voulot
|
||||
#10/05/2016
|
||||
|
||||
from operator import sub
|
||||
|
||||
|
||||
#Procedure:
|
||||
#I switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
||||
#I change the current of the gun soleoid
|
||||
#I look at the centroid position (BPM or screen) downstream of the gun.
|
||||
|
||||
#TO BE PUT THE SIGNAL I-READ IN THE DEVICE DEFINITION GUN SOLENOID
|
||||
|
||||
#caput("shutter:state", Closed)
|
||||
|
||||
start_I = 0.001 #20
|
||||
end_I = 0.005 #150
|
||||
step_I = 0.001 #1
|
||||
|
||||
#Scan using the screen
|
||||
r = lscan(gun_sol_current, [center_x, center_y], start_I, end_I, step_I, latency = 0.2)
|
||||
#Scan using the BPM
|
||||
#r = lscan(gun_sol_current, bpm_1_down_gun, start_I, end_I, step_I, latency = 0.2)
|
||||
|
||||
#I take the result of the scan and I do the plots
|
||||
x = r.getReadable(0)
|
||||
y = r.getReadable(1)
|
||||
p = plot(y, xdata=x, title = "CM")
|
||||
yerr = 0.1
|
||||
xerr = 0.5
|
||||
|
||||
|
||||
#I save the entry in the logbook
|
||||
#elog(title, message, attachments = [], author = None, category = "Info", domain = "", logbook = "SwissFEL commissioning data", encoding=1):
|
||||
#elog("Test Simona", "message", author = "Simona", get_plot_snapshots(), logbook = "SwissFEL commissioning data", encoding=1)
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
# Tool to align the laser on the cathode.
|
||||
# S. Bettoni, A. Gobbo, D. Voulot
|
||||
# 06/06/2016
|
||||
|
||||
# Procedure:
|
||||
# switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
||||
# change the phase of the gun RF
|
||||
# look at the centroid position (BPM or screen) downstream of the gun.
|
||||
|
||||
phi_set = Channel("SINEG01-RSYS:SET-BEAM-PHASE")
|
||||
phi_get = Channel("SINEG01-RSYS:GET-BEAM-PHASE")
|
||||
# cam_x, cam_y = ... # some camtool command / channel?
|
||||
bpm_x = Channel("SINEG01-DBPM340:X1")
|
||||
bpm_y = Channel("SINEG01-DBPM340:Y1")
|
||||
|
||||
def ccr(mag):
|
||||
n = 1
|
||||
while n > 0:
|
||||
sleep(0.5)
|
||||
n = caget(mag + ":I-COMP")
|
||||
def laser_on():
|
||||
caput("SIN-CVME-TIMAST-TMA:LaserDelayControl", 0)
|
||||
def laser_off():
|
||||
caput("SIN-CVME-TIMAST-TMA:LaserDelayControl", 1)
|
||||
|
||||
phi1 = 20.0
|
||||
phi2 = 150.0
|
||||
dphi = 1.0
|
||||
|
||||
# Switch off magnets
|
||||
mag = [ "SINEG01-MCRX120","SINEG01-MCRY120",
|
||||
"SINEG01-MQUA140",
|
||||
"SINEG01-MQUA150",
|
||||
"SINEG01-MCRX160","SINEG01-MCRY160",
|
||||
"SINEG01-MCRX180","SINEG01-MCRY180",
|
||||
"SINEG01-MCRX200","SINEG01-MCRY200",
|
||||
"SINEG01-MCRX220","SINEG01-MCRY220",
|
||||
"SINEG01-MQUA310",
|
||||
"SINEG01-MQUA320" ]
|
||||
for m in mag:
|
||||
caput(m + ":I-SET", 0.0)
|
||||
for m in mag:
|
||||
ccr(m)
|
||||
|
||||
# Scan using the screen
|
||||
#r = lscan(phi_set, [phi_get, cam_x, cam_y], phi1, phi2, dphi, 0.5)
|
||||
# Scan using the BPM
|
||||
r = lscan(phi_set, [phi_get, bpm_x, bpm_y], phi1, phi2, dphi, 0.5, before_read = laser_on(), after_read = laser_off())
|
||||
|
||||
# take the result of the scan and do the plots
|
||||
plot(r.getReadable(2), xdata=r.getReadable(1), title = "Centroid excursion")
|
||||
|
||||
# save the entry in the logbook
|
||||
msg = str(r)
|
||||
msg = msg + "\nFile: " + get_context().path
|
||||
msg = msg + "\n\n" + r.print()
|
||||
elog("Gun solenoid current scan", msg , get_plot_snapshots())
|
||||
@@ -1,25 +0,0 @@
|
||||
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) = hfit(r.getReadable(2), xdata = r.getReadable(0))
|
||||
|
||||
caput(rsys + ":SET-ON-CREST-VSUM-PHASE", maximum)
|
||||
|
||||
set_return(r.print())
|
||||
348
script/local.py
348
script/local.py
@@ -1,149 +1,199 @@
|
||||
###################################################################################################
|
||||
# Deployment specific global definitions - executed after startup.py
|
||||
###################################################################################################
|
||||
|
||||
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list, Gaussian
|
||||
from mathutils import fit_polynomial,fit_gaussian, fit_harmonic, calculate_peaks
|
||||
from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator
|
||||
|
||||
import java.awt.Color as Color
|
||||
|
||||
|
||||
def fit(ydata, xdata = None):
|
||||
"""
|
||||
Gaussian fit
|
||||
"""
|
||||
if xdata is None:
|
||||
xdata = frange(0, len(ydata), 1)
|
||||
max_y= max(ydata)
|
||||
index_max = ydata.index(max_y)
|
||||
max_x= xdata[index_max]
|
||||
print "Max index:" + str(index_max),
|
||||
print " x:" + str(max_x),
|
||||
print " y:" + str(max_y)
|
||||
gaussians = fit_gaussians(ydata, xdata, [index_max,])
|
||||
(norm, mean, sigma) = gaussians[0]
|
||||
p = plot([ydata],["data"],[xdata], title="Fit" )[0]
|
||||
fitted_gaussian_function = Gaussian(norm, mean, sigma)
|
||||
scale_x = [float(min(xdata)), float(max(xdata)) ]
|
||||
points = max((len(xdata)+1), 100)
|
||||
resolution = (scale_x[1]-scale_x[0]) / points
|
||||
fit_y = []
|
||||
fit_x = frange(scale_x[0],scale_x[1],resolution, True)
|
||||
for x in fit_x:
|
||||
fit_y.append(fitted_gaussian_function.value(x))
|
||||
p.addSeries(LinePlotSeries("fit"))
|
||||
p.getSeries(1).setData(fit_x, fit_y)
|
||||
|
||||
if abs(mean - xdata[index_max]) < ((scale_x[0] + scale_x[1])/2):
|
||||
print "Mean -> " + str(mean)
|
||||
p.addMarker(mean, None, "Mean="+str(round(norm,2)), Color.MAGENTA.darker())
|
||||
return (norm, mean, sigma)
|
||||
else:
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY)
|
||||
print "Invalid gaussian fit: " + str(mean)
|
||||
return (None, None, None)
|
||||
|
||||
|
||||
def hfit(ydata, xdata = None):
|
||||
"""
|
||||
Harmonic fit
|
||||
"""
|
||||
if xdata is None:
|
||||
xdata = frange(0, len(ydata), 1)
|
||||
|
||||
max_y= max(ydata)
|
||||
index_max = ydata.index(max_y)
|
||||
max_x= xdata[index_max]
|
||||
|
||||
start,end = min(xdata), max(xdata)
|
||||
(amplitude, angular_frequency, phase) = fit_harmonic(ydata, xdata)
|
||||
fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase)
|
||||
|
||||
print "amplitude = ", amplitude
|
||||
print "angular frequency = ", angular_frequency
|
||||
print "phase = ", phase
|
||||
|
||||
f = angular_frequency/ (2* math.pi)
|
||||
print "frequency = ", f
|
||||
|
||||
resolution = 0.01
|
||||
fit_y = []
|
||||
for x in frange(start,end,resolution, True):
|
||||
fit_y.append(fitted_harmonic_function.value(x))
|
||||
fit_x = frange(start, end+resolution, resolution)
|
||||
|
||||
p = plot(ydata,"data", xdata, title="HFit")[0]
|
||||
p.addSeries(LinePlotSeries("fit"))
|
||||
p.getSeries(1).setData(fit_x, fit_y)
|
||||
|
||||
#m = (phase + math.pi)/ angular_frequency
|
||||
m = -phase / angular_frequency
|
||||
if (m<start):
|
||||
m+=(1.0/f)
|
||||
|
||||
if start <=m <=end:
|
||||
print "fit = ", m
|
||||
p.addMarker(m, None, "Fit="+str(round(m ,2)), Color.MAGENTA.darker())
|
||||
return (amplitude, angular_frequency, phase, True, m)
|
||||
else:
|
||||
print "max = ",max_x
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x ,2)), Color.MAGENTA.darker())
|
||||
return (amplitude, angular_frequency, phase, False, max_x)
|
||||
|
||||
|
||||
def elog(title, message, attachments = [], author = None, category = "Info", domain = "", logbook = "SwissFEL commissioning data", encoding=1):
|
||||
"""
|
||||
Add entry to ELOG.
|
||||
"""
|
||||
if author is None:
|
||||
author = "pshell" #controller.getUser().name
|
||||
typ = "pshell"
|
||||
entry = ""
|
||||
|
||||
cmd = 'G_CS_ELOG_add -l "' + logbook+ '" '
|
||||
cmd = cmd + '-a "Author=' + author + '" '
|
||||
cmd = cmd + '-a "Type=' + typ + '" '
|
||||
cmd = cmd + '-a "Entry=' + entry + '" '
|
||||
cmd = cmd + '-a "Title=' + title + '" '
|
||||
cmd = cmd + '-a "Category=' + category + '" '
|
||||
cmd = cmd + '-a "Domain=' + domain + '" '
|
||||
for attachment in attachments:
|
||||
cmd = cmd + '-f "' + attachment + '" '
|
||||
cmd = cmd + '-n ' + str(encoding)
|
||||
cmd = cmd + ' "' + message + '"'
|
||||
#print cmd
|
||||
#os.system (cmd)
|
||||
#print os.popen(cmd).read()
|
||||
import subprocess
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
|
||||
(out, err) = proc.communicate()
|
||||
if (err is not None) and err!="":
|
||||
raise Exception(err)
|
||||
print out
|
||||
|
||||
def get_plot_snapshots(title = None, file_type = "jpg", temp_path = controller.setup.getContextPath()):
|
||||
"""
|
||||
Returns list with file names of plots snapshots from a plotting context.
|
||||
"""
|
||||
sleep(0.02) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
ret = []
|
||||
for p in get_plots(title):
|
||||
file_name = os.path.abspath(temp_path + "/" + p.getTitle() + "." + file_type)
|
||||
p.saveSnapshot(file_name , file_type)
|
||||
ret.append(file_name)
|
||||
return ret
|
||||
|
||||
|
||||
class Sinusoid(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
self.x = self.x + 5.0 if hasattr(self, 'x') else 0.0
|
||||
return math.sin(self.x * math.pi / 180.0)
|
||||
|
||||
add_device(Sinusoid("phase"), True)
|
||||
add_device(Sinusoid("bpm_q"), True)
|
||||
|
||||
add_device(Sinusoid("center_x"), True)
|
||||
add_device(Sinusoid("center_y"), True)
|
||||
center_x.setPolling(100)
|
||||
center_y.setPolling(100)
|
||||
###################################################################################################
|
||||
# Deployment specific global definitions - executed after startup.py
|
||||
###################################################################################################
|
||||
|
||||
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list, Gaussian
|
||||
from mathutils import fit_polynomial,fit_gaussian, fit_harmonic, calculate_peaks
|
||||
from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator
|
||||
import math
|
||||
import random
|
||||
|
||||
import java.awt.Color as Color
|
||||
|
||||
|
||||
def fit(ydata, xdata = None):
|
||||
"""
|
||||
"""
|
||||
if xdata is None:
|
||||
xdata = frange(0, len(ydata), 1)
|
||||
max_y= max(ydata)
|
||||
index_max = ydata.index(max_y)
|
||||
max_x= xdata[index_max]
|
||||
print "Max index:" + str(index_max),
|
||||
print " x:" + str(max_x),
|
||||
print " y:" + str(max_y)
|
||||
gaussians = fit_gaussians(ydata, xdata, [index_max,])
|
||||
p = plot([ydata],["data"],[xdata], title="Fit" )[0]
|
||||
if gaussians[0] is None:
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY)
|
||||
print "Fitting error"
|
||||
return (None, None, None)
|
||||
|
||||
(norm, mean, sigma) = gaussians[0]
|
||||
fitted_gaussian_function = Gaussian(norm, mean, sigma)
|
||||
scale_x = [float(min(xdata)), float(max(xdata)) ]
|
||||
points = max((len(xdata)+1), 100)
|
||||
resolution = (scale_x[1]-scale_x[0]) / points
|
||||
fit_y = []
|
||||
fit_x = frange(scale_x[0],scale_x[1],resolution, True)
|
||||
for x in fit_x:
|
||||
fit_y.append(fitted_gaussian_function.value(x))
|
||||
p.addSeries(LinePlotSeries("fit"))
|
||||
p.getSeries(1).setData(fit_x, fit_y)
|
||||
|
||||
if abs(mean - xdata[index_max]) < ((scale_x[0] + scale_x[1])/2):
|
||||
print "Mean -> " + str(mean)
|
||||
p.addMarker(mean, None, "Mean="+str(round(norm,2)), Color.MAGENTA.darker())
|
||||
return (norm, mean, sigma)
|
||||
else:
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY)
|
||||
print "Invalid gaussian fit: " + str(mean)
|
||||
return (None, None, None)
|
||||
|
||||
|
||||
|
||||
def hfit(ydata, xdata = None):
|
||||
if xdata is None:
|
||||
xdata = frange(0, len(ydata), 1)
|
||||
|
||||
max_y= max(ydata)
|
||||
index_max = ydata.index(max_y)
|
||||
max_x= xdata[index_max]
|
||||
|
||||
start,end = min(xdata), max(xdata)
|
||||
(amplitude, angular_frequency, phase) = fit_harmonic(ydata, xdata)
|
||||
fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase)
|
||||
|
||||
print "amplitude = ", amplitude
|
||||
print "angular frequency = ", angular_frequency
|
||||
print "phase = ", phase
|
||||
|
||||
f = angular_frequency/ (2* math.pi)
|
||||
resolution = 0.01
|
||||
fit_y = []
|
||||
for x in frange(start,end,resolution, True):
|
||||
fit_y.append(fitted_harmonic_function.value(x))
|
||||
fit_x = frange(start, end+resolution, resolution)
|
||||
|
||||
p = plot(ydata,"data", xdata, title="HFit")[0]
|
||||
p.addSeries(LinePlotSeries("fit"))
|
||||
p.getSeries(1).setData(fit_x, fit_y)
|
||||
|
||||
#m = (phase + math.pi)/ angular_frequency
|
||||
fit_max = -phase / angular_frequency
|
||||
if (fit_max<start):
|
||||
fit_max+=(1.0/f)
|
||||
|
||||
print "fit max= ", fit_max
|
||||
p.addMarker(fit_max, None, "Fit max="+str(round(fit_max ,2)), Color.MAGENTA.darker())
|
||||
return (amplitude, angular_frequency, phase, fit_max)
|
||||
|
||||
|
||||
|
||||
def elog(title, message, attachments = [], author = None, category = "Info", domain = "", logbook = "SwissFEL commissioning data", encoding=1):
|
||||
"""
|
||||
Add entry to ELOG.
|
||||
"""
|
||||
if author is None:
|
||||
author = "pshell" #controller.getUser().name
|
||||
typ = "pshell"
|
||||
entry = ""
|
||||
|
||||
cmd = 'G_CS_ELOG_add -l "' + logbook+ '" '
|
||||
cmd = cmd + '-a "Author=' + author + '" '
|
||||
cmd = cmd + '-a "Type=' + typ + '" '
|
||||
cmd = cmd + '-a "Entry=' + entry + '" '
|
||||
cmd = cmd + '-a "Title=' + title + '" '
|
||||
cmd = cmd + '-a "Category=' + category + '" '
|
||||
cmd = cmd + '-a "Domain=' + domain + '" '
|
||||
for attachment in attachments:
|
||||
cmd = cmd + '-f "' + attachment + '" '
|
||||
cmd = cmd + '-n ' + str(encoding)
|
||||
cmd = cmd + ' "' + message + '"'
|
||||
#print cmd
|
||||
#os.system (cmd)
|
||||
#print os.popen(cmd).read()
|
||||
import subprocess
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
|
||||
(out, err) = proc.communicate()
|
||||
if (err is not None) and err!="":
|
||||
raise Exception(err)
|
||||
print out
|
||||
|
||||
def get_plot_snapshots(title = None, file_type = "jpg", temp_path = controller.setup.getContextPath()):
|
||||
"""
|
||||
Returns list with file names of plots snapshots from a plotting context.
|
||||
"""
|
||||
sleep(0.02) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
ret = []
|
||||
for p in get_plots(title):
|
||||
file_name = os.path.abspath(temp_path + "/" + p.getTitle() + "." + file_type)
|
||||
p.saveSnapshot(file_name , file_type)
|
||||
ret.append(file_name)
|
||||
return ret
|
||||
|
||||
|
||||
class Sinusoid(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
if not hasattr(self, 'step') : self.step = 10
|
||||
self.x = self.x + self.step if hasattr(self, 'x') else 0.0
|
||||
noise = (random.random() - 0.5) * 0.2
|
||||
return math.sin(self.x * math.pi / 180.0) + noise
|
||||
|
||||
add_device(Sinusoid("sim"), True)
|
||||
|
||||
|
||||
|
||||
#------------- CAS --------------------
|
||||
import ch.psi.pshell.epics.CAS as CAS
|
||||
|
||||
#CAS.setServerPort(5070)
|
||||
|
||||
class ArrayDevice(ReadonlyRegisterBase, ReadonlyRegisterArray):
|
||||
def doRead(self):
|
||||
return self.take()
|
||||
|
||||
def getSize(self):
|
||||
global scan_result
|
||||
return len(self.take())
|
||||
|
||||
def append(self, value):
|
||||
c = self.take()
|
||||
c.append(value)
|
||||
self.set(c)
|
||||
|
||||
def set(self, value):
|
||||
self.onReadout(to_array(value, 'd'))
|
||||
|
||||
|
||||
class ScalarDevice(RegisterBase):
|
||||
def doRead(self):
|
||||
return self.val if hasattr(self, 'val') else 0.0
|
||||
|
||||
def doWrite(self, val):
|
||||
self.val = val
|
||||
|
||||
|
||||
add_device(ArrayDevice("scan_pos"), True)
|
||||
add_device(ArrayDevice("scan_val"), True)
|
||||
add_device(ScalarDevice("scan_start"), True)
|
||||
add_device(ScalarDevice("scan_stop"), True)
|
||||
add_device(ScalarDevice("scan_step"), True)
|
||||
scan_start.write(-10.0)
|
||||
scan_stop.write(10.0)
|
||||
scan_step.write(1.0)
|
||||
|
||||
if not controller.localMode:
|
||||
CAS.setServerPort(12345)
|
||||
cas1=CAS("PSHELL:scanpos",scan_pos, "double")
|
||||
cas2=CAS("PSHELL:scanval",scan_val, "double")
|
||||
cas3=CAS("PSHELL:scanstart",scan_start, "double")
|
||||
cas4=CAS("PSHELL:scanstop",scan_stop, "double")
|
||||
cas5=CAS("PSHELL:scanstep",scan_step, "double")
|
||||
|
||||
#scan_pos.set([] )
|
||||
#scan_val.set([])
|
||||
#TODO: this is workaround to CAS not supporting dynamic arrays
|
||||
MAX_ARRAY_DEV_SIZE = 5000
|
||||
scan_pos.set([0.0,] * MAX_ARRAY_DEV_SIZE )
|
||||
scan_val.set([0.0,] * MAX_ARRAY_DEV_SIZE )
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
# Tool to align the solenoid on the gun.
|
||||
# S. Bettoni, A. Gobbo, D. Voulot
|
||||
# 30/05/2016
|
||||
|
||||
# Procedure:
|
||||
# switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
||||
# change the current of the gun soleoid
|
||||
# look at the centroid position (BPM or screen) downstream of the gun.
|
||||
|
||||
I_set = Channel("SINEG01-MSOL130:I-SET")
|
||||
I_get = Channel("SINEG01-MSOL130:I-READ")
|
||||
# cam_x, cam_y = ... # some camtool command / channel?
|
||||
bpm_x = ai1 # Channel("SINEG01-DBPM340:X1")
|
||||
bpm_y = ai2 # Channel("SINEG01-DBPM340:Y1")
|
||||
|
||||
def ccr(mag):
|
||||
n = 1
|
||||
while n > 0:
|
||||
sleep(0.5)
|
||||
n = caget(mag + ":I-COMP")
|
||||
def laser_on():
|
||||
print(laser_on) #caput("SIN-CVME-TIMAST-TMA:LaserDelayControl", 0)
|
||||
def laser_off():
|
||||
print(laser_off) #caput("SIN-CVME-TIMAST-TMA:LaserDelayControl", 1)
|
||||
|
||||
I1 = 2.0
|
||||
I2 = 5.0
|
||||
dI = 0.5
|
||||
|
||||
# Switch off magnets
|
||||
mag = ["SINEG01-MCRX120","SINEG01-MCRY120"]
|
||||
for m in mag:
|
||||
caput(m + ":I-SET", 0.0)
|
||||
for m in mag:
|
||||
ccr(m)
|
||||
|
||||
# Scan using the screen
|
||||
#r = lscan(I_set, [I_get, cam_x, cam_y], I1, I2, dI, passes = 2, zigzag = True)
|
||||
# Scan using the BPM
|
||||
r = lscan(I_set, [I_get, bpm_x, bpm_y], I1, I2, dI, 1.0, before_read = laser_on(), after_read = laser_off())
|
||||
|
||||
# take the result of the scan and do the plots
|
||||
plot(r.getReadable(2), xdata=r.getReadable(1), title = "Centroid excursion")
|
||||
|
||||
# save the entry in the logbook
|
||||
msg = str(r)
|
||||
msg = msg + "\nFile: " + get_context().path
|
||||
msg = msg + "\n\n" + r.print()
|
||||
elog("Gun solenoid current scan", msg , get_plot_snapshots())
|
||||
@@ -1 +0,0 @@
|
||||
ascan((SARUN02_MCRX080,SARUN02_MCRY080), (SARUN03_DBPM070), (-2.0,-2.0), (2.0,2.0), (5,5), 0.01)
|
||||
@@ -1,21 +0,0 @@
|
||||
###################################################################################################
|
||||
# Demonstrate use of scan callbacks to trigger a detector at falling edge.
|
||||
###################################################################################################
|
||||
|
||||
|
||||
def BeforeReadout():
|
||||
ao1.write(1)
|
||||
ao1.write(0)
|
||||
|
||||
#Example with an epics direct channel access
|
||||
#caput("CHANNEL_NAME", 1)
|
||||
#caput("CHANNEL_NAME", 0)
|
||||
|
||||
index=0
|
||||
|
||||
def AfterReadout():
|
||||
global index
|
||||
print "Aquired frame: " + str(index)
|
||||
index=index+1
|
||||
|
||||
a= lscan((m1,m2), (ai1, ai2), (0,0), (4,8), steps=20, latency = 0.01, before_read=BeforeReadout, after_read=AfterReadout)
|
||||
@@ -1,36 +0,0 @@
|
||||
"""
|
||||
Parameters:
|
||||
prefix
|
||||
"""
|
||||
|
||||
prefix = "MINSB03-RSYS"
|
||||
start = -179.0
|
||||
stop = 180.0
|
||||
step = 10.0
|
||||
|
||||
|
||||
|
||||
rf_phase_setpoint = Channel(prefix + ":SET-VSUM-PHASE")
|
||||
rf_phase_readback = Channel(prefix + ":GET-VSUM-PHASE")
|
||||
rf_ampl_readback = Channel(prefix + ":GET-VSUM-AMPLT")
|
||||
|
||||
r = lscan(rf_phase_setpoint, [rf_phase_readback, rf_ampl_readback, sim], start, stop, step , latency=0.2)
|
||||
|
||||
plot(r.getReadable(2), xdata = r.getReadable(0), title = "data")
|
||||
|
||||
#fit(r.getReadable(1))
|
||||
|
||||
|
||||
set_return(r.print())
|
||||
|
||||
|
||||
"""
|
||||
r = lscan(rf_phase, [rf_phase_rb, rf_ampl_rb, sim], -179.0, 180, 10.0, latency=0.2)
|
||||
|
||||
plot(r.getReadable(2), xdata = r.getReadable(0), title = "data")
|
||||
|
||||
fit(r.getReadable(1))
|
||||
|
||||
|
||||
set_return(r.print())
|
||||
"""
|
||||
@@ -1,15 +0,0 @@
|
||||
prefix = "MINSB03-RSYS" # SINEG01-RSYS
|
||||
start = -175.0
|
||||
stop = 180.0
|
||||
step = 5.0
|
||||
|
||||
rf_phase_setpoint = ao1 # Channel(prefix + ":SET-VSUM-PHASE")
|
||||
rf_phase_readback = phase # Channel(prefix + ":GET-VSUM-PHASE")
|
||||
rf_ampl_readback = ai2 # Channel(prefix + ":GET-VSUM-AMPLT")
|
||||
bpm_q = bpm # SINEG01-DBPM340:Q1, SINEG01-DWCM170:Q_B1
|
||||
|
||||
r = lscan(rf_phase_setpoint, [rf_phase_readback, rf_ampl_readback, bpm_q], start, stop, step , latency=0.5)
|
||||
|
||||
plot(r.getReadable(2), xdata = r.getReadable(0), title = "data")
|
||||
|
||||
set_return(r.print())
|
||||
@@ -1,29 +0,0 @@
|
||||
###################################################################################################
|
||||
# Demonstrate the use of Line Scan: one or multiple positioners move together linearly.
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#This optional preference limits the displayed plots
|
||||
#set_preference(Preference.ENABLED_PLOTS, [ai1, ai2,])
|
||||
|
||||
#This optional preference displays wf1 as a 1d plot at each scan point, instead of a matrix plot
|
||||
#set_preference(Preference.PLOT_TYPES, {wf1:1})
|
||||
|
||||
#Execute the scan: 200 steps, a1 from 0 to 40
|
||||
a= lscan(ao1, (ai1,ai2,wf1), 0, 40, 200, 0.01)
|
||||
|
||||
#Also samples an image:
|
||||
#a= lscan(ao1, (ai1,ai2,wf1), 0, 40, 200, 0.01)
|
||||
|
||||
#Alternative: Steps of size 0.1, a1 from 0 to 40
|
||||
#a= lscan(ao1, (ai1,ai2,wf1), 0, 40, 0.5, 0.01)
|
||||
|
||||
#2 positioners moving together in 200 steps, a1 from 0 to 40 and a2 from 0 to 100
|
||||
#a= lscan((ao1,ao2), (ai1,ai2,wf1), (0, 0), (40, 100), 200, 0.01)
|
||||
|
||||
#Setting attributes to the scan group
|
||||
path = get_current_group()
|
||||
set_attribute(path, "AttrString", "Value")
|
||||
set_attribute(path, "AttrInteger", 1)
|
||||
set_attribute(path, "AttrDouble", 2.0)
|
||||
set_attribute(path, "AttrBoolean", True)
|
||||
@@ -1,7 +0,0 @@
|
||||
#Execute the scan: 3 regions with different number of steps
|
||||
a= rscan(ao1, (ai1,ai2), [(0,5,5), (10,15,20), (20,25,5)] , 0.01)
|
||||
|
||||
msg = str(a)
|
||||
msg = msg + "\nFile: " + get_context().path
|
||||
msg = msg + "\n\n" + a.print()
|
||||
elog("Region scan", msg , get_plot_snapshots())
|
||||
@@ -1 +0,0 @@
|
||||
lscan(SINSB01_phase, energy_BC1, 0.0, 360.0, 10.0, 2.0)
|
||||
@@ -1,2 +0,0 @@
|
||||
caput("SINEG01-MCRX120:I-SET", 5.0)
|
||||
print(caget("SINEG01-MCRX120:I-READ"))
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# example data
|
||||
x = np.arange(0.5, 5.5, 0.5)
|
||||
y = np.exp(-x)
|
||||
xerr = 0.1
|
||||
yerr = 0.2
|
||||
ls = 'dotted'
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(1, 1, 1)
|
||||
|
||||
# standard error bars
|
||||
plt.errorbar(x, y, xerr=xerr, yerr=yerr, ls=ls, color='blue')
|
||||
|
||||
# including upper limits
|
||||
uplims = np.zeros(x.shape)
|
||||
uplims[[1, 5, 9]] = True
|
||||
plt.errorbar(x, y + 0.5, xerr=xerr, yerr=yerr, uplims=uplims, ls=ls,
|
||||
color='green')
|
||||
|
||||
# including lower limits
|
||||
lolims = np.zeros(x.shape)
|
||||
lolims[[2, 4, 8]] = True
|
||||
plt.errorbar(x, y + 1.0, xerr=xerr, yerr=yerr, lolims=lolims, ls=ls,
|
||||
color='red')
|
||||
|
||||
# including upper and lower limits
|
||||
plt.errorbar(x, y + 1.5, marker='o', ms=8, xerr=xerr, yerr=yerr,
|
||||
lolims=lolims, uplims=uplims, ls=ls, color='magenta')
|
||||
|
||||
# including xlower and xupper limits
|
||||
xerr = 0.2
|
||||
yerr = np.zeros(x.shape) + 0.2
|
||||
yerr[[3, 6]] = 0.3
|
||||
xlolims = lolims
|
||||
xuplims = uplims
|
||||
lolims = np.zeros(x.shape)
|
||||
uplims = np.zeros(x.shape)
|
||||
lolims[[6]] = True
|
||||
uplims[[3]] = True
|
||||
plt.errorbar(x, y + 2.1, marker='o', ms=8, xerr=xerr, yerr=yerr,
|
||||
xlolims=xlolims, xuplims=xuplims, uplims=uplims, lolims=lolims,
|
||||
ls='none', mec='blue', capsize=0, color='cyan')
|
||||
|
||||
ax.set_xlim((0, 5.5))
|
||||
ax.set_title('Errorbar upper and lower limits')
|
||||
plt.show()
|
||||
@@ -1,21 +0,0 @@
|
||||
###################################################################################################
|
||||
# Demonstrate use of Vector Scan: one or multiple positioners set according to a position vector.
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#1D vector scan, plot to 1D Vector tab
|
||||
vector = [ 1, 3, 5, 10, 25, 40, 45, 47, 49]
|
||||
a= vscan(ao1,(ai1,ai2),vector,False, 0.5, context = "1D Vector")
|
||||
|
||||
|
||||
|
||||
|
||||
#2D vector scan, plot to 2D Vector tab
|
||||
vector = [ [1,1] , [1,2] , [1,3] , [1,4] ,
|
||||
[1.5,2.5] ,
|
||||
[2,1] , [2,2] , [2,3] , [2,4] ,
|
||||
[2.5,2.5] ,
|
||||
[3,1] , [3,2] , [3,3] , [3,4] ]
|
||||
|
||||
a= vscan((m1,m2),(ai1,ai2),vector,False, 0.1, context = "2D Vector")
|
||||
|
||||
Reference in New Issue
Block a user