01.2025
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
{
|
||||
"camera_calibration": null,
|
||||
"camera_calibration": {
|
||||
"reference_marker": [
|
||||
512,
|
||||
140,
|
||||
4223,
|
||||
3875
|
||||
],
|
||||
"reference_marker_width": 20000.0,
|
||||
"reference_marker_height": 20000.0,
|
||||
"angle_horizontal": 0.0,
|
||||
"angle_vertical": 0.0
|
||||
},
|
||||
"mirror_x": false,
|
||||
"mirror_y": false,
|
||||
"rotate": 0,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"camera_calibration": null,
|
||||
"mirror_x": false,
|
||||
"mirror_y": false,
|
||||
"rotate": 0,
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
{
|
||||
"camera_calibration": {
|
||||
"reference_marker": [
|
||||
575,
|
||||
360,
|
||||
650,
|
||||
430
|
||||
],
|
||||
"reference_marker_width": 2000.0,
|
||||
"reference_marker_height": 2000.0,
|
||||
"angle_horizontal": 0.0,
|
||||
"angle_vertical": 0.0
|
||||
},
|
||||
"mirror_x": false,
|
||||
"mirror_y": false,
|
||||
"rotate": 0,
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
{
|
||||
"camera_calibration": null,
|
||||
"camera_calibration": {
|
||||
"reference_marker": [
|
||||
230,
|
||||
195,
|
||||
1405,
|
||||
1025
|
||||
],
|
||||
"reference_marker_width": 20000.0,
|
||||
"reference_marker_height": 20000.0,
|
||||
"angle_horizontal": 0.0,
|
||||
"angle_vertical": 0.0
|
||||
},
|
||||
"mirror_x": false,
|
||||
"mirror_y": false,
|
||||
"rotate": 0,
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
{
|
||||
"camera_calibration": {
|
||||
"reference_marker": [
|
||||
100,
|
||||
100,
|
||||
219,
|
||||
219
|
||||
],
|
||||
"reference_marker_width": 500.0,
|
||||
"reference_marker_height": 500.0,
|
||||
"angle_horizontal": 0.0,
|
||||
"angle_vertical": 0.0
|
||||
},
|
||||
"mirror_x": false,
|
||||
"mirror_y": false,
|
||||
"rotate": 0,
|
||||
@@ -9,6 +21,6 @@
|
||||
"name": "X01DD-FE-CAM1",
|
||||
"source": "X01DD-FE-CAM1",
|
||||
"group": [
|
||||
"Ring"
|
||||
"Frontend"
|
||||
]
|
||||
}
|
||||
@@ -4,11 +4,11 @@
|
||||
"rotate": 0,
|
||||
"roi": null,
|
||||
"image_background": null,
|
||||
"source_type": "epics",
|
||||
"source_type": "bsread",
|
||||
"prefix": "X08DB-FE-CAM1",
|
||||
"name": "X08DB-FE-CAM1",
|
||||
"source": "X08DB-FE-CAM1",
|
||||
"group": [
|
||||
"Ring"
|
||||
"Frontend"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"mirror_x": false,
|
||||
"mirror_y": false,
|
||||
"rotate": 0,
|
||||
"roi": null,
|
||||
"image_background": null,
|
||||
"source_type": "bsread",
|
||||
"prefix": "X08DB-FE-CAM2",
|
||||
"name": "X08DB-FE-CAM2",
|
||||
"source": "X08DB-FE-CAM2",
|
||||
"group": [
|
||||
"Frontend"
|
||||
]
|
||||
}
|
||||
@@ -9,5 +9,7 @@
|
||||
"camera_name": "ABODI-SM-1S1",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ABODI-SM-1S1_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true,
|
||||
"reload": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ABODI-SM-1S2",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ABODI-SM-1S2_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ABRTL-DSCR-0440",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ABRTL-DSCR-0440_proc",
|
||||
"throw_epics_errors": true,
|
||||
"max_frame_rate": 10.1
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ABRTL-DSCR-0680",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ABRTL-DSCR-0680_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ABRTL-DSCR-0870",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ABRTL-DSCR-0870_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ALIDI-SM-3",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ALIDI-SM-3_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ALIDI-SM-4",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ALIDI-SM-4_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ALIDI-SM-5",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ALIDI-SM-5_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "ALIDI-SM-5_sp_proc",
|
||||
"pipeline_type": "stream",
|
||||
"input_pipeline": "ALIDI-SM-5_sp",
|
||||
"mode": "PUB",
|
||||
"block": false,
|
||||
"function": "epics_forwarder_sp.py",
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true,
|
||||
"abort_on_timeout": true,
|
||||
"stream_timeout": 60
|
||||
}
|
||||
@@ -9,5 +9,7 @@
|
||||
"camera_name": "ALIDI-SM-E",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ALIDI-SM-E_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true,
|
||||
"reload": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ARS01-DSCR-0750",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ARS01-DSCR-0750_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ARS05-RCAM-0060",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ARS05-RCAM-0060_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
+5
-2
@@ -6,6 +6,9 @@
|
||||
"image_good_region": null,
|
||||
"image_slices": null,
|
||||
"pipeline_type": "processing",
|
||||
"camera_name": "ARIDI-SM-1L2",
|
||||
"name": "ARIDI-SM-1L2_sp"
|
||||
"camera_name": "ARS05-RCAM-0060",
|
||||
"function": "proc_sr1",
|
||||
"reload": true,
|
||||
"abort_on_error": false,
|
||||
"name": "ARS05-RCAM-0060_proc2"
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ARS05-RCAM-0140",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ARS05-RCAM-0140_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ARS05-RCAM-0230",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ARS05-RCAM-0230_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "ARS05-RCAM-0310",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "ARS05-RCAM-0310_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "X01DD-FE-CAM1",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "X01DD-FE-CAM1_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
"camera_name": "X08DB-FE-CAM1",
|
||||
"function": "epics_forwarder.py",
|
||||
"name": "X08DB-FE-CAM1_proc",
|
||||
"max_frame_rate": 10.1
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
+2
-2
@@ -6,6 +6,6 @@
|
||||
"image_good_region": null,
|
||||
"image_slices": null,
|
||||
"pipeline_type": "processing",
|
||||
"camera_name": "ARIDI-SM-1L1",
|
||||
"name": "ARIDI-SM-1L1_sp"
|
||||
"camera_name": "X08DB-FE-CAM2",
|
||||
"name": "X08DB-FE-CAM2_sp"
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
"copy": true,
|
||||
"name": "emmitance_pipolar",
|
||||
"function": "pipolar.py",
|
||||
"camera_name": "source_h5",
|
||||
"_camera_name": "X09DA-FE-BEAMSZY",
|
||||
"camera_name": "ALBDI-SM-2",
|
||||
"_camera_name": "source_h5",
|
||||
"fit": {
|
||||
"delta_height": 50,
|
||||
"bg_range_low": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"#emmitance_pipolar": "emmitance_pipolar",
|
||||
"#ALIDI-SM-5_proc": "ALIDI-SM-5_proc",
|
||||
"#simulation_proc_sp": "simulation_proc_sp",
|
||||
"#simulation_sp1": "simulation_sp",
|
||||
"ABODI-SM-1S1_proc": "ABODI-SM-1S1_proc",
|
||||
"ABODI-SM-1S2_proc": "ABODI-SM-1S2_proc",
|
||||
@@ -8,13 +9,15 @@
|
||||
"ABRTL-DSCR-0870_proc": "ABRTL-DSCR-0870_proc",
|
||||
"ALIDI-SM-3_proc": "ALIDI-SM-3_proc",
|
||||
"ALIDI-SM-4_proc": "ALIDI-SM-4_proc",
|
||||
"ALIDI-SM-5_proc": "ALIDI-SM-5_proc",
|
||||
"ALIDI-SM-5_sp_proc": "ALIDI-SM-5_sp_proc",
|
||||
"ALIDI-SM-E_proc": "ALIDI-SM-E_proc",
|
||||
"ARS01-DSCR-0750_proc": "ARS01-DSCR-0750_proc",
|
||||
"ARS05-RCAM-0060_proc": "ARS05-RCAM-0060_proc",
|
||||
"ARS05-RCAM-0060_proc2": "ARS05-RCAM-0060_proc2",
|
||||
"ARS05-RCAM-0140_proc": "ARS05-RCAM-0140_proc",
|
||||
"ARS05-RCAM-0230_proc": "ARS05-RCAM-0230_proc",
|
||||
"ARS05-RCAM-0310_proc": "ARS05-RCAM-0310_proc",
|
||||
"X01DD-FE-CAM1_proc": "X01DD-FE-CAM1_proc",
|
||||
"X08DB-FE-CAM1_proc": "X08DB-FE-CAM1_proc"
|
||||
"X08DB-FE-CAM1_proc": "X08DB-FE-CAM1_proc",
|
||||
"emmitance_pipolar": "emmitance_pipolar"
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
{
|
||||
"http://sls-daqsync-01.psi.ch:8881": {
|
||||
"cameras": [
|
||||
"simulation"
|
||||
],
|
||||
"enabled": true,
|
||||
"expanding": true,
|
||||
"instances": [
|
||||
"simulation_sp:9000",
|
||||
"emmitance_pipolar:9001"
|
||||
"#emmitance_pipolar:9001"
|
||||
]
|
||||
},
|
||||
"http://sls-daqsync-22.psi.ch:8881": {
|
||||
@@ -20,18 +23,29 @@
|
||||
"ALBDI-SM-3",
|
||||
"ALBDI-SM-4",
|
||||
"ABODI-SM-1S1",
|
||||
"ABODI-SM-1S2"
|
||||
"ABODI-SM-1S2",
|
||||
"ABODI-SM-5S",
|
||||
"ABRTL-DSCR-0440",
|
||||
"ABRTL-DSCR-0680",
|
||||
"ABRTL-DSCR-0870",
|
||||
"ARS01-DSCR-0750",
|
||||
"X01DD-FE-CAM1"
|
||||
],
|
||||
"enabled": true,
|
||||
"expanding": false,
|
||||
"instances": []
|
||||
"instances": [
|
||||
"ALIDI-SM-5_sp_proc",
|
||||
"emmitance_pipolar:9001"
|
||||
]
|
||||
},
|
||||
"http://sls-daqsync-43.psi.ch:8881": {
|
||||
"cameras": [
|
||||
"ARS05-RCAM-0060",
|
||||
"ARS05-RCAM-0140",
|
||||
"ARS05-RCAM-0230",
|
||||
"ARS05-RCAM-0310"
|
||||
"ARS05-RCAM-0310",
|
||||
"X08DB-FE-CAM1",
|
||||
"X08DB-FE-CAM2"
|
||||
],
|
||||
"enabled": true,
|
||||
"expanding": false,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "simulation_proc_direct",
|
||||
"pipeline_type": "processing",
|
||||
"camera_name": "simulation",
|
||||
"image_background_enable": false,
|
||||
"image_background": null,
|
||||
"image_threshold": null,
|
||||
"image_region_of_interest": null,
|
||||
"image_good_region": null,
|
||||
"image_slices": null,
|
||||
"function": "epics_forwarder.py",
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "simulation_proc_sp",
|
||||
"pipeline_type": "stream",
|
||||
"input_pipeline": "simulation_sp",
|
||||
"mode": "PUB",
|
||||
"block": false,
|
||||
"function": "epics_forwarder_sp.py",
|
||||
"max_frame_rate": 10.1,
|
||||
"throw_epics_errors": true,
|
||||
"_abort_on_timeout": false,
|
||||
"_stream_timeout": 20
|
||||
}
|
||||
@@ -2,35 +2,43 @@ from collections import OrderedDict
|
||||
from cam_server.pipeline.data_processing import functions
|
||||
from cam_server.utils import create_thread_pvs, epics_lock
|
||||
from logging import getLogger
|
||||
import math
|
||||
|
||||
_logger = getLogger(__name__)
|
||||
|
||||
mean_x_pv, mean_y_pv, sig_x_pv, sig_y_pv = None, None, None, None
|
||||
mean_x_name, mean_y_name, sig_x_name, sig_y_name = None, None, None, None
|
||||
ampl_x_pv, ampl_y_pv, integ_x_pv, integ_y_pv = None, None, None, None
|
||||
ampl_x_name, ampl_y_name, integ_x_name, integ_y_name = None, None, None, None
|
||||
sent_pid = -1
|
||||
|
||||
initialized = False
|
||||
def initialize(parameters):
|
||||
global initialized
|
||||
global mean_x_name, mean_y_name, sig_x_name, sig_y_name
|
||||
global mean_x_name, mean_y_name, sig_x_name, sig_y_name, ampl_x_name, ampl_y_name, integ_x_name, integ_y_name
|
||||
prefix = parameters["camera_name"]
|
||||
mean_x_name = prefix + ":POS-X"
|
||||
mean_y_name = prefix + ":POS-Y"
|
||||
sig_x_name = prefix + ":SIG-X"
|
||||
sig_y_name = prefix + ":SIG-Y"
|
||||
ampl_x_name = prefix + ":AMPL-X"
|
||||
ampl_y_name = prefix + ":AMPL-Y"
|
||||
integ_x_name = prefix + ":INTEG-X"
|
||||
integ_y_name = prefix + ":INTEG-Y"
|
||||
initialized = True
|
||||
|
||||
|
||||
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata):
|
||||
global initialized, sent_pid
|
||||
global mean_x_pv, mean_y_pv, sig_x_pv, sig_y_pv
|
||||
global mean_x_name, mean_y_name, sig_x_name, sig_y_name
|
||||
global mean_x_pv, mean_y_pv, sig_x_pv, sig_y_pv, ampl_x_pv, ampl_y_pv, integ_x_pv, integ_y_pv
|
||||
global mean_x_name, mean_y_name, sig_x_name, sig_y_name, ampl_x_name, ampl_y_name, integ_x_name, integ_y_name
|
||||
|
||||
if not initialized:
|
||||
initialize(parameters)
|
||||
initialized = True
|
||||
|
||||
ret = OrderedDict()
|
||||
throw_epics_errors = parameters.get("throw_epics_errors", True)
|
||||
prefix = parameters["camera_name"]
|
||||
(x_profile, y_profile) = functions.get_x_y_profile(image)
|
||||
x_fit_gauss_function, x_fit_offset, x_fit_amplitude, x_fit_mean, x_fit_standard_deviation, x_center_of_mass, x_rms = functions.gauss_fit(x_profile, x_axis)
|
||||
@@ -38,6 +46,9 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
|
||||
x_fwhm = functions.get_fw(x_axis,x_profile)
|
||||
y_fwhm = functions.get_fw(y_axis,y_profile)
|
||||
intensity = x_profile.sum()
|
||||
x_fit_integ = x_fit_amplitude * x_fit_standard_deviation * math.sqrt(2*math.pi)
|
||||
y_fit_integ = y_fit_amplitude * y_fit_standard_deviation * math.sqrt(2*math.pi)
|
||||
|
||||
ret[prefix+":intensity"] = intensity
|
||||
ret[prefix+":x_fit_mean"] = x_fit_mean
|
||||
ret[prefix+":y_fit_mean"] = y_fit_mean
|
||||
@@ -49,22 +60,46 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
|
||||
ret[prefix+":y_rms"] = y_rms
|
||||
ret[prefix+":x_fwhm"] = x_fwhm
|
||||
ret[prefix+":y_fwhm"] = y_fwhm
|
||||
ret[prefix+":x_fit_amplitude"] = x_fit_amplitude
|
||||
ret[prefix+":y_fit_amplitude"] = y_fit_amplitude
|
||||
ret[prefix+":x_fit_integ"] = x_fit_integ
|
||||
ret[prefix+":y_fit_integ"] = y_fit_integ
|
||||
|
||||
mean_x_pv, mean_y_pv, sig_x_pv, sig_y_pv = create_thread_pvs([mean_x_name, mean_y_name, sig_x_name, sig_y_name])
|
||||
|
||||
if epics_lock.acquire(False):
|
||||
try:
|
||||
if pulse_id > sent_pid:
|
||||
sent_pid = pulse_id
|
||||
mean_x_pv, mean_y_pv, sig_x_pv, sig_y_pv, ampl_x_pv, ampl_y_pv, integ_x_pv, integ_y_pv = create_thread_pvs([mean_x_name, mean_y_name, sig_x_name, sig_y_name, ampl_x_name, ampl_y_name, integ_x_name, integ_y_name])
|
||||
epics_error = None
|
||||
|
||||
if pulse_id > sent_pid:
|
||||
sent_pid = pulse_id
|
||||
if epics_lock.acquire(False):
|
||||
try:
|
||||
for (pv, value) in [ (mean_x_pv, x_fit_mean), \
|
||||
(mean_y_pv, y_fit_mean), \
|
||||
(sig_x_pv, x_fit_standard_deviation), \
|
||||
(sig_y_pv, y_fit_standard_deviation) \
|
||||
]:
|
||||
|
||||
(sig_y_pv, y_fit_standard_deviation), \
|
||||
(ampl_x_pv, x_fit_amplitude), \
|
||||
(ampl_y_pv, y_fit_amplitude), \
|
||||
(integ_x_pv, x_fit_integ), \
|
||||
(integ_y_pv, y_fit_integ) \
|
||||
]:
|
||||
if pv and pv.connected:
|
||||
pv.put(value)
|
||||
finally:
|
||||
epics_lock.release()
|
||||
|
||||
return ret
|
||||
pv.put(value)
|
||||
else:
|
||||
_logger.warning("PV not connected: %s" % (str(pv),))
|
||||
#epics_error = "PV not connected: %s" % (str(pv),)
|
||||
except Exception as e:
|
||||
epics_error = "Error writing PVs: %s" % (str(e),)
|
||||
finally:
|
||||
epics_lock.release()
|
||||
else:
|
||||
_logger.warning("Cannot aquire EPICS lock")
|
||||
|
||||
if epics_error:
|
||||
_logger.warning(epics_error)
|
||||
if throw_epics_errors:
|
||||
raise Exception(epics_error)
|
||||
|
||||
return ret
|
||||
else:
|
||||
_logger.warning("Invalid PID: %s last:%s"% (str(pulse_id), str(sent_pid),))
|
||||
sent_pid = 0 # It should be single threaded, assumes the camera instance restarted
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
from collections import OrderedDict
|
||||
from cam_server.utils import create_thread_pvs, epics_lock
|
||||
from logging import getLogger
|
||||
import json
|
||||
import math
|
||||
|
||||
_logger = getLogger(__name__)
|
||||
|
||||
mean_x_name, mean_y_name, sig_x_name, sig_y_name = None, None, None, None
|
||||
ampl_x_name, ampl_y_name, integ_x_name, integ_y_name = None, None, None, None
|
||||
camera_name = None
|
||||
sent_pid = -1
|
||||
|
||||
initialized = False
|
||||
|
||||
|
||||
def initialize(parameters, data):
|
||||
global initialized, camera_name
|
||||
global mean_x_name, mean_y_name, sig_x_name, sig_y_name, ampl_x_name, ampl_y_name, integ_x_name, integ_y_name
|
||||
processing_parameters = json.loads(data["processing_parameters"])
|
||||
camera_name = processing_parameters["camera_name"]
|
||||
mean_x_name = camera_name + ":POS-X"
|
||||
mean_y_name = camera_name + ":POS-Y"
|
||||
sig_x_name = camera_name + ":SIG-X"
|
||||
sig_y_name = camera_name + ":SIG-Y"
|
||||
ampl_x_name = camera_name + ":AMPL-X"
|
||||
ampl_y_name = camera_name + ":AMPL-Y"
|
||||
integ_x_name = camera_name + ":INTEG-X"
|
||||
integ_y_name = camera_name + ":INTEG-Y"
|
||||
initialized = True
|
||||
|
||||
|
||||
def process(data, pulse_id, timestamp, parameters):
|
||||
global initialized, sent_pid, camera_name
|
||||
global mean_x_name, mean_y_name, sig_x_name, sig_y_name
|
||||
|
||||
if not initialized:
|
||||
initialize(parameters, data)
|
||||
initialized = True
|
||||
|
||||
mean_x_pv, mean_y_pv, sig_x_pv, sig_y_pv, ampl_x_pv, ampl_y_pv, integ_x_pv, integ_y_pv = create_thread_pvs([mean_x_name, mean_y_name, sig_x_name, sig_y_name, ampl_x_name, ampl_y_name, integ_x_name, integ_y_name])
|
||||
|
||||
ret = OrderedDict()
|
||||
throw_epics_errors = parameters.get("throw_epics_errors", True)
|
||||
|
||||
x_fit_integ = data["x_fit_amplitude"] * data["x_fit_standard_deviation"] * math.sqrt(2*math.pi)
|
||||
y_fit_integ = data["y_fit_amplitude"] * data["y_fit_standard_deviation"] * math.sqrt(2*math.pi)
|
||||
|
||||
channels = ["intensity", "x_fit_mean", "y_fit_mean", "x_fit_standard_deviation", "y_fit_standard_deviation",
|
||||
"x_center_of_mass", "y_center_of_mass", "x_rms", "y_rms", "x_fwhm", "y_fwhm","x_fit_amplitude", "y_fit_amplitude"]
|
||||
|
||||
for c in channels:
|
||||
ret[camera_name + ":" + c] = data[c]
|
||||
ret[camera_name + ":x_fit_integ"] = x_fit_integ
|
||||
ret[camera_name + ":y_fit_integ"] = y_fit_integ
|
||||
|
||||
epics_error = None
|
||||
|
||||
if pulse_id > sent_pid:
|
||||
sent_pid = pulse_id
|
||||
if epics_lock.acquire(False):
|
||||
try:
|
||||
for (pv, value) in [(mean_x_pv, data["x_fit_mean"]), \
|
||||
(mean_y_pv, data["y_fit_mean"]), \
|
||||
(sig_x_pv, data["x_fit_standard_deviation"]), \
|
||||
(sig_y_pv, data["y_fit_standard_deviation"]), \
|
||||
(ampl_x_pv, data["x_fit_amplitude"]), \
|
||||
(ampl_y_pv, data["y_fit_amplitude"]), \
|
||||
(integ_x_pv, x_fit_integ), \
|
||||
(integ_y_pv, y_fit_integ) \
|
||||
]:
|
||||
if pv and pv.connected:
|
||||
pv.put(value)
|
||||
else:
|
||||
_logger.warning("PV not connected: %s" % (str(pv),))
|
||||
# epics_error = "PV not connected: %s" % (str(pv),)
|
||||
except Exception as e:
|
||||
epics_error = "Error writing PVs: %s" % (str(e),)
|
||||
finally:
|
||||
epics_lock.release()
|
||||
else:
|
||||
_logger.warning("Cannot aquire EPICS lock")
|
||||
|
||||
if epics_error:
|
||||
_logger.warning(epics_error)
|
||||
if throw_epics_errors:
|
||||
raise Exception(epics_error)
|
||||
return ret
|
||||
else:
|
||||
_logger.warning("Invalid PID: %s last:%s" % (str(pulse_id), str(sent_pid),))
|
||||
sent_pid = 0 # It should be single threaded, assumes the camera instance restarted
|
||||
@@ -22,13 +22,8 @@ class PpolPeakValley():
|
||||
self.x, self.y = self.ppol_interpol()
|
||||
|
||||
def ppol_interpol(self, plot_flag=False):
|
||||
ipv = [0.0, 0.0164, 0.0328, 0.0492, 0.0656,
|
||||
0.082, 0.157, 0.296, 0.42, 0.53, 0.706, 0.833, 0.918, 0.97, 0.995]
|
||||
sig = [0.0, 1.254192, 2.508384, 3.7626, 5.016768,
|
||||
6.27096483804526, 8.86848352312841, 12.5419296760905,
|
||||
15.3606640481458, 17.7369670462568, 21.723259423944,
|
||||
25.083859352181, 28.0446073247603, 30.7213280962917,
|
||||
33.1828268837964]
|
||||
ipv = [32.97634439, 20.84823973, 15.30617974, 12.12078244, 10.04998987, 8.59541134, 7.517605624, 6.687085031, 6.027635302, 5.491463995, 5.047070496, 4.67284665, 4.353472754, 4.077788974, 3.837472599, 3.439012834, 3.122374348, 2.86497533, 2.651841232, 0.0]
|
||||
sig = [3.7, 5.2, 6.3, 7.3, 8.2, 9.0, 9.7, 10.3, 11.0, 11.6, 12.1, 12.7, 13.2, 13.7, 14.2, 15.2, 16, 16.8, 17.5, 0.0]
|
||||
sig2 = [element * element for element in sig]
|
||||
x = np.linspace(0, 999999, 999999)
|
||||
x = [(1+val)/1000000*max(ipv) for val in x]
|
||||
@@ -100,12 +95,12 @@ def calculate_emittance(image, fit_pars):
|
||||
max_indices = np.where(projy == max_element)
|
||||
peaks, _ = find_peaks(projy, height=(max_element - DELTA_HEIGHT))
|
||||
|
||||
_logger.info("max indices /peaks " + str(max_indices) + " " + str(peaks))
|
||||
_logger.debug("max indices /peaks " + str(max_indices) + " " + str(peaks))
|
||||
|
||||
if len(peaks) != 2:
|
||||
mess = "Too few peaks found! " if len(peaks) < 2 else \
|
||||
"Too many peaks found "
|
||||
_logger.info(mess + str(peaks))
|
||||
_logger.debug(mess + str(peaks))
|
||||
peaks_buffer = []
|
||||
for val in peaks:
|
||||
### COMMENTED BY ALEX
|
||||
@@ -122,7 +117,7 @@ def calculate_emittance(image, fit_pars):
|
||||
peaks = peaks_buffer
|
||||
|
||||
if (peaks[1] - peaks[0]) < 6:
|
||||
_logger.info("Peaks are too close: " + str(peaks[1] - peaks[0]))
|
||||
_logger.debug("Peaks are too close: " + str(peaks[1] - peaks[0]))
|
||||
raise Exception("Peaks are too close")
|
||||
|
||||
#peaks =[569, 577]
|
||||
@@ -216,7 +211,7 @@ def calculate_emittance(image, fit_pars):
|
||||
emittance = ppol.get_emittance(ratio_corrected)
|
||||
emittance2 = ppol.get_emittance(ratio_max)
|
||||
|
||||
_logger.info("ratio=%f emittance %f ratio2=%f emittance2 %f" % (ratio_corrected, emittance, ratio_max, emittance2))
|
||||
_logger.debug("ratio=%f emittance %f ratio2=%f emittance2 %f" % (ratio_corrected, emittance, ratio_max, emittance2))
|
||||
return (emittance, emittance2)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#########################################################################
|
||||
# The interface to integrate into the pipeline server
|
||||
# The following files are needed to be added to the library:
|
||||
# - CamDataProcess.py
|
||||
# - Config_Param.py
|
||||
# - LocalPV.py
|
||||
# - RecordTemplate.py
|
||||
# - RemotePV.py
|
||||
# - Service_Log.py
|
||||
# - Service_RFStation.py
|
||||
# - Service_Screen.py
|
||||
# - elog.py
|
||||
#
|
||||
# Created by Zheqiao Geng on 29.05.2024
|
||||
#########################################################################
|
||||
import os
|
||||
import time
|
||||
|
||||
from cam_server.pipeline.data_processing import functions, processor
|
||||
from cam_server import utils
|
||||
from logging import getLogger
|
||||
|
||||
from CamDataProcess import *
|
||||
from Service_RFStation import *
|
||||
from Config_Param import *
|
||||
from Service_Log import *
|
||||
|
||||
# ===============================================================
|
||||
# global variables
|
||||
# ===============================================================
|
||||
_logger = getLogger(__name__)
|
||||
initialized = False
|
||||
moduleName = 'ARS05-RCAM-0060'
|
||||
instName = 'SR1'
|
||||
srvRFs = None
|
||||
srvLog = None
|
||||
camPrc = None
|
||||
|
||||
# ===============================================================
|
||||
# init function
|
||||
# ===============================================================
|
||||
def initialize():
|
||||
global srvRFs, srvLog, camPrc, moduleName, instName
|
||||
|
||||
# get the RF station info
|
||||
if instName == 'TS':
|
||||
cav_label = ts_cav_label
|
||||
cpl_label = ts_cpl_label
|
||||
elif instName == 'SR1':
|
||||
cav_label = sr1_cav_label
|
||||
cpl_label = sr1_cpl_label
|
||||
elif instName == 'SR2':
|
||||
cav_label = sr2_cav_label
|
||||
cpl_label = sr2_cpl_label
|
||||
elif instName == 'SR3':
|
||||
cav_label = sr3_cav_label
|
||||
cpl_label = sr3_cpl_label
|
||||
elif instName == 'SR4':
|
||||
cav_label = sr4_cav_label
|
||||
cpl_label = sr4_cpl_label
|
||||
else:
|
||||
cav_label = ''
|
||||
cpl_label = ''
|
||||
|
||||
# define the services
|
||||
srvRFs = Service_RFStation(loc = instName,
|
||||
cav_label = cav_label,
|
||||
cpl_label = cpl_label)
|
||||
srvLog = Service_Log(moduleName, loc = instName)
|
||||
|
||||
# define the jobs
|
||||
camPrc = CamDataProcess(moduleName,
|
||||
instName,
|
||||
srv_scr = None,
|
||||
srv_rfs = srvRFs,
|
||||
srv_log = srvLog,
|
||||
f_path = file_path)
|
||||
|
||||
# connect to all PVs
|
||||
RemotePV.connect()
|
||||
time.sleep(2.0)
|
||||
|
||||
# start the threads
|
||||
camPrc.start()
|
||||
_logger.info('EPICS_CA_ADDR_LIST = ' + str(os.environ.get('EPICS_CA_ADDR_LIST')))
|
||||
_logger.info('Data Path: ' + camPrc.f_path)
|
||||
_logger.info("Initialized")
|
||||
|
||||
# ===============================================================
|
||||
# implement the image processing function (replacing the thread
|
||||
# function "DataRecvProcFunc" in "CamDataProcess.py")
|
||||
# ===============================================================
|
||||
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
|
||||
# declare the global variables
|
||||
global camPrc, initialized
|
||||
|
||||
try:
|
||||
# initialization
|
||||
if not initialized:
|
||||
initialize()
|
||||
initialized = True
|
||||
|
||||
# basic process of the image
|
||||
data = { 'timestamp' : utils.timestamp_as_float(timestamp),
|
||||
'width' : len(image[0]),
|
||||
'height' : len(image),
|
||||
'image' : image,
|
||||
'arc_found' : 0}
|
||||
|
||||
# calculate the properties for arc detection
|
||||
x_profile, y_profile = functions.get_x_y_profile(image)
|
||||
min_value, max_value = functions.get_min_max(image)
|
||||
intensity = x_profile.sum()
|
||||
|
||||
data['intensity'] = intensity
|
||||
data['min_value'] = min_value
|
||||
data['max_value'] = max_value
|
||||
data['x_profile'] = x_profile
|
||||
data['y_profile'] = y_profile
|
||||
|
||||
# store to the circular buffer
|
||||
camPrc.receiveImage(data)
|
||||
return data
|
||||
except Exception as e:
|
||||
_logger.warning(str(e))
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user