Add loading data file from c extension for Furka

This commit is contained in:
root
2023-06-07 17:00:38 +02:00
parent 103adcab03
commit 850baa5816
21 changed files with 226 additions and 123 deletions

View File

@@ -1,10 +1,10 @@
{
"camera_calibration": {
"reference_marker": [
1412,
1469,
1513,
1569
1266,
1337,
1367,
1438
],
"reference_marker_width": 23.5,
"reference_marker_height": 21.2,

View File

@@ -1,13 +1,13 @@
{
"camera_calibration": {
"reference_marker": [
1076,
851,
1133,
893
1029,
842,
1034,
852
],
"reference_marker_width": 73.0,
"reference_marker_height": 54.0,
"reference_marker_width": 50.0,
"reference_marker_height": 50.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},

View File

@@ -1,10 +1,10 @@
{
"camera_calibration": {
"reference_marker": [
945,
565,
954,
573
880,
585,
980,
686
],
"reference_marker_width": 9.0,
"reference_marker_height": 16.0,

View File

@@ -1,12 +1,12 @@
{
"camera_calibration": {
"reference_marker": [
204,
108,
349,
934
652,
278,
836,
316
],
"reference_marker_width": 5000.0,
"reference_marker_width": 50.0,
"reference_marker_height": 2000.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0

View File

@@ -2,9 +2,9 @@
"camera_calibration": {
"reference_marker": [
265,
72,
1253,
1066
166,
1277,
1116
],
"reference_marker_width": 5000.0,
"reference_marker_height": 5000.0,

View File

@@ -1,13 +1,13 @@
{
"camera_calibration": {
"reference_marker": [
0,
0,
100,
100
304,
135,
411,
245
],
"reference_marker_width": 100.0,
"reference_marker_height": 100.0,
"reference_marker_width": 5000.0,
"reference_marker_height": 5000.0,
"angle_horizontal": 0.0,
"angle_vertical": 0.0
},

View File

@@ -3,6 +3,8 @@
"mirror_x": false,
"mirror_y": true,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "bsread",
"name": "SLAAR21-LCAM-CS841",
"protocol": "tcp",

View File

@@ -3,6 +3,8 @@
"mirror_x": false,
"mirror_y": true,
"rotate": 0,
"roi": null,
"image_background": null,
"source_type": "bsread",
"name": "SLAAR21-LCAM-CS842",
"protocol": "tcp",

View File

@@ -1,17 +1,17 @@
{
"down_calib": 0.05773750366645945,
"down_calib": 0.5591511338550219,
"xpos_odd_w_pvname": "SAROP21-PBPS103:XPOS-ODD-HIST-W",
"ypos_all_y_pvname": "SAROP21-PBPS103:YPOS-ALL-HIST-Y",
"ypos_all_w_pvname": "SAROP21-PBPS103:YPOS-ALL-HIST-W",
"name": "SAROP21-PBPS103_proc",
"vert_calib": -4.013266539044132,
"vert_calib": -3.9958078717518144,
"bsread_address": "",
"right": "SAROP21-CVME-PBPS1:Lnk9Ch2-DATA-SUM",
"ypos_dif_w_pvname": "SAROP21-PBPS103:YPOS-DIF-HIST-W",
"ypos_odd_x_pvname": "SAROP21-PBPS103:YPOS-ODD-HIST-X",
"function": "pbps.py",
"port": "9009",
"left_calib": 0.033940788499696006,
"left_calib": 0.36904567566640284,
"down": "SAROP21-CVME-PBPS1:Lnk9Ch3-DATA-SUM",
"ypos_odd_w_pvname": "SAROP21-PBPS103:YPOS-ODD-HIST-W",
"xpos_odd_y_pvname": "SAROP21-PBPS103:XPOS-ODD-HIST-Y",
@@ -23,7 +23,7 @@
"ypos_evn_x_pvname": "SAROP21-PBPS103:YPOS-EVN-HIST-X",
"uJ_calib": 605.9512700123181,
"xpos_evn_m_pvname": "SAROP21-PBPS103:XPOS-EVN-HIST-M",
"horiz_calib": 4.422571387563297,
"horiz_calib": 4.361157752097061,
"ypos_all_m_pvname": "SAROP21-PBPS103:YPOS-ALL-HIST-M",
"ypos_dif_m_pvname": "SAROP21-PBPS103:YPOS-DIF-HIST-M",
"bsread_channels": [
@@ -37,7 +37,7 @@
"pipeline_type": "stream",
"stream_timeout": 20,
"ypos_all_x_pvname": "SAROP21-PBPS103:YPOS-ALL-HIST-X",
"right_calib": 0.030184745278420903,
"right_calib": 0.33414240272743095,
"xpos_all_m_pvname": "SAROP21-PBPS103:XPOS-ALL-HIST-M",
"xpos_odd_m_pvname": "SAROP21-PBPS103:XPOS-ODD-HIST-M",
"left": "SAROP21-CVME-PBPS1:Lnk9Ch1-DATA-SUM",
@@ -51,7 +51,7 @@
"ypos_evn_y_pvname": "SAROP21-PBPS103:YPOS-EVN-HIST-Y",
"xpos_odd_x_pvname": "SAROP21-PBPS103:XPOS-ODD-HIST-X",
"threshold": 0,
"up_calib": 0.05333779168125384,
"up_calib": 0.535888712120923,
"ypos_odd_m_pvname": "SAROP21-PBPS103:YPOS-ODD-HIST-M",
"xpos_all_x_pvname": "SAROP21-PBPS103:XPOS-ALL-HIST-X",
"up": "SAROP21-CVME-PBPS1:Lnk9Ch4-DATA-SUM",
@@ -62,9 +62,9 @@
0.3
],
"calib_x_norm": [
-0.06746482707403895,
0.0004445333663804517,
0.06820285297455421
-0.06947260244733981,
-0.0005099883066721613,
0.06810554402339729
],
"calib_y_range": [
-0.3,
@@ -72,19 +72,19 @@
0.3
],
"calib_y_norm": [
0.07421884402169887,
-9.213746650202566e-05,
-0.07528530531967688
0.07645446869263132,
0.00011733719876510883,
-0.07370290104520648
],
"calib_x_norm_std": [
0.01260021920786719,
0.013510267720896078,
0.011985970517095955
0.3832642548643102,
0.36376451461448284,
0.3725425364709937
],
"calib_y_norm_std": [
0.015069277154299072,
0.015346341477740713,
0.015281728159302189
0.3869867302072751,
0.3994940062239071,
0.3769217744089247
],
"calib_datetime": "2023-05-09 09:56:48"
"calib_datetime": "2023-06-07 06:54:21"
}

View File

@@ -3,10 +3,10 @@
"image_background": "SATBD02-DSCR050_20221013_123827_350915",
"image_threshold": null,
"image_region_of_interest": [
28,
1092,
6,
1007
155,
1216,
52,
1302
],
"image_good_region": null,
"image_slices": null,

View File

@@ -1,6 +1,6 @@
{
"image_background_enable": "passive",
"image_background": "SATES21-CAMS-PATT1_20230531_133321_260634",
"image_background": "SATES21-CAMS-PATT1_20230607_073009_718877",
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
@@ -17,17 +17,25 @@
"project_axis": 0,
"no_client_timeout": 0,
"port": "9003",
"threshold": 5,
"threshold": 20,
"roi_background": [
103,
1153,
72,
1147
0,
1154,
0,
1280
],
"roi_signal": [
103,
1153,
72,
1147
]
0,
1154,
0,
1280
],
"roi_radial": [
0,
1154,
0,
1280
],
"radial_x0": "550",
"radial_y0": "550"
}

View File

@@ -1,6 +1,6 @@
{
"image_background_enable": "passive",
"image_background": "SATES21-CAMS154-M1_20230530_152447_004964",
"image_background": "SATES21-CAMS154-M1_20230607_091358_573996",
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
@@ -14,29 +14,16 @@
"thread_buffer_size": 30,
"project_axis": 0,
"roi_signal": [
7,
895,
251,
470,
0,
2523
2516
],
"threshold": 5,
"roi_background": [
"(",
"7",
",",
" ",
"8",
"9",
"5",
",",
" ",
"0",
",",
" ",
"2",
"5",
"2",
"3",
")"
251,
470,
0,
2516
]
}

View File

@@ -1,6 +1,6 @@
{
"image_background_enable": "passive",
"image_background": "SATES24-CAMS161-M1_20230531_144316_923916",
"image_background": "SATES24-CAMS161-M1_20230607_091554_570079",
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
@@ -11,9 +11,9 @@
"name": "SATES24-CAMS161-M1_spec_db",
"mode": "PUSH",
"roi_signal": [
11,
782,
15,
0,
798,
0,
2540
],
"processing_threads": 4,
@@ -21,9 +21,10 @@
"project_axis": 0,
"threshold": 5,
"roi_background": [
11,
782,
15,
0,
798,
0,
2540
]
],
"reload": true
}

View File

@@ -1,6 +1,6 @@
{
"image_background_enable": true,
"image_background": "SATES30-RIXS-CAM01_20230601_093318_381947",
"image_background": "SATES30-RIXS-CAM01_20230602_115820_621889",
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,
@@ -13,5 +13,6 @@
"block": false,
"threshold": 10.0,
"_max_frame_rate": 5.1,
"libs": "threshold_2d_start600_800.txt",
"reload": true
}

View File

@@ -1,6 +1,5 @@
{
"image_background_enable": false,
"image_background": null,
"image_threshold": null,
"image_region_of_interest": null,
"image_good_region": null,

View File

@@ -9,10 +9,10 @@
"#SAROP21-PPRM102_proc": "SAROP21-PPRM102_proc",
"#SAROP31-PPRM113_proc": "SAROP31-PPRM113_proc",
"#SATES30-RIXS-CAM01_sp1": "SATES30-RIXS-CAM01_sp",
"#SATES31-CAMS187-RIXS1_sp1": "SATES31-CAMS187-RIXS1_sp",
"#SATMA02_calib": "SATMA02_calib",
"#SINBC02-DSRM310_profiles": "SINBC02-DSRM310_profiles",
"#jungfrau_proc": "jungfrau_proc",
"#test_load_file": "test_load_file",
"#test_merge": "test_merge",
"#test_proc_with_bs": "test_proc_with_bs",
"#test_str": "test_str",
@@ -52,6 +52,7 @@
"SATES30-CAMS182-GIGE2_profiles": "SATES30-CAMS182-GIGE2_profiles",
"SATES30-RIXS-CAM01_proc": "SATES30-RIXS-CAM01_proc",
"SATES31-CAMS187-RIXS1_proc": "SATES31-CAMS187-RIXS1_proc",
"SATES31-CAMS187-RIXS1_sp1": "SATES31-CAMS187-RIXS1_sp",
"SATOP21-PMOS127-2D_pmos": "SATOP21-PMOS127-2D_pmos",
"SATOP31-PMOS132-2D_pmos": "SATOP31-PMOS132-2D_pmos",
"SINDI02-DSCR075_profiles": "SINDI02-DSCR075_profiles",

View File

@@ -253,6 +253,7 @@
"SATES31-CAMS187-RIXS1_ib:9001",
"SATES30-RIXS-CAM01_sp",
"SATES30-RIXS-CAM01_proc:9006",
"test_load_file",
"SATES30-CAMS182-GIGE1_sp",
"SATES30-CAMS182-GIGE2_sp",
"SATES30-CAMS182-GIGE1_profiles:9002",

View File

@@ -66,8 +66,8 @@ def edge(filter_name, backgrounds, signals, peakback):
# interpolate to get evenly sampled in frequency space
sig_interp = interpolate(nus, nus_new, sig_norm)
# Fourier filter
#sig_filtered = fourier_filter(sig_interp, ffilter)
sig_filtered = sig_interp
sig_filtered = fourier_filter(sig_interp, ffilter)
#sig_filtered = sig_interp
# interpolate to get unevenly sampled in frequency space (back to original wavelength space)
sig_uninterp = interpolate(nus_new, nus, sig_filtered[..., 0:2048]) + 1
# peak via the derivative

View File

@@ -14,7 +14,7 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
image_buffer.append(image)
try:
frames = numpy.array(image_buffer)
image = numpy.average(frames, 0)
image = numpy.average(frames, 0)*averaging
#_logger.info("Averaged: %d" % len(image_buffer))
except:
# Different shapes

View File

@@ -25,6 +25,81 @@ void setArrayToValue(double array[], int size, double value) {
}
}
//Initialization: Threshold & background
initialized = 0;
//const char *THRESHOLD_FILE = "/configuration/user_scripts/lib/Thresh_2D_start600_size800.npy";
const char *THRESHOLD_FILE = "/configuration/user_scripts/lib/threshold_2d_start600_800.txt";
int threshold_num_elements=-1;
double *threshold= NULL;
double *background= NULL;
const int MAX_LINE_LENGTH = 50000;
int initialize(int size_x, int size_y, PyObject *pars){
//background (all matrices are indexed in 1d)
background = malloc(size_x*size_y*sizeof(double));
for(int i=0; i<size_y;i++) {
for(int j=0;j<size_x;j++) {
background[i*size_x+j]=0.0;
}
}
threshold = (double *)malloc(size_x*size_y*sizeof(double));
int ret = 1;
if (THRESHOLD_FILE!=NULL){
FILE *file = fopen(THRESHOLD_FILE, "rb");
if (file == NULL) {
printf("Failed to open file.\n");
return -1;
}
char line[MAX_LINE_LENGTH];
int x = 0;
int y = 0;
while (fgets(line, sizeof(line), file) != NULL) {
char* token = strtok(line, " ");
while (token != NULL) {
threshold[y * size_x + x] = atof(token);
token = strtok(NULL, " ");
x++;
}
y++;
if (x != size_x){
printf("Invalid threshold file: wrong number of columns\n");
ret = -2;
break;
}
x = 0;
}
if (y != size_y){
printf("Invalid threshold file: wrong number of rows\n");
ret = -3;
}
fclose(file);
if (ret<0){
free(threshold); threshold = NULL;
}
} else {
PyObject* threshold_obj = PyDict_GetItemString(pars, "threshold");
double threshold_val = 60000.0;
if (threshold_obj!=NULL){
if (PyFloat_Check(threshold_obj)) {
threshold_val = PyFloat_AsDouble(threshold_obj);
} else if (PyLong_Check(threshold_obj)) {
threshold_val = PyLong_AsDouble(threshold_obj);
}
}
for(int i=0; i<size_y;i++) {
for(int j=0;j<size_x;j++) {
threshold[i*size_x+j]=100.0;//threshold_val; #FIX ME
}
}
}
return ret;
}
//def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
PyObject *process(PyObject *self, PyObject *args)
{
@@ -55,33 +130,16 @@ PyObject *process(PyObject *self, PyObject *args)
unsigned short* img_data = (unsigned short*)image->data;
//Initialization
if (initialized==0){
initialized = initialize(size_x, size_y, pars);
}
int i,j,l;
int i_dim=size_y;
int j_dim=size_x;
PyObject* threshold_obj = PyDict_GetItemString(pars, "threshold");
double threshold_val = 60000.0;
if (threshold_obj!=NULL){
if (PyFloat_Check(threshold_obj)) {
threshold_val = PyFloat_AsDouble(threshold_obj);
} else if (PyLong_Check(threshold_obj)) {
threshold_val = PyLong_AsDouble(threshold_obj);
}
}
double *threshold = malloc(i_dim*j_dim*sizeof(double));
for(i=0; i<i_dim;i++) {
for(j=0;j<j_dim;j++) {
threshold[i*j_dim+j]=100.0;//threshold_val;
}
}
//background (all matrices are indexed in 1d)
double *background = malloc(i_dim*j_dim*sizeof(double));
for(i=0; i<i_dim;i++) {
for(j=0;j<j_dim;j++) {
background[i*j_dim+j]=0.0;
}
}
double *frameBKsub = malloc(i_dim*j_dim*sizeof(double));
for(i=0; i<i_dim;i++) {
@@ -89,7 +147,10 @@ PyObject *process(PyObject *self, PyObject *args)
frameBKsub[i*j_dim+j]=(double)img_data[i*j_dim+j] - background[i*j_dim+j];
}
}
int evnt_num = func_ph_1d_double( frameBKsub, i_dim, j_dim, threshold);
// int evnt_num = func_ph_1d_double( (double)img_data, i_dim, j_dim, threshold);
//Create return dictionary
PyObject *ret = PyDict_New();
@@ -111,8 +172,6 @@ PyObject *process(PyObject *self, PyObject *args)
//}
//free(evns1d.evnt_ijc);
free(frameBKsub);
free(background);
free(threshold);
return ret;
}

View File

@@ -1,5 +1,7 @@
import sys
import json
from functools import lru_cache
import numpy as np
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
@@ -16,12 +18,17 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
project_axis = parameters.get("project_axis", 0)
threshold = parameters.get("threshold")
roi_radial = parameters.get("roi_radial")
radial_x0 = parameters.get("radial_x0")
radial_y0 = parameters.get("radial_y0")
# maintain the structure of processing_parameters
background_shape = None
# maintain the structure of res
projection_signal = projection_background = None
projection_radial_bins = projection_radial_counts = None
try:
@@ -40,6 +47,9 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
if roi_background is not None:
projection_background = get_roi_projection(image, roi_background, project_axis)
if roi_radial is not None:
projection_radial_bins, projection_radial_counts = get_radial_projection(image, roi_radial, radial_x0, radial_y0)
except Exception as e:
lineno = sys.exc_info()[2].tb_lineno
tn = type(e).__name__
@@ -60,6 +70,10 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
"project_axis": project_axis,
"threshold": threshold,
"roi_radial": roi_radial,
"radial_x0": radial_x0,
"radial_y0": radial_y0,
"status": status
}
@@ -69,7 +83,10 @@ def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata
camera_name + ".processing_parameters": processing_parameters,
camera_name + ".projection_signal": projection_signal,
camera_name + ".projection_background": projection_background
camera_name + ".projection_background": projection_background,
camera_name + ".projection_radial_bins": projection_radial_bins,
camera_name + ".projection_radial_counts": projection_radial_counts
}
return res
@@ -83,3 +100,28 @@ def get_roi_projection(image, roi, axis):
return project
def get_radial_projection(image, roi, x0, y0):
x_start, x_stop, y_start, y_stop = roi
image = image[x_start:x_stop, y_start:y_stop]
r, norm, ur = calc_r_norm_ur(image.shape, x0, y0)
image = image.ravel()
count = np.bincount(r, image)
res = count / norm
return ur, res
@lru_cache
def calc_r_norm_ur(shape, x0, y0):
r = calc_r(shape, x0, y0)
norm = np.bincount(r)
ur = np.unique(r)
return r, norm, ur
def calc_r(shape, x0, y0):
y, x = np.indices(shape)
r = np.sqrt((x - x0)**2 + (y - y0)**2)
r = r.ravel().astype(int)
return r