diff --git a/devices/Beam phase.properties b/devices/Beam phase.properties index 1b0f9d3..a4e6d44 100644 --- a/devices/Beam phase.properties +++ b/devices/Beam phase.properties @@ -1,4 +1,4 @@ -#Mon Nov 06 09:33:43 CET 2017 +#Mon Nov 13 08:29:32 CET 2017 maxValue=360.0 minValue=-360.0 offset=0.0 diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index f90a8df..f673ed5 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,19 +1,19 @@ -#Thu Nov 09 10:26:13 CET 2017 +#Mon Nov 13 09:48:57 CET 2017 \u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000= -colormap=Rainbow -colormapAutomatic=false -colormapMax=376.0 +colormap=Flame +colormapAutomatic=true +colormapMax=1792.0 colormapMin=50.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=652 -imageWidth=589 +imageHeight=1628 +imageWidth=1280 invert=false -regionStartX=332 -regionStartY=103 +regionStartX=865 +regionStartY=267 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 @@ -24,9 +24,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-299.5085076886633 -spatialCalOffsetY=-310.4762027834781 -spatialCalScaleX=-29.103002431441325 -spatialCalScaleY=-26.490066364247312 +spatialCalOffsetX=-341.5066993679644 +spatialCalOffsetY=-480.6332485949483 +spatialCalScaleX=-8.737659471350296 +spatialCalScaleY=-8.834897808789577 spatialCalUnits= transpose=false diff --git a/devices/cam_server.properties b/devices/cam_server.properties index 95e13be..0ae677d 100644 --- a/devices/cam_server.properties +++ b/devices/cam_server.properties @@ -1,4 +1,4 @@ -#Thu Nov 09 09:03:48 CET 2017 +#Mon Nov 13 08:15:30 CET 2017 colormap=Flame colormapAutomatic=true colormapMax=NaN @@ -16,9 +16,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-50.03909304143862 -spatialCalOffsetY=-50.048875855327466 -spatialCalScaleX=-1.0 -spatialCalScaleY=-1.0 +spatialCalOffsetX=-861.4939970777481 +spatialCalOffsetY=-820.4883730911062 +spatialCalScaleX=-18.90359092620482 +spatialCalScaleY=-19.37984500632817 spatialCalUnits=mm transpose=false diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index f85b0fe..4946b50 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -2839,25 +2839,37 @@ public class ScreenPanel extends Panel { private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed try { if (camera != null) { - if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) { - boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); + boolean laserOn = getLaserState(); + OptionResult ret = null; + if (laserOn){ + ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to put laser on delay for capturing background?", OptionType.YesNoCancel); + if (ret == OptionResult.No){ + laserOn = false; } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server != null) { - server.captureBackground(5); - } else { - camera.captureBackground(5, 0); - } - } finally { - if (laserOn) { - setLaserState(true); - } - } - SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); + } else { + ret = SwingUtils.showOption(getTopLevel(), "Capture Background", "Do you want to capture background now?", OptionType.OkCancel); } + + if (ret == OptionResult.Cancel){ + return; + } + + if (laserOn) { + setLaserState(false); + } + try { + System.out.println("Grabbing background for: " + cameraName); + if (server != null) { + server.captureBackground(5); + } else { + camera.captureBackground(5, 0); + } + } finally { + if (laserOn) { + setLaserState(true); + } + } + SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); } } catch (Exception ex) { showException(ex); diff --git a/script/RFscan/GunEnergyScan.py b/script/RFscan/GunEnergyScan.py index f8592b2..b168600 100644 --- a/script/RFscan/GunEnergyScan.py +++ b/script/RFscan/GunEnergyScan.py @@ -1,5 +1,5 @@ import ch.psi.pshell.epics.Positioner as Positioner -import ch.psi.pshell.epics.Camtool as Camtool +#import ch.psi.pshell.epics.Camtool as Camtool dry_run = False do_elog = True diff --git a/script/Tools/save_snapshot.py b/script/Tools/save_snapshot.py index 4f85bb8..6840ddd 100644 --- a/script/Tools/save_snapshot.py +++ b/script/Tools/save_snapshot.py @@ -4,15 +4,15 @@ import org.python.core.PyLong as PyLong import json if get_exec_pars().source == CommandSource.ui: - camera_name = "SLG-LCAM-C041" - shared = True - logbook = "SwissFEL commissioning data" - comment = "Test" + camera_name = "SLG-LCAM-C041_sp" + shared = False + #logbook = "SwissFEL commissioning data" + #comment = "Test" else: camera_name = args[0] shared = args[1].lower() == "true" - logbook = args[2] - comment = args[3] + #logbook = args[2] + #comment = args[3] set_exec_pars(name="camera_snapshot") path = "/image" @@ -43,13 +43,16 @@ for id in stream_value.identifiers: else: set_attribute(path, id, val) -set_exec_pars(open = False) #Enforce the same timestamp to data & image files. -snapshot_file = get_exec_pars().path+ ".png"; +set_exec_pars(open = False) +data_file = get_exec_pars().path +snapshot_file = data_file+ ".png"; ImageBuffer.saveImage(cam_server.output, snapshot_file, "png"); -msg = "Camera: " + camera_name -msg += "\nShared: " + str(shared) -msg += "\nData file: " + str(get_exec_pars().path) -msg += "\nComment: " + str(comment) -elog("Camera Snapshot", msg, [snapshot_file,], logbook=logbook) +#msg = "Camera: " + camera_name +#msg += "\nShared: " + str(shared) +#msg += "\nData file: " + str(get_exec_pars().path) +#msg += "\nComment: " + str(comment) +#elog("Camera Snapshot", msg, [snapshot_file,], logbook=logbook) + +set_return([data_file, snapshot_file]) \ No newline at end of file diff --git a/script/Tools/save_snapshot_client.py b/script/Tools/save_snapshot_client.py index 22f0c40..d288345 100644 --- a/script/Tools/save_snapshot_client.py +++ b/script/Tools/save_snapshot_client.py @@ -1,10 +1,28 @@ - -def save_snapshot(camera_name = "SLG-LCAM-C041", shared = True, logbook = "SwissFEL commissioning data", comment = ""): +def save_snapshot(camera_name = "SLG-LCAM-C041_sp", shared = False ): #, logbook = "SwissFEL commissioning data", comment = ""): import requests base = "http://sf-daq-mgmt:8090/" - url = base + "run/Tools/save_snapshot(%s,%s,%s,%s)" % (camera_name, str(shared), logbook, "'" + str(comment) + "'") + #url = base + "run/Tools/save_snapshot(%s,%s,%s,%s)" % (camera_name, str(shared), logbook, "'" + str(comment) + "'") + url = base + "run/Tools/save_snapshot(%s,%s)" % (camera_name, str(shared)) r = requests.get(url) if r.status_code != 200: raise Exception(r.text) + #print "Ret: ", r.text + return json.loads(r.text.replace("'", '"') .replace('u"', '"')) -save_snapshot() \ No newline at end of file + +r=None +def save_snapshot_mult(camera_name = "SLG-LCAM-C041_sp", shared = False, images = 1, interval = 1000): + global r + import requests + base = "http://sf-daq-mgmt:8090/" + #url = base + "run/Tools/save_snapshot(%s,%s,%s,%s)" % (camera_name, str(shared), logbook, "'" + str(comment) + "'") + url = base + "run/Tools/save_snapshot_mult(%s,%s, %s,%s)" % (camera_name, str(shared), str(images), str(interval)) + r = requests.get(url) + if r.status_code != 200: + raise Exception(r.text) + #print "Ret: ", r.text + #return json.loads(r.text.replace("'", '"') .replace('u"', '"')) + return r + + +print save_snapshot_mult() \ No newline at end of file diff --git a/script/Tools/save_snapshot_mult.py b/script/Tools/save_snapshot_mult.py new file mode 100644 index 0000000..82db8d8 --- /dev/null +++ b/script/Tools/save_snapshot_mult.py @@ -0,0 +1,115 @@ +import ch.psi.pshell.imaging.ImageBuffer as ImageBuffer +import java.math.BigInteger as BigInteger +import org.python.core.PyLong as PyLong +import org.python.core.PyFloat as PyFloat +import json +import traceback +import datetime + +PARALLELIZE = True + +if get_exec_pars().source == CommandSource.ui: + camera_name = "SLG-LCAM-C041_sp" + shared = False + images = 10 + interval = 1000 +else: + camera_name = args[0] + shared = args[1].lower() == "true" + images = int(args[2]) + interval = int(args[3]) + +set_exec_pars(name="camera_snapshot") +path_image = "/image" +path_pid = "/pulse_id" +path_timestamp_str = "/timestamp_str" +snapshotFile = None + +if shared: + cam_server.start(camera_name + "_sp1", shared) +else: + cam_server.start(camera_name) + + +def append_frame(data, stream_value, index): + global path_image + print "Saving frame :", index + append_dataset(path_image, data, index) + append_dataset(path_pid, stream_value.getPulseId(), index) + append_dataset(path_timestamp_str, datetime.datetime.fromtimestamp(stream_value.timestampNanos/1e9).strftime('%Y-%m-%d %H:%M:%S'), index) + + for id in stream_value.identifiers: + try: + val = stream_value.getValue(id) + if id == "image": + pass + elif isinstance(val, PyArray): + append_dataset("/"+id, val, index) + elif isinstance(val, PyLong): + append_dataset("/"+id, int(val), index) + elif isinstance(val, PyFloat): + append_dataset("/"+id, float(val), index) + else: + pass + except: + print id, val + traceback.print_exc() + + print "Saved frame :", index + +tasks = [] + +cam_server.waitNext(10000) +for i in range(images): + if i==0: + stream_value = cam_server.stream.take() + width = cam_server.data.width + height = cam_server.data.height + create_dataset(path_image, 'd', dimensions = [height, width, images]) + create_dataset(path_pid, 'l', dimensions = [images]) + create_dataset(path_timestamp_str, 's', dimensions = [images]) + for id in stream_value.identifiers: + val = stream_value.getValue(id) + if id == "image": + pass + elif id == "processing_parameters": + val = json.loads(val) + for key in val.keys(): + set_attribute(path_image, key, "" if val[key] is None else val[key] ) + elif isinstance(val, PyArray): + create_dataset("/"+id, 'd', dimensions = [images, len(val)]) + elif isinstance(val, PyLong): + create_dataset("/"+id, 'l', dimensions = [images]) + elif isinstance(val, PyFloat): + create_dataset("/"+id, 'd', dimensions = [images]) + else: + print "Unmanaged stream type: ", val, type(val) + pass + + + start = time.time() + stream_value = cam_server.stream.take() + if PARALLELIZE: + tasks.extend( fork((append_frame,(cam_server.data.matrix,stream_value, i)),) ) + else: + append_frame(cam_server.data.matrix, stream_value, i) + + if i< (images-1): + if interval<=0: + cam_server.waitNext(10000) + else: + sleep_time = float(interval)/1000.0 - (time.time()-start) + if (sleep_time>0): + print "Sleeping ", sleep_time + time.sleep(sleep_time) + +print "Waiting finish persisting..." +join(tasks) +print "Done" + + +#Enforce the same timestamp to data & image files. +set_exec_pars(open = False) +data_file = get_exec_pars().path + +set_return(data_file) \ No newline at end of file