October 2020

This commit is contained in:
root
2020-10-13 11:19:38 +02:00
parent ddaf7fd3ef
commit a445ef58f2
45 changed files with 1177 additions and 0 deletions
@@ -0,0 +1,23 @@
{
"camera_calibration": {
"reference_marker": [
1093,
427,
1463,
802
],
"reference_marker_width": 1.0,
"reference_marker_height": 1.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "epics",
"prefix": "SLAAR21-LCAM-C532",
"name": "Bernina_samplecam_inline",
"source": "SLAAR21-LCAM-C532"
}
@@ -0,0 +1,23 @@
{
"camera_calibration": {
"reference_marker": [
1524,
945,
1622,
1046
],
"reference_marker_width": 1.0,
"reference_marker_height": 1.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "epics",
"prefix": "SARES20-CAMS142-C1",
"name": "Bernina_samplecam_sideview",
"source": "SARES20-CAMS142-C1"
}
@@ -0,0 +1,12 @@
{
"camera_calibration": null,
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "epics",
"prefix": "SARES20-CAMS142-C3",
"name": "Bernina_samplecam_xrd",
"source": "SARES20-CAMS142-C3"
}
@@ -0,0 +1,23 @@
{
"camera_calibration": {
"reference_marker": [
416,
275,
438,
286
],
"reference_marker_width": 16.0,
"reference_marker_height": 8.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "epics",
"name": "Bernina_xeye",
"prefix": "SARES20-PROF142-M1",
"source": "SARES20-PROF142-M1"
}
@@ -0,0 +1,22 @@
{
"camera_calibration": {
"reference_marker": [
565,
345,
666,
445
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "epics",
"name": "IR_Beam_Monitor_I",
"source": "SLAAR21-LCAM-C511"
}
@@ -0,0 +1,22 @@
{
"camera_calibration": {
"reference_marker": [
568,
440,
668,
540
],
"reference_marker_width": 118.0,
"reference_marker_height": 87.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "epics",
"name": "IR_Beam_Monitor_II",
"source": "SLAAR21-LCAM-C531"
}
@@ -0,0 +1,22 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "bsread",
"name": "SARES12-CAMS128-M1",
"prefix": "SARES12-CAMS128-M1",
"source": "SARES12-CAMS128-M1",
"connections": 2
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE1",
"source": "SATES21-CAMS154-GIGE1"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE2",
"source": "SATES21-CAMS154-GIGE2"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE3",
"source": "SATES21-CAMS154-GIGE3"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE4",
"source": "SATES21-CAMS154-GIGE4"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE5",
"source": "SATES21-CAMS154-GIGE5"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE6",
"source": "SATES21-CAMS154-GIGE6"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE7",
"source": "SATES21-CAMS154-GIGE7"
}
@@ -0,0 +1,22 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "bsread",
"name": "SATES21-CAMS154-GIGE7b",
"prefix": "SATES21-CAMS154-GIGE7",
"source": "SATES21-CAMS154-GIGE7",
"connections": 1
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATES21-CAMS154-GIGE8",
"source": "SATES21-CAMS154-GIGE8"
}
@@ -0,0 +1,23 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "bsread",
"name": "SATES21-CAMS154-M1",
"prefix": "SATES21-CAMS154-M1",
"source": "SATES21-CAMS154-M1",
"connections": 4,
"buffer_size": 100
}
@@ -0,0 +1,23 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"name": "SATES24-CAMS161-M1",
"prefix": "SATES24-CAMS161-M1",
"source": "SATES24-CAMS161-M1",
"source_type": "bsread",
"connections": 4,
"buffer_size": 100
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATFE10-PSRD066",
"source": "SATFE10-PSRD066"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
100,
46,
565,
438
],
"reference_marker_width": 13000.0,
"reference_marker_height": 11000.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATOP11-PSCR074",
"source": "SATOP11-PSCR074"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
114,
43,
539,
329
],
"reference_marker_width": 12000.0,
"reference_marker_height": 9000.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATOP11-PSCR086",
"source": "SATOP11-PSCR086"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
91,
97,
559,
492
],
"reference_marker_width": 13000.0,
"reference_marker_height": 11000.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"name": "SATOP11-PSCR090",
"source": "SATOP11-PSCR090"
}
@@ -0,0 +1,20 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "epics",
"source": "SATOP21-PSCR140",
"name": "SATOP21-PSCR140"
}
+39
View File
@@ -0,0 +1,39 @@
{
"http://sf-daqsync-01.psi.ch:8880": {
"expanding": true,
"instances": [
]
},
"http://sf-daqsync-02.psi.ch:8880": {
"expanding": false,
"instances": [
"SARFE10-PSSS059"
]
},
"http://sf-daqsync-03.psi.ch:8880": {
"expanding": true,
"instances": [
]
},
"http://sf-daqsync-04.psi.ch:8880": {
"expanding": false,
"instances": [
"SATES21-CAMS154-M1",
"SATES24-CAMS161-M1"
]
},
"http://sf-daqsync-05.psi.ch:8880": {
"expanding": true,
"instances": [
"SARES11-SPEC125-M1",
"SARES11-SPEC125-M2"
]
},
"http://sf-daqsync-06.psi.ch:8880": {
"expanding": true,
"instances": [
"SARES20-CAMS142-M4",
"SARES20-CAMS142-M5"
]
}
}
+34
View File
@@ -0,0 +1,34 @@
{
"http://sf-daqsync-01.psi.ch:8880": {
"expanding": true,
"instances": [
]
},
"http://sf-daqsync-02.psi.ch:8880": {
"expanding": false,
"instances": [
"SARFE10-PSSS059"
]
},
"http://sf-daqsync-04.psi.ch:8880": {
"expanding": false,
"instances": [
"SATES21-CAMS154-M1",
"SATES24-CAMS161-M1"
]
},
"http://sf-daqsync-05.psi.ch:8880": {
"expanding": true,
"instances": [
"SARES11-SPEC125-M1",
"SARES11-SPEC125-M2"
]
},
"http://sf-daqsync-06.psi.ch:8880": {
"expanding": true,
"instances": [
"SARES20-CAMS142-M4",
"SARES20-CAMS142-M5"
]
}
}
@@ -0,0 +1,25 @@
{
"camera_calibration": {
"reference_marker": [
211,
173,
1063,
793
],
"reference_marker_width": 30000.0,
"reference_marker_height": 30000.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},
"mirror_x": false,
"mirror_y": false,
"rotate": 0,
"source_type": "simulation",
"name": "simulation_big",
"source": "",
"frame_rate": 5,
"size_x": 20,
"size_y":20,
"simulate_pulse_id": true,
"image_type": "static_raw"
}
@@ -0,0 +1,19 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": [
0,
659,
0,
494
],
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"camera_name": "SARES11-SPEC125-M2",
"name": "Alvra_PSEN_align",
"bsread_channels": [
"SARFE10-PSSS059:SPECTRUM_CENTER"
]
}
@@ -0,0 +1,25 @@
{
"image_background_enable": false,
"image_background": "SARES12-CAMS128-M1_20200604_125721_845028",
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"function": "psen_min_processing",
"camera_name": "SARES12-CAMS128-M1",
"name": "SARES12-CAMS128-M1_psen_db",
"mode": "PUSH",
"roi_background": [
800,
450,
1300,
450
],
"roi_signal": [
800,
450,
700,
450
]
}
@@ -0,0 +1,12 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "store",
"camera_name": "SARES12-CAMS128-M1",
"name": "SARES12-CAMS128-M1_psen_ib",
"stream_port": 0
}
@@ -0,0 +1,16 @@
{
"image_background_enable": "passive",
"image_background": "SARFE10-PSSS059:FPICTURE_12826023152_25",
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"camera_name": "SARFE10-PSSS059",
"name": "SARFE10-PSSS059_psss",
"function": "psss.py",
"mode": "PUSH",
"no_client_timeout": 0,
"port": "8889",
"reload": false
}
@@ -0,0 +1,5 @@
{
"pipeline_type": "store",
"camera_name": "SARFE10-PSSS059",
"name": "SARFE10-PSSS059_store"
}
@@ -0,0 +1,27 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"function": "psen_min_processing",
"camera_name": "SATES21-CAMS154-M1",
"name": "SATES21-CAMS154-M1_psen_db",
"mode": "PUSH",
"roi_background": [
300,
2048,
600,
400
],
"roi_signal": [
300,
2048,
1150,
400
],
"no_client_timeout": 0,
"port": "9001"
}
@@ -0,0 +1,12 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "store",
"camera_name": "SATES21-CAMS154-M1",
"name": "SATES21-CAMS154-M1_psen_ib",
"stream_port": 0
}
@@ -0,0 +1,25 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"function": "psen_min_processing",
"camera_name": "SATES24-CAMS161-M1",
"name": "SATES24-CAMS161-M1_psen_db",
"mode": "PUSH",
"roi_background": [
300,
2048,
600,
400
],
"roi_signal": [
300,
2048,
1150,
400
]
}
@@ -0,0 +1,12 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "store",
"camera_name": "SATES24-CAMS161-M1",
"name": "SATES24-CAMS161-M1_psen_ib",
"stream_port": 0
}
@@ -0,0 +1,17 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"include": [
"x_center_of_mass",
"y_center_of_mass",
"x_fit_mean",
"y_fit_mean"
],
"camera_name": "SATOP11-PSCR074",
"name": "SATOP11-PSCR074_acd"
}
@@ -0,0 +1,17 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"include": [
"x_center_of_mass",
"y_center_of_mass",
"x_fit_mean",
"y_fit_mean"
],
"camera_name": "SATOP11-PSCR086",
"name": "SATOP11-PSCR086_acd"
}
@@ -0,0 +1,17 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"include": [
"x_center_of_mass",
"y_center_of_mass",
"x_fit_mean",
"y_fit_mean"
],
"camera_name": "SATOP11-PSCR090",
"name": "SATOP11-PSCR090_acd"
}
@@ -0,0 +1,17 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
"image_slices": null,
"pipeline_type": "processing",
"include": [
"x_center_of_mass",
"y_center_of_mass",
"x_fit_mean",
"y_fit_mean"
],
"camera_name": "SATOP21-PSCR140",
"name": "SATOP21-PSCR140_acd"
}
@@ -0,0 +1,12 @@
import json
import numpy
from cam_server.pipeline.data_processing import functions
from logging import getLogger
_logger = getLogger(__name__)
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata):
ret = {}
ret["test"] = 1
return ret
+14
View File
@@ -0,0 +1,14 @@
from cam_server.pipeline.data_processing import processor
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
if parameters.get("binning_x") or parameters.get("binning_y"):
by, bx = int(parameters.get("binning_y",1)), int(parameters.get("binning_x",1))
sy, sx = image.shape
x_axis = x_axis.reshape(int(sx / bx), int(bx)).mean(axis=(1))
y_axis = y_axis.reshape(int(sy / by), int(by)).mean(axis=(1))
image = image.reshape(int(sy / by), int(by), int(sx / bx), int(bx) ).sum(axis=(1, 3)).astype("uint16")
ret = processor.process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata)
return ret
@@ -0,0 +1,45 @@
import json
from collections import deque
from logging import getLogger
_logger = getLogger(__name__)
background = deque(maxlen=4)
DEFAULT_ROI_SIGNAL = None
DEFAULT_ROI_BACKGROUND = None
def get_roi_x_profile(image, roi):
offset_x, size_x, offset_y, size_y = roi
roi_image = image[offset_y:offset_y + size_y, offset_x:offset_x + size_x]
return roi_image.sum(0)
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, image_background_array=None):
processed_data = dict()
by, bx = 2,2
sy, sx = image.shape
#x_axis = x_axis.reshape(int(sx / bx), int(bx)).mean(axis=(1))
#y_axis = y_axis.reshape(int(sy / by), int(by)).mean(axis=(1))
image = image.reshape(int(sy / by), int(by), int(sx / bx), int(bx) ).sum(axis=(1, 3)).astype("uint16")
image_property_name = parameters["camera_name"]
roi_signal = parameters.get("roi_signal", DEFAULT_ROI_SIGNAL)
roi_background = parameters.get("roi_background", DEFAULT_ROI_BACKGROUND)
processed_data[image_property_name + ".processing_parameters"] = json.dumps({"roi_signal": roi_signal,
"roi_background": roi_background})
if roi_signal:
signal_profile = get_roi_x_profile(image, roi_signal)
processed_data[image_property_name + ".roi_signal_x_profile"] = signal_profile
if roi_background:
processed_data[image_property_name + ".roi_background_x_profile"] = get_roi_x_profile(image, roi_background)
return processed_data
+161
View File
@@ -0,0 +1,161 @@
from logging import getLogger
from cam_server.pipeline.data_processing import functions
from cam_server.pipeline.data_processing.functions import chunk_copy
import json
import numpy
import scipy.signal
import scipy.optimize
import numba
numba.set_num_threads(4)
import epics
_logger = getLogger(__name__)
output_pv, center_pv, fwhm_pv, ymin_pv, ymax_pv, axis_pv = None, None, None, None, None, None
roi = [0, 0]
initialized = False
@numba.njit(parallel=True)
def get_spectrum (image, background):
y = image.shape[0]
x = image.shape[1]
profile = numpy.zeros(x, dtype=numpy.uint32)
b = 0
for i in numba.prange(y):
for j in range(x):
v = image[i,j]
b = background[i,j]
if v > b:
v -= b
else:
v = 0
profile[j] += v
return profile
def initialize(parameters):
global ymin_pv, ymax_pv, axis_pv, output_pv, center_pv, fwhm_pv
epics_pv_name_prefix = parameters["camera_name"]
output_pv_name = epics_pv_name_prefix + ":SPECTRUM_Y"
center_pv_name = epics_pv_name_prefix + ":SPECTRUM_CENTER"
fwhm_pv_name = epics_pv_name_prefix + ":SPECTRUM_FWHM"
ymin_pv_name = epics_pv_name_prefix + ":SPC_ROI_YMIN"
ymax_pv_name = epics_pv_name_prefix + ":SPC_ROI_YMAX"
axis_pv_name = epics_pv_name_prefix + ":SPECTRUM_X"
epics.ca.clear_cache()
output_pv = epics.PV(output_pv_name)
center_pv = epics.PV(center_pv_name)
fwhm_pv = epics.PV(fwhm_pv_name)
ymin_pv = epics.PV(ymin_pv_name)
ymax_pv = epics.PV(ymax_pv_name)
axis_pv = epics.PV(axis_pv_name)
ymin_pv.wait_for_connection()
ymax_pv.wait_for_connection()
axis_pv.wait_for_connection()
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None, background=None):
global roi, initialized
global ymin_pv, ymax_pv, axis_pv, output_pv, center_pv, fwhm_pv
if not initialized:
initialize(parameters)
initialized = True
processed_data = dict()
epics_pv_name_prefix = parameters["camera_name"]
if ymin_pv and ymin_pv.connected:
roi[0] = ymin_pv.value
if ymax_pv and ymax_pv.connected:
roi[1] = ymax_pv.value
if axis_pv and axis_pv.connected:
axis = axis_pv.value
else:
axis = None
if axis is None:
_logger.warning("Energy axis not connected");
return None
if len(axis) < image.shape[1]:
_logger.warning("Energy axis length %d < image width %d", len(axis), image.shape[1])
return None
# match the energy axis to image width
axis = axis[:image.shape[1]]
processing_image = image
nrows, ncols = processing_image.shape
# validate background data
background_image = parameters.pop('background_data', None)
if isinstance(background_image, numpy.ndarray):
#background_image = chunk_copy(background_image)
if background_image.shape != processing_image.shape:
background_image = None
else:
background_image = None
processed_data[epics_pv_name_prefix + ":processing_parameters"] = json.dumps(
{"roi": roi, "background": None if (background_image is None) else parameters.get('image_background')})
# crop the image in y direction
ymin, ymax = int(roi[0]), int(roi[1])
if nrows >= ymax > ymin >= 0:
if (nrows != ymax) or (ymin != 0):
processing_image = processing_image[ymin: ymax, :]
if background_image is not None:
background_image = background_image[ymin:ymax, :]
# remove the background and collapse in y direction to get the spectrum
if background_image is not None:
spectrum = get_spectrum(processing_image, background_image)
else:
spectrum = processing_image.sum(0, 'uint32')
# smooth the spectrum with savgol filter with 51 window size and 3rd order polynomial
smoothed_spectrum = scipy.signal.savgol_filter(spectrum, 51, 3)
# check wether spectrum has only noise. the average counts per pixel at the peak
# should be larger than 1.5 to be considered as having real signals.
minimum, maximum = smoothed_spectrum.min(), smoothed_spectrum.max()
amplitude = maximum - minimum
skip = True
if amplitude > nrows * 1.5:
skip = False
# gaussian fitting
offset, amplitude, center, sigma = functions.gauss_fit_psss(smoothed_spectrum[::2], axis[::2],
offset=minimum, amplitude=amplitude, skip=skip)
# outputs
processed_data[epics_pv_name_prefix + ":SPECTRUM_Y"] = spectrum
processed_data[epics_pv_name_prefix + ":SPECTRUM_X"] = axis
processed_data[epics_pv_name_prefix + ":SPECTRUM_CENTER"] = center
processed_data[epics_pv_name_prefix + ":SPECTRUM_FWHM"] = 2.355 * sigma
if output_pv and output_pv.connected:
output_pv.put(processed_data[epics_pv_name_prefix + ":SPECTRUM_Y"])
_logger.debug("caput on %s for pulse_id %s", output_pv, pulse_id)
if center_pv and center_pv.connected:
center_pv.put(processed_data[epics_pv_name_prefix + ":SPECTRUM_CENTER"])
if fwhm_pv and fwhm_pv.connected:
fwhm_pv.put(processed_data[epics_pv_name_prefix + ":SPECTRUM_FWHM"])
return processed_data
+138
View File
@@ -0,0 +1,138 @@
from logging import getLogger
from cam_server.pipeline.data_processing import functions
import json
import numpy
import scipy.signal
import scipy.optimize
import epics
_logger = getLogger(__name__)
output_pv, center_pv, fwhm_pv, ymin_pv, ymax_pv, axis_pv = None, None, None, None, None, None
roi = [0, 0]
initialized = False
def initialize(parameters):
global ymin_pv, ymax_pv, axis_pv, output_pv, center_pv, fwhm_pv
epics_pv_name_prefix = parameters["camera_name"]
_logger.warning("epics_pv_name_prefix: " + str(epics_pv_name_prefix))
output_pv_name = epics_pv_name_prefix + ":SPECTRUM_Y"
center_pv_name = epics_pv_name_prefix + ":SPECTRUM_CENTER"
fwhm_pv_name = epics_pv_name_prefix + ":SPECTRUM_FWHM"
ymin_pv_name = epics_pv_name_prefix + ":SPC_ROI_YMIN"
ymax_pv_name = epics_pv_name_prefix + ":SPC_ROI_YMAX"
axis_pv_name = epics_pv_name_prefix + ":SPECTRUM_X"
epics.ca.clear_cache()
output_pv = epics.PV(output_pv_name)
center_pv = epics.PV(center_pv_name)
fwhm_pv = epics.PV(fwhm_pv_name)
ymin_pv = epics.PV(ymin_pv_name)
ymax_pv = epics.PV(ymax_pv_name)
axis_pv = epics.PV(axis_pv_name)
ymin_pv.wait_for_connection()
ymax_pv.wait_for_connection()
axis_pv.wait_for_connection()
_logger.warning("output_pv_name: " + str(output_pv_name))
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
global roi, initialized
global ymin_pv, ymax_pv, axis_pv, output_pv, center_pv, fwhm_pv
if not initialized:
initialize(parameters)
initialized = True
processed_data = dict()
epics_pv_name_prefix = parameters["camera_name"]
if ymin_pv and ymin_pv.connected:
roi[0] = ymin_pv.value
if ymax_pv and ymax_pv.connected:
roi[1] = ymax_pv.value
if axis_pv and axis_pv.connected:
axis = axis_pv.value
else:
axis = None
if axis is None or len(axis) != image.shape[1]:
_logger.warning("Invalid energy axis")
return None
#processed_data[epics_pv_name_prefix + ":processing_parameters"] = json.dumps({"roi": roi, "background": parameters['background']})
parameters["roi"] = roi
processed_data[epics_pv_name_prefix + ":processing_parameters"] = json.dumps(parameters)
processing_image = image
nrows, ncols = processing_image.shape
"""
# validate background data
background_image = parameters.get('background_data')
if isinstance(background_image, numpy.ndarray):
if background_image.shape != processing_image.shape:
background_image = None
else:
background_image = None
"""
# crop the image in y direction
ymin, ymax = roi
if nrows >= ymax > ymin >= 0:
if (nrows != ymax) or (ymin != 0):
processing_image = processing_image[int(ymin):int(ymax), :]
"""
if background_image is not None:
background_image = background_image[ymin:ymax, :]
# remove the background and collapse in y direction to get the spectrum
if background_image is not None:
spectrum = functions.get_spectrum(processing_image, background_image)
else:
"""
spectrum = processing_image.sum(0, 'uint32')
# smooth the spectrum with savgol filter with 51 window size and 3rd order polynomial
smoothed_spectrum = scipy.signal.savgol_filter(spectrum, 51, 3)
# check wether spectrum has only noise. the average counts per pixel at the peak
# should be larger than 1.5 to be considered as having real signals.
minimum, maximum = smoothed_spectrum.min(), smoothed_spectrum.max()
amplitude = maximum - minimum
skip = True
if amplitude > nrows * 1.5:
skip = False
# gaussian fitting
offset, amplitude, center, sigma = functions.gauss_fit_psss(smoothed_spectrum[::2], axis[::2],
offset=minimum, amplitude=amplitude, skip=skip)
# outputs
processed_data[epics_pv_name_prefix + ":SPECTRUM_Y"] = spectrum
processed_data[epics_pv_name_prefix + ":SPECTRUM_X"] = axis
processed_data[epics_pv_name_prefix + ":SPECTRUM_CENTER"] = center
processed_data[epics_pv_name_prefix + ":SPECTRUM_FWHM"] = 2.355 * sigma
if output_pv and output_pv.connected:
output_pv.put(processed_data[epics_pv_name_prefix + ":SPECTRUM_Y"])
_logger.debug("caput on %s for pulse_id %s", output_pv, pulse_id)
if center_pv and center_pv.connected:
center_pv.put(processed_data[epics_pv_name_prefix + ":SPECTRUM_CENTER"])
if fwhm_pv and fwhm_pv.connected:
fwhm_pv.put(processed_data[epics_pv_name_prefix + ":SPECTRUM_FWHM"])
return processed_data
@@ -0,0 +1,13 @@
import json
import numpy
from cam_server.pipeline.data_processing import functions
from logging import getLogger
_logger = getLogger(__name__)
def process(data, pulse_id, timestamp, parameters):
ret = {}
ret["test"] = 1
return ret