Startup
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user