Startup
This commit is contained in:
@@ -10,11 +10,14 @@
|
||||
|
||||
import datetime
|
||||
|
||||
mode = "camtool" # "camtool", "bpm" or "direct"
|
||||
is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
|
||||
|
||||
camera_name = "SINEG01-DSCR190"
|
||||
use_good_region=False
|
||||
do_elog = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
if not is_panel:
|
||||
source = "direct" # "camtool", "bpm" or "direct"
|
||||
I1 = 100.0
|
||||
I2 = 105.0
|
||||
dI = 1.0
|
||||
@@ -22,27 +25,45 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
plot_image = False
|
||||
number_images = 5
|
||||
use_background = True
|
||||
multiple_background = True
|
||||
number_backgrounds = 5
|
||||
do_elog = False
|
||||
centroid_excursion_plot = True
|
||||
else:
|
||||
centroid_excursion_plot = False
|
||||
multiple_background = False
|
||||
number_backgrounds = 5
|
||||
plots = get_plots(title = "Centroid excursion")
|
||||
if len(plots)==0:
|
||||
centroid_plot = plot(None, title = "Centroid excursion")[0]
|
||||
centroid_plot.clear()
|
||||
else:
|
||||
centroid_plot = plots[0]
|
||||
|
||||
|
||||
kill_camtool()
|
||||
check_camtool()
|
||||
centroid_plot_index = 1 if ((len(centroid_plot.getAllSeries()) == 0) or (not globals().has_key("centroid_plot_index"))) else (centroid_plot_index + 1)
|
||||
print "Plot index: ", centroid_plot_index
|
||||
centroid_plot.setLegendVisible(True)
|
||||
centroid_plot.setStyle(centroid_plot.Style.ErrorXY)
|
||||
centroid_plot.getAxis(centroid_plot.AxisId.Y).setLabel("")
|
||||
centroid_plot.getAxis(centroid_plot.AxisId.X).setLabel("Centroid Excursion")
|
||||
scan_series = LinePlotErrorSeries(str(centroid_plot_index))
|
||||
centroid_plot.addSeries(scan_series)
|
||||
scan_series.setLinesVisible(False)
|
||||
scan_series.setPointSize(4)
|
||||
|
||||
#Simulation
|
||||
camera_name = "SLG-LCAM-C041"
|
||||
def laser_on():
|
||||
print "Laser On"
|
||||
def laser_off():
|
||||
print "Laser Off"
|
||||
def switch_off_magnets(magnets = None):
|
||||
pass
|
||||
add_device(DummyPositioner("gun_solenoid"), True)
|
||||
do_elog = False
|
||||
|
||||
laser_was_on = is_laser_on()
|
||||
original_gun_solenoid = gun_solenoid.read()
|
||||
|
||||
|
||||
original_gun_solenoid = gun_solenoid.read()
|
||||
multiple_background = multiple_background and use_background
|
||||
print "Parameters: ", I1, I2, dI, settling_time, plot_image, number_images, use_background, multiple_background, number_backgrounds
|
||||
|
||||
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
|
||||
|
||||
|
||||
if mode == "camtool":
|
||||
if source == "camtool":
|
||||
check_camtool()
|
||||
if use_background:
|
||||
laser_off()
|
||||
if not multiple_background:
|
||||
@@ -50,20 +71,28 @@ if mode == "camtool":
|
||||
camtool.grabBackground(camera_name, number_backgrounds)
|
||||
camtool.start(camera_name, 0, use_background, None, 0.0, None)
|
||||
else:
|
||||
if mode == "bpm":
|
||||
if source == "bpm":
|
||||
run("Devices/BpmStats")
|
||||
add_device(BpmStats("image_stats", camera_name), True)
|
||||
else:
|
||||
add_device(ImageStats(PsiCamera("image_stats", camera_name)), True)
|
||||
multiple_background = False
|
||||
use_background = False
|
||||
multiple_background = False
|
||||
use_background = False
|
||||
else:
|
||||
run("Devices/ImageStats")
|
||||
add_device(ImageStats("image_stats", camera_name), True)
|
||||
add_device(image_stats.source, True)
|
||||
image_stats.enableBackground(use_background)
|
||||
if use_background:
|
||||
laser_off()
|
||||
if not multiple_background:
|
||||
image_stats.grabBackground(number_backgrounds)
|
||||
image_stats.setNumberOfImages(max(number_images,1))
|
||||
|
||||
#switch_off_magnets()
|
||||
|
||||
# add here gun phase setting see wiki page
|
||||
|
||||
def before_sample():
|
||||
if mode == "camtool":
|
||||
def before_sample(position, scan):
|
||||
if source == "camtool":
|
||||
if multiple_background:
|
||||
camtool.stop()
|
||||
camtool.grabBackground(camera_name, number_backgrounds)
|
||||
@@ -71,9 +100,20 @@ def before_sample():
|
||||
laser_on()
|
||||
wait_camtool_message(number_images) #Wait filing the averager cache
|
||||
else:
|
||||
if multiple_background:
|
||||
image_stats.grabBackground(number_backgrounds)
|
||||
laser_on()
|
||||
image_stats.update()
|
||||
|
||||
def after_sample():
|
||||
def after_sample(record, scan):
|
||||
x = record.values[0]
|
||||
y = record.values[1]
|
||||
stdev_x = record.values[2]
|
||||
stdev_y = record.values[3]
|
||||
if source == "camtool":
|
||||
#x, y, stdev_x, stdev_y = x.mean, y.mean, stdev_x.mean, stdev_y.mean
|
||||
x, y, stdev_x, stdev_y = x.mean, y.mean, x.stdev, y.stdev
|
||||
scan_series.appendData(x, y, abs(stdev_x), abs(stdev_y));
|
||||
if multiple_background:
|
||||
laser_off()
|
||||
|
||||
@@ -82,37 +122,60 @@ if not multiple_background:
|
||||
laser_on()
|
||||
|
||||
try:
|
||||
if mode != "camtool":
|
||||
if source != "camtool":
|
||||
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
|
||||
if plot_image and (source == "direct"):
|
||||
sensors.append(image_stats.source.getDataMatrix())
|
||||
else:
|
||||
sensors = get_camtool_stats(number_images, good_region=use_good_region)
|
||||
|
||||
|
||||
sensors = get_camtool_stats(number_images, good_region=use_good_region)
|
||||
if plot_image:
|
||||
sensors.append(camtool.getDataMatrix())
|
||||
r = lscan(gun_solenoid, sensors , I1, I2, dI, settling_time, before_read = before_sample, after_read = after_sample)
|
||||
finally:
|
||||
if mode == "camtool": camtool.stop()
|
||||
if source == "camtool":
|
||||
camtool.stop()
|
||||
else:
|
||||
image_stats.stop()
|
||||
gun_solenoid.write(original_gun_solenoid)
|
||||
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)
|
||||
else:
|
||||
(hx,hy)= convex_hull(x=to_array(r.getReadable(0), 'd'), y=to_array(r.getReadable(1),'d'))
|
||||
hx.append(hx[0]); hy.append(hy[0])
|
||||
(hx,hy)= convex_hull(x=to_array(r.getReadable(0), 'd'), y=to_array(r.getReadable(1),'d'))
|
||||
hx.append(hx[0]); hy.append(hy[0])
|
||||
hx = Convert.toDouble(hx)
|
||||
hy = Convert.toDouble(hy)
|
||||
hull = LinePlotErrorSeries(scan_series.name + "H", scan_series.color);
|
||||
centroid_plot.addSeries(hull);
|
||||
hull.setData(hx, hy);
|
||||
|
||||
#Include metadata do hdf5
|
||||
path = get_exec_pars().scanPath
|
||||
|
||||
set_attribute(path, "Settling time", settling_time)
|
||||
set_attribute(path, "Images", number_images)
|
||||
set_attribute(path, "Background enabled", use_background)
|
||||
set_attribute(path, "Background multiple", multiple_background)
|
||||
set_attribute(path, "Background images", number_backgrounds)
|
||||
set_attribute(path, "Plot index", centroid_plot_index)
|
||||
|
||||
# save the entry in the logbook
|
||||
gsa_log_msg = "Data file: " + get_exec_pars().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:
|
||||
elog("Gun solenoid current scan", gsa_log_msg , get_plot_snapshots())
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Data file: " + get_exec_pars().path
|
||||
log_msg = log_msg + "\nI1: " + str(I1)
|
||||
log_msg = log_msg + "\nI2: " + str(I2)
|
||||
log_msg = log_msg + "\ndI: " + str(dI)
|
||||
log_msg = log_msg + "\nSettling time: " + str(settling_time)
|
||||
log_msg = log_msg + "\nImages: " + str(number_images)
|
||||
log_msg = log_msg + "\nBackground: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
|
||||
log_msg = log_msg + "\nPlot index: " + str(centroid_plot_index)
|
||||
log_msg = log_msg + "\n\n" + r.print()
|
||||
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/centroid_excursion.png")
|
||||
centroid_plot.saveSnapshot(file_name , "png")
|
||||
elog("Gun solenoid alignment", log_msg, [file_name,])
|
||||
|
||||
set_return([r, hx, hy])
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
|
||||
import datetime
|
||||
|
||||
mode = "camtool" # "camtool", "bpm" or "direct"
|
||||
is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
|
||||
|
||||
camera_name = "SINEG01-DSCR190"
|
||||
use_good_region=False
|
||||
do_elog = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
if not is_panel:
|
||||
source = "camtool" # "camtool", "bpm" or "direct"
|
||||
phi1= 95.0
|
||||
phi2 = 100.0
|
||||
dphi = 1.0
|
||||
@@ -23,23 +26,46 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
number_images = 5
|
||||
use_background = True
|
||||
multiple_background = False
|
||||
number_backgrounds = 5
|
||||
do_elog = False
|
||||
centroid_excursion_plot = True
|
||||
else:
|
||||
centroid_excursion_plot = False
|
||||
number_backgrounds = 5
|
||||
plots = get_plots(title = "Centroid excursion")
|
||||
if len(plots)==0:
|
||||
centroid_plot = plot(None, title = "Centroid excursion")[0]
|
||||
centroid_plot.clear()
|
||||
else:
|
||||
centroid_plot = plots[0]
|
||||
|
||||
kill_camtool()
|
||||
check_camtool()
|
||||
|
||||
centroid_plot_index = 1 if ((len(centroid_plot.getAllSeries()) == 0) or (not globals().has_key("centroid_plot_index"))) else (centroid_plot_index + 1)
|
||||
print "Plot index: ", centroid_plot_index
|
||||
centroid_plot.setLegendVisible(True)
|
||||
centroid_plot.setStyle(centroid_plot.Style.ErrorXY)
|
||||
centroid_plot.getAxis(centroid_plot.AxisId.Y).setLabel("")
|
||||
centroid_plot.getAxis(centroid_plot.AxisId.X).setLabel("Centroid Excursion")
|
||||
scan_series = LinePlotErrorSeries(str(centroid_plot_index))
|
||||
centroid_plot.addSeries(scan_series)
|
||||
scan_series.setLinesVisible(False)
|
||||
scan_series.setPointSize(4)
|
||||
|
||||
#Testing
|
||||
camera_name = "SLG-LCAM-C041"
|
||||
def laser_on():
|
||||
print "Laser On"
|
||||
def laser_off():
|
||||
print "Laser Off"
|
||||
def switch_off_magnets(magnets = None):
|
||||
pass
|
||||
add_device(DummyPositioner("gun_phase"), True)
|
||||
do_elog = False
|
||||
|
||||
laser_was_on = is_laser_on()
|
||||
original_phase = gun_phase.read()
|
||||
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')
|
||||
|
||||
if mode == "camtool":
|
||||
if source == "camtool":
|
||||
#kill_camtool()
|
||||
check_camtool()
|
||||
if use_background:
|
||||
laser_off()
|
||||
if not multiple_background:
|
||||
@@ -47,20 +73,28 @@ if mode == "camtool":
|
||||
camtool.grabBackground(camera_name, number_backgrounds)
|
||||
camtool.start(camera_name, 0, use_background, None, 0.0, None)
|
||||
else:
|
||||
if mode == "bpm":
|
||||
if source == "bpm":
|
||||
run("Devices/BpmStats")
|
||||
add_device(BpmStats("image_stats", camera_name), True)
|
||||
multiple_background = False
|
||||
use_background = False
|
||||
else:
|
||||
add_device(ImageStats(PsiCamera("image_stats", camera_name)), True)
|
||||
multiple_background = False
|
||||
use_background = False
|
||||
run("Devices/ImageStats")
|
||||
add_device(ImageStats("image_stats", camera_name), True)
|
||||
add_device(image_stats.source, True)
|
||||
image_stats.enableBackground(use_background)
|
||||
if use_background:
|
||||
laser_off()
|
||||
if not multiple_background:
|
||||
image_stats.grabBackground(number_backgrounds)
|
||||
image_stats.setNumberOfImages(max(number_images,1))
|
||||
|
||||
#switch_off_magnets()
|
||||
|
||||
# add here gun phase setting see wiki page
|
||||
|
||||
def before_sample():
|
||||
if mode == "camtool":
|
||||
def before_sample(position, scan):
|
||||
if source == "camtool":
|
||||
if multiple_background:
|
||||
camtool.stop()
|
||||
camtool.grabBackground(camera_name, number_backgrounds)
|
||||
@@ -68,26 +102,42 @@ def before_sample():
|
||||
laser_on()
|
||||
wait_camtool_message(number_images) #Wait filing the averager cache
|
||||
else:
|
||||
if multiple_background:
|
||||
image_stats.grabBackground(number_backgrounds)
|
||||
laser_on()
|
||||
image_stats.update()
|
||||
|
||||
def after_sample():
|
||||
def after_sample(record, scan):
|
||||
x = record.values[0]
|
||||
y = record.values[1]
|
||||
stdev_x = record.values[2]
|
||||
stdev_y = record.values[3]
|
||||
if source == "camtool":
|
||||
#x, y, stdev_x, stdev_y = x.mean, y.mean, stdev_x.mean, stdev_y.mean
|
||||
x, y, stdev_x, stdev_y = x.mean, y.mean, x.stdev, y.stdev
|
||||
scan_series.appendData(x, y, abs(stdev_x), abs(stdev_y));
|
||||
if multiple_background:
|
||||
laser_off()
|
||||
laser_off()
|
||||
|
||||
r = None
|
||||
if not multiple_background:
|
||||
laser_on()
|
||||
|
||||
try:
|
||||
if mode != "camtool":
|
||||
if source != "camtool":
|
||||
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
|
||||
if plot_image and (source == "direct"):
|
||||
sensors.append(image_stats.source.getDataMatrix())
|
||||
else:
|
||||
sensors = get_camtool_stats(number_images, good_region=use_good_region)
|
||||
if plot_image:
|
||||
sensors.append(camtool.getDataMatrix())
|
||||
r = lscan(gun_phase, sensors , phi1, phi2, dphi, settling_time, before_read = before_sample, after_read = after_sample)
|
||||
finally:
|
||||
if mode == "camtool": camtool.stop()
|
||||
if source == "camtool":
|
||||
camtool.stop()
|
||||
else:
|
||||
image_stats.stop()
|
||||
gun_phase.write(original_phase)
|
||||
if laser_was_on:
|
||||
laser_on()
|
||||
@@ -95,23 +145,45 @@ 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)
|
||||
else:
|
||||
(hx,hy)= convex_hull(x=to_array(r.getReadable(0), 'd'), y=to_array(r.getReadable(1),'d'))
|
||||
hx.append(hx[0]); hy.append(hy[0])
|
||||
(hx,hy)= convex_hull(x=to_array(r.getReadable(0), 'd'), y=to_array(r.getReadable(1),'d'))
|
||||
hx.append(hx[0]); hy.append(hy[0])
|
||||
hx = Convert.toDouble(hx)
|
||||
hy = Convert.toDouble(hy)
|
||||
hull = LinePlotErrorSeries(scan_series.name + "H", scan_series.color);
|
||||
centroid_plot.addSeries(hull);
|
||||
hull.setData(hx, hy);
|
||||
|
||||
#Include metadata do hdf5
|
||||
path = get_exec_pars().scanPath
|
||||
set_attribute(path, "phi1", phi1)
|
||||
set_attribute(path, "phi2", phi2)
|
||||
set_attribute(path, "dphi", dphi)
|
||||
set_attribute(path, "Settling time", settling_time)
|
||||
set_attribute(path, "Images", number_images)
|
||||
set_attribute(path, "Background enabled", use_background)
|
||||
set_attribute(path, "Background multiple", multiple_background)
|
||||
set_attribute(path, "Background images", number_backgrounds)
|
||||
set_attribute(path, "Plot index", centroid_plot_index)
|
||||
|
||||
print "Done"
|
||||
# save the entry in the logbook
|
||||
gsa_log_msg = "Data file: " + get_exec_pars().path
|
||||
gsa_log_msg = gsa_log_msg + "\nImages: " + str(number_images) + " Background: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
|
||||
gsa_log_msg = gsa_log_msg + "\nPhase range: " + str(phi1) + " to " + str(phi2)
|
||||
gsa_log_msg = gsa_log_msg + "\nLaser position on cathod: " + str(caget("SLG-LCAM-C103:FIT-XPOS")) + "/" + str(caget("SLG-LCAM-C103:FIT-YPOS"))
|
||||
gsa_log_msg = gsa_log_msg + "\n\n" + r.print()
|
||||
if do_elog:
|
||||
elog("Laser alignment with phase scan", gsa_log_msg , get_plot_snapshots())
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Data file: " + get_exec_pars().path
|
||||
log_msg = log_msg + "\nI1: " + str(I1)
|
||||
log_msg = log_msg + "\nI2: " + str(I2)
|
||||
log_msg = log_msg + "\ndI: " + str(dI)
|
||||
log_msg = log_msg + "\nSettling time: " + str(settling_time)
|
||||
log_msg = log_msg + "\nImages: " + str(number_images)
|
||||
log_msg = log_msg + "\nBackground: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
|
||||
log_msg = log_msg + "\nPlot index: " + str(centroid_plot_index)
|
||||
log_msg = log_msg + "\n\n" + r.print()
|
||||
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/centroid_excursion.png")
|
||||
centroid_plot.saveSnapshot(file_name , "png")
|
||||
elog("Laser alignment with phase scan", log_msg, [file_name,])
|
||||
|
||||
|
||||
set_return([r, hx, hy])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user