X-shooter Pipeline Reference Manual 3.8.15
xsh_data_resid_tab.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2013-03-20 12:25:43 $
23 * $Revision: 1.46 $
24 * $Name: not supported by cvs2svn $
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31
32
33/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
43/*-----------------------------------------------------------------------------
44 Includes
45 ----------------------------------------------------------------------------*/
46
47#include <xsh_data_resid_tab.h>
48#include <xsh_utils.h>
49#include <xsh_error.h>
50#include <xsh_msg.h>
51#include <xsh_pfits.h>
52#include <cpl.h>
53#include <xsh_drl.h>
54#include <xsh_utils_table.h>
55#include <xsh_data_wavesol.h>
56
57/*----------------------------------------------------------------------------
58 Function implementation
59 ----------------------------------------------------------------------------*/
60
61
83/*---------------------------------------------------------------------------*/
85xsh_resid_tab_create(int size, double *lambda, double *order,
86 double *slit, double* sn, int *slit_index,
87 double *thpre_x, double *thpre_y,
88 double*corr_x, double* corr_y,
89 double *gaussian_norm,
90 double *gaussian_fit_x, double *gaussian_fit_y,
91 double *gaussian_sigma_x, double *gaussian_sigma_y,
92 double *gaussian_fwhm_x, double *gaussian_fwhm_y, int* flag,
93 xsh_wavesol *wavesol, int wavesol_type)
94{
96 xsh_resid_tab* result = NULL;
97 int i;
98
99 /* verify input */
101 XSH_ASSURE_NOT_NULL( lambda);
103 XSH_ASSURE_NOT_NULL( slit);
104 XSH_ASSURE_NOT_NULL( slit_index);
105 XSH_ASSURE_NOT_NULL( thpre_x);
106 XSH_ASSURE_NOT_NULL( thpre_y);
107
108 XSH_ASSURE_NOT_NULL( gaussian_fit_x);
109 XSH_ASSURE_NOT_NULL( gaussian_fit_y);
110 XSH_ASSURE_NOT_NULL( gaussian_sigma_x);
111 XSH_ASSURE_NOT_NULL( gaussian_sigma_y);
112 XSH_ASSURE_NOT_NULL( gaussian_fwhm_x);
113 XSH_ASSURE_NOT_NULL( gaussian_fwhm_y);
114 XSH_ASSURE_NOT_NULL( gaussian_norm);
115
116 XSH_CALLOC( result, xsh_resid_tab, 1);
117
118 XSH_CALLOC( result->lambda, double, size);
119 XSH_CALLOC( result->order, double, size);
120 XSH_CALLOC( result->slit, double, size);
121 XSH_CALLOC( result->sn, double, size);
122 XSH_CALLOC( result->slit_index, int, size);
123 XSH_CALLOC( result->thpre_x, double, size);
124 XSH_CALLOC( result->thpre_y, double, size);
125 XSH_CALLOC( result->thcor_x, double, size);
126 XSH_CALLOC( result->thcor_y, double, size);
127 XSH_CALLOC( result->xgauss, double, size);
128 XSH_CALLOC( result->ygauss, double, size);
129 XSH_CALLOC( result->sig_xgauss, double, size);
130 XSH_CALLOC( result->sig_ygauss, double, size);
131 XSH_CALLOC( result->norm_gauss, double, size);
132 XSH_CALLOC( result->fwhm_xgauss, double, size);
133 XSH_CALLOC( result->fwhm_ygauss, double, size);
134
135 XSH_CALLOC( result->xpoly, double, size);
136 XSH_CALLOC( result->ypoly, double, size);
137 if(flag) {
138 XSH_CALLOC( result->flag, int, size);
139 }
140 check (result->header = cpl_propertylist_new());
141
142 result->size = size;
143 result->solution_type = wavesol_type;
144
145 if (wavesol != NULL) {
146 check (type = xsh_wavesol_get_type( wavesol));
147 }
148 else{
150 }
151
152 for( i=0; i<size; i++){
153
154 result->lambda[i] = lambda[i];
155 result->order[i] = order[i];
156 result->slit[i] = slit[i];
157 if(sn != NULL) {
158 result->sn[i] = sn[i];
159 } else {
160 result->sn[i]=0;
161 }
162 result->slit_index[i] = slit_index[i];
163 result->thpre_x[i] = thpre_x[i];
164 result->thpre_y[i] = thpre_y[i];
165 result->thcor_x[i] = thpre_x[i]+corr_x[i];
166 result->thcor_y[i] = thpre_y[i]+corr_y[i];
167 result->xgauss[i] = gaussian_fit_x[i];
168 result->ygauss[i] = gaussian_fit_y[i];
169 result->sig_xgauss[i] = gaussian_sigma_x[i];
170 result->sig_ygauss[i] = gaussian_sigma_y[i];
171 result->fwhm_xgauss[i] = gaussian_fwhm_x[i];
172 result->fwhm_ygauss[i] = gaussian_fwhm_y[i];
173 result->norm_gauss[i] = gaussian_norm[i];
174 if(flag) {
175 result->flag[i] = flag[i];
176 }
177 if ( type == XSH_WAVESOL_2D){
178 double polx, poly;
179
180 check( polx = xsh_wavesol_eval_polx( wavesol, lambda[i],
181 order[i], slit[i]));
182 check( poly = xsh_wavesol_eval_poly( wavesol, lambda[i],
183 order[i], slit[i]));
184 result->xpoly[i] = polx;
185 result->ypoly[i] = poly;
186 }
187 else if ( type == XSH_WAVESOL_GUESS){
188 check( result->xpoly[i] = xsh_wavesol_eval_polx( wavesol,
189 lambda[i], order[i], slit[i])+result->thcor_x[i]);
190 check( result->ypoly[i] = xsh_wavesol_eval_poly( wavesol,
191 lambda[i], order[i], slit[i])+result->thcor_y[i]);
192 }
193 else{
194 result->xpoly[i] = 0.0;
195 result->ypoly[i] = 0.0;
196 }
197
198 }
199
200/* check (xsh_tools_get_statistics( result->diff_poly_fit_x, size,
201 &result->median_diff_poly_fit_x, &result->mean_diff_poly_fit_x,
202 &result->stdev_diff_poly_fit_x));
203 check (xsh_tools_get_statistics( result->diff_poly_fit_y, size,
204 &result->median_diff_poly_fit_y, &result->mean_diff_poly_fit_y,
205 &result->stdev_diff_poly_fit_y));
206*/
207 cleanup:
208 if ( cpl_error_get_code() != CPL_ERROR_NONE){
209 xsh_resid_tab_free( &result);
210 }
211 return result;
212}
213
214
215
217xsh_resid_tab_create_not_flagged(int size, double *lambda, double *order,
218 double *slit, double* sn, int *slit_index, double *thpre_x, double *thpre_y,
219 double*corr_x, double* corr_y, double *gaussian_norm,
220 double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x,
221 double *gaussian_sigma_y, double *gaussian_fwhm_x, double *gaussian_fwhm_y,
222 int* flag, xsh_wavesol *wavesol, int wavesol_type) {
224 xsh_resid_tab* result = NULL;
225 int i;
226 int ngood = 0;
227
228
229 /* As several lines has been flagged we need to count the good pixels */
230 for (i = 0; i < size; i++) {
231
232 if (flag != NULL && flag[i] == 0) {
233 ngood++;
234 }
235
236 }
237
238 /* verify input */
240 XSH_ASSURE_NOT_NULL( lambda);
242 XSH_ASSURE_NOT_NULL( slit);
243 XSH_ASSURE_NOT_NULL( slit_index);
244 XSH_ASSURE_NOT_NULL( thpre_x);
245 XSH_ASSURE_NOT_NULL( thpre_y);
246
247 XSH_ASSURE_NOT_NULL( gaussian_fit_x);
248 XSH_ASSURE_NOT_NULL( gaussian_fit_y);
249 XSH_ASSURE_NOT_NULL( gaussian_sigma_x);
250 XSH_ASSURE_NOT_NULL( gaussian_sigma_y);
251 XSH_ASSURE_NOT_NULL( gaussian_fwhm_x);
252 XSH_ASSURE_NOT_NULL( gaussian_fwhm_y);
253 XSH_ASSURE_NOT_NULL( gaussian_norm);
254
255 XSH_CALLOC( result, xsh_resid_tab, 1);
256
257 /* the result table contains only values corresponding to good pixels */
258 XSH_CALLOC ( result->lambda, double, ngood);
259 XSH_CALLOC( result->order, double, ngood);
260 XSH_CALLOC ( result->slit, double, ngood);
261 XSH_CALLOC( result->sn, double, ngood);
262 XSH_CALLOC ( result->slit_index, int, ngood);
263 XSH_CALLOC( result->thpre_x, double,ngood);
264 XSH_CALLOC ( result->thpre_y, double, ngood);
265 XSH_CALLOC( result->thcor_x, double,ngood);
266 XSH_CALLOC ( result->thcor_y, double, ngood);
267 XSH_CALLOC( result->xgauss, double, ngood);
268 XSH_CALLOC ( result->ygauss, double, ngood);
269 XSH_CALLOC( result->sig_xgauss, double, ngood);
270 XSH_CALLOC ( result->sig_ygauss, double, ngood);
271 XSH_CALLOC( result->norm_gauss,double, ngood);
272 XSH_CALLOC ( result->fwhm_xgauss, double, ngood);
273 XSH_CALLOC( result->fwhm_ygauss,double, ngood);
274 XSH_CALLOC ( result->xpoly, double, ngood);
275 XSH_CALLOC( result->ypoly, double, ngood);
276
277 if( flag) {
278 XSH_CALLOC( result->flag, int, ngood);
279 }
280 check(result->header = cpl_propertylist_new());
281
282 result->size = ngood;
283 result->solution_type = wavesol_type;
284
285 if (wavesol != NULL) {
286 check(type = xsh_wavesol_get_type( wavesol));
287 } else {
289 }
290
291 /* we need an additional variable because result has a different size than
292 input arrays */
293
294 int k = 0;
295 for (i = 0; i < size; i++) {
296 if (flag != NULL && flag[i] == 0) {
297 result->lambda[k] = lambda[i];
298 result->order[k] = order[i];
299 result->slit[k] = slit[i];
300 if (sn != NULL) {
301 result->sn[k] = sn[i];
302 } else {
303 result->sn[k] = 0;
304 }
305 result->slit_index[k] = slit_index[i];
306 result->thpre_x[k] = thpre_x[i];
307 result->thpre_y[k] = thpre_y[i];
308 result->thcor_x[k] = thpre_x[i] + corr_x[i];
309 result->thcor_y[k] = thpre_y[i] + corr_y[i];
310 result->xgauss[k] = gaussian_fit_x[i];
311 result->ygauss[k] = gaussian_fit_y[i];
312 result->sig_xgauss[k] = gaussian_sigma_x[i];
313 result->sig_ygauss[k] = gaussian_sigma_y[i];
314 result->fwhm_xgauss[k] = gaussian_fwhm_x[i];
315 result->fwhm_ygauss[k] = gaussian_fwhm_y[i];
316 result->norm_gauss[k] = gaussian_norm[i];
317 if (flag) {
318 result->flag[k] = flag[i];
319 }
320 if (type == XSH_WAVESOL_2D) {
321 double polx, poly;
322
323 check(
324 polx = xsh_wavesol_eval_polx( wavesol, lambda[i], order[i], slit[i]));
325 check(
326 poly = xsh_wavesol_eval_poly( wavesol, lambda[i], order[i], slit[i]));
327 result->xpoly[k] = polx;
328 result->ypoly[k] = poly;
329 } else if (type == XSH_WAVESOL_GUESS) {
330 check(
331 result->xpoly[k] = xsh_wavesol_eval_polx( wavesol, lambda[i], order[i], slit[i])+result->thcor_x[k]);
332 check(
333 result->ypoly[k] = xsh_wavesol_eval_poly( wavesol, lambda[i], order[i], slit[i])+result->thcor_y[k]);
334 } else {
335 result->xpoly[k] = 0.0;
336 result->ypoly[k] = 0.0;
337 }
338 k++;
339 }
340 }
341
342 cleanup: if (cpl_error_get_code() != CPL_ERROR_NONE) {
343 xsh_resid_tab_free(&result);
344 }
345 return result;
346}
347
348cpl_frame*
349xsh_resid_tab_erase_flagged( cpl_frame* resid,const char* name)
350{
351
352 cpl_frame* result = NULL;
353 cpl_table* tab = NULL;
354 cpl_table* ext = NULL;
355 const char* fname = NULL;
356
357 cpl_propertylist* header=NULL;
358 //int bad=0;
359
360 result=cpl_frame_duplicate(resid);
361 check( fname = cpl_frame_get_filename( resid));
362 tab=cpl_table_load(fname,1,0);
363 header=cpl_propertylist_load(fname,0);
364 cpl_table_and_selected_int(tab,XSH_RESID_TAB_TABLE_COLNAME_FLAG,
365 CPL_GREATER_THAN,0);
366 cpl_table_erase_selected(tab);
367 cpl_table_save(tab,header,NULL,name,CPL_IO_DEFAULT);
368 cpl_frame_set_filename(result,name);
369
370 cleanup:
371 xsh_free_table(&ext);
372 xsh_free_table(&tab);
373 xsh_free_propertylist(&header);
374
375 return result;
376}
377/*---------------------------------------------------------------------------*/
387/*---------------------------------------------------------------------------*/
388
389xsh_resid_tab* xsh_resid_tab_load( cpl_frame* resid_tab_frame)
390{
391 xsh_resid_tab* result = NULL;
392 cpl_table* table = NULL;
393 const char* tablename = NULL;
394 int i = 0;
395 int size = 0;
396 double *lambda = NULL;
397 double *order = NULL;
398 double *slit = NULL;
399 int *slit_index = NULL;
400 double *thx = NULL;
401 double *thy = NULL;
402 double *thcorx = NULL;
403 double *thcory = NULL;
404 double *xgauss = NULL;
405 double *ygauss = NULL;
406 double *sig_xgauss = NULL;
407 double *sig_ygauss = NULL;
408 double *fwhm_xgauss = NULL;
409 double *fwhm_ygauss = NULL;
410 double *norm_gauss = NULL;
411 double *xpoly = NULL;
412 double *ypoly = NULL;
413 double *thanneal_x = NULL;
414 double *thanneal_y = NULL;
415 int* flag=NULL;
416 int solution_type = XSH_DETECT_ARCLINES_TYPE_POLY;
417 const char* wavesol_type = NULL;
418 /* verify input */
419 XSH_ASSURE_NOT_NULL( resid_tab_frame);
420
421 /* get table */
422 check( tablename = cpl_frame_get_filename( resid_tab_frame));
423
424 XSH_TABLE_LOAD( table, tablename);
425
426 check( size = cpl_table_get_nrow(table));
427
428 XSH_CALLOC( result, xsh_resid_tab, 1);
429 check (result->header = cpl_propertylist_load( tablename, 0));
431 if (cpl_error_get_code() == CPL_ERROR_NONE){
432 if ( strcmp(wavesol_type, XSH_WAVESOLTYPE_MODEL)==0){
433 solution_type = XSH_DETECT_ARCLINES_TYPE_MODEL;
434 }
435 }
436 else{
437 xsh_msg("Can't read keyword %s", XSH_WAVESOLTYPE);
438 cpl_error_reset();
439 }
440 result->size = size;
441 result->solution_type = solution_type;
442
443 XSH_CALLOC( lambda, double, size);
444 XSH_CALLOC( order, double, size);
445 XSH_CALLOC( slit, double, size);
446 XSH_CALLOC( slit_index, int, size);
447 XSH_CALLOC( thx, double, size);
448 XSH_CALLOC( thy, double, size);
449 XSH_CALLOC( thcorx, double, size);
450 XSH_CALLOC( thcory, double, size);
451 XSH_CALLOC( xgauss, double, size);
452 XSH_CALLOC( ygauss, double, size);
453 XSH_CALLOC( sig_xgauss, double, size);
454 XSH_CALLOC( sig_ygauss, double, size);
455 XSH_CALLOC( fwhm_xgauss, double, size);
456 XSH_CALLOC( fwhm_ygauss, double, size);
457 XSH_CALLOC( norm_gauss, double, size);
458 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
459 XSH_CALLOC( thanneal_x, double, size);
460 XSH_CALLOC( thanneal_y, double, size);
461 }
462 else{
463 XSH_CALLOC( xpoly, double, size);
464 XSH_CALLOC( ypoly, double, size);
465 }
466 XSH_CALLOC( flag, int, size);
467
468 for(i=0; i<size;i++){
469 int orderv, slit_indexv;
470 double lambdav, slitv, thxv, thyv;
471 double thcorxv=0, thcoryv=0;
472 double xgaussv, ygaussv, xpolyv, ypolyv;
473 double sig_xgaussv, sig_ygaussv;
474 double fwhm_xgaussv, fwhm_ygaussv;
475 double norm_gaussv;
476 int flagv=0;
477
478 check( xsh_get_table_value( table,
480 CPL_TYPE_DOUBLE, i, &lambdav));
481
482 check( xsh_get_table_value( table,
484 CPL_TYPE_INT, i, &orderv));
485
486 check( xsh_get_table_value( table,
488 CPL_TYPE_DOUBLE, i, &slitv));
489
492 CPL_TYPE_INT, i, &slit_indexv));
493
496 CPL_TYPE_DOUBLE, i, &thxv));
497
500 CPL_TYPE_DOUBLE, i, &thyv));
501
502 /* AMO: Decided with reflex review to remove those columns
503 check( xsh_get_table_value( table,
504 XSH_RESID_TAB_TABLE_COLNAME_XTHCOR,
505 CPL_TYPE_DOUBLE, i, &thcorxv));
506
507 check( xsh_get_table_value( table,
508 XSH_RESID_TAB_TABLE_COLNAME_YTHCOR,
509 CPL_TYPE_DOUBLE, i, &thcoryv));
510 */
513 CPL_TYPE_DOUBLE, i, &xgaussv));
514
517 CPL_TYPE_DOUBLE, i, &ygaussv));
518
521 CPL_TYPE_DOUBLE, i, &sig_xgaussv));
522
525 CPL_TYPE_DOUBLE, i, &sig_ygaussv));
526
527
530 CPL_TYPE_DOUBLE, i, &fwhm_xgaussv));
531
534 CPL_TYPE_DOUBLE, i, &fwhm_ygaussv));
535
538 CPL_TYPE_DOUBLE, i, &norm_gaussv));
539
540 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
543 CPL_TYPE_DOUBLE, i, &xpolyv));
544 thanneal_x[i] = xpolyv;
547 CPL_TYPE_DOUBLE, i, &ypolyv));
548 thanneal_y[i] = ypolyv;
549 }
550 else{
553 CPL_TYPE_DOUBLE, i, &xpolyv));
554 xpoly[i] = xpolyv;
557 CPL_TYPE_DOUBLE, i, &ypolyv));
558 ypoly[i] = ypolyv;
559 }
560 if (cpl_table_has_column(table,XSH_RESID_TAB_TABLE_COLNAME_FLAG)) {
563 CPL_TYPE_INT, i, &flagv));
564 }
565 lambda[i] = lambdav;
566 order[i] = (double) orderv;
567 slit[i] = slitv;
568 slit_index[i] = slit_indexv;
569 thx[i] = thxv;
570 thy[i] = thyv;
571 thcorx[i] =thcorxv;
572 thcory[i] = thcoryv;
573 xgauss[i] = xgaussv;
574 ygauss[i] = ygaussv;
575 sig_xgauss[i] = sig_xgaussv;
576 sig_ygauss[i] = sig_ygaussv;
577 fwhm_xgauss[i] = fwhm_xgaussv;
578 fwhm_ygauss[i] = fwhm_ygaussv;
579 norm_gauss[i] = norm_gaussv;
580 flag[i]=flagv;
581 }
582
583 result->lambda = lambda;
584 result->order = order;
585 result->slit = slit;
586 result->slit_index = slit_index;
587 result->thpre_x = thx;
588 result->thpre_y = thy;
589 result->thcor_x = thcorx;
590 result->thcor_y = thcory;
591 result->xgauss = xgauss;
592 result->ygauss = ygauss;
593 result->sig_xgauss = sig_xgauss;
594 result->sig_ygauss = sig_ygauss;
595 result->fwhm_xgauss = fwhm_xgauss;
596 result->fwhm_ygauss = fwhm_ygauss;
597 result->norm_gauss = norm_gauss;
598 if ( solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
599 result->thanneal_x = thanneal_x;
600 result->thanneal_y = thanneal_y;
601 }
602 else{
603 result->xpoly = xpoly;
604 result->ypoly = ypoly;
605 }
606 result->flag = flag;
607
608 cleanup:
609 if (cpl_error_get_code () != CPL_ERROR_NONE) {
610 xsh_error_msg("can't load frame %s",
611 cpl_frame_get_filename(resid_tab_frame));
612 xsh_resid_tab_free(&result);
613 return NULL;
614 } else {
615 XSH_TABLE_FREE( table);
616 return result;
617 }
618}
619
620/*---------------------------------------------------------------------------*/
628/*---------------------------------------------------------------------------*/
630 if ( resid && *resid) {
631 XSH_FREE( (*resid)->lambda);
632 XSH_FREE( (*resid)->order);
633 XSH_FREE( (*resid)->slit);
634 XSH_FREE( (*resid)->slit_index);
635 XSH_FREE( (*resid)->thpre_x);
636 XSH_FREE( (*resid)->thpre_y);
637 XSH_FREE( (*resid)->thcor_x);
638 XSH_FREE( (*resid)->thcor_y);
639 XSH_FREE( (*resid)->xgauss);
640 XSH_FREE( (*resid)->ygauss);
641 XSH_FREE( (*resid)->sig_xgauss);
642 XSH_FREE( (*resid)->sig_ygauss);
643 XSH_FREE( (*resid)->fwhm_xgauss);
644 XSH_FREE( (*resid)->fwhm_ygauss);
645 XSH_FREE( (*resid)->norm_gauss);
646 XSH_FREE( (*resid)->xpoly);
647 XSH_FREE( (*resid)->ypoly);
648 XSH_FREE( (*resid)->thanneal_x);
649 XSH_FREE( (*resid)->thanneal_y);
650 XSH_FREE( (*resid)->flag);
651 if( (*resid)->sn) XSH_FREE( (*resid)->sn) ;
652 xsh_free_propertylist( &(*resid)->header);
653 cpl_free(*resid);
654 *resid = NULL;
655 }
656
657}
658
659
660/*---------------------------------------------------------------------------*/
669/*---------------------------------------------------------------------------*/
670void xsh_resid_tab_log( xsh_resid_tab* resid, const char* filename)
671{
672
673 FILE* logfile = NULL;
674 int i = 0;
675
676 XSH_ASSURE_NOT_NULL( resid);
677 XSH_ASSURE_NOT_NULL( filename);
678
679 logfile = fopen(filename,"w");
680
682 fprintf( logfile,
683 "# lambda order slit thx, thy, gaussx, gaussy, xpoly, ypoly");
684 for ( i=0; i< resid->size; i++){
685 double lambda, order, slit;
686
687 lambda = resid->lambda[i];
688 order = resid->order[i];
689 slit = resid->slit[i];
690 fprintf( logfile,
691 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
692 lambda, order, slit, resid->thpre_x[i], resid->thpre_y[i],
693 resid->xgauss[i], resid->ygauss[i],
694 resid->xpoly[i], resid->ypoly[i]
695 );
696 }
697 }
698 else{
699 fprintf( logfile,
700 "# lambda order slit thx, thy, gaussx, gaussy, thanneal_x, thanneal_y");
701 for ( i=0; i< resid->size; i++){
702 double lambda, order, slit;
703
704 lambda = resid->lambda[i];
705 order = resid->order[i];
706 slit = resid->slit[i];
707 fprintf( logfile,
708 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
709 lambda, order, slit, resid->thpre_x[i], resid->thpre_y[i],
710 resid->xgauss[i], resid->ygauss[i],
711 resid->thanneal_x[i], resid->thanneal_y[i]
712 );
713 }
714 }
715 fclose( logfile);
716 cleanup:
717 return;
718}
719
720/*---------------------------------------------------------------------------*/
732/*---------------------------------------------------------------------------*/
733cpl_frame* xsh_resid_tab_save( xsh_resid_tab* resid, const char* filename,
734 xsh_instrument* instr,const char* tag)
735{
736 cpl_frame *result = NULL ;
737 cpl_table *table = NULL;
738 cpl_propertylist *header = NULL;
739 int i = 0;
740
741 double residx_min=0;
742 double residx_max=0;
743 double residx_rms=0;
744
745 double residy_min=0;
746 double residy_max=0;
747 double residy_rms=0;
748
749 XSH_ASSURE_NOT_NULL( resid);
750 XSH_ASSURE_NOT_NULL( filename);
751 XSH_ASSURE_NOT_NULL( instr);
752
753 /* create a table */
754 check( table = cpl_table_new( XSH_RESID_TAB_TABLE_NB_COL));
755 header = resid->header;
756 /* copy some QC parameters */
758 check( xsh_pfits_set_qc( header, &(resid->mean_diff_poly_fit_x),
760 check( xsh_pfits_set_qc( header, &(resid->median_diff_poly_fit_x),
762 check( xsh_pfits_set_qc( header, &(resid->stdev_diff_poly_fit_x),
764 check( xsh_pfits_set_qc( header, &(resid->mean_diff_poly_fit_y),
766 check( xsh_pfits_set_qc( header, &(resid->median_diff_poly_fit_y),
768 check( xsh_pfits_set_qc( header, &(resid->stdev_diff_poly_fit_y),
770 }
771
772 /* create columns */
774 XSH_RESID_TAB_TABLE_UNIT_WAVELENGTH, CPL_TYPE_DOUBLE);
775
777 XSH_RESID_TAB_TABLE_UNIT_ORDER, CPL_TYPE_INT);
778
781
784
786 XSH_RESID_TAB_TABLE_UNIT_XTHPRE, CPL_TYPE_DOUBLE);
787
789 XSH_RESID_TAB_TABLE_UNIT_YTHPRE, CPL_TYPE_DOUBLE);
790
791 /* AMO: decided with Reflex review to remove those columns
792 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XTHCOR,
793 XSH_RESID_TAB_TABLE_UNIT_XTHCOR, CPL_TYPE_DOUBLE);
794
795 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YTHCOR,
796 XSH_RESID_TAB_TABLE_UNIT_YTHCOR, CPL_TYPE_DOUBLE);
797 */
798
800 XSH_RESID_TAB_TABLE_UNIT_XGAUSS, CPL_TYPE_DOUBLE);
801
803 XSH_RESID_TAB_TABLE_UNIT_YGAUSS, CPL_TYPE_DOUBLE);
804
806 XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS, CPL_TYPE_DOUBLE);
807
809 XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS, CPL_TYPE_DOUBLE);
810
812 XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS, CPL_TYPE_DOUBLE);
813
815 XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS, CPL_TYPE_DOUBLE);
816
818 XSH_RESID_TAB_TABLE_UNIT_NORMGAUSS, CPL_TYPE_DOUBLE);
819
821 XSH_RESID_TAB_TABLE_UNIT_SN, CPL_TYPE_DOUBLE);
822
824 XSH_RESID_TAB_TABLE_UNIT_XPOLY, CPL_TYPE_DOUBLE);
825
827 XSH_RESID_TAB_TABLE_UNIT_YPOLY, CPL_TYPE_DOUBLE);
828
830 XSH_RESID_TAB_TABLE_UNIT_XTHANNEAL, CPL_TYPE_DOUBLE);
831
833 XSH_RESID_TAB_TABLE_UNIT_YTHANNEAL, CPL_TYPE_DOUBLE);
834
836 XSH_RESID_TAB_TABLE_UNIT_RESIDXPOLY, CPL_TYPE_DOUBLE);
837
839 XSH_RESID_TAB_TABLE_UNIT_RESIDYPOLY, CPL_TYPE_DOUBLE);
840
842 XSH_RESID_TAB_TABLE_UNIT_RESIDXMODEL, CPL_TYPE_DOUBLE);
843
845 XSH_RESID_TAB_TABLE_UNIT_RESIDYMODEL, CPL_TYPE_DOUBLE);
846
847 if(resid->flag) {
848
850 XSH_RESID_TAB_TABLE_UNIT_FLAG, CPL_TYPE_INT);
851
852 }
853 check(cpl_table_set_size( table, resid->size));
854
855 /* insert data */
856 for (i=0; i<resid->size; i++) {
857 double lambda, order, slit,sn;
858 int slit_index;
859 double thpre_x, thpre_y;
860 //double thcor_x, thcor_y;
861 double xgauss, ygauss;
862 double xpoly, ypoly;
863 double sig_xgauss, sig_ygauss;
864 double fwhm_xgauss, fwhm_ygauss;
865 double norm_gauss;
866 int flag=0;
867 lambda = resid->lambda[i];
868 order = resid->order[i];
869 slit = resid->slit[i];
870 sn = resid->sn[i];
871
872 slit_index = resid->slit_index[i];
873 thpre_x = resid->thpre_x[i];
874 thpre_y = resid->thpre_y[i];
875 //thcor_x = resid->thcor_x[i];
876 //thcor_y = resid->thcor_y[i];
877 xgauss = resid->xgauss[i];
878 ygauss = resid->ygauss[i];
879 sig_xgauss = resid->sig_xgauss[i];
880 sig_ygauss = resid->sig_ygauss[i];
881 fwhm_xgauss = resid->fwhm_xgauss[i];
882 fwhm_ygauss = resid->fwhm_ygauss[i];
883 norm_gauss = resid->norm_gauss[i];
884 xpoly = resid->xpoly[i];
885 ypoly = resid->ypoly[i];
886 if(resid->flag) {
887 flag = resid->flag[i];
888 }
889 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
890 i, lambda));
891 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SN,
892 i, sn));
893
894 check(cpl_table_set(table,XSH_RESID_TAB_TABLE_COLNAME_ORDER,
895 i, order));
896 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
897 i, slit));
898 check(cpl_table_set_int(table,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
899 i, slit_index));
900 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
901 i, thpre_x));
902 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
903 i, thpre_y));
904
905 /* AMO: Decided with Reflex review to remove those columns
906 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XTHCOR,
907 i, thcor_x));
908 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YTHCOR,
909 i, thcor_y));
910 */
911
912 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
913 i, xgauss));
914 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
915 i, ygauss));
916 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
917 i, sig_xgauss));
918 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
919 i, sig_ygauss));
920
921 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_FWHMXGAUSS,
922 i, fwhm_xgauss));
923 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_FWHMYGAUSS,
924 i, fwhm_ygauss));
925 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_NORMGAUSS,
926 i, norm_gauss));
927
929 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
930 i, xpoly));
931 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
932 i, ypoly));
933 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY,
934 i, xpoly-xgauss));
935 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY,
936 i, ypoly-ygauss));
937 }
938 if(resid->flag) {
939
940 check(cpl_table_set_int(table,XSH_RESID_TAB_TABLE_COLNAME_FLAG,
941 i, flag));
942 }
943 } /* end loop over table size */
944
945 /* create fits file */
948
949 check(residx_min=cpl_table_get_column_min(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
950 check(residx_max=cpl_table_get_column_max(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
951 check(residx_rms=cpl_table_get_column_stdev(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
952
953 check(residy_min=cpl_table_get_column_min(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
954 check(residy_max=cpl_table_get_column_max(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
955 check(residy_rms=cpl_table_get_column_stdev(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
956
957 cpl_propertylist_append_double(header,"ESO QC POLY RESX_MIN",residx_min);
958 cpl_propertylist_append_double(header,"ESO QC POLY RESX_MAX",residx_max);
959 cpl_propertylist_append_double(header,"ESO QC POLY RESX_RMS",residx_rms);
960
961
962 cpl_propertylist_append_double(header,"ESO QC POLY RESY_MIN",residy_min);
963 cpl_propertylist_append_double(header,"ESO QC POLY RESY_MAX",residy_max);
964 cpl_propertylist_append_double(header,"ESO QC POLY RESY_RMS",residy_rms);
965
966 }
967 else{
968 int size;
969
970 size = cpl_propertylist_get_size( header);
971 XSH_REGDEBUG("write MODEL in header size %d", size);
973 size = cpl_propertylist_get_size( header);
974 XSH_REGDEBUG("write MODEL in header new size %d", size);
975
976 /* QC results are added later from model_kernel
977 function xsh_model_pipe_anneal*/
978
979 }
980
981 /* added for QC request */
982 int nfound4=0;
983 int nfound4clean=0;
984 nfound4=cpl_table_and_selected_int(table,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
985 CPL_EQUAL_TO,4);
986 check( xsh_pfits_set_qc_nlinefound_fib4( header,nfound4));
987 if(resid->flag) {
988 nfound4clean=cpl_table_and_selected_int(table,XSH_RESID_TAB_TABLE_COLNAME_FLAG,
989 CPL_EQUAL_TO,0);
990 check( xsh_pfits_set_qc_nlinefound_clean_fib4( header,nfound4clean));
991 }
992 cpl_table_select_all(table);
993 XSH_REGDEBUG("save filename %s", filename);
994 check( xsh_pfits_set_pcatg(header, tag));
995 check( cpl_table_save(table, header,NULL,filename, CPL_IO_DEFAULT));
996
997 /* Create the frame */
998 check(result=xsh_frame_product(filename,
999 tag,
1000 CPL_FRAME_TYPE_TABLE,
1001 CPL_FRAME_GROUP_PRODUCT,
1002 CPL_FRAME_LEVEL_TEMPORARY));
1003
1004
1005 //check (xsh_add_temporary_file( filename));
1006
1007 cleanup:
1008
1009 if (cpl_error_get_code() != CPL_ERROR_NONE){
1010 xsh_free_frame(&result);
1011 }
1012 XSH_TABLE_FREE( table);
1013 return result ;
1014}
1015
1016/*---------------------------------------------------------------------------*/
1026
1027
1036{
1037 double * result = NULL ;
1038
1039 XSH_ASSURE_NOT_NULL( resid);
1040 result = resid->lambda ;
1041
1042 cleanup:
1043 return result;
1044}
1045
1055{
1056 double * result = NULL ;
1057
1058 XSH_ASSURE_NOT_NULL( resid);
1059 result = resid->order ;
1060
1061 cleanup:
1062 return result;
1063}
1064
1074{
1075 double * result = NULL ;
1076
1077 XSH_ASSURE_NOT_NULL( resid);
1078 result = resid->slit ;
1079
1080 cleanup:
1081 return result;
1082}
1083
1092RESID_TAB_PROPERTY_GET ( slit_index, int*, NULL)
1093
1094
1103{
1104 double * result = NULL ;
1105
1106 XSH_ASSURE_NOT_NULL( resid);
1107 result = resid->thpre_x ;
1108
1109 cleanup:
1110 return result;
1111}
1112
1122{
1123 double * result = NULL ;
1124
1125 XSH_ASSURE_NOT_NULL( resid);
1126 result = resid->thpre_y ;
1127
1128 cleanup:
1129 return result;
1130}
1131
1141{
1142 double * result = NULL ;
1143
1144 XSH_ASSURE_NOT_NULL( resid);
1145 result = resid->xgauss;
1146
1147 cleanup:
1148 return result;
1149}
1150
1160{
1161 double * result = NULL ;
1162
1163 XSH_ASSURE_NOT_NULL( resid);
1164 result = resid->ygauss ;
1165
1166 cleanup:
1167 return result;
1168}
1169
1170
1171
1172cpl_error_code
1173xsh_frame_table_resid_merge(cpl_frame* self, cpl_frame* right,
1174 const int solution_type)
1175{
1176 cpl_table* stab=NULL;
1177 cpl_table* rtab=NULL;
1178 cpl_propertylist* shead=NULL;
1179 cpl_propertylist* rhead=NULL;
1180 cpl_propertylist* qc_head=NULL;
1181 const char* sname=NULL;
1182 const char* rname=NULL;
1183 //const char* tag=NULL;
1184 int i=0;
1185 int srow=0;
1186 int rrow=0;
1187 double wtol=0.001;
1188
1189 double* pWaveSelf=NULL;
1190 int* pFlagSelf=NULL;
1191
1192 int* pSlitIndexSelf=NULL;
1193 int* pOrderSelf=NULL;
1194 double* pXThAnnealSelf=NULL;
1195 double* pYThAnnealSelf=NULL;
1196 double* pXpolySelf=NULL;
1197 double* pYpolySelf=NULL;
1198
1199 double* pResidXpolySelf=NULL;
1200 double* pResidYpolySelf=NULL;
1201 double* pResidXmodelSelf=NULL;
1202 double* pResidYmodelSelf=NULL;
1203
1204
1205 double* pWaveRight=NULL;
1206 int* pSlitIndexRight=NULL;
1207 int* pOrderRight=NULL;
1208 double* pXThAnnealRight=NULL;
1209 double* pYThAnnealRight=NULL;
1210 double* pXpolyRight=NULL;
1211 double* pYpolyRight=NULL;
1212
1213 double* pResidXpolyRight=NULL;
1214 double* pResidYpolyRight=NULL;
1215 double* pResidXmodelRight=NULL;
1216 double* pResidYmodelRight=NULL;
1217 double itol=0.001;
1218 int k=0;
1219
1220 sname=cpl_frame_get_filename(self);
1221 rname=cpl_frame_get_filename(right);
1222 //tag=cpl_frame_get_filename(right);
1223
1224 shead=cpl_propertylist_load(sname,0);
1225 rhead=cpl_propertylist_load(rname,0);
1226 qc_head=cpl_propertylist_load_regexp(sname,0,"^ESO QC",0);
1227
1228 cpl_propertylist_append(rhead,qc_head);
1229 stab=cpl_table_load(sname,1,0);
1230 rtab=cpl_table_load(rname,1,0);
1231 srow=cpl_table_get_nrow(stab);
1232 rrow=cpl_table_get_nrow(rtab);
1233
1234 pWaveRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH);
1235 pSlitIndexRight=cpl_table_get_data_int(rtab,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX);
1236 pOrderRight=cpl_table_get_data_int(rtab,XSH_RESID_TAB_TABLE_COLNAME_ORDER);
1237 pXThAnnealRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL);
1238 pYThAnnealRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL);
1239
1240 pXpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_XPOLY);
1241 pYpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_YPOLY);
1242
1243 pResidXpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY);
1244 pResidYpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY);
1245 pResidXmodelRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL);
1246 pResidYmodelRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL);
1247
1248
1249 pWaveSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH);
1250 pSlitIndexSelf=cpl_table_get_data_int(stab,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX);
1251 pOrderSelf=cpl_table_get_data_int(stab,XSH_RESID_TAB_TABLE_COLNAME_ORDER);
1252 pFlagSelf=cpl_table_get_data_int(stab,XSH_RESID_TAB_TABLE_COLNAME_FLAG);
1253
1254 pXThAnnealSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL);
1255 pYThAnnealSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL);
1256
1257 pXpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_XPOLY);
1258 pYpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_YPOLY);
1259
1260 pResidXpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY);
1261 pResidYpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY);
1262 pResidXmodelSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL);
1263 pResidYmodelSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL);
1264
1265 /* TODO: here we need to check also for matching order id */
1266 for(i=0;i<srow;i++) {
1267
1268 for (k = 0; k < rrow; k++) {
1269 if ((fabs(pWaveSelf[i] - pWaveRight[k]) < wtol)
1270 && (fabs(pSlitIndexSelf[i] - pSlitIndexRight[k]) < itol)
1271 && (fabs(pOrderSelf[i] - pOrderRight[k]) < itol)
1272 && pFlagSelf[i] == 0) {
1273 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL) {
1274 pXThAnnealSelf[i] = pXThAnnealRight[k];
1275 pYThAnnealSelf[i] = pYThAnnealRight[k];
1276 pResidXmodelSelf[i] = pResidXmodelRight[k];
1277 pResidYmodelSelf[i] = pResidYmodelRight[k];
1278 } else {
1279 pXpolySelf[i] = pXpolyRight[k];
1280 pYpolySelf[i] = pYpolyRight[k];
1281 pResidXpolySelf[i] = pResidXpolyRight[k];
1282 pResidYpolySelf[i] = pResidYpolyRight[k];
1283
1284 }
1285 }
1286 }
1287 }
1288
1289 check(cpl_table_save(stab,rhead,NULL,sname,CPL_IO_DEFAULT));
1290
1291
1292 cleanup:
1293 xsh_free_table(&stab);
1294 xsh_free_table(&rtab);
1295 xsh_free_propertylist(&shead);
1296 xsh_free_propertylist(&rhead);
1297 xsh_free_propertylist(&qc_head);
1298
1299 return cpl_error_get_code();
1300
1301}
double * xsh_resid_tab_get_lambda_data(xsh_resid_tab *resid)
Get the size of the residual tab.
double * xsh_resid_tab_get_ygauss_data(xsh_resid_tab *resid)
Get the ygauss array of the residual tab.
void xsh_resid_tab_free(xsh_resid_tab **resid)
Free memory associated to a resid_tab.
cpl_frame * xsh_resid_tab_erase_flagged(cpl_frame *resid, const char *name)
xsh_resid_tab * xsh_resid_tab_load(cpl_frame *resid_tab_frame)
Load a residual tab from a frame.
xsh_resid_tab * xsh_resid_tab_create(int size, double *lambda, double *order, double *slit, double *sn, int *slit_index, double *thpre_x, double *thpre_y, double *corr_x, double *corr_y, double *gaussian_norm, double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x, double *gaussian_sigma_y, double *gaussian_fwhm_x, double *gaussian_fwhm_y, int *flag, xsh_wavesol *wavesol, int wavesol_type)
Create a residual tab structure.
double * xsh_resid_tab_get_thpre_y_data(xsh_resid_tab *resid)
Get the thpre_y array of the residual tab.
double * xsh_resid_tab_get_slitpos_data(xsh_resid_tab *resid)
Get the slit_pos array of the residual tab.
double * xsh_resid_tab_get_thpre_x_data(xsh_resid_tab *resid)
Get the slit_index array of the residual tab.
cpl_error_code xsh_frame_table_resid_merge(cpl_frame *self, cpl_frame *right, const int solution_type)
xsh_resid_tab * xsh_resid_tab_create_not_flagged(int size, double *lambda, double *order, double *slit, double *sn, int *slit_index, double *thpre_x, double *thpre_y, double *corr_x, double *corr_y, double *gaussian_norm, double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x, double *gaussian_sigma_y, double *gaussian_fwhm_x, double *gaussian_fwhm_y, int *flag, xsh_wavesol *wavesol, int wavesol_type)
void xsh_resid_tab_log(xsh_resid_tab *resid, const char *filename)
Log the residual tab in a ASCII file
cpl_frame * xsh_resid_tab_save(xsh_resid_tab *resid, const char *filename, xsh_instrument *instr, const char *tag)
Save a residual tab to a frame.
double * xsh_resid_tab_get_order_data(xsh_resid_tab *resid)
Get the Orders array of the residual tab.
double * xsh_resid_tab_get_xgauss_data(xsh_resid_tab *resid)
Get the xgauss array of the residual tab.
double xsh_wavesol_eval_poly(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in Y
double xsh_wavesol_eval_polx(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in X
enum wavesol_type xsh_wavesol_get_type(xsh_wavesol *wsol)
get the type of the wave table
#define XSH_REGDEBUG(...)
Definition: xsh_error.h:132
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_msg(...)
Definition: xsh_error.h:94
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
int size
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
Definition: xsh_pfits.c:1008
void xsh_pfits_set_wavesoltype(cpl_propertylist *plist, const char *value)
Write the WAVESOL TYPE value.
Definition: xsh_pfits.c:3172
const char * xsh_pfits_get_wavesoltype(const cpl_propertylist *plist)
Find out the WAVESOL TYPE.
Definition: xsh_pfits.c:3151
void xsh_pfits_set_qc_nlinefound_fib4(cpl_propertylist *plist, double value)
Definition: xsh_pfits_qc.c:607
void xsh_pfits_set_qc_nlinefound_clean_fib4(cpl_propertylist *plist, double value)
Definition: xsh_pfits_qc.c:616
void xsh_pfits_set_qc(cpl_propertylist *plist, void *value, const char *kw, xsh_instrument *instrument)
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
Definition: xsh_utils.c:2133
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_get_table_value(const cpl_table *table, const char *colname, cpl_type coltype, int i, void *result)
Read a table value from a fits table.
double median_diff_poly_fit_x
cpl_propertylist * header
double stdev_diff_poly_fit_y
double stdev_diff_poly_fit_x
double median_diff_poly_fit_y
#define XSH_RESID_TAB_TABLE_UNIT_RESIDYPOLY
#define XSH_RESID_TAB_TABLE_UNIT_YPOLY
#define XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION
#define XSH_RESID_TAB_TABLE_COLNAME_FWHMYGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL
#define XSH_RESID_TAB_TABLE_COLNAME_ORDER
#define XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_YPOLY
#define XSH_RESID_TAB_TABLE_UNIT_WAVELENGTH
#define XSH_RESID_TAB_TABLE_COLNAME_NORMGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_YTHPRE
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY
#define XSH_RESID_TAB_TABLE_COLNAME_YTHPRE
#define XSH_RESID_TAB_TABLE_COLNAME_SN
#define XSH_RESID_TAB_TABLE_UNIT_SN
#define XSH_RESID_TAB_TABLE_COLNAME_FWHMXGAUSS
#define XSH_RESID_TAB_TABLE_NB_COL
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY
#define XSH_RESID_TAB_TABLE_UNIT_ORDER
#define XSH_RESID_TAB_TABLE_UNIT_FLAG
#define XSH_RESID_TAB_TABLE_COLNAME_XGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH
#define XSH_RESID_TAB_TABLE_COLNAME_YGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_XGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_XPOLY
#define XSH_RESID_TAB_TABLE_UNIT_SLITINDEX
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL
#define RESID_TAB_PROPERTY_GET(PROPERTY, TYPE, DEFAULT)
#define XSH_RESID_TAB_TABLE_COLNAME_XPOLY
#define XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX
#define XSH_RESID_TAB_TABLE_COLNAME_FLAG
#define XSH_RESID_TAB_TABLE_UNIT_SLITPOSITION
#define XSH_RESID_TAB_TABLE_UNIT_NORMGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_YGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL
#define XSH_RESID_TAB_TABLE_UNIT_XTHPRE
#define XSH_RESID_TAB_TABLE_UNIT_YTHANNEAL
#define XSH_RESID_TAB_TABLE_UNIT_XTHANNEAL
#define XSH_RESID_TAB_TABLE_UNIT_RESIDYMODEL
#define XSH_RESID_TAB_TABLE_UNIT_RESIDXMODEL
#define XSH_RESID_TAB_TABLE_COLNAME_XTHPRE
#define XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_RESIDXPOLY
wavesol_type
@ XSH_WAVESOL_GUESS
@ XSH_WAVESOL_2D
@ XSH_WAVESOL_UNDEFINED
int order
Definition: xsh_detmon_lg.c:80
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
Definition: xsh_dfs.c:930
#define XSH_DETECT_ARCLINES_TYPE_POLY
Definition: xsh_drl.h:225
#define XSH_DETECT_ARCLINES_TYPE_MODEL
Definition: xsh_drl.h:226
#define XSH_WAVESOLTYPE_POLYNOMIAL
Definition: xsh_pfits.h:213
#define XSH_WAVESOLTYPE_MODEL
Definition: xsh_pfits.h:214
#define XSH_WAVESOLTYPE
Definition: xsh_pfits.h:212
#define XSH_QC_FMTCHK_POLY_DIFFXMED
#define XSH_QC_FMTCHK_POLY_DIFFYMED
#define XSH_QC_FMTCHK_POLY_DIFFXAVG
#define XSH_QC_FMTCHK_POLY_DIFFYAVG
#define XSH_QC_FMTCHK_POLY_DIFFYSTD
#define XSH_QC_FMTCHK_POLY_DIFFXSTD
#define XSH_TABLE_NEW_COL(TABLE, NAME, UNIT, TYPE)
Definition: xsh_utils.h:113
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)