diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 70f1daf..6cf69d4 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,13 +1,13 @@ -#Fri Mar 24 10:44:34 CET 2017 +#Tue Mar 28 08:07:12 CEST 2017 colormap=Flame colormapAutomatic=false -colormapMax=4000.0 +colormapMax=400.0 colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1024 -imageWidth=1280 +imageHeight=2160 +imageWidth=2560 invert=false regionStartX=1 regionStartY=1 @@ -21,9 +21,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-737.8500604360871 -spatialCalOffsetY=-532.454701361865 -spatialCalScaleX=-8.510638139102149 -spatialCalScaleY=-8.235816890357906 +spatialCalOffsetX=-1057.4895329398094 +spatialCalOffsetY=-1420.5549062527236 +spatialCalScaleX=-8.510638153514359 +spatialCalScaleY=-8.235817137431614 spatialCalUnits=mm transpose=false diff --git a/script/Alignment/Gun_solenoid_alignment.py b/script/Alignment/Gun_solenoid_alignment.py index 10e034a..c55924e 100755 --- a/script/Alignment/Gun_solenoid_alignment.py +++ b/script/Alignment/Gun_solenoid_alignment.py @@ -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() diff --git a/script/Alignment/Laser_gun_alignment.py b/script/Alignment/Laser_gun_alignment.py index b662067..8fc5521 100755 --- a/script/Alignment/Laser_gun_alignment.py +++ b/script/Alignment/Laser_gun_alignment.py @@ -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) diff --git a/script/local.py b/script/local.py index 7924849..4421e9b 100755 --- a/script/local.py +++ b/script/local.py @@ -31,7 +31,17 @@ def ccr(magnet): while caget(magnet+ ":I-COMP") > 0: sleep(0.5) -def switch_off_magnets(magnets): +def switch_off_magnets(magnets = None): + if magnets is None: + magnets = [ "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" ] magnets = to_list(magnets) for m in magnets: caput(m + ":I-SET", 0.0) @@ -186,11 +196,36 @@ center_y.setPolling(100) """ #Camtool "child" pseudo-devices class CamtoolValue(Readable): - def __init__(self, channel): + def __init__(self, channel, alias = None): self.channel=channel + set_device_alias(self, channel if (alias is None) else alias) def read(self): return camtool.getValue(self.channel) + +class CamtoolArray(ReadableArray): + def __init__(self, channel, alias = None): + self.channel=channel + set_device_alias(self, channel if (alias is None) else alias) + + def read(self): + return camtool.getValue(self.channel) + + def getSize(self): + return len(camtool.getValue(self.channel)) + +class CamtoolImage(ReadableMatrix): + def __init__(self, alias = None): + set_device_alias(self, camtool.getCurrentCamera() + " image" if (alias is None) else alias) + + def read(self): + return camtool.getData().matrix + + def getWidth(self): + return camtool.getData().width + + def getHeight(self): + return camtool.getData().height #Convex hull plots