diff --git a/config/devices.properties b/config/devices.properties index aee991f..fb1560a 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -2,7 +2,7 @@ virtual_accelerator_set=ch.psi.pshell.epics.ChannelDouble|VA-SINBC01-MCRX070:I-S virtual_accelerator_read=ch.psi.pshell.epics.ChannelDouble|VA-SINBC01-DBPM100:X1|||true gun_solenoid=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:I-SET SINEG01-MSOL130:I-READ|||true gun_phase=ch.psi.pshell.epics.Positioner|SINEG01-RSYS:SET-BEAM-PHASE SINEG01-RSYS:GET-BEAM-PHASE|||true -SINSB01_phase=ch.psi.pshell.epics.Positioner|VA-SINSB01-RSYS100:SET-BEAM-PHASE VA-SINSB01-RSYS100:GET-BEAM-PHASE|||true +#SINSB01_phase=ch.psi.pshell.epics.Positioner|VA-SINSB01-RSYS100:SET-BEAM-PHASE VA-SINSB01-RSYS100:GET-BEAM-PHASE|||true dispatcher=ch.psi.pshell.bs.Dispatcher|https://dispatcher-api.psi.ch/sf||| stream=ch.psi.pshell.bs.Stream|dispatcher|||true #ref10=ch.psi.pshell.bs.Scalar|stream SINEG01-RLLE-REF10:SIG-PHASE-AVG 10||| @@ -45,5 +45,5 @@ gsry=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:ROT_Y_SP SINEG01-MSOL130:ROT camtool=ch.psi.pshell.bs.Camtool|localhost:10005||| cam_server=ch.psi.pshell.bs.PipelineServer|sf-daqsync-01:8889||| #SINEG01-DBPM340:Q=ch.psi.pshell.device.Averager|SINEG01-DBPM340:Q|||true -adc_xh1=ch.psi.pshell.epics.ChannelInteger|SARFE10-PBPG050:HAMP-014-x-h1-DATA-SUM|||true -adc_yh2=ch.psi.pshell.epics.ChannelInteger|SARFE10-PBPG050:HAMP-011-y-h2-DATA-SUM|||true +#adc_xh1=ch.psi.pshell.epics.ChannelInteger|SARFE10-PBPG050:HAMP-014-x-h1-DATA-SUM|||true +#adc_yh2=ch.psi.pshell.epics.ChannelInteger|SARFE10-PBPG050:HAMP-011-y-h2-DATA-SUM|||true diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 966ba43..91775d3 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,4 +1,4 @@ -#Wed Nov 15 08:34:00 CET 2017 +#Wed Nov 15 12:07:39 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= @@ -9,11 +9,11 @@ colormapMin=86.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1628 -imageWidth=1280 +imageHeight=1200 +imageWidth=1246 invert=false -regionStartX=865 -regionStartY=267 +regionStartX=304 +regionStartY=8 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 @@ -24,9 +24,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-145.62499649229636 -spatialCalOffsetY=-440.5890253136218 -spatialCalScaleX=-8.737659322804419 -spatialCalScaleY=-8.834898186495984 +spatialCalOffsetX=-456.693006929345 +spatialCalOffsetY=-219.4442130289473 +spatialCalScaleX=-14.937285913160144 +spatialCalScaleY=-11.834319139832656 spatialCalUnits= transpose=false diff --git a/devices/cam1.properties b/devices/cam1.properties index 0303c5e..58e80df 100644 --- a/devices/cam1.properties +++ b/devices/cam1.properties @@ -1,4 +1,4 @@ -#Thu Oct 26 19:06:08 CEST 2017 +#Wed Nov 15 11:06:12 CET 2017 colormap=Temperature colormapAutomatic=true colormapMax=30000.0 @@ -6,13 +6,13 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1628 -imageWidth=1280 +imageHeight=2160 +imageWidth=2560 invert=false offsetX=0.0 offsetY=0.0 -regionStartX=865 -regionStartY=267 +regionStartX=1 +regionStartY=1 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 diff --git a/devices/cam_server.properties b/devices/cam_server.properties index cc14a75..bfb80ba 100644 --- a/devices/cam_server.properties +++ b/devices/cam_server.properties @@ -1,4 +1,4 @@ -#Wed Nov 15 09:13:12 CET 2017 +#Wed Nov 15 11:25:21 CET 2017 colormap=Flame colormapAutomatic=true colormapMax=NaN diff --git a/script/Photonics/PbpgPosScan.py b/script/Photonics/PbpgPosScan.py index 617c013..c40b0ff 100644 --- a/script/Photonics/PbpgPosScan.py +++ b/script/Photonics/PbpgPosScan.py @@ -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 diff --git a/script/Tools/save_snapshot_mult.py b/script/Tools/save_snapshot_mult.py index 8c9292b..3dd5946 100644 --- a/script/Tools/save_snapshot_mult.py +++ b/script/Tools/save_snapshot_mult.py @@ -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) \ No newline at end of file