Files
sf-op/script/save_snapshot.py
2017-11-02 08:53:26 +01:00

57 lines
1.6 KiB
Python

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)