47 lines
1.9 KiB
Python
47 lines
1.9 KiB
Python
import jungfrau_utils as ju
|
|
import zmq
|
|
import numpy
|
|
from logging import getLogger
|
|
_logger = getLogger(__name__)
|
|
|
|
flags=0
|
|
|
|
ju_stream_adapter = None
|
|
visualisation_socket = None
|
|
zmq_context = None
|
|
#metadata = {'frame': 68544604, 'is_good_frame': 1, 'daq_rec': 3856, 'pulse_id': 12711246781, 'pedestal_file': '/sf/jungfrau/data/pedestal/JF02T09V02/20210816_183002.h5', 'gain_file': '/sf/jungfrau/config/gainMaps/JF02T09V02/gains.h5', 'number_frames_expected': 10000, 'run_name': '12711240000', 'detector_name': 'JF02T09V02', 'htype': 'array-1.0', 'type': 'uint16', 'shape': [4608, 1024]}
|
|
|
|
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, metadata):
|
|
global ju_stream_adapter, flags,visualisation_socket,zmq_context
|
|
|
|
visualisation = parameters["visualisation"]
|
|
|
|
if ju_stream_adapter is None:
|
|
ju_stream_adapter = ju.StreamAdapter()
|
|
if visualisation:
|
|
zmq_context = zmq.Context(io_threads=4)
|
|
visualisation_socket = zmq_context.socket(zmq.PUB)
|
|
visualisation_socket.connect(parameters["visualisation_socket"])
|
|
visualisation_socket.set_hwm(10)
|
|
|
|
image = ju_stream_adapter.process(image,metadata)
|
|
|
|
if parameters.get("threshold") is not None:
|
|
image[image < parameters.get("threshold")] = 0.0
|
|
|
|
shape = [2,2] if image is None else [image.shape[0],image.shape[1]]
|
|
metadata['shape']=shape
|
|
metadata['pulse_id']=pulse_id
|
|
metadata['type']= str(image.dtype) if (image is not None) else ""
|
|
for key,value in metadata.items():
|
|
if isinstance(value, numpy.integer):
|
|
metadata[key] = int(value)
|
|
|
|
if visualisation_socket is not None:
|
|
if image is not None:
|
|
visualisation_socket.send_json(metadata, flags | zmq.SNDMORE)
|
|
visualisation_socket.send(image, flags, copy=True, track=True)
|
|
|
|
return metadata
|
|
|