This commit is contained in:
2016-06-22 15:14:07 +02:00
parent a3b342f56d
commit dbe1078ff3
44 changed files with 227 additions and 880 deletions

View File

@@ -1,27 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAvEQPJ+OW/ctH32MZKHln9+vXvMpST3UOJbk9nPTGM7bYYMjs
bEjg9hHNTHtr+VA4AtQzmzOXeAPqG5zy1lAcoPMrz3Kj9fou86cdMxbN6ei3rFVb
9dDSMLGrGAVuR+iTAch0FNVru5BvZm4s+fn3pyYuy1GcKLv7/pyYdoqiYdUm7ZDL
VhFJjtSmIswCArcv5rpvlTHLGmLirEq9KC6xkcoWnyPACAw/rbWKUuVobXcrcoic
G6N4gZt5Ekl7qg3AUFnKtw2/l6rfx4WFZjRdevGx7k14I4m6UCv/t040dMhCyUXJ
zP73WZTdV3TR4C643ZXkoXNlnlm8uOeSvOy85wIDAQABAoIBAFJddEP/Tg+637bb
pCYQ92t/wuLVoS0iCQ53/HyumggF9qRhQw4c1E7Tev37AUIR1m9mZy1/ZMUc8U8j
Wxpn8h54RLJ9dT4oNmJiumOflna/WZwLvC/PLCYhlLjtp1HOboJZMG/s7zUf+5zU
ltjGg5KdIdvR2H/5vkWmPQ2fmWszFVKbB+RPX9NbAcQMIXwATcIN3tbsISuydaf6
w0Laa07oGpcMYTJzP1TJAVluUHWfouPoHdDcVc0g737o1wIFQ35e6bbYzM5zBkHJ
dQo7CeET+5+HZjsC9MQRiWw853GYJp0w+bKjDov/aIBJt6ZVx+KB8sZccSofVbaY
JvpwAAECgYEA6nHID0Lgo/P0aFneo38c9MlEdGRLxrfXwsY8LhnKtkF0wgz1Is40
be6cVIz/XzXvHnB3WrAMsdz2MPiU4COz5T48z9hNcb/BMrVvNCN3x2Bu/FU4qMVU
vKJIhsL9Hq/TF3W0crA+DObvl9Kv4tIQ7hQK/xvbGpsoOiqV4A26Lu8CgYEAzZNa
Nl3W5Ut+VqaEdnED26pbZtzM8eLwioUNme9Etl+WrJQervNf8j8GJ8BUhOVjQrDT
hqA2bkXfBqxYaW2G8wnOVhq6jqLFfb3yZjpOsUf1T2x7naHW2Z3VEPlnMez2GJB/
/jkRegcXqPMtk8TahbaY/gTjOc+eFTefuDuQUYkCgYAKxlfve59faaLd+ONmmDz4
cxeWUdW5uFFOPlYduEm8vp1jHb1WcCuwsbq1mBVUhuIKgBi8LkMnGYSnE4WkF3/5
FTcuRj6o76stbXFC8C5dF22CY1hLSWZvlPXIW8XOVz5YYax9aOQxK5vvWluDDSyC
BKHMv7b+LgtXQQXKWlcoOQKBgAv7hsqcdaYv3FFYq2fr9nmbWHCKdjezLqokT0Kl
u6+Vqsasa41vCiyol8dBYqvMYxjEDdBPDl0nHXTaHt0mUTNhYvGJ5U3jFvfZVoO2
6ldTBm12uU3a3RcaKA0xPF6gnUeZRJyg3u/p8esbIZD3bHVWy1wjFMuN2n0KHPk0
H5lhAoGAO8YqRVnHOoz7HeA16+LZoOorDA9r/NEN3/K/jgOJPfrm3CV205Ew7mvQ
Y6im34HAcjHp2fz/kxE0S4vd2iWapMpiQu0U2yvLdX+861pkM/ffAg6x3nEJChzp
lh8rxqEJy4PukTBxUAL0h5wnOWkRYFgOVcx60rHvYJZ8+Qf3lbc=
-----END RSA PRIVATE KEY-----

View File

@@ -1,26 +1,21 @@
#Thu May 19 13:16:56 CEST 2016
#Thu May 19 13:18:31 CEST 2016
autoSaveScanData=true
createSessionFiles=false
dataLayout=default
dataPath={data}/{year}_{month}/{date}/{date}_{time}_{exec}
dataProvider=default
dataPath={data}/{year}_{month}/{date}/{date}_{time}_{name}
dataProvider=h5
dataScanFlushRecords=true
dataScanStrategy=default
dataServerPort=-1
devicePoolFile={config}/devices.properties
deviceUpdateStrategyFile={config}/update.properties
hostName=null
instanceName=OP
instanceName=RF
logDaysToLive=-1
logLevel=Info
logLevel=Fine
logLevelConsole=Off
logPath={logs}/{date}_{time}
scanStreamerPort=-1
scanStreamingPort=-1
serverEnabled=true
serverPort=8080
serverPort=8090
simulation=false
tasksFile={config}/tasks.properties
terminalEnabled=false
terminalPort=3579
userAuthenticator=
@@ -28,4 +23,4 @@ userManagement=false
versionTrackingEnabled=true
versionTrackingLogin={context}/svcusr-hlapp_robot
versionTrackingManual=false
versionTrackingRemote=git@git.psi.ch\:pshell_config/sf-op.git
versionTrackingRemote=git@git.psi.ch\:pshell_config/sf-rf.git

