March 2023
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from collections import deque
|
||||
from collections import deque, OrderedDict
|
||||
from logging import getLogger
|
||||
from scipy.signal import savgol_filter
|
||||
import numpy as np
|
||||
@@ -67,7 +67,7 @@ def find_edge(data, step_length=50, edge_type="falling", refinement=1):
|
||||
def process(data, pulse_id, timestamp, params):
|
||||
if not initialized:
|
||||
initialize(params)
|
||||
output = {}
|
||||
output = OrderedDict()
|
||||
|
||||
# Read stream inputs
|
||||
prof_sig = data[params["prof_sig"]]
|
||||
@@ -84,6 +84,7 @@ def process(data, pulse_id, timestamp, params):
|
||||
|
||||
except:
|
||||
output[f"{device}:raw_wf"] = prof_sig
|
||||
return None
|
||||
return output # added for intermitent cases with prof_sig shorter than filter window
|
||||
events = data[params["events"]]
|
||||
|
||||
@@ -125,9 +126,11 @@ def process(data, pulse_id, timestamp, params):
|
||||
edge_results["arrival_time_odd"] = edge_results["edge_pos"] * calib
|
||||
except:
|
||||
edge_results["arrival_time_odd"] = calib
|
||||
|
||||
|
||||
# push pulse ID for debuging
|
||||
edge_results["pulse_id"] = pulse_id
|
||||
|
||||
|
||||
#debug just return arrival tim
|
||||
#output[f"{device}:arrival_time"] = edge_results["arrival_time"]
|
||||
#try:
|
||||
@@ -135,8 +138,19 @@ def process(data, pulse_id, timestamp, params):
|
||||
#except:
|
||||
# output[f"{device}:arrival_time_even"] = None
|
||||
# Set bs outputs
|
||||
#log = ""
|
||||
for key, value in edge_results.items():
|
||||
output[f"{device}:{key}"] = value
|
||||
if isinstance(value,np.floating):
|
||||
value=float(value)
|
||||
if isinstance(value,np.integer):
|
||||
value=int(value)
|
||||
if type(value) == list:
|
||||
value = np.array(value)
|
||||
#if isinstance(value,np.ndarray):
|
||||
# log = log + " | " + str(key) + " - " + str(value.dtype) + " - " + str(value.shape)
|
||||
#log = log + " | " + str(key) + " - " + str(type(value))
|
||||
output[f"{device}:{key}"] = value
|
||||
#_logger.info(log)
|
||||
|
||||
#output[f"{device}:raw_wf"] = prof_sig
|
||||
#output[f"{device}:raw_wf_savgol"] = prof_sig_savgol
|
||||
|
||||
@@ -149,9 +149,9 @@ def process(data, pulse_id, timestamp, params):
|
||||
# Set bs outputs
|
||||
output = {}
|
||||
device, _ = params["up"].split(":", 1)
|
||||
output[f"{device}:INTENSITY"] = intensity
|
||||
output[f"{device}:INTENSITY_UJ"] = intensity_uJ
|
||||
output[f"{device}:XPOS"] = xpos
|
||||
output[f"{device}:YPOS"] = ypos
|
||||
|
||||
output[f"{device}:INTENSITY"] = float(intensity)
|
||||
output[f"{device}:INTENSITY_UJ"] = float(intensity_uJ)
|
||||
output[f"{device}:XPOS"] = float(xpos)
|
||||
output[f"{device}:YPOS"] = float(ypos)
|
||||
#_logger.info(str(type(intensity)) + " - " +str(type(intensity_uJ)) + " - " +str(type(xpos)) + " - " +str(type(ypos)) + " - " + " - " +str(xpos) + " - " +str(ypos) + " - " )
|
||||
return output
|
||||
|
||||
@@ -157,10 +157,10 @@ def process(data, pulse_id, timestamp, params):
|
||||
|
||||
# Set bs outputs
|
||||
output = {}
|
||||
output[intensity_ch_name] = intensity
|
||||
output[f"{device}:INTENSITY_UJ"] = intensity_uJ
|
||||
output[xpos_ch_name] = xpos
|
||||
output[ypos_ch_name] = ypos
|
||||
output[intensity_ch_name] = float(intensity)
|
||||
output[f"{device}:INTENSITY_UJ"] = float(intensity_uJ)
|
||||
output[xpos_ch_name] = float(xpos)
|
||||
output[ypos_ch_name] = float(ypos)
|
||||
|
||||
intensity_pv, xpos_pv, ypos_pv = create_thread_pvs([intensity_ch_name, xpos_ch_name, ypos_ch_name])
|
||||
if epics_lock.acquire(False):
|
||||
|
||||
@@ -5,7 +5,9 @@ from cam_server.pipeline.data_processing import functions, processor
|
||||
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata):
|
||||
r = processor.process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata)
|
||||
ret = OrderedDict()
|
||||
channels = ["intensity","x_center_of_mass","x_fwhm","x_rms","x_fit_amplitude", "x_fit_mean","x_fit_offset","x_fit_standard_deviation","x_profile","y_center_of_mass","y_fwhm","y_rms","y_fit_amplitude", "y_fit_mean","y_fit_offset","y_fit_standard_deviation","y_profile","gr_x_fit_amplitude", "gr_x_fit_mean","gr_x_fit_offset","gr_x_fit_standard_deviation","gr_x_profile","gr_y_fit_amplitude", "gr_y_fit_mean","gr_y_fit_offset","gr_y_fit_standard_deviation","gr_y_profile"]
|
||||
#channels = ["intensity","x_center_of_mass","x_fwhm","x_rms","x_fit_amplitude", "x_fit_mean","x_fit_offset","x_fit_standard_deviation","x_profile","y_center_of_mass","y_fwhm","y_rms","y_fit_amplitude", "y_fit_mean","y_fit_offset","y_fit_standard_deviation","y_profile","gr_x_fit_amplitude", "gr_x_fit_mean","gr_x_fit_offset","gr_x_fit_standard_deviation","gr_x_profile","gr_y_fit_amplitude", "gr_y_fit_mean","gr_y_fit_offset","gr_y_fit_standard_deviation","gr_y_profile"]
|
||||
#removed "gr_x_profile" and "gr_y_profile"
|
||||
channels = ["intensity","x_center_of_mass","x_fwhm","x_rms","x_fit_amplitude", "x_fit_mean","x_fit_offset","x_fit_standard_deviation","x_profile","y_center_of_mass","y_fwhm","y_rms","y_fit_amplitude", "y_fit_mean","y_fit_offset","y_fit_standard_deviation","y_profile","gr_x_fit_amplitude", "gr_x_fit_mean","gr_x_fit_offset","gr_x_fit_standard_deviation","gr_y_fit_amplitude", "gr_y_fit_mean","gr_y_fit_offset","gr_y_fit_standard_deviation"]
|
||||
prefix = parameters["camera_name"]
|
||||
for c in channels:
|
||||
ret[prefix+":"+c] = r[c]
|
||||
|
||||
@@ -14,6 +14,7 @@ import scipy.signal
|
||||
import scipy.optimize
|
||||
import numba
|
||||
import time
|
||||
import sys
|
||||
from threading import Thread
|
||||
|
||||
numba.set_num_threads(4)
|
||||
@@ -77,14 +78,14 @@ def initialize(params):
|
||||
global channel_names, spectra_buffer
|
||||
# fit.recompile()
|
||||
camera_name = params["camera_name"]
|
||||
output_pv_name = camera_name + ":SPECTRUM_Y"
|
||||
output_pv_name = params["e_int_name"]
|
||||
axis_pv_name = params["e_axis_name"]
|
||||
center_pv_name = camera_name + ":FIT-COM"
|
||||
fwhm_pv_name = camera_name + ":FIT-FWHM"
|
||||
fit_rms_pv_name = camera_name + ":FIT-RMS"
|
||||
fit_res_pv_name = camera_name + ":FIT-RES"
|
||||
ymin_pv_name = camera_name + ":SPC_ROI_YMIN"
|
||||
ymax_pv_name = camera_name + ":SPC_ROI_YMAX"
|
||||
axis_pv_name = camera_name + ":SPECTRUM_X"
|
||||
com_pv_name = camera_name + ":SPECT-COM"
|
||||
std_pv_name = camera_name + ":SPECT-RMS"
|
||||
res_pv_name = camera_name + ":SPECT-RES"
|
||||
@@ -94,6 +95,7 @@ def initialize(params):
|
||||
|
||||
|
||||
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None, background=None):
|
||||
try:
|
||||
global roi, initialized, sent_pid, nrows, axis
|
||||
global channel_names, buffer
|
||||
|
||||
@@ -177,9 +179,9 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
|
||||
spectrum_sum = np.sum(spectrum)
|
||||
|
||||
# outputs
|
||||
processed_data[camera_name + ":SPECTRUM_Y"] = spectrum
|
||||
processed_data[parameters["e_int_name"]] = spectrum
|
||||
processed_data[camera_name + ":SPECTRUM_Y_SUM"] = spectrum_sum
|
||||
processed_data[camera_name + ":SPECTRUM_X"] = axis
|
||||
processed_data[parameters["e_axis_name"]] = axis
|
||||
processed_data[camera_name + ":FIT-COM"] = np.float64(center)
|
||||
processed_data[camera_name + ":FIT-FWHM"] = np.float64(2.355 * sigma)
|
||||
processed_data[camera_name + ":FIT-RMS"] = np.float64(sigma)
|
||||
@@ -191,10 +193,12 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
|
||||
try:
|
||||
if pulse_id > sent_pid:
|
||||
sent_pid = pulse_id
|
||||
buffer.append((processed_data[camera_name + ":SPECTRUM_Y"], processed_data[camera_name + ":FIT-COM"],
|
||||
buffer.append((processed_data[parameters["e_int_name"]], processed_data[camera_name + ":FIT-COM"],
|
||||
processed_data[camera_name + ":FIT-FWHM"], processed_data[camera_name + ":SPECT-COM"],
|
||||
processed_data[camera_name + ":SPECT-RMS"],processed_data[camera_name + ":FIT-RMS"],processed_data[camera_name + ":FIT-RES"],processed_data[camera_name + ":SPECT-RES"]))
|
||||
processed_data[camera_name + ":SPECT-RMS"],processed_data[camera_name + ":FIT-RMS"],
|
||||
processed_data[camera_name + ":FIT-RES"],processed_data[camera_name + ":SPECT-RES"] ))
|
||||
finally:
|
||||
epics_lock.release()
|
||||
return processed_data
|
||||
|
||||
except Exception as ex:
|
||||
_logger.warning(str(sys.exc_info))
|
||||
@@ -30,7 +30,7 @@ def update_avg_spectrum(y_pvname, m_pvname, w_pvname):
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
if len(spectra_buffer) != spectra_buffer.maxlen:intervension
|
||||
if len(spectra_buffer) != spectra_buffer.maxlen:
|
||||
continue
|
||||
|
||||
_buffer = np.array(spectra_buffer)
|
||||
|
||||
Reference in New Issue
Block a user