40 #include <uves_physmod_regress_echelle.h>
42 #include <uves_physmod_necregr.h>
43 #include <uves_utils_polynomial.h>
44 #include <uves_utils_wrappers.h>
45 #include <uves_pfits.h>
46 #include <uves_error.h>
54 #define SELECT_FUNC_DOUBLE cpl_table_and_selected_double
55 #define SELECT_FUNC_INT cpl_table_and_selected_int
100 const char *recipe_id,
101 const cpl_parameterlist* parameters,
142 double mean_sq_err_y=0;
143 double outputd[10][10];
152 "Could not read start factor from input header");
155 "Could not read start factor from input header");
158 "Could not read step factor from input header");
160 "Could not read step factor from input header");
165 "Could not read scan1 factor from input header");
167 "Could not read scan2 factor from input header");
178 "Could not read naxis1 from input header");
180 "Could not read naxis2 from input header");
183 start1,start2,step1,step2,naxis1,naxis2);
193 check( uves_get_parameter(parameters, NULL, recipe_id,
194 "def_pol1", CPL_TYPE_INT, &def_pol1 ),
195 "Could not read parameter");
197 check( uves_get_parameter(parameters, NULL, recipe_id,
198 "def_pol2", CPL_TYPE_INT, &def_pol2 ),
199 "Could not read parameter");
207 inpr2 = start1+(imsize1-1)*step1;
221 cpl_table_get_column_min(*o_tbl,
"X"),
222 cpl_table_get_column_max(*o_tbl,
"X"));
224 check(nraw=SELECT_FUNC_DOUBLE(*o_tbl,
"X",CPL_NOT_LESS_THAN,inpr1),
"Selection on X failed");
228 check(nraw=SELECT_FUNC_DOUBLE(*o_tbl,
"X",CPL_NOT_GREATER_THAN,inpr2),
"Selection on X failed");
232 inpr1 = start2+(scan1-1)*step2;
233 inpr2 = start2+(scan2-1)*step2;
244 check(nraw=SELECT_FUNC_DOUBLE(*o_tbl,
"Y",CPL_NOT_LESS_THAN,inpr1),
"Selection on Y failed");
247 check(nraw=SELECT_FUNC_DOUBLE(*o_tbl,
"Y",CPL_NOT_GREATER_THAN,inpr2),
"Selection on Y failed");
257 *s_tbl=cpl_table_duplicate(*w_tbl);
262 uves_propertylist_append_bool(plist,
"RMS",0);
263 uves_table_sort(*s_tbl,plist);
264 uves_free_propertylist(&plist);
266 ord_min=cpl_table_get_column_min(*o_tbl,
"ORDER");
267 ord_max=cpl_table_get_column_max(*o_tbl,
"ORDER");
268 ECHORD_1=(ord_max-ord_min+1);
269 ORDER=(ord_max-ord_min+1)/2;
270 ORDER=uves_max_int(1,ORDER);
274 RMSMAX=cpl_table_get_double(*s_tbl,
"RMS",ORDER,&status);
278 if (RMSMAX < 0.05) RMSMAX = 0.05;
285 if( OUTMODE !=
'S') {
286 uves_msg(
"Maximum admissible rms: %f pixels",RMSMAX);
290 for (ORDER = 0; ORDER<ECHORD_1; ORDER++){
291 RMS = cpl_table_get_double(*w_tbl,
"RMS",ORDER,&status);
296 if (OUTMODE !=
'S') {
299 REJECT[NBREJ] = ORDER;
306 for(ORDER = 1; ORDER<NBREJ; ORDER++){
307 check(SELECT_FUNC_INT(*o_tbl,
"ORDER",
308 CPL_NOT_EQUAL_TO,REJECT[NBREJ]),
"Error1 selecting ORDER");
311 INPUTI_1 = def_pol2 + 1;
312 INPUTI_2 = ECHORD_1 - NBREJ;
313 if (INPUTI_1 > INPUTI_2) {
314 uves_msg(
"*****************************************************");
315 uves_msg(
"**** Warning : Number of selected orders {INPUTI(2)}");
316 uves_msg(
"**** is too small for the current value of echelle");
317 uves_msg(
"**** parameter DEFPOL(2)=%d", def_pol2);
318 uves_msg(
"*****************************************************");
324 NULL,def_pol1,def_pol2,
"YFIT",
326 &mean_sq_err_y,NULL,NULL,-1,-1),
327 "Fitting YFIT failed");
328 cpl_table_set_column_unit(*o_tbl,
"YFIT",
"pix");
329 cpl_table_set_column_unit(*o_tbl,
"X",
"pix");
330 cpl_table_set_column_unit(*o_tbl,
"Y",
"pix");
342 cpl_table_duplicate_column(*o_tbl,
"RESIDUAL",*o_tbl,
"Y");
343 cpl_table_subtract_columns(*o_tbl,
"RESIDUAL",
"YFIT");
344 cpl_table_set_column_unit(*o_tbl,
"RESIDUAL",
"pix");
347 THRESH = kappa * sqrt(mean_sq_err_y);
348 if (THRESH > tol) THRESH = tol;
351 check(SELECT_FUNC_DOUBLE(*o_tbl,
"RESIDUAL",
352 CPL_LESS_THAN,THRESH),
"Error1 selecting RESIDUAL");
354 check(SELECT_FUNC_DOUBLE(*o_tbl,
"RESIDUAL",
355 CPL_GREATER_THAN,-THRESH),
"Error2 selecting RESIDUAL");
357 if (num_outliers >= 1)
361 for(CNT = 1; CNT<num_outliers; CNT++) {
372 NULL,def_pol1,def_pol2,
"YFIT",
374 &mean_sq_err_y,NULL,NULL,-1,-1),
375 "Fitting YFIT failed");
377 if (OUTMODE !=
'S') {
379 cpl_table_get_nrow(*o_tbl),sqrt(mean_sq_err_y));
382 cpl_table_duplicate_column(*o_tbl,
"RESIDUAL",*o_tbl,
"Y");
383 cpl_table_subtract_columns(*o_tbl,
"RESIDUAL",
"YFIT");
385 THRESH = kappa * sqrt(mean_sq_err_y);
386 if (THRESH > tol) THRESH = tol;
388 check(SELECT_FUNC_DOUBLE(*o_tbl,
"RESIDUAL",
389 CPL_LESS_THAN,THRESH),
"Error3 selecting RESIDUAL");
390 check(SELECT_FUNC_DOUBLE(*o_tbl,
"RESIDUAL",
391 CPL_GREATER_THAN,-THRESH),
"Error4 selecting RESIDUAL");
399 uves_free_propertylist(&plist);