From fa5cd8e4084de261a437c89566013c7e0a8efa9b Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Nov 2017 08:53:26 +0100 Subject: [PATCH] Startup --- config/mail.properties | 9 ++++ script/Photonics/KValueScan.py | 38 ++++++++++++++++ script/Photonics/PhaseShifterScan.py | 38 ++++++++++++++++ script/Tools/save_snapshot.py | 55 +++++++++++++++++++++++ script/Tools/save_snapshot_client.py | 10 +++++ script/save_snapshot.py | 56 +++++++++++++++++++++++ script/test/SaveCamera.py | 66 ++++++++++++++++++++++++++++ 7 files changed, 272 insertions(+) create mode 100644 config/mail.properties create mode 100644 script/Photonics/KValueScan.py create mode 100644 script/Photonics/PhaseShifterScan.py create mode 100644 script/Tools/save_snapshot.py create mode 100644 script/Tools/save_snapshot_client.py create mode 100644 script/save_snapshot.py create mode 100644 script/test/SaveCamera.py diff --git a/config/mail.properties b/config/mail.properties new file mode 100644 index 0000000..3d9d609 --- /dev/null +++ b/config/mail.properties @@ -0,0 +1,9 @@ +#Mon Oct 23 10:33:20 CEST 2017 +auth=None +from= +host= +port=0 +pwd= +smsSuffix=@sms.switch.ch +to= +usr= diff --git a/script/Photonics/KValueScan.py b/script/Photonics/KValueScan.py new file mode 100644 index 0000000..fe2655e --- /dev/null +++ b/script/Photonics/KValueScan.py @@ -0,0 +1,38 @@ +CAMERA = "SARBD01-DSCR110" +GAP = "SARUN15-UIND030" +SAMPLES = 20 +TOLERANCE = 0.01 +TIMEOUT = 10.0 + +#shared stream - make sure the camera is running on a screenpanel on the same console! +cam_server.start(CAMERA + "_sp1", True) + +intensity = cam_server.stream.getChild("intensity") + +gap = Channel(GAP + ":K_SET", alias = "gap") +#readout = Channel(GAP + ":GAP") + +av = create_averager(intensity, SAMPLES, interval = -1, name = None) + +def before(position, scan): + caput(GAP + ":GO", 1) + start = time.time() +# while abs(readout.read() - gap.read()) > TOLERANCE: + time.sleep(0.1) +# if time.time() - start > TIMEOUT: +# raise Exception ("Timeout waiting gap change") + +ret = lscan (gap, av, 1.195, 1.205, 21, latency=1.0, before_read=before) + + +#run("CPython/wrapper") +#xdata = ret.getPositions(0) +#ydata = ret.getReadable(0) +#(fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(ydata , xdata) +#print fit_amplitude, fit_phase_deg, fit_offset +#plt = get_plots()[0] +#if plt is not None: +# plt.addSeries(LinePlotErrorSeries("fit")) +# plt.getSeries(1).setData(fit_x, fit_y) +# plt.getSeries(1).setPointsVisible(False) +# plt.setLegendVisible(True) diff --git a/script/Photonics/PhaseShifterScan.py b/script/Photonics/PhaseShifterScan.py new file mode 100644 index 0000000..992954b --- /dev/null +++ b/script/Photonics/PhaseShifterScan.py @@ -0,0 +1,38 @@ +CAMERA = "SARBD01-DSCR110" +GAP = "SARUN10-UPHS060" +SAMPLES = 20 +TOLERANCE = 0.01 +TIMEOUT = 10.0 + +#shared stream - make sure the camera is running on a screenpanel on the same console! +cam_server.start(CAMERA + "_sp1", True) + +intensity = cam_server.stream.getChild("intensity") + +gap = Channel(GAP + ":GAP_SP", alias = "gap") +readout = Channel(GAP + ":GAP") + +av = create_averager(intensity, SAMPLES, interval = -1, name = None) + +def before(position, scan): + caput(GAP + ":GO", 1) + start = time.time() + while abs(readout.read() - gap.read()) > TOLERANCE: + time.sleep(0.1) + if time.time() - start > TIMEOUT: + raise Exception ("Timeout waiting gap change") + +ret = lscan (gap, av, 17.5, 20, 40, latency=1.0, before_read=before) + + +#run("CPython/wrapper") +#xdata = ret.getPositions(0) +#ydata = ret.getReadable(0) +#(fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(ydata , xdata) +#print fit_amplitude, fit_phase_deg, fit_offset +#plt = get_plots()[0] +#if plt is not None: +# plt.addSeries(LinePlotErrorSeries("fit")) +# plt.getSeries(1).setData(fit_x, fit_y) +# plt.getSeries(1).setPointsVisible(False) +# plt.setLegendVisible(True) diff --git a/script/Tools/save_snapshot.py b/script/Tools/save_snapshot.py new file mode 100644 index 0000000..4f85bb8 --- /dev/null +++ b/script/Tools/save_snapshot.py @@ -0,0 +1,55 @@ +import ch.psi.pshell.imaging.ImageBuffer as ImageBuffer +import java.math.BigInteger as BigInteger +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" +else: + camera_name = args[0] + shared = args[1].lower() == "true" + logbook = args[2] + comment = args[3] + +set_exec_pars(name="camera_snapshot") +path = "/image" +snapshotFile = None + +if shared: + cam_server.start(camera_name + "_sp1", shared) +else: + cam_server.start(camera_name) + +cam_server.waitNext(10000) + +stream_value = cam_server.stream.take() + +save_dataset(path, cam_server.data.matrix) +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, key, "" if val[key] is None else val[key] ) + elif isinstance(val, PyArray): + save_dataset("/"+id, val) + elif isinstance(val, PyLong): + save_dataset("/"+id, int(val)) + 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"; +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) diff --git a/script/Tools/save_snapshot_client.py b/script/Tools/save_snapshot_client.py new file mode 100644 index 0000000..22f0c40 --- /dev/null +++ b/script/Tools/save_snapshot_client.py @@ -0,0 +1,10 @@ + +def save_snapshot(camera_name = "SLG-LCAM-C041", shared = True, 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) + "'") + r = requests.get(url) + if r.status_code != 200: + raise Exception(r.text) + +save_snapshot() \ No newline at end of file diff --git a/script/save_snapshot.py b/script/save_snapshot.py new file mode 100644 index 0000000..65b2fea --- /dev/null +++ b/script/save_snapshot.py @@ -0,0 +1,56 @@ +import ch.psi.pshell.imaging.ImageBuffer as ImageBuffer +import java.math.BigInteger as BigInteger +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" +else: + camera_name = args[0] + shared = args[1].lower == "true" + logbook = args[2] + comment = args[3] + + +set_exec_pars(name="camera_snapshot") +path = "/image" +snapshotFile = None + +if shared: + cam_server.start(camera_name + "_sp1", shared) +else: + cam_server.start(camera_name) + +cam_server.waitNext(10000) + +stream_value = cam_server.stream.take() + +save_dataset(path, cam_server.data.matrix) +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, key, "" if val[key] is None else val[key] ) + elif isinstance(val, PyArray): + save_dataset("/"+id, val) + elif isinstance(val, PyLong): + save_dataset("/"+id, int(val)) + 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"; +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) diff --git a/script/test/SaveCamera.py b/script/test/SaveCamera.py new file mode 100644 index 0000000..fe1e131 --- /dev/null +++ b/script/test/SaveCamera.py @@ -0,0 +1,66 @@ +import ch.psi.pshell.imaging.ImageBuffer as ImageBuffer +import java.math.BigInteger as BigInteger +import org.python.core.PyLong as PyLong +import json + +if get_exec_pars().source == CommandSource.ui: + camera_name = "SLG-LCAM-C041" +else: + camera_name =args[0] + + +set_exec_pars(name="snapshot") +path = "/image" +snapshotFile = None + + + + +#cam_server.start(camera_name + "_sp", camera_name + "_sp1") +cam_server.start(camera_name + "_sp1", True) +cam_server.waitNext(10000) + +stream_value = cam_server.stream.take() + +save_dataset(path, cam_server.data.matrix) +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, key, "" if val[key] is None else val[key] ) + elif isinstance(val, PyArray): + save_dataset("/"+id, val) + elif isinstance(val, PyLong): + save_dataset("/"+id, int(val)) + else: + print id, val + set_attribute(path, id, val) + + + +#writeFrameMetadata(path, id); + +set_exec_pars(open = False) +#Enforce the same timestamp to data & image files. +snapshot_file = get_exec_pars().path+ ".png"; + + +#ImageBuffer.saveImage(cam_server.output, snapshot_file, "png"); + +""" +StringBuilder message = new StringBuilder(); +message.append("Camera: ").append(cameraName).append(" ("). + append((server != null) ? "server" : "direct").append(")").append("\n"); +message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); +message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); +message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); +message.append("Comment: ").append(textComment.getText()).append("\n"); +if ((fitOv != null) && (fitOv.length > 5)) { + Overlays.Text text = (Overlays.Text) fitOv[5]; + message.append(text.getText()).append("\n"); +} +elog((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); +""" \ No newline at end of file