48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
from cam_server.pipeline.data_processing import functions, processor
|
|
from cam_server.utils import create_thread_pvs
|
|
from collections import OrderedDict
|
|
import numpy as np
|
|
|
|
initialized = False
|
|
offset_x = offset_y = None
|
|
background = None
|
|
x_axis_px = y_axis_px = None
|
|
|
|
|
|
def initialize(parameters, image):
|
|
global background, offset_x, offset_y, x_axis_px, y_axis_px, initialized
|
|
camera_name = parameters["camera_name"]
|
|
offset_x_ch, offset_y_ch = create_thread_pvs([camera_name + ":REGIONX_START", camera_name + ":REGIONY_START"])
|
|
offset_x_ch.wait_for_connection()
|
|
offset_y_ch.wait_for_connection()
|
|
offset_x = offset_x_ch.get()
|
|
offset_y = offset_y_ch.get()
|
|
background = parameters.get("background_data")
|
|
if background is not None:
|
|
background = background.astype(int)
|
|
#Axis in pixel
|
|
ysize, xsize = image.shape
|
|
x_axis_px = np.array(range(xsize)).astype('float')
|
|
y_axis_px = np.array(range(ysize)).astype('float')
|
|
initialized = True
|
|
|
|
|
|
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
|
|
if not initialized:
|
|
initialize(parameters, image)
|
|
|
|
r = processor.process_image(image, pulse_id, timestamp, x_axis_px, y_axis_px, parameters, bsdata)
|
|
camera_name = parameters["camera_name"]
|
|
|
|
ret = OrderedDict()
|
|
channels = ["intensity", "x_fwhm", "x_fit_amplitude", "x_fit_mean", "x_fit_offset", "x_fit_standard_deviation",
|
|
"y_fwhm", "y_fit_amplitude", "y_fit_mean", "y_fit_offset", "y_fit_standard_deviation"]
|
|
prefix = camera_name
|
|
for c in channels:
|
|
ret[prefix + ":" + c] = r[c]
|
|
|
|
ret[prefix + ":x_fit_mean_ccd_px"] = r["x_fit_mean"] + offset_x
|
|
ret[prefix + ":y_fit_mean_ccd_px"] = r["y_fit_mean"] + offset_y
|
|
ret[prefix + ":roi_x"] = offset_x
|
|
ret[prefix + ":roi_y"] = offset_y
|
|
return ret |