This commit is contained in:
root
2017-11-15 16:26:24 +01:00
parent 2c73e72037
commit 32ab7cb2db
3 changed files with 38 additions and 32 deletions

View File

@@ -1,9 +1,9 @@
#Wed Nov 15 12:07:39 CET 2017
#Wed Nov 15 16:07:50 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=Flame
colormapAutomatic=false
colormapAutomatic=true
colormapMax=10239.0
colormapMin=86.0
flipHorizontally=false
@@ -24,9 +24,9 @@ rotation=0.0
rotationCrop=false
scale=1.0
serverURL=localhost\:10000
spatialCalOffsetX=-456.693006929345
spatialCalOffsetY=-219.4442130289473
spatialCalScaleX=-14.937285913160144
spatialCalScaleY=-11.834319139832656
spatialCalOffsetX=-50.075987841945285
spatialCalOffsetY=-50.10141987829615
spatialCalScaleX=-1.0
spatialCalScaleY=-1.0
spatialCalUnits=
transpose=false

View File

@@ -1,6 +1,7 @@
run("Devices/Elements")
def _create_tables( stream_value, paths, data_type, shape):
def _create_tables(paths, stream_value, data_type, shape):
root = paths["root"]
create_dataset(paths["image"], data_type, dimensions = [images, shape[0], shape[1]])
create_dataset(paths["pid"], 'l', dimensions = [images])
create_dataset(paths["timestamp_str"], 's', dimensions = [images])
@@ -13,19 +14,20 @@ def _create_tables( stream_value, paths, data_type, shape):
for key in val.keys():
set_attribute(paths["image"], key, "" if val[key] is None else val[key] )
elif isinstance(val, PyArray):
create_dataset("/"+id, 'd', dimensions = [images, len(val)])
create_dataset(root + id, 'd', dimensions = [images, len(val)])
elif isinstance(val, PyLong):
create_dataset("/"+id, 'l', dimensions = [images])
create_dataset(root + id, 'l', dimensions = [images])
elif isinstance(val, PyFloat):
create_dataset("/"+id, 'd', dimensions = [images])
create_dataset(root + id, 'd', dimensions = [images])
else:
print "Unmanaged stream type: ", val, type(val)
pass
def _append_frame(stream_value, index, paths, data_type, shape):
def _append_frame(paths, stream_value, index, data_type, shape):
print "Saving frame :", index
#append_dataset(paths["image"], data, index, type = data_type)
root = paths["root"]
append_dataset(paths["image"], stream_value.getValue("image"),[index,0,0], type = data_type, shape=[1, shape[0], shape[1]])
append_dataset(paths["pid"], stream_value.getPulseId(), index)
append_dataset(paths["timestamp_str"], datetime.datetime.fromtimestamp(stream_value.timestampNanos/1e9).strftime('%Y-%m-%d %H:%M:%S'), index)
@@ -36,11 +38,11 @@ def _append_frame(stream_value, index, paths, data_type, shape):
if id == "image":
pass
elif isinstance(val, PyArray):
append_dataset("/"+id, val, index)
append_dataset(root + id, val, index)
elif isinstance(val, PyLong):
append_dataset("/"+id, int(val), index)
append_dataset(root + id, int(val), index)
elif isinstance(val, PyFloat):
append_dataset("/"+id, float(val), index)
append_dataset(root + id, float(val), index)
else:
pass
except:
@@ -50,25 +52,27 @@ def _append_frame(stream_value, index, paths, data_type, shape):
print "Saved frame: ", index
def _write_metadata(camera_name, shared = False, images = 1, interval = -1):
set_attribute("/", "Camera", camera_name)
set_attribute("/", "Shared", shared)
set_attribute("/", "Images", images)
set_attribute("/", "Interval", interval)
def _write_metadata(paths, camera_name, shared = False, images = 1, interval = -1):
root = paths["root"]
set_attribute(root, "Name", camera_name)
set_attribute(root, "Shared", shared)
set_attribute(root, "Images", images)
set_attribute(root, "Interval", interval)
cam_type = get_camera_type(camera_name)
set_attribute("/", "Type", cam_type)
set_attribute(root, "Type", cam_type)
if cam_type=="ELECTRONS":
set_attribute("/", "Screen", caget(camera_name + (":POSITION" if (camera_name.startswith("DSRM")) else ":GET_SCREEN1_POS"), 's'))
set_attribute("/", "Filter", caget(camera_name + ":GET_FILTER", 's'))
set_attribute(root, "Screen", caget(camera_name + (":POSITION" if (camera_name.startswith("DSRM")) else ":GET_SCREEN1_POS"), 's'))
set_attribute(root, "Filter", caget(camera_name + ":GET_FILTER", 's'))
def save_camera_data(server, camera_name, shared = False, images = 1, interval = -1, parallel = True, pause = False):
def save_camera_data(server, camera_name, shared = False, root = "/", images = 1, interval = -1, parallel = True, pause = False):
stream_value = server.stream.take()
if stream_value is None:
server.waitNext(10000)
stream_value = server.stream.take()
paths = {"image":"/image", "pid":"/pulse_id", "timestamp_str":"/timestamp_str"}
if not root.endswith('/'):
root = root + "/"
paths = {"root": root, "image":root+"image", "pid":root+"/pulse_id", "timestamp_str":root+"/timestamp_str"}
shape = [stream_value.getValue("height"),stream_value.getValue("width")]
data_type = stream_value.getValue("image").typecode
@@ -77,16 +81,16 @@ def save_camera_data(server, camera_name, shared = False, images = 1, interval =
server.paused = True
try:
for i in range(images):
if i==0:
_write_metadata(camera_name, shared, images, interval)
_create_tables(stream_value, paths, data_type, shape)
if i==0:
_create_tables(paths, stream_value, data_type, shape)
_write_metadata(paths, camera_name, shared, images, interval)
start = time.time()
stream_value = server.stream.take()
if parallel:
tasks.extend( fork((_append_frame,(stream_value, i, paths, data_type, shape)),) )
tasks.extend( fork((_append_frame,(paths, stream_value, i, data_type, shape)),) )
else:
_append_frame(stream_value, i, paths, data_type, shape)
_append_frame(paths, stream_value, i, data_type, shape)
if i< (images-1):
if interval<=0:

View File

@@ -10,7 +10,7 @@ import datetime
if get_exec_pars().source == CommandSource.ui:
camera_name = "SARBD02-DSCR050" # "SLG-LCAM-C041_sp"
shared = True
images = 1
images = 5
interval = -1
roi = "" #"[540, 200, 430,100]"
else:
@@ -23,6 +23,8 @@ else:
run("Tools/CameraTools")
set_exec_pars(name="camera_snapshot")
root = "/camera1"
parallel = True
cam_server.start(camera_name + "_sp1" if shared else camera_name, shared)
@@ -37,7 +39,7 @@ if roi is not None and len(roi.strip())>0:
else:
cam_server.waitNext(10000)
save_camera_data(cam_server, camera_name, shared, images, interval, parallel=True, pause=True)
save_camera_data(cam_server, camera_name, shared, root, images, interval, parallel, pause=True)
cam_server.stop()