Startup
This commit is contained in:
@@ -6,8 +6,8 @@ print "Starting"
|
||||
|
||||
|
||||
#Creating averaging devices
|
||||
av_adc_xh1 = create_averager(adc_xh1, count = 10, interval = -1, name = "av_adc_xh1")
|
||||
av_adc_xh2 = create_averager(adc_yh2, count = 10, interval = -1, name = "av_adc_xh2")
|
||||
av_adc_xh1 = create_averager("ca://SARFE10-PBPG050:HAMP-014-x-h1-DATA-SUM", count = 10, interval = -1, name = "av_adc_xh1")
|
||||
av_adc_xh2 = create_averager("ca://SARFE10-PBPG050:HAMP-011-y-h2-DATA-SUM", count = 10, interval = -1, name = "av_adc_xh2")
|
||||
av_adc_xh2.monitored = True
|
||||
|
||||
#The actuals scan
|
||||
|
||||
@@ -6,12 +6,11 @@ import json
|
||||
import traceback
|
||||
import datetime
|
||||
|
||||
PARALLELIZE = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
camera_name = "SARBD02-DSCR050_sp1" # "SLG-LCAM-C041_sp"
|
||||
shared = True
|
||||
images = 10
|
||||
images = 1
|
||||
interval = -1
|
||||
roi = "" #"[540, 200, 430,100]"
|
||||
else:
|
||||
@@ -23,16 +22,9 @@ else:
|
||||
|
||||
|
||||
set_exec_pars(name="camera_snapshot")
|
||||
path_image = "/image"
|
||||
path_pid = "/pulse_id"
|
||||
path_timestamp_str = "/timestamp_str"
|
||||
snapshotFile = None
|
||||
|
||||
|
||||
cam_server.start(camera_name, shared)
|
||||
|
||||
|
||||
|
||||
if roi is not None and len(roi.strip())>0:
|
||||
roi = json.loads(roi)
|
||||
cam_server.setRoi(roi[0], roi[2], roi[1], roi[3])
|
||||
@@ -44,15 +36,11 @@ if roi is not None and len(roi.strip())>0:
|
||||
else:
|
||||
cam_server.waitNext(10000)
|
||||
|
||||
width = cam_server.data.width
|
||||
height = cam_server.data.height
|
||||
type_image = 'f'
|
||||
|
||||
def create_tables(stream_value):
|
||||
global width, height, type_image
|
||||
create_dataset(path_image, type_image, dimensions = [images, height, width])
|
||||
create_dataset(path_pid, 'l', dimensions = [images])
|
||||
create_dataset(path_timestamp_str, 's', dimensions = [images])
|
||||
def _create_tables( stream_value, paths, data_type, shape):
|
||||
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])
|
||||
for id in stream_value.identifiers:
|
||||
val = stream_value.getValue(id)
|
||||
if id == "image":
|
||||
@@ -60,7 +48,7 @@ def create_tables(stream_value):
|
||||
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] )
|
||||
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)])
|
||||
elif isinstance(val, PyLong):
|
||||
@@ -72,13 +60,12 @@ def create_tables(stream_value):
|
||||
pass
|
||||
|
||||
|
||||
def append_frame(data, stream_value, index):
|
||||
global path_image, width, height, type_image
|
||||
def _append_frame(stream_value, index, paths, data_type, shape):
|
||||
print "Saving frame :", index
|
||||
#append_dataset(path_image, data, index, type = type_image)
|
||||
append_dataset(path_image, stream_value.getValue("image"),[index,0,0], type = type_image, shape=[1, height, width])
|
||||
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)
|
||||
#append_dataset(paths["image"], data, index, type = data_type)
|
||||
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)
|
||||
|
||||
for id in stream_value.identifiers:
|
||||
try:
|
||||
@@ -97,41 +84,59 @@ def append_frame(data, stream_value, index):
|
||||
print id, val
|
||||
traceback.print_exc()
|
||||
|
||||
print "Saved frame :", index
|
||||
print "Saved frame: ", index
|
||||
|
||||
def save_camera(camera_name, shared = False, server = cam_server, 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"}
|
||||
shape = [stream_value.getValue("height"),stream_value.getValue("width")]
|
||||
|
||||
tasks = []
|
||||
cam_server.paused = True
|
||||
|
||||
try:
|
||||
for i in range(images):
|
||||
if i==0:
|
||||
create_tables(cam_server.stream.take())
|
||||
data_type = type(stream_value.getValue("image")[0])
|
||||
if data_type== float: data_type = 'f'
|
||||
elif data_type == short: data_type = 'h'
|
||||
elif data_type == int: data_type = 'i'
|
||||
elif data_type == long: data_type = 'l'
|
||||
elif data_type == byte: data_type = 'b'
|
||||
else: data_type = 'd'
|
||||
print "Data type: ", data_type
|
||||
|
||||
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.stream.waitCacheChange(10000)
|
||||
tasks = []
|
||||
if pause:
|
||||
server.paused = True
|
||||
try:
|
||||
for i in range(images):
|
||||
if i==0:
|
||||
_create_tables(stream_value, paths, data_type, shape)
|
||||
|
||||
start = time.time()
|
||||
stream_value = server.stream.take()
|
||||
if parallel:
|
||||
tasks.extend( fork((_append_frame,(stream_value, i, paths, data_type, shape)),) )
|
||||
else:
|
||||
sleep_time = float(interval)/1000.0 - (time.time()-start)
|
||||
time.sleep(max(sleep_time,0))
|
||||
finally:
|
||||
cam_server.paused = False
|
||||
pass
|
||||
_append_frame(stream_value, i, paths, data_type, shape)
|
||||
|
||||
if i< (images-1):
|
||||
if interval<=0:
|
||||
server.stream.waitCacheChange(10000)
|
||||
else:
|
||||
sleep_time = float(interval)/1000.0 - (time.time()-start)
|
||||
time.sleep(max(sleep_time,0))
|
||||
finally:
|
||||
if pause:
|
||||
server.paused = False
|
||||
pass
|
||||
|
||||
print "Waiting finish persisting..."
|
||||
join(tasks)
|
||||
print "Done"
|
||||
|
||||
print "Waiting finish persisting..."
|
||||
join(tasks)
|
||||
print "Done"
|
||||
save_camera(camera_name, shared, cam_server, images, interval, True, True)
|
||||
|
||||
|
||||
#Enforce the same timestamp to data & image files.
|
||||
set_exec_pars(open = False)
|
||||
data_file = get_exec_pars().path
|
||||
|
||||
set_return(data_file)
|
||||
Reference in New Issue
Block a user