Script execution

This commit is contained in:
sfop
2016-08-29 11:41:53 +02:00
parent 8ae81ce8d2
commit c2c0a83716
+57 -26
View File
@@ -1,35 +1,58 @@
# Tool to align the laser on the cathode.
# Tool to align the solenoid on the gun.
# S. Bettoni, A. Gobbo, D. Voulot
# 16/06/2016
# 06/06/2016
#Code ok with the GUI
# 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
# change the current of the gun soleoid
# look at the centroid position (BPM or screen) downstream of the gun.
import datetime
from camtool import CamTool
use_bpm = True
if get_context().source == CommandSource.ui:
phi1 = 95.0
phi1= 95.0
phi2 = 100.0
dphi = 1.0
settling_time = 0.1
plot_image = False
number_images = 1
number_images = 5
use_background = True
multiple_background = True
multiple_background = False
number_backgrounds = 5
zero_solenoids=False
do_elog = False
centroid_excursion_plot = True
else:
centroid_excursion_plot = False
from camtool import CamTool
from ImageStats import ImageStats, get_simulated_source
multiple_background = multiple_background and use_background
print "Parameters: ", phi1, phi2, dphi, settling_time, plot_image, number_images, use_background, multiple_background, number_backgrounds
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
multiple_background = multiple_background and use_background
if (use_bpm):
add_device(BpmStats("image_stats", "SINEG01-DBPM340"), True)
else:
latch = True
if get_device("image_stats") is None:
print "Instantiating camtool"
add_device(CamTool("image_stats", prefix = "cam:", latch = latch, camera = "SINEG01-DSCR350"), True)
if (latch):
image_stats.start()
#add_device(ImageStats("image_stats", get_simulated_source(image)), True)
image_stats.setNumberOfImages(max(number_images,1))
image_stats.enableBackground (use_background)
if use_background:
laser_off()
if not multiple_background:
image_stats.captureBackground(number_backgrounds)
# Switch off magnets
mag = [ "SINEG01-MCRX120","SINEG01-MCRY120",
@@ -41,46 +64,54 @@ mag = [ "SINEG01-MCRX120","SINEG01-MCRY120",
"SINEG01-MCRX220","SINEG01-MCRY220",
"SINEG01-MQUA310",
"SINEG01-MQUA320" ]
if zero_solenoids:
multiple_background(mag)
#switch_off_magnets(mag)
# add here gun phase setting see wiki page
def br():
def before_sample():
if multiple_background:
camtool.captureBackground(number_backgrounds)
image_stats.captureBackground(number_backgrounds)
laser_on()
camtool.update()
image_stats.update()
def ar():
def after_sample():
if multiple_background:
laser_off()
laser_off()
r = None
if not multiple_background:
laser_on()
try:
sensors = [camtool.com_x_mean, camtool.com_y_mean, camtool.com_x_stdev, camtool.com_y_stdev]
try:
#sensors = [image_stats.com_x, image_stats.com_y]
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
if plot_image:
sensors.append(camtool.image)
r = lscan(gun_solenoid, sensors , I1, I2, dI, settling_time, before_read = br, after_read = ar)
sensors.append(image_stats.image)
r = lscan(gun_phase, sensors , phi1, phi2, dphi, settling_time, before_read = before_sample, after_read = after_sample)
finally:
laser_off()
image_stats.stop()
# take the result of the scan and generate convex hull plot
if centroid_excursion_plot:
(hx,hy)=add_convex_hull_plot ("Centroid excursion", r.getReadable(0),r.getReadable(1), plot_name)
else:
(hx,hy)= convex_hull(x=r.getReadable(0), y=r.getReadable(1))
hx.append(hx[0]); hy.append(hy[0])
# save the entry in the logbook
gsa_log_msg = "Data file: " + get_context().path
gsa_log_msg = gsa_log_msg + "\nImages: " + str(number_images)
gsa_log_msg = gsa_log_msg + "\nBackground: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
gsa_log_msg = gsa_log_msg + "\n\n" + r.print()
if do_elog:
msg = str(r)
msg = msg + "\nFile: " + get_context().path
msg = msg + "\n\n" + r.print()
elog("Gun solenoid current scan", msg , get_plot_snapshots())
elog("Gun solenoid current scan", gsa_log_msg , get_plot_snapshots())
set_return([r, hx, hy])
set_return([r, hx,hy])