View File

@@ -1,16 +1,4 @@
bpm_1_down_gun=ch.psi.pshell.epics.Positioner|SINEG01-DBPM340:X1 SINEG01-DBPM340:Y1|Read||true
gun_sol_current=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:I-SET SINEG01-MSOL130:I-SET|||true
gun_phase=ch.psi.pshell.epics.Positioner|SINEG01-RSYS:SET-VSUM-PHASE SINEG01-RSYS:SET-VSUM-PHASE|||true
#SINSB01_phase=ch.psi.pshell.epics.Positioner|VA-SINSB01-RSYS100:SET-BEAM-PHASE VA-SINSB01-RSYS100:GET-BEAM-PHASE|||true
#BC1_energy=ch.psi.pshell.epics.ChannelDouble|VA-SINBC02-DBPM140:ENERGY|Read||true
#SARUN02_MCRX080=ch.psi.pshell.epics.Positioner|VA-SARUN02-MCRX080:I-SET VA-SARUN02-MCRX080:I-READ|||true
#SARUN02_MCRY080=ch.psi.pshell.epics.Positioner|VA-SARUN02-MCRY080:I-SET VA-SARUN02-MCRY080:I-READ|||true
#SARUN03_DBPM070_X=ch.psi.pshell.epics.ChannelDouble|VA-SARUN03-DBPM070:X1|Read||true
#chd=ch.psi.pshell.epics.ChannelDouble|VA-SINSB01-RSYS100:SET-BEAM-PHASE 3|||true
#pv=ch.psi.pshell.epics.ProcessVariable|VA-SINSB01-RSYS100:SET-BEAM-PHASE|||true
#cv=ch.psi.pshell.epics.ControlledVariable|VA-SINSB01-RSYS100:SET-BEAM-PHASE VA-SINSB01-RSYS100:GET-BEAM-PHASE|||true
#pos=ch.psi.pshell.epics.Positioner|VA-SINSB01-RSYS100:SET-BEAM-PHASE VA-SINSB01-RSYS100:GET-BEAM-PHASE|||true
#mot=ch.psi.pshell.device.DummyMotor||||true
#rf_phase=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:SET-VSUM-PHASE|||true
#rf_phase_rb=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:GET-VSUM-PHASE|Read||true
#rf_ampl_rb=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:GET-VSUM-AMPLT|Read||true
$rf_phase=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:SET-VSUM-PHASE|||true
rf_phase_rb=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:GET-VSUM-PHASE|Read||true
rf_ampl_rb=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:GET-VSUM-AMPLT|Read||true
$pos=ch.psi.pshell.device.DummyPositioner||||true

View File

@@ -1,7 +1,8 @@
#Wed May 04 14:26:21 CEST 2016
ch.psi.jcae.ContextFactory.addressList=129.129.130.255 129.129.131.255 129.129.137.255
#Thu May 19 14:19:11 CEST 2016
ch.psi.jcae.ContextFactory.addressList=129.129.130.255 129.129.131.255 129.129.137.255 129.129.137.113 129.129.146.255 127.0.0.1\:12345
ch.psi.jcae.ContextFactory.maxArrayBytes=10000000
ch.psi.jcae.ChannelFactory.retries=2
ch.psi.jcae.ChannelFactory.timeout=500
ch.psi.jcae.impl.DefaultChannelService.retries=4
ch.psi.jcae.impl.DefaultChannelService.timeout=1000
ch.psi.jcae.ContextFactory.serverPort=

View File

@@ -1,9 +1,8 @@
#Wed Dec 09 13:50:24 CET 2015
#Tue May 10 16:47:46 CEST 2016
configFile={config}/config.properties
configFileDevices={config}/devices.properties
configFilePlugins={config}/plugins.properties
configFileTasks={config}/tasks.properties
configFileUpdateStrategy={config}/update.properties
configPath={home}/config
contextPath={outp}/context
dataPath={outp}/data

8
devices/Phase.properties Normal file
View File

@@ -0,0 +1,8 @@
#Mon May 30 09:53:36 CEST 2016
maxValue=0.0
minValue=0.0
offset=0.0
precision=0
resolution=NaN
scale=1.0
unit=DEG

View File

@@ -1,8 +0,0 @@
#Wed Jan 06 17:01:23 CET 2016
maxValue=5.0
minValue=-5.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=A

View File

@@ -1,8 +0,0 @@
#Wed Jan 06 17:01:36 CET 2016
maxValue=5.0
minValue=-5.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=A

View File

@@ -1,8 +0,0 @@
#Wed Jan 06 17:10:52 CET 2016
maxValue=5.0
minValue=-5.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=A

