This commit is contained in:
sfop
2017-03-28 08:11:10 +02:00
parent cbd5b3ed9f
commit be5254ed8b
4 changed files with 99 additions and 103 deletions

View File

@@ -10,7 +10,8 @@
import datetime
use_bpm = False
mode = "camtool" # "camtool", "bpm" or "direct"
camera_name = "SINEG01-DSCR190"
if get_exec_pars().source == CommandSource.ui:
I1 = 95.0
@@ -27,10 +28,6 @@ if get_exec_pars().source == CommandSource.ui:
else:
centroid_excursion_plot = False
#from camtool import CamTool
run("camtool")
#from ImageStats import ImageStats, get_simulated_source
laser_was_on = is_laser_on()
original_gun_solenoid = gun_solenoid.read()
@@ -41,45 +38,31 @@ print "Parameters: ", I1, I2, dI, settling_time, plot_image, number_images, use_
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
if (use_bpm):
add_device(BpmStats("image_stats", "SINEG01-DBPM340"), True)
use_background = False
multiple_background = False
if mode == "camtool":
if camtool.getCurrentCamera() != camera_name:
camtool.start(camera_name, None, use_background, None, None, None)
if use_background:
laser_off()
if not multiple_background:
camtool.grabBackground(camera_name, 5)
else:
if get_device("image_stats") is None:
print "Instantiating camtool"
add_device(CamTool("image_stats", prefix = "SINEG01-DSCR190:", latch = True, camera = "SINEG01-DSCR190"), True)
if (image_stats.latch):
image_stats.start()
#add_device(ImageStats("image_stats", get_simulated_source(image)), True)
if mode == "bpm":
add_device(BpmStats("image_stats", camera_name), True)
else:
add_device(ImageStats(PsiCamera("image_stats", camera_name)), True)
multiple_background = False
use_background = False
image_stats.setNumberOfImages(max(number_images,1))
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",
"SINEG01-MQUA140",
"SINEG01-MQUA150",
"SINEG01-MCRX160","SINEG01-MCRY160",
"SINEG01-MCRX180","SINEG01-MCRY180",
"SINEG01-MCRX200","SINEG01-MCRY200",
"SINEG01-MCRX220","SINEG01-MCRY220",
"SINEG01-MQUA310",
"SINEG01-MQUA320" ]
#switch_off_magnets(mag)
#switch_off_magnets()
# add here gun phase setting see wiki page
def before_sample():
if multiple_background:
image_stats.captureBackground(number_backgrounds)
camtool.grabBackground(camera_name, 5)
laser_on()
image_stats.update()
if mode != "camtool":
image_stats.update()
def after_sample():
if multiple_background:
@@ -90,10 +73,12 @@ if not multiple_background:
laser_on()
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(image_stats.image)
if mode != "camtool":
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
else:
sensors = [CamtoolValue("gr_x_fit_mean"), CamtoolValue("gr_y_fit_mean"), CamtoolValue("gr_x_fit_standard_deviation"), CamtoolValue("gr_y_fit_standard_deviation")]
if plot_image and (mode == "camtool"):
sensors.append(CamtoolImage())
r = lscan(gun_solenoid, sensors , I1, I2, dI, settling_time, before_read = before_sample, after_read = after_sample)
finally:
#laser_off()

View File

@@ -10,7 +10,8 @@
import datetime
use_bpm = False
mode = "camtool" # "camtool", "bpm" or "direct"
camera_name = "SINEG01-DSCR190"
if get_exec_pars().source == CommandSource.ui:
phi1= 95.0
@@ -26,16 +27,9 @@ if get_exec_pars().source == CommandSource.ui:
centroid_excursion_plot = True
else:
centroid_excursion_plot = False
#from camtool import CamTool
#run("camtool")
#from ImageStats import ImageStats, get_simulated_source
#from BpmStats import BpmStats
check_camtool()
camtool.start("SINEG01-DSCR190")
check_camtool()
laser_was_on = is_laser_on()
original_phase = gun_phase.read()
multiple_background = multiple_background and use_background
@@ -43,49 +37,32 @@ print "Parameters: ", phi1, phi2, dphi, settling_time, plot_image, number_images
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
if (use_bpm):
add_device(BpmStats("image_stats", "SINEG01-DBPM340"), True)
use_background = False
multiple_background = False
if mode == "camtool":
if camtool.getCurrentCamera() != camera_name:
camtool.start(camera_name, None, use_background, None, None, None)
if use_background:
laser_off()
if not multiple_background:
camtool.grabBackground(camera_name, 5)
else:
camtool.start("SINEG01-DSCR190")
"""
latch = True
if get_device("image_stats") is None:
print "Instantiating camtool"
add_device(CamTool("image_stats", prefix = "SINEG01-DSCR190:", latch = True, camera = "SINEG01-DSCR190"), True)
if (image_stats.latch):
image_stats.start()
"""
#add_device(ImageStats("image_stats", get_simulated_source(image)), True)
if mode == "bpm":
add_device(BpmStats("image_stats", camera_name), True)
else :
add_device(ImageStats(PsiCamera("image_stats", camera_name)), True)
multiple_background = False
use_background = False
image_stats.setNumberOfImages(max(number_images,1))
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",
"SINEG01-MQUA140",
"SINEG01-MQUA150",
"SINEG01-MCRX160","SINEG01-MCRY160",
"SINEG01-MCRX180","SINEG01-MCRY180",
"SINEG01-MCRX200","SINEG01-MCRY200",
"SINEG01-MCRX220","SINEG01-MCRY220",
"SINEG01-MQUA310",
"SINEG01-MQUA320" ]
#switch_off_magnets(mag)
#switch_off_magnets()
# add here gun phase setting see wiki page
def before_sample():
if multiple_background:
image_stats.captureBackground(number_backgrounds)
camtool.grabBackground(camera_name, 5)
laser_on()
image_stats.update()
if mode != "camtool":
image_stats.update()
def after_sample():
if multiple_background:
@@ -96,23 +73,22 @@ if not multiple_background:
laser_on()
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(image_stats.image)
if mode != "camtool":
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
else:
sensors = [CamtoolValue("gr_x_fit_mean"), CamtoolValue("gr_y_fit_mean"), CamtoolValue("gr_x_fit_standard_deviation"), CamtoolValue("gr_y_fit_standard_deviation")]
if plot_image and (mode == "camtool"):
sensors.append(CamtoolImage())
r = lscan(gun_phase, sensors , phi1, phi2, dphi, settling_time, before_read = before_sample, after_read = after_sample)
finally:
pass
#image_stats.stop()
gun_phase.write(original_phase)
if laser_was_on:
laser_on()
else:
laser_off()
# 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)