31#include "moo_compute_slitoffset.h"
34#include "moo_badpix.h"
49_moo_compute_slitoffset_single(moo_single *det,
51 moo_compute_slitoffset_params *params)
54 cpl_vector *sumfluxv = NULL;
55 cpl_matrix *xpos = NULL;
56 cpl_vector *values = NULL;
57 cpl_polynomial *poly = NULL;
59 cpl_ensure(det != NULL, CPL_ERROR_NULL_INPUT, NAN);
60 cpl_ensure(loc != NULL, CPL_ERROR_NULL_INPUT, NAN);
61 cpl_ensure(params != NULL, CPL_ERROR_NULL_INPUT, NAN);
63 cpl_errorstate prestate = cpl_errorstate_get();
66 int nb_fibres = cpl_image_get_size_y(fcentroids);
67 int nx = cpl_image_get_size_x(fcentroids);
71 cpl_image *image = hdrl_image_get_image(himage);
73 double min = params->min;
74 double max = params->max;
75 double step = params->step;
77 int size = (int)((max - min) / step + 1);
78 moo_try_check(sumfluxv = cpl_vector_new(size),
" ");
80 double *sumflux = cpl_vector_get_data(sumfluxv);
81 for (
int i = 0; i < size; i++) {
92#if (__GNUC__ == 9) && (__GNUC_MINOR__ < 3)
93#pragma omp parallel shared(sumflux, size, min, max, step, nb_fibres, nx, \
96#pragma omp parallel default(none) \
97 shared(sumflux, size, min, max, step, nb_fibres, nx, fcentroids, image)
102 for (
int s = 0; s < size; s++) {
103 double delta = min + s * step;
104 for (
int j = 1; j <= nb_fibres; j++) {
105 for (
int i = 1; i <= nx; i++) {
107 double yc = cpl_image_get(fcentroids, i, j, &rej);
109 int nyc = (int)round(yc + delta);
110 double flux = cpl_image_get(image, i, nyc, &rej);
121 double vmax = cpl_vector_get_max(sumfluxv);
122 double lim = vmax * 0.9;
125 for (
int i = 0; i < size; i++) {
126 double v = sumflux[i];
134 for (
int i = size - 1; i >= 0; i--) {
135 double v = sumflux[i];
142 int fitsize = imax - imin + 1;
143 xpos = cpl_matrix_new(1, fitsize);
144 values = cpl_vector_new(fitsize);
146 for (
int i = imin; i <= imax; i++) {
147 double v = sumflux[i];
148 double s = min + i * step;
149 cpl_matrix_set(xpos, 0, i - imin, s);
150 cpl_vector_set(values, i - imin, v);
152 poly = cpl_polynomial_new(1);
153 const cpl_boolean sampsym = CPL_TRUE;
154 const cpl_size maxdeg1d = 2;
155 cpl_polynomial_fit(poly, xpos, &sampsym, values, NULL, CPL_FALSE, NULL,
159 double a = cpl_polynomial_get_coeff(poly, &power);
161 double b = cpl_polynomial_get_coeff(poly, &power);
165 cpl_polynomial_delete(poly);
166 cpl_matrix_delete(xpos);
167 cpl_vector_delete(values);
168 cpl_vector_delete(sumfluxv);
170 if (!cpl_errorstate_is_equal(prestate)) {
171 cpl_msg_error(__func__,
"Error in compute_slitoffset");
172 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
175 cpl_errorstate_set(prestate);
199 moo_compute_slitoffset_params *params)
201 float *offsets = NULL;
203 cpl_ensure(det != NULL, CPL_ERROR_NULL_INPUT, NULL);
204 cpl_ensure(loc != NULL, CPL_ERROR_NULL_INPUT, NULL);
205 cpl_ensure(params != NULL, CPL_ERROR_NULL_INPUT, NULL);
210 offsets = cpl_calloc(6,
sizeof(
float));
211 cpl_msg_info(
"compute_slitoffset",
212 "Compute slit offset with [%f,%f] step %f", params->min,
213 params->max, params->step);
215 for (
int i = 1; i <= 2; i++) {
216 for (
int j = 0; j < 3; j++) {
217 int idx = j + (i - 1) * 3;
218 moo_single *det_single =
221 if (det_single != NULL && loc_single != NULL) {
223 (float)_moo_compute_slitoffset_single(det_single,
#define MOO_BADPIX_OUTSIDE_DATA_RANGE
#define MOO_BADPIX_CALIB_DEFECT
#define MOO_BADPIX_COSMETIC
moo_single * moo_det_load_single(moo_det *self, moo_detector_type type, int num, int level)
Load the type part in DET and return it.
cpl_image * moo_loc_single_get_f_centroids(moo_loc_single *self)
Get image of fit centroids.
moo_loc_single * moo_loc_get_single(moo_loc *self, moo_detector_type type, int ntas)
Get the type part in LOC and return it.
hdrl_image * moo_single_get_image(moo_single *self)
Get the IMAGE part (DATA,ERR) of single DET.
float * moo_compute_slitoffset(moo_det *det, moo_loc *loc, moo_compute_slitoffset_params *params)
Compute slit offset in LOC.