View File

@@ -1,8 +0,0 @@
#Wed Jan 06 17:11:05 CET 2016
maxValue=5.0
minValue=-5.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=A

View File

@@ -1,8 +0,0 @@
#Wed Jan 06 16:18:41 CET 2016
maxValue=360.0
minValue=0.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=Degree

View File

@@ -1,8 +0,0 @@
#Wed Dec 09 14:42:00 CET 2015
maxValue=360.0
minValue=0.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=Degree

View File

@@ -1,8 +0,0 @@
#Tue May 10 13:57:11 CEST 2016
maxValue=NaN
minValue=NaN
offset=0.0
precision=-1
resolution=NaN
scale=1.0
unit=null

View File

@@ -1,8 +0,0 @@
#Fri Jan 08 10:12:30 CET 2016
maxValue=360.0
minValue=0.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=Degree

View File

@@ -1,11 +0,0 @@
#Wed Dec 09 13:57:47 CET 2015
motor1=0.0|4.0|8.0|0.0
motor2=0.0|5.0|3.0|NaN
motor3=null
motor4=null
motor5=null
motor6=null
motor7=null
motor8=null
positions=Park|Ready|Out|Clear
precision=-1

View File

@@ -1,8 +0,0 @@
#Tue May 10 09:59:44 CEST 2016
maxValue=180.0
minValue=-179.99
offset=0.0
precision=2
resolution=1.0
scale=1.0
unit=DEG

View File

@@ -1,8 +0,0 @@
#Tue May 10 09:38:33 CEST 2016
maxValue=210.0
minValue=0.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
unit=A

View File

@@ -1,12 +0,0 @@
#Wed Dec 09 13:57:47 CET 2015
defaultSpeed=1.0
estbilizationDelay=0
maxSpeed=10.0
maxValue=10.0
minSpeed=0.1
minValue=-10.0
offset=0.0
precision=2
resolution=NaN
scale=1.0
unit=mm

View File

@@ -1,12 +0,0 @@
#Wed Dec 09 13:57:47 CET 2015
defaultSpeed=1.0
estbilizationDelay=0
maxSpeed=10.0
maxValue=10.0
minSpeed=0.1
minValue=-10.0
offset=0.0
precision=2
resolution=NaN
scale=1.0
unit=mm

View File

@@ -1,12 +0,0 @@
#Fri Jan 08 10:18:25 CET 2016
defaultSpeed=1.0
estbilizationDelay=0
maxSpeed=10.0
maxValue=10.0
minSpeed=0.1
minValue=-10.0
offset=0.0
precision=2
resolution=NaN
scale=1.0
unit=mm

View File

@@ -1,12 +0,0 @@
#Fri Jan 08 10:07:38 CET 2016
defaultSpeed=1.0
estbilizationDelay=0
maxSpeed=10.0
maxValue=10.0
minSpeed=0.1
minValue=-10.0
offset=0.0
precision=2
resolution=NaN
scale=1.0
unit=mm

View File

@@ -1,8 +0,0 @@
#Wed Dec 09 13:57:47 CET 2015
maxValue=1000.0
minValue=0.0
offset=0.0
precision=-1
resolution=NaN
scale=1.0
unit=mm

View File

@@ -1,8 +1,8 @@
#Fri Jan 08 10:13:11 CET 2016
maxValue=90.0
minValue=0.0
#Thu May 12 10:17:39 CEST 2016
maxValue=180.0
minValue=-180.0
offset=0.0
precision=3
precision=1
resolution=NaN
scale=1.0
unit=Degree
unit=null

View File

@@ -1,8 +0,0 @@
#Fri Jan 08 10:09:44 CET 2016
maxValue=0.0
minValue=0.0
offset=0.0
precision=3
resolution=0.01
scale=1.0
unit=Degree

View File

@@ -1,13 +0,0 @@
#Wed Dec 09 13:57:47 CET 2015
colormap=Temperature
colormapAutomatic=true
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
rotation=0.0
scale=1.0

View File

@@ -1,13 +0,0 @@
#Wed Dec 09 13:57:47 CET 2015
colormap=Grayscale
colormapAutomatic=true
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
rotation=0.0
scale=1.0

View File

@@ -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

View File

@@ -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())

View File

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

View File

@@ -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())

View File

@@ -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())

View File

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

View File

@@ -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())

View File

@@ -1 +0,0 @@
ascan((SARUN02_MCRX080,SARUN02_MCRY080), (SARUN03_DBPM070), (-2.0,-2.0), (2.0,2.0), (5,5), 0.01)

View File

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

View File

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

View File

@@ -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())

View File

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

View File

@@ -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())

View File

@@ -1 +0,0 @@
lscan(SINSB01_phase, energy_BC1, 0.0, 360.0, 10.0, 2.0)

View File

@@ -1,2 +0,0 @@
caput("SINEG01-MCRX120:I-SET", 5.0)
print(caget("SINEG01-MCRX120:I-READ"))

View File

@@ -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()

View File

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