X-shooter Pipeline Reference Manual 3.8.15
xsh_utils_scired_slit.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-08-16 08:25:29 $
23 * $Revision: 1.97 $
24 *
25*/
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30/*----------------------------------------------------------------------------
31 Includes
32 ----------------------------------------------------------------------------*/
34#include <xsh_dfs.h>
35#include <xsh_utils.h>
36#include <xsh_utils_table.h>
38#include <xsh_data_spectrum.h>
39#include <xsh_model_utils.h>
40#include <xsh_error.h>
41#include <xsh_drl_check.h>
42#include <xsh_pfits.h>
43#include <xsh_hdrl_functions.h>
44/*
45static int
46xsh_frame_has_same_nod_pos(cpl_frame* ref, cpl_frame* cmp)
47{
48 int result=0;
49
50 cpl_propertylist* href=NULL;
51 cpl_propertylist* hcmp=NULL;
52
53 const char* name_ref=NULL;
54 const char* name_cmp=NULL;
55
56 double ref_yoff=0;
57 double ref_ra=0;
58 double ref_dec=0;
59
60 double cmp_yoff=0;
61 double cmp_ra=0;
62 double cmp_dec=0;
63
64 name_ref=cpl_frame_get_filename(ref);
65 name_cmp=cpl_frame_get_filename(cmp);
66 href=cpl_propertylist_load(name_ref,0);
67 hcmp=cpl_propertylist_load(name_cmp,0);
68
69 if(cpl_propertylist_has(href, XSH_NOD_CUMULATIVE_OFFSETY)){
70
71 check(ref_yoff=xsh_pfits_get_cumoffsety(href));
72 check(cmp_yoff=xsh_pfits_get_cumoffsety(hcmp));
73
74 if(ref_yoff==cmp_yoff) {
75 result=1;
76 }
77
78 } else {
79
80 check(ref_ra=xsh_pfits_get_ra_cumoffset(href));
81 check(ref_dec=xsh_pfits_get_dec_cumoffset(href));
82
83 check(cmp_ra=xsh_pfits_get_ra_cumoffset(hcmp));
84 check(cmp_dec=xsh_pfits_get_dec_cumoffset(hcmp));
85
86 if((ref_ra==cmp_ra) && (ref_ra==cmp_ra)) {
87 result=1;
88 }
89
90 }
91 cleanup:
92 xsh_free_propertylist(&href);
93 xsh_free_propertylist(&hcmp);
94
95 return result;
96
97}
98*/
99
105/*--------------------------------------------------------------------------*/
116/*--------------------------------------------------------------------------*/
117
118cpl_error_code
119xsh_stare_params_bin_scale(cpl_frameset* raws,
121 xsh_opt_extract_param *opt_extract_par,
122 int* sub_sky_nbkpts1,
123 int* sub_sky_nbkpts2)
124{
125
126 cpl_frame* frame=NULL;
127 const char* name=NULL;
128 cpl_propertylist *plist=NULL;
129 int binx=0;
130 int biny=0;
131
132 check(frame=cpl_frameset_get_frame(raws,0));
133 check(name=cpl_frame_get_filename(frame));
134 check(plist=cpl_propertylist_load(name,0));
137 xsh_free_propertylist( &plist);
138
139 if(biny>1) {
140
141 /* backg->sampley=backg->sampley/biny;
142 number of points of the grid in y direction.
143 Not to be bin dependent
144 */
145
146 backg->radius_y=backg->radius_y/biny;
147
148 /* bin dependent */
149 *sub_sky_nbkpts1*=0.75*biny;
150 *sub_sky_nbkpts2*=0.75*biny;
151
152
153 /*
154 if(backg->smooth_y>0) {
155 backg->smooth_y=backg->smooth_y/biny;
156 }
157 Smoothing radius' half size in x direction.
158 For the moment not bin dependent, but for optimal results probably yes
159 */
160 /*
161 rectify_par->rectif_radius=rectify_par->rectif_radius/biny;
162 Rectify Interpolation radius
163 For the moment not bin dependent, but for optimal results probably yes
164 */
165
166 /*
167 rectify_par->rectif_bin_lambda=rectify_par->rectif_bin_lambda/biny;
168 Rectify Wavelength Step
169 For the moment not bin dependent, but for optimal results probably yes
170 */
171
172 /*
173 loc_obj_par->loc_chunk_nb=loc_obj_par->loc_chunk_nb/biny;
174 Localization Nb of chunks
175 Not bin dependent
176 */
177
178 /*
179 opt_extract_par->chunk_size=opt_extract_par->chunk_size/biny;
180 Chunk size.
181 */
182
183 /*
184 opt_extract_par->lambda_step=opt_extract_par->lambda_step/biny;
185 Lambda step.
186 For the moment not bin dependent, but for optimal results probably yes
187 */
188
189
190 }
191
192
193 if(binx>1) {
194
195 backg->radius_x=backg->radius_x/binx;
196
197 /*
198 if(backg->smooth_x>0) {
199 backg->smooth_x=backg->smooth_x/binx;
200 }
201 Smoothing radius' half size in x direction
202 For the moment not bin dependent, but for optimal results probably yes
203 */
204
205 /*
206 rectify_par->rectif_bin_space=rectify_par->rectif_bin_space/binx;
207 Rectify Position Step
208 For the moment not bin dependent, but for optimal results probably yes
209 */
210
211 /*
212 loc_obj_par->nod_step=loc_obj_par->nod_step/binx;
213 Step (arcsec) between A and B images in nodding mode
214 Not bin dependent
215 */
216
217 opt_extract_par->box_hsize=opt_extract_par->box_hsize/binx;
218
219 }
220
221 cleanup:
222 xsh_free_propertylist(&plist);
223 return cpl_error_get_code();
224
225}
226
227
228cpl_frameset* xsh_nod_group_by_reloff( cpl_frameset *ord_set,xsh_instrument *instrument, xsh_stack_param* stack_par)
229{
230
231 cpl_frameset *result = NULL;
232 cpl_frameset *rmcrh_set = NULL;
233 const cpl_frame *frame = NULL;
234 cpl_propertylist *header = NULL;
235
236 const char* nod_name = NULL;
237
238 double rel_ra=0;
239 double rel_dec=0;
240 double A_cum_ra=0;
241 double A_cum_dec=0;
242 int A_number=1, B_number =1;
243 int nod_number;
244 char ftag[40];
245 char name[40];
246
247 cpl_frame *crhm_frame = NULL;
248 cpl_frameset_iterator* it = NULL;
249 XSH_ASSURE_NOT_NULL( ord_set);
251 XSH_ASSURE_NOT_NULL( stack_par);
252
253 check( result=cpl_frameset_new());
254
255 it = cpl_frameset_iterator_new(ord_set);
256 frame = cpl_frameset_iterator_get(it);
257
258 check( nod_name = cpl_frame_get_filename( frame));
259 check( header = cpl_propertylist_load( nod_name, 0));
260
261 check( A_cum_ra = xsh_pfits_get_ra_cumoffset( header));
262 check( A_cum_dec = xsh_pfits_get_dec_cumoffset( header));
263
264 xsh_free_propertylist( &header);
265 /* loops over the input frames and identifies all
266 * nod positions (having different value of RA-cumoff and/or DEC-cumoff
267 * Frames at same nod position are combined to improve statistics
268 * In this way a sequence like:
269 * AAA BBB BBB AAA AAA BBBBB BBBBB AAAAAA is (median or sigma-clipped mean) combined in
270 * A B B A A B B A
271 * And then one can build usual pairs A-B B-A and apply the usual [(A-B) - shifted(B-A)]
272 * nod algorithm
273 * */
274 while( frame != NULL){
275 double cum_ra=0;
276 double cum_dec=0;
277 double nrel_ra, nrel_dec;
278 const char *type= NULL;
279
280 check( nod_name = cpl_frame_get_filename( frame));
281 check( header = cpl_propertylist_load( nod_name, 0));
282 check( cum_ra = xsh_pfits_get_ra_cumoffset( header));
283 check( cum_dec = xsh_pfits_get_dec_cumoffset( header));
284 check( rel_ra = xsh_pfits_get_ra_reloffset( header));
285 check( rel_dec = xsh_pfits_get_dec_reloffset( header));
286
287 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
288 type = "A";
289 nod_number = A_number;
290 }
291 else{
292 type = "B";
293 nod_number = B_number;
294 }
295
296 xsh_msg("name %s cumoffset %f %f reloffset %f %f nod_seq_number : %s%d", nod_name,
297 cum_ra, cum_dec, rel_ra, rel_dec, type, nod_number);
298
299 xsh_free_propertylist( &header);
300
301 check( rmcrh_set = cpl_frameset_new());
302 cpl_frameset_insert( rmcrh_set, cpl_frame_duplicate( frame));
303
304 cpl_frameset_iterator_advance(it, 1);
305 frame = cpl_frameset_iterator_get_const(it);
306
307 /* finds frame with same nod position to the current one and store them in the same frameset */
308 while( frame != NULL){
309 check( nod_name = cpl_frame_get_filename( frame));
310 check( header = cpl_propertylist_load( nod_name, 0));
311 check( nrel_ra = xsh_pfits_get_ra_reloffset( header));
312 check( nrel_dec = xsh_pfits_get_dec_reloffset( header));
313 xsh_free_propertylist( &header);
314
315 if ( rel_ra == nrel_ra && nrel_dec == rel_dec){
316 cpl_frameset_insert( rmcrh_set, cpl_frame_duplicate( frame));
317 }
318 else{
319 break;
320 }
321
322 cpl_frameset_iterator_advance(it, 1);
323 frame = cpl_frameset_iterator_get_const(it);
324
325 }
326
327 /* Combine frames with same nod position. This to improve statistics and also remove cosmic ray hits */
328 sprintf( ftag,"med_%s%d", type, nod_number);
329 sprintf(name,"%s.fits",ftag);
330 check( crhm_frame = xsh_remove_crh_multiple( rmcrh_set, ftag, stack_par,NULL,instrument, NULL,NULL,1 ));
331
332 check( cpl_frameset_insert( result, crhm_frame));
334
335 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
336 A_number++;
337 }
338 else{
339 B_number++;
340 }
341 xsh_free_frameset( &rmcrh_set);
342 }
343
344 cleanup:
345 cpl_frameset_iterator_delete(it);
346 if ( cpl_error_get_code() != CPL_ERROR_NONE){
347 xsh_free_propertylist( &header);
348 xsh_free_frameset( &rmcrh_set);
349 xsh_free_frameset( &result);
350 }
351 return result;
352}
353
354
355
356cpl_frameset* xsh_nod_group_by_reloff2( cpl_frameset *ord_set,xsh_instrument *instrument, xsh_stack_param* stack_par)
357{
358
359 cpl_frameset *result = NULL;
360 cpl_frameset *tmp_set = NULL;
361 cpl_frame *frame = NULL;
362 cpl_propertylist *header = NULL;
363
364 const char* nod_name = NULL;
365
366 double rel_ra=0;
367 double rel_dec=0;
368 double A_cum_ra=0;
369 double A_cum_dec=0;
370 int A_number=1, B_number =1;
371 int nod_number;
372 char ftag[40];
373 char name[40];
374 cpl_vector* vec_ra=NULL;
375 cpl_vector* vec_dec=NULL;
376 cpl_frame *crhm_frame = NULL;
377 double* pvec_ra=NULL;
378 double* pvec_dec=NULL;
379 int nraw=0;
380 int nnod=1;
381 int i=0;
382 int j=0;
383 double frm_ra=0;
384 double frm_dec=0;
385 XSH_ASSURE_NOT_NULL( ord_set);
387 XSH_ASSURE_NOT_NULL( stack_par);
388 double tol_ra=0.1;
389 double tol_dec=0.1;
390 const char *type= NULL;
391
392 nraw=cpl_frameset_get_size(ord_set);
393 //cpl_frameset_dump(ord_set,stdout);
394
395 check( result=cpl_frameset_new());
396
397 check( frame = cpl_frameset_get_frame( ord_set,0));
398
399 check( nod_name = cpl_frame_get_filename( frame));
400 check( header = cpl_propertylist_load( nod_name, 0));
401
402 check( A_cum_ra = xsh_pfits_get_ra_cumoffset( header));
403 check( A_cum_dec = xsh_pfits_get_dec_cumoffset( header));
404 check( frm_ra = xsh_pfits_get_ra_cumoffset( header));
405 check( frm_dec = xsh_pfits_get_dec_cumoffset( header));
406
407 xsh_free_propertylist( &header);
408 vec_ra=cpl_vector_new(nraw);
409 vec_dec=cpl_vector_new(nraw);
410 pvec_ra=cpl_vector_get_data(vec_ra);
411 pvec_dec=cpl_vector_get_data(vec_dec);
412
413
414
415 pvec_ra[0]=frm_ra;
416 pvec_dec[0]=frm_dec;
417 for(i=1;i<nraw;i++) {
418 check( frame = cpl_frameset_get_frame( ord_set,i));
419 check( header = cpl_propertylist_load( nod_name, 0));
420 check( frm_ra = xsh_pfits_get_ra_cumoffset( header));
421 check( frm_dec = xsh_pfits_get_dec_cumoffset( header));
422
423 int newtag = 1;
424 for(j=0;j<nnod;j++) {
425 if( fabs(pvec_ra[j] - frm_ra) < tol_ra &&
426 fabs(pvec_dec[j] - frm_dec) < tol_dec )
427 {
428 newtag = 0;
429 }
430 }
431 if (newtag == 1) {
432 pvec_ra[nnod]=frm_ra;
433 pvec_dec[nnod]=frm_dec;
434 nnod++;
435 }
436 xsh_free_propertylist( &header);
437 }
438 cpl_vector_set_size(vec_ra, nnod);
439 cpl_vector_set_size(vec_dec, nnod);
440 cpl_vector_dump(vec_ra,stdout);
441 cpl_vector_dump(vec_dec,stdout);
442
443 while( frame != NULL){
444 double cum_ra=0;
445 double cum_dec=0;
446 //double nrel_ra, nrel_dec;
447
448 check( nod_name = cpl_frame_get_filename( frame));
449 check( header = cpl_propertylist_load( nod_name, 0));
450 check( cum_ra = xsh_pfits_get_ra_cumoffset( header));
451 check( cum_dec = xsh_pfits_get_dec_cumoffset( header));
452 check( rel_ra = xsh_pfits_get_ra_reloffset( header));
453 check( rel_dec = xsh_pfits_get_dec_reloffset( header));
454
455 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
456 type = "A";
457 nod_number = A_number;
458 }
459 else{
460 type = "B";
461 nod_number = B_number;
462 }
463
464
465
466 }
467 while( frame != NULL){
468 double cum_ra=0;
469 double cum_dec=0;
470 double nrel_ra, nrel_dec;
471
472 check( nod_name = cpl_frame_get_filename( frame));
473 check( header = cpl_propertylist_load( nod_name, 0));
474 check( cum_ra = xsh_pfits_get_ra_cumoffset( header));
475 check( cum_dec = xsh_pfits_get_dec_cumoffset( header));
476 check( rel_ra = xsh_pfits_get_ra_reloffset( header));
477 check( rel_dec = xsh_pfits_get_dec_reloffset( header));
478
479 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
480 type = "A";
481 nod_number = A_number;
482 }
483 else{
484 type = "B";
485 nod_number = B_number;
486 }
487
488 xsh_msg("name %s cumoffset %f %f reloffset %f %f nod_seq_number : %s%d", nod_name,
489 cum_ra, cum_dec, rel_ra, rel_dec, type, nod_number);
490
491 xsh_free_propertylist( &header);
492
493 check( tmp_set = cpl_frameset_new());
494 cpl_frameset_insert( tmp_set, cpl_frame_duplicate( frame));
495
496 frame = cpl_frameset_get_next( ord_set);
497
498 while( frame != NULL){
499 check( nod_name = cpl_frame_get_filename( frame));
500 check( header = cpl_propertylist_load( nod_name, 0));
501 check( nrel_ra = xsh_pfits_get_ra_reloffset( header));
502 check( nrel_dec = xsh_pfits_get_dec_reloffset( header));
503 xsh_free_propertylist( &header);
504
505 if ( rel_ra == nrel_ra && nrel_dec == rel_dec){
506 cpl_frameset_insert( tmp_set, cpl_frame_duplicate( frame));
507 }
508 else{
509 break;
510 }
511 check( frame = cpl_frameset_get_next( ord_set));
512 }
513
514 /* Create the remove cosmics frame */
515 sprintf( ftag,"med_%s%d", type, nod_number);
516 sprintf(name,"%s.fits",ftag);
517 check( crhm_frame = xsh_remove_crh_multiple( tmp_set, ftag, stack_par,NULL,instrument, NULL,NULL,1 ));
518
519 check( cpl_frameset_insert( result, crhm_frame));
521
522 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
523 A_number++;
524 }
525 else{
526 B_number++;
527 }
528 xsh_free_frameset( &tmp_set);
529 }
530
531 cleanup:
532 if ( cpl_error_get_code() != CPL_ERROR_NONE){
533 xsh_free_propertylist( &header);
534 xsh_free_frameset( &tmp_set);
535 xsh_free_frameset( &result);
536 }
537 return result;
538}
539
540
541static cpl_frame* xsh_frame_divide_flat( int do_flat, cpl_frame* src,
542 cpl_frame *mflat, const char* tag, xsh_instrument* instr)
543{
544 cpl_frame *result = NULL;
545
546 if ( do_flat == CPL_TRUE){
547 xsh_msg( "Divide by flat");
548 xsh_msg("sci name: %s flat name: %s",cpl_frame_get_filename(src),cpl_frame_get_filename(mflat));
549 check( result = xsh_divide_flat( src, mflat, tag, instr));
550 }
551 else{
552 xsh_msg("divide ok1 %s",cpl_frame_get_filename(src));
553 xsh_pre* xframe = xsh_pre_load( src, instr);
554 char fname[FILENAME_MAX];
555 sprintf(fname,"tmp_%s",cpl_frame_get_filename(src));
556 result = xsh_pre_save(xframe,fname,cpl_frame_get_tag(src),1);
557 cpl_frame_set_filename(result,fname);
558 xsh_msg("fname=%s",fname);
559 xsh_pre_free(&xframe);
560 //check( result = cpl_frame_duplicate( src));
561 }
562
563 cleanup:
564 return result;
565}
566
567/*
568static cpl_frame*
569xsh_nod_median_correct_ima_per_wavelength(cpl_frame *input)
570{
571
572
573 int next=0;
574 int i=0;
575 int j=0;
576 int k=0;
577
578 cpl_image* data=NULL;
579 cpl_image* errs=NULL;
580 cpl_image* qual=NULL;
581 cpl_frame* result=NULL;
582
583 const char* fname=NULL;
584 char fname_new[256];
585 cpl_propertylist* hdata=NULL;
586 cpl_propertylist* herrs=NULL;
587 cpl_propertylist* hqual=NULL;
588 int sx=0;
589 int sy=0;
590 double median=0;
591 //int naxis1=0;
592 float* pdata=NULL;
593
594 next = cpl_frame_get_nextensions(input);
595 fname=cpl_frame_get_filename(input);
596
597
598 sprintf(fname_new,"MED_COR_%s",fname);
599 result=cpl_frame_duplicate(input);
600 cpl_frame_set_filename(result,fname_new);
601
602 xsh_msg("ok1");
603 hdata=cpl_propertylist_load(fname,0);
604 //naxis1=xsh_pfits_get_naxis1(hdata);
605 xsh_free_propertylist(&hdata);
606
607 for(k=0; k<next;k+=3) {
608
609 data=cpl_image_load(fname,XSH_PRE_DATA_TYPE,0,k);
610 errs=cpl_image_load(fname,XSH_PRE_ERRS_TYPE,0,k+1);
611 qual=cpl_image_load(fname,XSH_PRE_QUAL_TYPE,0,k+2);
612
613 pdata=cpl_image_get_data_float(data);
614 hdata=cpl_propertylist_load(fname,k);
615 herrs=cpl_propertylist_load(fname,k+1);
616 hqual=cpl_propertylist_load(fname,k+2);
617
618 sx=cpl_image_get_size_x(data);
619 sy=cpl_image_get_size_y(data);
620 xsh_msg("ok5");
621 // correct the image by median subtraction at each wavelength (y position)
622 for(i=1;i<=sx;i++) {
623 median=cpl_image_get_median_window(data,i,1,i,sy);
624 for(j=0;j<sy;j++) {
625 pdata[j*sx+i-1]-=median;
626 }
627 }
628
629 if(k==0) {
630 cpl_image_save(data, fname_new, XSH_PRE_DATA_BPP, hdata, CPL_IO_DEFAULT);
631 cpl_image_save(errs, fname_new, XSH_PRE_ERRS_BPP, herrs, CPL_IO_EXTEND);
632 cpl_image_save(qual, fname_new, XSH_PRE_QUAL_BPP, hqual, CPL_IO_EXTEND);
633 } else {
634 cpl_image_save(data, fname_new, XSH_PRE_DATA_BPP, hdata, CPL_IO_EXTEND);
635 cpl_image_save(errs, fname_new, XSH_PRE_ERRS_BPP, herrs, CPL_IO_EXTEND);
636 cpl_image_save(qual, fname_new, XSH_PRE_QUAL_BPP, hqual, CPL_IO_EXTEND);
637 }
638
639 xsh_free_image(&data);
640 xsh_free_image(&errs);
641 xsh_free_image(&qual);
642 xsh_free_propertylist(&hdata);
643 xsh_free_propertylist(&herrs);
644 xsh_free_propertylist(&hqual);
645
646 }
647
648 //cleanup:
649 xsh_free_image(&data);
650 xsh_free_image(&errs);
651 xsh_free_image(&qual);
652 xsh_free_propertylist(&hdata);
653 xsh_free_propertylist(&herrs);
654 xsh_free_propertylist(&hqual);
655 return result;
656}
657*/
658
659
660
661static cpl_frame*
663{
664
665 cpl_frame* frame_o=NULL;
666 xsh_rec_list* list_o=NULL;
667
668 const char* fname_i=NULL;
669 char fname_o[256];
670 cpl_image* image=NULL;
671 const char* tag_o;
672 int next=0;
673 int i=0;
674 int j=0;
675 int k=0;
676 int sx=0;
677 int sy=0;
678 float* pdata=NULL;
679 double median=0;
680
681 /* check input parameters */
682 XSH_ASSURE_NOT_NULL(frame_i);
684
685 next = cpl_frame_get_nextensions(frame_i);
686 fname_i=cpl_frame_get_filename(frame_i);
687
688 list_o=xsh_rec_list_load(frame_i,inst);
689
690 for(k=0; k<next;k++) {
691
692 sx=list_o->list[k].nlambda;
693 sy=list_o->list[k].nslit;
694
695 pdata= xsh_rec_list_get_data1(list_o,k);
696
697 image=cpl_image_wrap_float(sx,sy,pdata);
698 /* median correct the image at each wavelength (y position) */
699 for(i=1;i<=sx;i++) {
700 median=cpl_image_get_median_window(image,i,1,i,sy);
701 for(j=0;j<sy;j++) {
702 pdata[j*sx+i-1]-=median;
703 }
704 }
705 cpl_image_unwrap(image);
706
707 }
708
709 tag_o=cpl_frame_get_tag(frame_i);
710 sprintf(fname_o,"MED_COR_%s",fname_i);
711 frame_o=xsh_rec_list_save(list_o,fname_o,tag_o,1);
712 cpl_frame_set_filename(frame_o,fname_o);
713 xsh_add_temporary_file(fname_o);
714
715 cleanup:
716 xsh_rec_list_free(&list_o);
717 return frame_o;
718}
719
720
721static cpl_error_code
723 const char* qual_name,
724 const char* rec_prefix,
725 cpl_frame* frame2D,
726 cpl_frame* order_tab_edges,
727 cpl_frame* wave_tab,
728 cpl_frame* model_config_frame,
729 cpl_frame* spectral_format,
730 cpl_frame* disp_tab_frame,
732 const int corr_sky,
733 xsh_rectify_param *rectify_par,
734 double** ref_ra,
735 double** ref_dec,
736 cpl_frame **shift2_frame,
737 cpl_frame **shift1_frame)
738
739{
740
741 //HERE BUG
742 char file_name[256];
743 cpl_frame * rec2_frame = NULL ;
744 cpl_frame * rec2eso_frame = NULL ;
745 cpl_frame * rec2tab_frame = NULL ;
746 cpl_frame *shift2eso_frame = NULL;
747 cpl_frame * rec1_frame = NULL ;
748 cpl_frame *shift1eso_frame = NULL;
749 cpl_frame * rec2_frame_median_correct=NULL;
750
751 /* Localization should be done following the order trace, not rectifying */
752 sprintf(file_name,"REC2_%s_%s",qual_name,nod_name);
753 check(rec2_frame = xsh_rectify( frame2D,order_tab_edges,
754 wave_tab,model_config_frame,instrument,
755 rectify_par,spectral_format,disp_tab_frame,
756 file_name,&rec2eso_frame,&rec2tab_frame,
757 rec_prefix));
758 xsh_add_temporary_file(file_name);
759
760 sprintf(file_name,"SHIFT2_%s_%s",qual_name,nod_name);
761
762 if(corr_sky) {
763 rec2_frame_median_correct=xsh_nod_median_correct_list_per_wavelength(rec2_frame,instrument);
764
765
766 check( *shift2_frame = shift_with_kw( rec2_frame_median_correct, instrument,rectify_par,
767 file_name, &shift2eso_frame,
768 ref_ra,ref_dec, 0));
769 xsh_add_temporary_file(file_name);
770 sprintf(file_name,"REC1_FAST_%s_%s",qual_name,nod_name);
771 check( rec1_frame = xsh_rec_list_frame_invert( rec2_frame_median_correct, file_name,
772 instrument));
773 xsh_add_temporary_file(cpl_frame_get_filename(rec1_frame));
774
775 } else {
776 check( *shift2_frame = shift_with_kw( rec2_frame, instrument,rectify_par,
777 file_name, &shift2eso_frame,
778 ref_ra,ref_dec, 0));
779 xsh_add_temporary_file(file_name);
780 sprintf(file_name,"REC1_FAST_%s_%s",qual_name,nod_name);
781 check( rec1_frame = xsh_rec_list_frame_invert( rec2_frame, file_name,
782 instrument));
783 xsh_add_temporary_file(cpl_frame_get_filename(rec1_frame));
784
785 }
786
787
788 sprintf(file_name,"SHIFT1_FAST_%s_%s",qual_name,nod_name);
789 check( *shift1_frame = shift_with_kw( rec1_frame, instrument,
790 rectify_par, file_name,
791 &shift1eso_frame, ref_ra,
792 ref_dec, 1));
793 xsh_add_temporary_file(file_name);
794 cleanup:
795
796 xsh_free_frame( &rec1_frame);
797 xsh_free_frame( &rec2_frame);
798 xsh_free_frame( &shift1eso_frame);
799 xsh_free_frame( &shift2eso_frame);
800 xsh_free_frame( &rec2eso_frame);
801 xsh_free_frame( &rec2tab_frame);
802 xsh_free_frame( &rec2_frame_median_correct);
803 return cpl_error_get_code();
804}
805
806cpl_frameset*
808 cpl_frameset *nod_set,
809 cpl_frame* spectral_format,
810 cpl_frame* master_flat,
811 cpl_frame* order_tab_edges,
812 cpl_frame* wave_tab,
813 cpl_frame* model_config_frame,
814 cpl_frame* disp_tab_frame,
815 cpl_frame* wavemap,
817 xsh_remove_crh_single_param *crh_single_par,
818 xsh_rectify_param *rectify_par,
819 const int do_flatfield,
820 const int corr_sky,
821 const int compute_eff,
822 const char* rec_prefix,
823 cpl_frameset **comb_eff_set)
824
825{
826
827 /* Intermediate frames */
828 //cpl_frame *rm_crh = NULL;
829 cpl_frame * div2_frame = NULL ;
830 cpl_frame * eff2_frame = NULL ;
831 cpl_frame *shift1_frame = NULL;
832 cpl_frame *shift2_frame = NULL;
833 cpl_frame *shift1_eff_frame = NULL;
834 cpl_frame *shift2_eff_frame = NULL;
835 double* ref_ra=NULL;
836 double* ref_dec=NULL;
837 double* ref_eff_ra=NULL;
838 double* ref_eff_dec=NULL;
839 cpl_frameset* comb_set=NULL;
840
841 /* Output Frames (results)*/
842 int i=0;
843 int nb_pairs=0;
844
845 xsh_msg("Method fast");
846 check( comb_set = cpl_frameset_new());
847
848 if(compute_eff) {
849 check( *comb_eff_set = cpl_frameset_new());
850 }
851
852 /* Now subtract B to A */
853 check( nb_pairs = cpl_frameset_get_size( nod_set));
854
855 for( i = 0; i< nb_pairs; i++){
856 cpl_frame *nod_frame = NULL;
857 const char* nod_name = NULL;
858 char tag[256];
859 char name[256];
860
861 nod_frame = cpl_frameset_get_frame( nod_set, i);
862 nod_name = cpl_frame_get_filename( nod_frame);
863 xsh_msg_dbg_high( "***** Frame %s", nod_name);
864
865 /*
866 No background subtraction in nodding because bkg goes away with A-B
867 */
868
869
870
871 /* we now correct the absolute frame back to original layout */
872 /* divide by flat */
873 sprintf(tag,"DIV2_FLATFIELD_%s", xsh_instrument_arm_tostring(instrument)) ;
874 sprintf(name,"%s.fits",tag);
875 check( div2_frame =xsh_frame_divide_flat( do_flatfield, nod_frame, master_flat,
876 tag, instrument));
878
879 /* Rectify */
880 check(xsh_nod_rectify_and_shift_with_key(nod_name,"RECTIFIED",rec_prefix,
881 div2_frame,order_tab_edges,
882 wave_tab,model_config_frame,
883 spectral_format,
884 disp_tab_frame,
885 instrument,corr_sky,
886 rectify_par,&ref_ra,&ref_dec,
887 &shift1_frame,&shift2_frame));
888
889 cpl_frameset_insert( comb_set, shift2_frame);
890 cpl_frameset_insert( comb_set, shift1_frame);
891
892 if(compute_eff) {
893 if(disp_tab_frame != NULL) {
894 int conserve_flux=rectify_par->conserve_flux;
895
896 sprintf(tag,"NOCRH_EFF_%s",xsh_instrument_arm_tostring(instrument)) ;
897 xsh_msg("before %s",cpl_frame_get_filename(nod_frame));
898 check( eff2_frame =xsh_frame_divide_flat(0, nod_frame, master_flat,
899 tag, instrument));
900 xsh_msg("after %s",cpl_frame_get_filename(eff2_frame));
901 rectify_par->conserve_flux=1;
902 check(xsh_nod_rectify_and_shift_with_key(nod_name,"EFF",rec_prefix,
903 eff2_frame,order_tab_edges,
904 wave_tab,model_config_frame,
905 spectral_format,
906 disp_tab_frame,
907 instrument,corr_sky,
908 rectify_par,
909 &ref_eff_ra,&ref_eff_dec,
910 &shift1_eff_frame,
911 &shift2_eff_frame));
912
913 rectify_par->conserve_flux=conserve_flux;
914 cpl_frameset_insert( *comb_eff_set, shift2_eff_frame);
915 cpl_frameset_insert( *comb_eff_set, shift1_eff_frame);
916 xsh_free_frame( &eff2_frame);
917
918 }
919 }
920 //xsh_free_frame( &rm_crh);
921 xsh_free_frame( &div2_frame);
922
923
924 } /* end loop on input pairs */
925
926 cleanup:
927 XSH_FREE( ref_ra);
928 XSH_FREE( ref_dec);
929 XSH_FREE( ref_eff_ra);
930 XSH_FREE( ref_eff_dec);
931 xsh_free_frame( &eff2_frame);
932 xsh_free_frame( &div2_frame);
933 return comb_set;
934}
935
936
937
938
939cpl_frameset*
941 cpl_frameset *nod_set,
942 cpl_frame* spectral_format,
943 cpl_frame* master_flat,
944 cpl_frame* order_tab_edges,
945 cpl_frame* wave_tab,
946 cpl_frame* model_config_frame,
947 cpl_frame* disp_tab_frame,
948 cpl_frame* wavemap,
949 cpl_frame *skymask_frame,
951 xsh_remove_crh_single_param *crh_single_par,
952 xsh_rectify_param *rectify_par,
953 xsh_localize_obj_param *loc_obj_par,
954 const char *throw_name,
955 const int do_flatfield,
956 const char* rec_prefix
957 )
958{
959 int i=0;
960 cpl_frame * a_b = NULL;
961
962 /* all what follows regards the old-slow method */
963 char file_tag[40];
964 char file_name[256];
965 //int npairs=0;
966 int nb_nod=0;
967 double *throw_shift = NULL;
968 double *throw_tab = NULL;
969 FILE* throw_file = NULL;
970
971 cpl_frame * loc_a_b = NULL, * loc_b_a = NULL ;
972 cpl_frame * loc_a_b_0 = NULL;
973
974 cpl_frameset *comb_set = NULL;
975
976 int file_exist=0;
977
978 xsh_msg("Method accurate");
979 check( comb_set = cpl_frameset_new());
980
981 check( nb_nod = cpl_frameset_get_size( nod_set));
982
983 file_exist=access(throw_name, F_OK);
984 if (file_exist != 0) {
985 xsh_msg_error("The Name %s of ASCII file containing the list of throw shifts with respect to the first exposure was not found. Exit.",throw_name);
986 cpl_error_set(cpl_func, CPL_ERROR_FILE_NOT_FOUND);
987 goto cleanup;
988 }
989
990 if ( strcmp( throw_name, "") != 0 && file_exist ==0 ){
991 char throw_line[200];
992 int iline;
993
994 xsh_msg("Load Throw shifts from file %s", throw_name);
995 throw_file = fopen( throw_name, "r");
996
997 XSH_CALLOC( throw_tab, double, nb_nod);
998
999 iline=0;
1000
1001 while (fgets( throw_line, 200, throw_file) != NULL){
1002 char shiftval[200];
1003
1004 /* Note: update the string format (the %__s) if shiftval changes size.
1005 * Remember: field width must equal 1 less than sizeof(shiftval). */
1006 sscanf( throw_line, "%199s",shiftval);
1007 if (iline < nb_nod){
1008 throw_tab[iline] = atof( shiftval);
1009 }
1010 iline++;
1011 }
1012 if (iline != nb_nod){
1013 xsh_error_msg("Invalid number of lines in ASCII file %s : %d - expected number : %d",
1014 throw_name, iline, nb_nod);
1015 }
1016 fclose( throw_file);
1017 throw_file = NULL;
1018 }
1019
1020 /* For each of frames */
1021 for( i = 0; i<nb_nod ; i++) {
1022 //cpl_frame * rm_crh = NULL ;
1023 cpl_frame * divided = NULL ;
1024 cpl_frame * shifted_a_b = NULL;
1025 cpl_frame * shifted_a_b_eso = NULL;
1026 cpl_frame * shifted_a_b_tab = NULL;
1027 cpl_frame *inv_shifted_a_b = NULL;
1028 cpl_frame *loc_rec = NULL;
1029 cpl_frame *loc_rec_eso = NULL;
1030 cpl_frame *loc_rec_tab = NULL;
1031 cpl_frame *inv_loc_rec = NULL;
1032 char str[16] ;
1033 //int mode =0;
1034
1035 if (throw_tab != NULL){
1036 throw_shift = &throw_tab[i];
1037 }
1038
1039 if (i%2 == 0){
1040 sprintf( str, "AB_%d_%s", i/2, xsh_instrument_arm_tostring(instrument)) ;
1041 //mode =0;
1042 }
1043 else{
1044 sprintf( str, "BA_%d_%s", i/2, xsh_instrument_arm_tostring(instrument)) ;
1045 //mode=1;
1046 }
1047 check( a_b = cpl_frameset_get_frame( nod_set, i));
1048 xsh_msg_dbg_high( "***** Frame %s", cpl_frame_get_filename( a_b ) ) ;
1049
1050 /* remove_crh : if we have done multiple don't do single
1051 xsh_msg( "Remove crh (single frame)" ) ;
1052 sprintf(file_tag, "SLIT_NOD_NOCRH_%s",str) ;
1053
1054 check( rm_crh = xsh_abs_remove_crh_single(a_b, instrument,
1055 crh_single_par, file_tag));
1056 */
1057 /*divide by flat field */
1058 sprintf(file_tag,"SLIT_NOD_NOCRH_FF_%s", str);
1059 check( divided = xsh_frame_divide_flat( do_flatfield, a_b,master_flat, file_tag,
1060 instrument));
1061
1062 if ( i > 1 && throw_shift == NULL){
1063 if (i%2 == 0){
1064 xsh_msg("TEST %d : on fait loc_ab et loc_ba", i);
1065 sprintf(file_name,"LOC_REC_%s.fits", str);
1066 check( loc_rec = xsh_rectify( divided, order_tab_edges,
1067 wave_tab, model_config_frame, instrument,
1068 rectify_par, spectral_format, disp_tab_frame,
1069 file_name, &loc_rec_eso, &loc_rec_tab, rec_prefix));
1070 xsh_msg( "Localize the object (A%d)", i/2);
1071 sprintf( file_name,"LOCALIZE_%s.fits", str);
1072 check( loc_a_b = xsh_localize_obj( loc_rec, skymask_frame, instrument, loc_obj_par,
1073 NULL, file_name));
1074 xsh_add_temporary_file(file_name);
1075
1076 xsh_msg( "Negative rectify");
1077 sprintf(file_name,"DRL_INV_LOC_REC_%s", str);
1078 check( inv_loc_rec = xsh_rec_list_frame_invert( loc_rec,
1079 file_name, instrument));
1080
1081 xsh_msg( "Localize the object (B%d)", i/2);
1082 sprintf(file_name,"INV_LOCALIZE_%s.fits", str);
1083 check( loc_b_a = xsh_localize_obj( inv_loc_rec, skymask_frame, instrument, loc_obj_par,
1084 NULL, file_name));
1085 }
1086 else{
1087 xsh_msg("TEST %d : loc_ab = loc_ba", i);
1088 loc_a_b = loc_b_a;
1089 }
1090 }
1091 /* Rectify and shift */
1092 xsh_msg( "Rectify and shift");
1093 sprintf(file_name,"SHIFT_REC_NOCRH_%s.fits", str);
1094
1095 check( shifted_a_b = xsh_rectify_and_shift( divided,order_tab_edges,
1096 wave_tab,
1097 model_config_frame,
1098 instrument,
1099 rectify_par,
1100 spectral_format,
1101 loc_a_b,
1102 loc_a_b_0,
1103 throw_shift,
1104 disp_tab_frame,
1105 file_name,
1106 &shifted_a_b_eso,
1107 &shifted_a_b_tab));
1108 xsh_free_frame( &loc_a_b);
1109
1110 if ( i==0 && throw_shift == NULL){
1111 xsh_msg( "Localize the object (A0)");
1112 sprintf(file_name,"LOCALIZE_%s.fits", str);
1113 check( loc_a_b_0 = xsh_localize_obj( shifted_a_b, skymask_frame, instrument, loc_obj_par,
1114 NULL, file_name));
1115 xsh_add_temporary_file(file_name);
1116
1117 xsh_msg( "Negative rectify");
1118 sprintf(file_name,"DRL_INV_LOC_REC_%s", str);
1119 check( inv_shifted_a_b = xsh_rec_list_frame_invert( shifted_a_b,
1120 file_name, instrument));
1121 xsh_msg( "Localize the object (B0)");
1122 sprintf(file_name,"INV_LOCALIZE_%s.fits", str);
1123 check( loc_a_b = xsh_localize_obj( inv_shifted_a_b, skymask_frame, instrument, loc_obj_par,
1124 NULL, file_name));
1125 }
1126 check( cpl_frameset_insert( comb_set, shifted_a_b));
1127
1128 //xsh_free_frame( &rm_crh);
1129 xsh_free_frame( &divided);
1130 xsh_free_frame( &shifted_a_b_eso);
1131 xsh_free_frame( &shifted_a_b_tab);
1132 xsh_free_frame( &inv_shifted_a_b);
1133 xsh_free_frame( &loc_rec);
1134 xsh_free_frame( &loc_rec_eso);
1135 xsh_free_frame( &loc_rec_tab);
1136 xsh_free_frame( &inv_loc_rec);
1137 } /* end loop on each pair */
1138
1139 cleanup:
1140 if (throw_file != NULL) fclose(throw_file);
1141 if ( cpl_error_get_code() != CPL_ERROR_NONE || file_exist!=0){
1142 xsh_free_frameset( &comb_set);
1143 }
1144 xsh_free_frame( &loc_a_b_0);
1145 xsh_free_frame( &loc_a_b);
1146 XSH_FREE( throw_tab);
1147 return comb_set;
1148
1149
1150}
1151
1152cpl_error_code
1153xsh_scired_get_proper_maps(cpl_frameset* raws, cpl_frameset* calib,
1154 cpl_frame* order_tab_edges,cpl_frame* master_flat,
1155 cpl_frame* model_config_frame,cpl_frame* disp_tab,
1156 xsh_instrument* instrument,const int do_computemap,
1157 const char* rec_prefix, cpl_frame** wavemap,
1158 cpl_frame** slitmap)
1159{
1160
1161 /* create proper size wave and slit maps */
1162 cpl_frame* ref_frame=NULL;
1163 int recipe_use_model=FALSE;
1164 if (xsh_mode_is_physmod(calib,instrument)){
1165 ref_frame=cpl_frameset_get_frame(raws,0);
1166 }
1167 else{
1168 ref_frame = master_flat;
1169 }
1170 check( xsh_check_get_map( disp_tab, order_tab_edges,
1171 ref_frame, model_config_frame, calib, instrument,
1172 do_computemap, recipe_use_model, rec_prefix,
1173 wavemap, slitmap));
1174cleanup:
1175return cpl_error_get_code();
1176
1177}
1178
1179cpl_error_code
1181 const char* recipe_id,int pscan,cpl_frame** spectral_format,
1182 cpl_frame** master_bias,
1183 cpl_frame** bpmap,cpl_frame** order_tab_edges,cpl_frame** master_flat)
1184{
1185
1186 check( *spectral_format = xsh_find_spectral_format( calib, instrument));
1187
1188
1189 if(pscan==0) {
1190 /* In UVB and VIS mode */
1192 /* RAWS frameset must have only one file */
1193 check(*master_bias = xsh_find_master_bias( calib, instrument));
1194 }
1195 }
1196
1197 check(*bpmap=xsh_check_load_master_bpmap(calib,instrument,recipe_id));
1198
1199 check( *order_tab_edges = xsh_find_order_tab_edges( calib, instrument));
1200
1201 if( NULL == (*master_flat = xsh_find_master_flat( calib,instrument))) {
1202 xsh_msg_error("You must provide a %s frame in input",
1204 goto cleanup;
1205 }
1206
1207 cleanup:
1208 return cpl_error_get_code();
1209}
1210
1211cpl_error_code
1213 const int do_computemap,
1214 cpl_frame** model_config_frame, cpl_frame** wave_tab,
1215 cpl_frame** wavemap)
1216{
1217 int recipe_use_model=FALSE;
1218 cpl_boolean mode_phys;
1219 mode_phys=xsh_mode_is_physmod(calib,instrument);
1220
1221 /* one should have either model config frame or wave sol frame */
1222 if(mode_phys) {
1223 recipe_use_model = TRUE;
1224 if((*model_config_frame = xsh_find_frame_with_tag(calib,
1226 instrument)) == NULL) {
1227
1229 if ((*model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_2D,
1230 instrument)) == NULL) {
1232
1233 if ((*model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
1234 instrument)) == NULL) {
1236 } else {
1237 xsh_msg("RECIPE USE REFERENCE MODEL");
1238 }
1239 } else {
1240 xsh_msg("RECIPE USE OPTIMISED 2D MODEL");
1241 }
1242 } else {
1243 xsh_msg("RECIPE USE OPTIMISED AFC MODEL");
1244 }
1245 } else {
1246 xsh_msg("RECIPE USE WAVE SOLUTION");
1247 check( *wave_tab = xsh_find_wave_tab( calib, instrument));
1248 recipe_use_model = FALSE;
1249 }
1250
1251 XSH_ASSURE_NOT_ILLEGAL( model_config_frame != NULL || wave_tab != NULL);
1252
1253 if(do_computemap && recipe_use_model==FALSE) {
1254 check( *wavemap = xsh_find_wavemap( calib, instrument));
1255 }
1256 cleanup:
1257 return cpl_error_get_code();
1258}
1259
1260static cpl_error_code
1262 const int use_sky_mask, cpl_frame** disp_tab_frame,
1263 cpl_frame** response_ord_frame, cpl_frame** frm_atmext,
1264 cpl_frame** skymask_frame) {
1265
1266 /* to compute efficiency */
1267 if(NULL == (*disp_tab_frame = xsh_find_disp_tab( calib, instrument))) {
1268 xsh_msg("To compute efficiency, you must provide a DISP_TAB_ARM input");
1269 }
1270
1271 if ( use_sky_mask == TRUE){
1272 xsh_msg("Using sky mask");
1273 check( *skymask_frame = xsh_find_frame_with_tag( calib, XSH_SKY_LINE_LIST,
1274 instrument));
1275 }
1276
1277 check( *response_ord_frame = xsh_find_frame_with_tag(calib,
1279
1280 if(*response_ord_frame != NULL) {
1282 if(*frm_atmext==NULL) {
1283 xsh_msg_error("Provide atmospheric extinction frame");
1284 }
1285 }
1286
1287 cleanup:
1288 return cpl_error_get_code();
1289}
1290
1291cpl_error_code
1293 xsh_instrument* instrument, cpl_frame** response_ord_frame,
1294 cpl_frame** frm_atmext)
1295{
1296
1297
1298 if((*response_ord_frame=xsh_find_frame_with_tag(calib,XSH_RESPONSE_MERGE1D_SLIT,
1299 instrument)) == NULL ) {
1300 check( *response_ord_frame = xsh_find_frame_with_tag(calib,
1302 instrument));
1303 }
1304 if(*response_ord_frame != NULL) {
1306 if(*frm_atmext==NULL) {
1307 xsh_msg_error("Provide atmospheric extinction frame");
1308 }
1309 }
1310 cleanup:
1311 return cpl_error_get_code();
1312}
1313//PIPPO
1314cpl_error_code
1316 cpl_frameset* calib,
1318 cpl_frame** bpmap,
1319 cpl_frame** master_bias,
1320 cpl_frame** master_flat,
1321 cpl_frame** order_tab_edges,
1322 cpl_frame** wave_tab,
1323 cpl_frame** model_config_frame,
1324 cpl_frame** wavemap,
1325 cpl_frame** slitmap,
1326 cpl_frame** disp_tab_frame,
1327 cpl_frame** spectral_format,
1328 cpl_frame** skymask_frame,
1329 cpl_frame** response_ord_frame,
1330 cpl_frame** frm_atmext,
1331 int do_computemap,
1332 int use_skymask,
1333 int pscan,
1334 const char* rec_prefix,
1335 const char* recipe_id)
1336
1337{
1338
1339 xsh_get_normal_calibs(calib, instrument, recipe_id, pscan, spectral_format,
1340 master_bias, bpmap, order_tab_edges, master_flat);
1341 int recipe_use_model=FALSE;
1342 cpl_frame* ref_frame=NULL;
1343 cpl_boolean mode_phys;
1344 mode_phys=xsh_mode_is_physmod(calib,instrument);
1345
1346
1347 /* one should have either model config frame or wave sol frame */
1348 if(mode_phys) {
1349 recipe_use_model = TRUE;
1350 if((*model_config_frame = xsh_find_frame_with_tag(calib,
1352 instrument)) == NULL) {
1353
1355 if ((*model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_2D,
1356 instrument)) == NULL) {
1358
1359 if ((*model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
1360 instrument)) == NULL) {
1362 } else {
1363 xsh_msg("RECIPE USE REFERENCE MODEL");
1364 }
1365 } else {
1366 xsh_msg("RECIPE USE OPTIMISED 2D MODEL");
1367 }
1368 } else {
1369 xsh_msg("RECIPE USE OPTIMISED AFC MODEL");
1370 }
1371 } else {
1372 xsh_msg("RECIPE USE WAVE SOLUTION");
1373 check( *wave_tab = xsh_find_wave_tab( calib, instrument));
1374 recipe_use_model = FALSE;
1375 }
1376
1377 XSH_ASSURE_NOT_ILLEGAL( model_config_frame != NULL || wave_tab != NULL);
1378
1379
1380 if(do_computemap && recipe_use_model==FALSE) {
1381 check( *wavemap = xsh_find_wavemap( calib, instrument));
1382 }
1383 /* to compute efficiency */
1384 if(NULL == (*disp_tab_frame = xsh_find_disp_tab( calib, instrument))) {
1385 xsh_msg("To compute efficiency, you must provide a DISP_TAB_ARM input");
1386 }
1387
1388 if ( recipe_use_model){
1389 ref_frame=cpl_frameset_get_frame(raws,0);
1390 }
1391 else{
1392 ref_frame = *master_flat;
1393 }
1394 check( xsh_check_get_map( *disp_tab_frame, *order_tab_edges,
1395 ref_frame, *model_config_frame, calib, instrument,
1396 do_computemap, recipe_use_model, rec_prefix,
1397 wavemap, slitmap));
1398
1399
1400 if ( use_skymask == TRUE){
1401 xsh_msg("Using sky mask");
1402 check( *skymask_frame = xsh_find_frame_with_tag( calib, XSH_SKY_LINE_LIST,
1403 instrument));
1404 }
1405
1406 xsh_get_calibs_to_flux_calibrate(calib, instrument, response_ord_frame,
1407 frm_atmext);
1408
1409 cleanup:
1410 return cpl_error_get_code();
1411}
1412
1413
1414
1415cpl_error_code
1418 cpl_frame** bpmap,
1419 cpl_frame** master_bias,
1420 cpl_frame** master_flat,
1421 cpl_frame** order_tab_edges,
1422 cpl_frame** wave_tab,
1423 cpl_frame** model_config_frame,
1424 cpl_frame** wavemap,
1425 cpl_frame** slitmap,
1426 cpl_frame** disp_tab_frame,
1427 cpl_frame** spectral_format,
1428 cpl_frame** skymask_frame,
1429 cpl_frame** response_ord_frame,
1430 cpl_frame** frm_atmext,
1431 int do_computemap,
1432 int use_skymask,
1433 int pscan,
1434 const char* rec_prefix,
1435 const char* recipe_id)
1436
1437{
1438
1439 xsh_get_normal_calibs(calib, instrument, recipe_id, pscan, spectral_format,
1440 master_bias, bpmap, order_tab_edges, master_flat);
1441
1442 xsh_get_dispersion_calibs(calib, instrument, do_computemap,
1443 model_config_frame, wave_tab, wavemap);
1444
1445 xsh_get_response_calibs(calib, instrument, use_skymask, disp_tab_frame,
1446 response_ord_frame, frm_atmext, skymask_frame);
1447
1448 return cpl_error_get_code();
1449}
1450
1451/* for the moment not used */
1457static cpl_error_code
1459 xsh_localize_obj_param * loc_obj_par)
1460{
1461
1462
1463
1464 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
1465 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
1466 rectify_par->rectif_bin_space);
1467
1468 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
1469 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
1470
1471 return cpl_error_get_code();
1472
1473}
1474
1475
1476
1477
1478cpl_error_code
1479xsh_scired_nod_get_parameters(cpl_parameterlist* parameters,
1481 xsh_remove_crh_single_param** crh_single_par,
1482 xsh_rectify_param** rectify_par,
1483 xsh_extract_param** extract_par,
1484 xsh_combine_nod_param** combine_nod_par,
1485 xsh_slit_limit_param** slit_limit_par,
1486 xsh_localize_obj_param** loc_obj_par,
1487 int* rectify_fast, int* pscan,
1488 int* generate_sdp_format,
1489 const char* rec_id
1490 )
1491
1492
1493{
1494 check( *loc_obj_par = xsh_parameters_localize_obj_get(rec_id,
1495 parameters));
1496 check( *rectify_par = xsh_parameters_rectify_get(rec_id,
1497 parameters));
1498 check( *rectify_fast = xsh_parameters_rectify_fast_get(rec_id,
1499 parameters));
1500 check( *crh_single_par = xsh_parameters_remove_crh_single_get(rec_id,
1501 parameters));
1502 cpl_msg_info(__func__, " Fetched crh_single params %f, %f, %f, %d",
1503 (*crh_single_par)->crh_frac_max,
1504 (*crh_single_par)->sigma_lim, (*crh_single_par)->f_lim,
1505 (*crh_single_par)->nb_iter);
1506 check( *extract_par=xsh_parameters_extract_get(rec_id, parameters));
1507 check( *combine_nod_par = xsh_parameters_combine_nod_get(rec_id,
1508 parameters)) ;
1509 check( *slit_limit_par = xsh_parameters_slit_limit_get(rec_id,
1510 parameters));
1511
1512 check(xsh_rectify_params_set_defaults(parameters,rec_id,instrument,*rectify_par));
1513
1514 check( xsh_scired_nod_params_monitor(*rectify_par,*loc_obj_par));
1515 check( *pscan=xsh_parameters_get_int(parameters,rec_id,"pre-overscan-corr"));
1516
1517 if (xsh_parameters_find(parameters, rec_id, "generate-SDP-format") != NULL) {
1518 check( *generate_sdp_format = xsh_parameters_get_boolean(parameters, rec_id,
1519 "generate-SDP-format"));
1520 }
1521
1522 cleanup:
1523 return cpl_error_get_code();
1524}
1525
1526
1527cpl_error_code
1528xsh_flux_calibrate1D(cpl_frame* rect1D,
1529 cpl_frame* atmext,
1530 cpl_frame* response,
1531 int mpar,
1532 xsh_instrument* inst,
1533 const char* rec_prefix,
1534 cpl_frame** fcal_rect_1D,
1535 cpl_frame** fcal_1D)
1536{
1537
1538 char file_tag[256];
1539 char file_name[256];
1540 char arm_str[8] ;
1541 cpl_frame* nrm_1D=NULL;
1542 const char* tag=NULL;
1543
1544
1545 tag=cpl_frame_get_tag(rect1D);
1546 sprintf(arm_str,"%s",xsh_instrument_arm_tostring(inst));
1547 xsh_msg("tag=%s",tag);
1548 if(strstr(tag,XSH_ORDER_OXT1D) == NULL) {
1549 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_NORM_ORDER1D,arm_str);
1550 } else {
1551 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_NORM_OXT1D,arm_str);
1552 }
1553 xsh_msg("file_tag1=%s",file_tag);
1554 sprintf(file_name,"%s.fits",file_tag);
1555 xsh_add_temporary_file(file_name);
1556
1557 check(nrm_1D=xsh_normalize_spectrum_ord(rect1D,atmext,1,inst,file_tag));
1558 if(strstr(tag,XSH_ORDER_OXT1D) == NULL) {
1559 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_FLUX_ORDER1D,arm_str);
1560 } else {
1561 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_FLUX_OXT1D,arm_str);
1562 }
1563 sprintf(file_name,"%s.fits",file_tag);
1564 //xsh_add_temporary_file(file_name);
1565
1566 check(*fcal_rect_1D=xsh_util_multiply_by_response_ord(nrm_1D,response,file_tag));
1567 check(*fcal_1D= xsh_merge_ord(*fcal_rect_1D,inst,mpar,rec_prefix));
1568 xsh_msg("file_tag2=%s",file_tag);
1569
1570
1571cleanup:
1572 xsh_free_frame(&nrm_1D);
1573 return cpl_error_get_code();
1574
1575}
1576
1577
1578
1579cpl_error_code
1580xsh_flux_calibrate2D(cpl_frame* rect2D,
1581 cpl_frame* atmext,
1582 cpl_frame* response,
1583 int mpar,
1584 xsh_instrument* inst,
1585 const char* rec_prefix,
1586 cpl_frame** fcal_rect_2D,
1587 cpl_frame** fcal_2D)
1588{
1589
1590
1591 char file_tag[256];
1592 char file_name[256];
1593 char arm_str[8] ;
1594 cpl_frame* nrm_2D=NULL;
1595
1596 sprintf(arm_str,"%s",xsh_instrument_arm_tostring(inst));
1597
1598 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_NORM_ORDER2D,arm_str);
1599 sprintf(file_name,"%s.fits",file_tag);
1600 check(nrm_2D=xsh_normalize_spectrum_ord(rect2D,atmext,1,inst,file_tag));
1601 xsh_add_temporary_file(file_name);
1602
1603
1604 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_FLUX_ORDER2D,arm_str);
1605 check(*fcal_rect_2D=xsh_util_multiply_by_response_ord(nrm_2D,response,file_tag));
1606 check(*fcal_2D = xsh_merge_ord(*fcal_rect_2D, inst,mpar,rec_prefix));
1607
1608cleanup:
1609 xsh_free_frame(&nrm_2D);
1610 return cpl_error_get_code();
1611
1612
1613}
1614
1615cpl_error_code
1616xsh_flux_calibrate(cpl_frame* rect2D,
1617 cpl_frame* rect1D,
1618 cpl_frame* atmext,
1619 cpl_frame* response,
1620 int mpar,
1621 xsh_instrument* inst,
1622 const char* rec_prefix,
1623 cpl_frame** fcal_rect_2D,
1624 cpl_frame** fcal_rect_1D,
1625 cpl_frame** fcal_2D,
1626 cpl_frame** fcal_1D)
1627{
1628
1629
1630 check(xsh_flux_calibrate2D(rect2D,atmext,response,mpar,inst,rec_prefix,
1631 fcal_rect_2D,fcal_2D));
1632 check(xsh_flux_calibrate1D(rect1D,atmext,response,mpar,inst,rec_prefix,
1633 fcal_rect_1D,fcal_1D));
1634
1635 cleanup:
1636
1637
1638 return cpl_error_get_code();
1639}
1640
1641
1642cpl_error_code
1643xsh_ifu_stare_get_calibs(cpl_frameset* calib,
1644 xsh_instrument* inst,
1645 cpl_frame** spectral_format,
1646 cpl_frame** mbias,
1647 cpl_frame** mdark,
1648 cpl_frame** mflat,
1649 cpl_frame** otab_edges,
1650 cpl_frame** model_cfg,
1651 cpl_frame** bpmap,
1652 cpl_frame** wmap,
1653 cpl_frame** smap,
1654 cpl_frame** ifu_cfg_tab,
1655 cpl_frame** ifu_cfg_cor,
1656 cpl_frame** wavesol,
1657 const char* rec_id,
1658 int * recipe_use_model,
1659 int pscan)
1660{
1661
1662 //cpl_boolean mode_phys;
1663 //mode_phys=xsh_mode_is_physmod(calib,inst);
1664 check(*spectral_format = xsh_find_spectral_format( calib, inst));
1665
1666 XSH_ASSURE_NOT_NULL_MSG(*spectral_format,"Null input spectral format frame");
1667 check(xsh_instrument_update_from_spectralformat(inst,*spectral_format));
1668
1669 /* In UVB and VIS mode */
1670
1671 if (pscan == 0) {
1672 xsh_msg("pscan=%d",pscan);
1673 if ( xsh_instrument_get_arm(inst) != XSH_ARM_NIR){
1674 /* RAWS frameset must have only one file */
1675 if((*mbias = xsh_find_master_bias( calib, inst)) == NULL) {
1676 xsh_msg_error("You must give a MASTER_BIAS_ARM frame");
1677 return CPL_ERROR_DATA_NOT_FOUND;
1678 }
1679 }
1680 }
1681
1682 /* IFU stuff (physmodel) */
1683 check(*ifu_cfg_tab = xsh_find_frame_with_tag(calib,XSH_IFU_CFG_TAB,inst));
1684 check(*ifu_cfg_cor = xsh_find_frame_with_tag(calib,XSH_IFU_CFG_COR,inst));
1685 check(*spectral_format=xsh_find_spectral_format( calib, inst ) ) ;
1686
1687 /* one should have either model config frame or wave sol frame */
1688 check( *model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC, inst));
1689 if( *model_cfg == NULL) {
1690 check(*wavesol=xsh_find_frame_with_tag(calib,XSH_WAVE_TAB_AFC, inst));
1691 }
1692 /*
1693 wave_tabs_ifu = xsh_find_wave_tab_ifu( calib, instrument);
1694 xsh_error_reset();
1695 */
1696 /* One of model config and wave tab must be present, but only one ! */
1697 if ( *model_cfg == NULL){
1698 xsh_msg("RECIPE USE WAVE SOLUTION");
1699 *recipe_use_model = FALSE;
1700 }
1701 else{
1702 xsh_msg("RECIPE USE MODEL");
1703 *recipe_use_model = TRUE;
1704 }
1705
1706 if( ( *model_cfg !=NULL) && (*wavesol != NULL) ) {
1707
1708 xsh_msg_error("You cannot provide both a %s and a %s frame. Decide if you are in poly or physical model mode. We exit",
1710 goto cleanup;
1711 }
1712
1713 if(( *model_cfg == NULL) && ( *wavesol == NULL) ) {
1714 xsh_msg_error("You must provide either a %s or a %s frame",
1716 goto cleanup;
1717 }
1718
1719 if ( ( *mdark = xsh_find_master_dark( calib, inst ) ) == NULL ){
1720 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
1722 }
1723
1724 check( *mflat = xsh_find_master_flat( calib, inst));
1725 if( *mflat == NULL) {
1726 xsh_msg_error("Frame %s not provided",XSH_MASTER_FLAT);
1727 goto cleanup;
1728 }
1729 check( *otab_edges = xsh_find_order_tab_edges( calib, inst));
1730 if( *otab_edges == NULL) {
1731 xsh_msg_error("Frame %s not provided",XSH_ORDER_TAB_EDGES_IFU);
1732 goto cleanup;
1733 }
1734
1735 /* optional frames */
1736 check(*bpmap=xsh_check_load_master_bpmap(calib,inst,rec_id));
1737 check(*wmap = xsh_find_frame_with_tag(calib,XSH_WAVE_MAP,inst));
1738 check(*smap = xsh_find_frame_with_tag(calib,XSH_SLIT_MAP,inst));
1739
1740 cleanup:
1741
1742 return cpl_error_get_code();
1743
1744}
1745
1746cpl_error_code
1748 cpl_frame** sky_list, cpl_frame** model_cfg, cpl_frame** qc_sky,
1749 cpl_frame** sframe_sky_sub_tab, cpl_frame** sky_orders_chunks)
1750{
1752 instrument));
1753 if ( *model_cfg != NULL){
1754
1755 if ( *sky_list != NULL){
1756 /* we compute unbinned THE map to easier plots from QC Garching */
1758 *sky_list,1,1,9,1));
1759 }
1760 }
1761
1762 /* optional frames */
1763 if ((*sframe_sky_sub_tab = xsh_find_frame_with_tag(calib,XSH_SKY_SUB_BKPTS,
1764 instrument)) == NULL) {
1766 } else {
1767 xsh_msg_warning("Data reduction with user defined break points number from file %s",
1768 cpl_frame_get_filename(*sframe_sky_sub_tab));
1769 }
1770 *sky_orders_chunks = xsh_find_frame_with_tag(calib,XSH_SKY_ORDERS_CHUNKS, instrument);
1771
1772 cleanup:
1773
1774 return cpl_error_get_code();
1775}
1776
1777
1778cpl_error_code
1779xsh_slit_stare_get_calibs(cpl_frameset* calib,
1781 cpl_frame** spectralformat,
1782 cpl_frame** mbias,
1783 cpl_frame** mdark,
1784 cpl_frame** mflat,
1785 cpl_frame** otab_edges,
1786 cpl_frame** model_cfg,
1787 cpl_frame** wave_tab,
1788 cpl_frame** sky_list,
1789 cpl_frame** sky_orders_chunks,
1790 cpl_frame** qc_sky,
1791 cpl_frame** bpmap,
1792 cpl_frame** sframe_sky_sub_tab,
1793 cpl_frame** wmap,
1794 cpl_frame** smap,
1795 const char* rec_id,
1796 int * recipe_use_model,
1797 int pscan)
1798{
1799
1800
1801 cpl_boolean mode_phys;
1802 mode_phys=xsh_mode_is_physmod(calib,instrument);
1803 check(*spectralformat = xsh_find_spectral_format( calib, instrument));
1804
1805 XSH_ASSURE_NOT_NULL_MSG(*spectralformat,"Null input spectral format frame");
1807
1808 /* In UVB and VIS mode */
1809 if (pscan == 0) {
1810 xsh_msg("pscan=%d",pscan);
1812 /* RAWS frameset must have only one file */
1813 if((*mbias = xsh_find_master_bias( calib, instrument)) == NULL) {
1814 xsh_msg_error("You must give a MASTER_BIAS_ARM frame");
1815 return CPL_ERROR_DATA_NOT_FOUND;
1816 }
1817 }
1818 }
1819
1820 if((*mdark = xsh_find_master_dark( calib, instrument))==NULL) {
1821 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
1823 }
1824 if( (*mflat = xsh_find_frame_with_tag(calib,XSH_MASTER_FLAT_SLIT,instrument)) == NULL) {
1825 xsh_msg_error("Missing required input %s",XSH_GET_TAG_FROM_MODE ( XSH_MASTER_FLAT, instrument));
1826 cpl_error_set(cpl_func, CPL_ERROR_FILE_NOT_FOUND);
1827 goto cleanup;
1828 }
1829 check( *mflat = xsh_find_master_flat( calib, instrument ));
1830 check(*otab_edges = xsh_find_order_tab_edges(calib,instrument));
1831
1832 /* one should have either model config frame or wave sol frame */
1833 if(mode_phys) {
1834 if((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
1835 instrument)) == NULL) {
1837 if ((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_2D,
1838 instrument)) == NULL) {
1840
1841 if ((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
1842 instrument)) == NULL) {
1844 } else {
1845 xsh_msg("RECIPE USE REFERENCE MODEL");
1846 }
1847 } else {
1848 xsh_msg("RECIPE USE OPTIMIZED 2D MODEL");
1849 }
1850 } else {
1851 xsh_msg("RECIPE USE OPTIMIZED AFC MODEL");
1852 }
1853 *recipe_use_model = TRUE;
1854 } else {
1855 xsh_msg("RECIPE USE WAVE SOLUTION");
1856 check( *wave_tab = xsh_find_wave_tab( calib, instrument));
1857 *recipe_use_model = FALSE;
1858 }
1860 instrument));
1861 if ( *model_cfg != NULL){
1862
1863 if ( *sky_list != NULL){
1864 /* we compute unbinned THE map to easier plots from QC garching */
1866 *sky_list,1,1,9,1));
1867 }
1868 }
1869
1870 /* optional frames */
1871 check(*bpmap=xsh_check_load_master_bpmap(calib,instrument,rec_id));
1872 if ((*sframe_sky_sub_tab = xsh_find_frame_with_tag(calib,XSH_SKY_SUB_BKPTS,
1873 instrument)) == NULL) {
1875 } else {
1876 xsh_msg_warning("Data reduction with user defined break points number from file %s",
1877 cpl_frame_get_filename(*sframe_sky_sub_tab));
1878 }
1879 *sky_orders_chunks = xsh_find_frame_with_tag(calib,XSH_SKY_ORDERS_CHUNKS, instrument);
1880
1883
1884 cleanup:
1885
1886 return cpl_error_get_code();
1887}
1888
1889cpl_error_code
1890xsh_slit_stare_get_calibs2(cpl_frameset* calib,
1892 cpl_frame** spectralformat,
1893 cpl_frame** mbias,
1894 cpl_frame** mdark,
1895 cpl_frame** mflat,
1896 cpl_frame** otab_edges,
1897 cpl_frame** model_cfg,
1898 cpl_frame** wave_tab,
1899 cpl_frame** sky_list,
1900 cpl_frame** sky_orders_chunks,
1901 cpl_frame** qc_sky,
1902 cpl_frame** bpmap,
1903 cpl_frame** sframe_sky_sub_tab,
1904 cpl_frame** wmap,
1905 cpl_frame** smap,
1906 const char* rec_id,
1907 int * recipe_use_model,
1908 int pscan)
1909{
1910
1911
1912 xsh_get_normal_calibs(calib, instrument, rec_id, pscan, spectralformat, mbias,
1913 bpmap, otab_edges, mflat);
1914 //The following should go in xsh_get_normal_calibs()
1916
1917
1918 if((*mdark = xsh_find_master_dark( calib, instrument))==NULL) {
1919 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
1921 }
1922
1923 //TODO: extra param, should come from recipe caller.
1924 int do_computemap=1;
1925 xsh_get_dispersion_calibs( calib, instrument, do_computemap, model_cfg,
1926 wave_tab, wmap);
1927 //TODO: the following two lines should be moved to xsh_get_dispersion_calibs()
1930
1931 xsh_get_slit_stare_calibs(calib, instrument, sky_list, model_cfg, qc_sky,
1932 sframe_sky_sub_tab, sky_orders_chunks);
1933
1934 cleanup:
1935
1936 return cpl_error_get_code();
1937}
1938
1939cpl_error_code
1941 cpl_frame** bpmap,cpl_frame** mbias,
1942 cpl_frame** mdark, cpl_frame** otab_edges,
1943 cpl_frame** model_cfg, cpl_frame** wave_tab,
1944 cpl_frame** mflat, cpl_frame** wmap, cpl_frame** smap,
1945 cpl_frame** spectral_format,const char* rec_id)
1946{
1947
1948 int pscan=0; //extra.
1949 xsh_get_normal_calibs(calib, instrument, rec_id, pscan, spectral_format,
1950 mbias, bpmap, otab_edges, mflat);
1951
1952 /* TODO: Is mdark input really needed? */
1953 if((*mdark=xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,instrument))==NULL){
1955 }
1956
1957 //The following need to be defined
1958 int do_computemap=1;
1959 xsh_get_dispersion_calibs(calib, instrument, do_computemap, model_cfg,
1960 wave_tab, wmap);
1961 //The following is also present in xsh_get_dispersion_calibs
1962 check( *wmap = xsh_find_wavemap( calib, instrument));
1963 //The following should be removed to xsh_get_dispersion_calibs
1964 check( *smap = xsh_find_slitmap( calib, instrument));
1965
1966 cleanup:
1967 return cpl_error_get_code();
1968
1969}
1970
1971cpl_error_code
1972xsh_slit_stare_get_params(cpl_parameterlist* parameters,
1973 const char* rec_id,
1974 int* pre_overscan_corr,
1975 xsh_background_param** backg_par,
1976 xsh_localize_obj_param** loc_obj_par,
1977 xsh_rectify_param** rectify_par,
1978 xsh_remove_crh_single_param** crh_single_par,
1979 int* sub_sky_nbkpts1,
1980 int* do_flatfield,
1981 int* sub_sky_nbkpts2,
1983 int* do_optextract,
1984 xsh_opt_extract_param** opt_extract_par,
1985 int* generate_sdp_format)
1986{
1987
1988 check( *pre_overscan_corr = xsh_parameters_get_int( parameters, rec_id,
1989 "pre-overscan-corr"));
1990
1991 check( *backg_par = xsh_parameters_background_get(rec_id,parameters));
1992
1993 check( *loc_obj_par = xsh_parameters_localize_obj_get(rec_id,parameters));
1994 check( *rectify_par = xsh_parameters_rectify_get(rec_id,parameters));
1995 check( *crh_single_par = xsh_parameters_remove_crh_single_get(rec_id,parameters));
1996
1998 rec_id,parameters));
1999
2001 rec_id,parameters));
2002 check( *sky_par= xsh_parameters_subtract_sky_single_get(rec_id,parameters));
2003
2004 check( *do_optextract = xsh_parameters_get_boolean( parameters, rec_id,
2005 "do-optextract"));
2006 check( *opt_extract_par = xsh_parameters_opt_extract_get(rec_id,parameters));
2007
2008 if (xsh_parameters_find(parameters, rec_id, "generate-SDP-format") != NULL) {
2009 check( *generate_sdp_format = xsh_parameters_get_boolean(parameters, rec_id,
2010 "generate-SDP-format"));
2011 }
2012
2013 cleanup:
2014 return cpl_error_get_code();
2015}
2016
2017
2018cpl_error_code
2019xsh_slit_offset_get_params(cpl_parameterlist* parameters,
2020 const char* rec_id,
2021 xsh_localize_obj_param** loc_obj_par,
2022 xsh_rectify_param** rectify_par,
2023 xsh_remove_crh_single_param** crh_single_par,
2024 xsh_extract_param**extract_par,
2025 xsh_combine_nod_param** combine_nod_param,
2026 int* do_flatfield,
2027 int* gen_sky,
2028 int* generate_sdp_format)
2029{
2030
2031
2032 check( *loc_obj_par = xsh_parameters_localize_obj_get(rec_id,parameters));
2033 check( *rectify_par = xsh_parameters_rectify_get(rec_id,parameters));
2034 check( *crh_single_par = xsh_parameters_remove_crh_single_get(rec_id,parameters));
2035 if ( (*rectify_par)->rectify_full_slit == 1 ){
2036
2037 xsh_msg( "Use Full Slit" ) ;
2038 }
2039 else {
2040 xsh_msg( "Use Max Possible Slit" ) ;
2041 }
2042
2043 /*
2044 check( *opt_kappa = xsh_parameters_optimal_extract_get_kappa(rec_id,parameters));
2045 */
2046
2047 check(*extract_par=xsh_parameters_extract_get(rec_id, parameters )) ;
2048
2049 check(*combine_nod_param = xsh_parameters_combine_nod_get(rec_id,parameters )) ;
2050
2051
2052 check( *gen_sky = xsh_parameters_get_boolean( parameters, rec_id,
2053 "gen-sky"));
2054
2055 if (xsh_parameters_find(parameters, rec_id, "generate-SDP-format") != NULL) {
2056 check( *generate_sdp_format = xsh_parameters_get_boolean(parameters, rec_id,
2057 "generate-SDP-format"));
2058 }
2059
2060 cleanup:
2061 return cpl_error_get_code();
2062
2063}
2064
2065/*---------------------------------------------------------------------------*/
2066
2098cpl_error_code
2100 xsh_remove_crh_single_param* crh_single_par,
2101 xsh_rectify_param* rectify_par,
2102 int do_sub_sky,
2103 const char* rec_prefix,
2104 cpl_frame* rmbkg,
2105 cpl_frame* order_tab_edges,
2106 cpl_frame* slitmap,
2107 cpl_frame* wavemap,
2108 cpl_frame* sky_map,
2109 cpl_frame* model_config,
2110 cpl_frame* single_frame_sky_sub_tab,
2112 int sub_sky_nbkpts1,
2114 cpl_frame* ref_sky_list,
2115 cpl_frame* sky_orders_chunks,
2116 cpl_frame** sky,
2117 cpl_frame** sky_eso,
2118 cpl_frame** sky_ima,
2119 cpl_frame* wave_tab,
2120 cpl_frame* disp_tab,
2121 cpl_frame* spectral_format,
2122 int nb_raw_frames,
2123 cpl_frame** loc_table,
2124 cpl_frame** clean,
2125 cpl_frame** clean_obj,const int clean_tmp)
2126{
2127
2128 char sky_tag[256];
2129 char sky_name[256];
2130 char rec_name[256];
2131 cpl_frame * sub_sky = NULL ;
2132 cpl_frame * rect = NULL ;
2134 if( (loc_obj_par->method != LOC_MANUAL_METHOD) ){
2135 // || (nb_raw_frames == 1 && crh_single_par->nb_iter > 0)){
2136
2137 xsh_msg("Preliminary sky subtraction for CRH single or automatic localization");
2138 xsh_msg("Sky will be put back later");
2139
2140 sprintf(sky_tag,"%s_TMPSKY",rec_prefix);
2141 sprintf(sky_name,"%s.fits",sky_tag);
2142
2143 if(do_sub_sky) {
2144 /* TODO AMO: added frame for DEBUG */
2145 xsh_msg("rmbkg=%p",rmbkg);
2146 check(xsh_frame_image_save(rmbkg,"rmbkg.fits"));
2147 xsh_msg("instrument=%p",instrument);
2148 check( sub_sky = xsh_check_subtract_sky_single( CPL_TRUE, rmbkg,
2149 order_tab_edges, slitmap, wavemap, NULL,
2150 single_frame_sky_sub_tab, instrument, sub_sky_nbkpts1,
2151 sky_par,ref_sky_list, sky_orders_chunks,sky, sky_eso, sky_ima, sky_tag,clean_tmp));
2152 xsh_add_temporary_file(sky_name);
2153
2154 /* TODO AMO: added frame for DEBUG */
2155 xsh_frame_image_save(sub_sky,"sub_sky.fits");
2156 //exit(0);
2157
2158 } else {
2159 sub_sky = cpl_frame_duplicate(rmbkg);
2160 xsh_add_temporary_file(sky_name);
2161 }
2162
2163 if( loc_obj_par->method != LOC_MANUAL_METHOD){
2164 xsh_msg("Localize auto");
2165 sprintf(rec_name,"%s_%s_%s.fits",
2166 rec_prefix,XSH_ORDER2D,
2168
2169 check( rect = xsh_rectify( sub_sky, order_tab_edges,
2170 wave_tab, model_config,
2171 instrument, rectify_par,
2172 spectral_format, disp_tab,
2173 rec_name, NULL, NULL,rec_prefix));
2174
2175 check( *loc_table = xsh_localize_obj( rect, NULL, instrument,
2176 loc_obj_par, NULL, NULL));
2177 xsh_free_frame( &rect);
2178 }
2179 else{
2180 check( *loc_table = xsh_localize_obj( NULL, NULL,
2181 instrument, loc_obj_par, NULL, NULL));
2182 }
2183
2184 /* NB Remove COSMICS single temporarily dis-activated for Daniel
2185 check( *clean = xsh_check_remove_crh_single( nb_raw_frames, sub_sky,
2186 crh_single_par, instrument, rec_prefix));
2187 */
2188 *clean = cpl_frame_duplicate(sub_sky);
2189
2190 if(clean_tmp) {
2191 xsh_add_temporary_file(cpl_frame_get_filename(*clean));
2192 }
2193 if(do_sub_sky) {
2194 check( *clean_obj = xsh_add_sky_model( *clean, *sky_ima,
2195 instrument, rec_prefix));
2196 } else {
2197 *clean_obj=cpl_frame_duplicate(*clean);
2198 }
2199
2200 xsh_free_frame( &sub_sky);
2201 xsh_free_frame( sky);
2202 xsh_free_frame( sky_eso);
2203 xsh_free_frame( sky_ima);
2204 }
2205 else {
2206 /* LOcalize manual && no CRH SINGLE */
2207 check( *clean_obj=cpl_frame_duplicate(rmbkg));
2208 check( *loc_table = xsh_localize_obj( NULL, NULL,
2209 instrument, loc_obj_par, NULL, NULL));
2210 }
2211
2212 cleanup:
2213
2214 xsh_free_frame(&sub_sky) ;
2215 xsh_free_frame(&rect) ;
2216
2217 return cpl_error_get_code();
2218
2219}
2220
2221
2222cpl_error_code
2223xsh_slit_stare_get_maps(cpl_frameset* calib,
2224 int do_compute_map,int recipe_use_model,
2225 const char* rec_prefix,xsh_instrument* instrument,
2226 cpl_frame* model_config_frame,cpl_frame* crhm_frame,
2227 cpl_frame* disp_tab_frame, cpl_frame* order_tab_edges,
2228 cpl_frame** wavemap_frame, cpl_frame** slitmap_frame)
2229{
2230 char wave_map_tag[256];
2231 char slit_map_tag[256];
2232 int found_temp=1;
2233 if ( do_compute_map){
2234 if (recipe_use_model){
2235 sprintf(wave_map_tag,"%s_%s_%s",rec_prefix,XSH_WAVE_MAP_MODEL,
2237 sprintf(slit_map_tag,"%s_%s_%s",rec_prefix,XSH_SLIT_MAP_MODEL,
2239
2240 check(xsh_model_temperature_update_frame(&model_config_frame,crhm_frame,
2241 instrument,&found_temp));
2242
2243 check( xsh_create_model_map( model_config_frame, instrument,
2244 wave_map_tag,slit_map_tag,
2245 wavemap_frame, slitmap_frame,0));
2246 }
2247 else{
2248 xsh_msg("Compute the wave map and the slit map");
2249 check( xsh_create_map( disp_tab_frame, order_tab_edges,
2250 crhm_frame, instrument,
2251 wavemap_frame, slitmap_frame,
2252 rec_prefix));
2253 }
2254 }
2255 else {
2256 xsh_msg( "Get the wave map and the slit map from sof" ) ;
2257 check( *slitmap_frame = xsh_find_slitmap(calib, instrument));
2258 check( *wavemap_frame = xsh_find_wavemap(calib, instrument));
2259 }
2260
2261 cleanup:
2262 return cpl_error_get_code();
2263}
2264
2265
2266cpl_error_code
2267xsh_scired_util_spectra_flux_calibrate(cpl_frame* res2D,cpl_frame* res1D,
2268 cpl_frame* response,cpl_frame* atmext,
2269 xsh_instrument* inst,
2270 const char* prefix,
2271 cpl_frame** fluxcal_2D,
2272 cpl_frame** fluxcal_1D)
2273{
2274 char file_tag[40];
2275 cpl_frame* nrm_1D=NULL;
2276 cpl_frame* nrm_2D=NULL;
2277
2278 sprintf(file_tag,"%s_NORM2D_%s",prefix,xsh_instrument_arm_tostring(inst));
2279 check(nrm_2D=xsh_normalize_spectrum(res2D,atmext,0,inst,file_tag));
2280 sprintf(file_tag,"%s_FLUXCAL2D_%s",prefix,xsh_instrument_arm_tostring(inst));
2281 check(*fluxcal_2D=xsh_util_multiply_by_response(nrm_2D,response,file_tag));
2282 sprintf(file_tag,"%s_NORM1D_%s",prefix,xsh_instrument_arm_tostring(inst));
2283 check(nrm_1D=xsh_normalize_spectrum(res1D,atmext,0,inst,file_tag));
2284 sprintf(file_tag,"%s_FLUXCAL1D_%s",prefix,xsh_instrument_arm_tostring(inst));
2285 check(*fluxcal_1D=xsh_util_multiply_by_response(nrm_1D,response,file_tag));
2286
2287 cleanup:
2288 xsh_free_frame(&nrm_1D);
2289 xsh_free_frame(&nrm_2D);
2290
2291 return cpl_error_get_code();
2292
2293}
2294
2295
2296cpl_frame* xsh_compute_efficiency(cpl_frame* mer1D, cpl_frame* std_cat,
2297 cpl_frame* atm_ext, cpl_frame* high_abs_win,
2298 xsh_instrument* instr)
2299{
2300
2301 cpl_frame* eff=NULL;
2302
2303 if(NULL == (eff=xsh_efficiency_compute(mer1D,std_cat,atm_ext,high_abs_win,instr))) {
2304 xsh_msg_error("An error occurred during efficiency computation");
2305 xsh_msg_error("The recipe recovers without efficiency product generation");
2306 cpl_error_reset();
2307 } else {
2308 check(xsh_frame_table_monitor_flux_qc(eff,"WAVELENGTH","EFF","EFF",instr));
2309 }
2310
2311 cleanup:
2312 return eff;
2313}
2314
2315static cpl_error_code
2316xsh_get_central_xy(cpl_frame* order_tab_edges,xsh_instrument* instrument, int* xcen, int* ycen)
2317{
2318
2319 const char* name = NULL;
2320 cpl_table* tab = NULL;
2321 int ord_min = 0;
2322 int ord_max = 0;
2323 int ord_avg = 0;
2324 int next = 0;
2325 int status=0;
2326
2327 cpl_table* ext = NULL;
2328
2329 XSH_ASSURE_NOT_NULL_MSG(order_tab_edges,"Null input order tab edges");
2330
2331 name = cpl_frame_get_filename(order_tab_edges);
2332 tab = cpl_table_load(name, 2, 0);
2333
2334 ord_min = cpl_table_get_column_min(tab, "ORDER");
2335 ord_max = cpl_table_get_column_max(tab, "ORDER");
2336 ord_avg = 0.5 * (ord_min + ord_max);
2337
2338 next = cpl_table_and_selected_int(tab, "ORDER", CPL_EQUAL_TO, ord_avg);
2339 ext = cpl_table_extract_selected(tab);
2340 xsh_free_table(&tab);
2341
2342 *xcen = (int) cpl_table_get_double(ext, "CENTER_X", next / 2, &status);
2343 *xcen /= instrument->binx;
2344
2345 *ycen = (int) cpl_table_get_double(ext, "CENTER_Y", next / 2, &status);
2346 *ycen /= instrument->biny;
2347
2348 cleanup:
2349 xsh_free_table(&tab);
2350 xsh_free_table(&ext);
2351 return cpl_error_get_code();
2352}
2353
2354static cpl_error_code xsh_frame_image_get_step(cpl_frame* frm_ima,
2355 const int xcen, const int ycen, const int direction, double* dif) {
2356
2357 int xmin = 0;
2358 int xmax = 0;
2359
2360 int ymin = 0;
2361 int ymax = 0;
2362
2363 const char* name = NULL;
2364 cpl_image* map_ima = NULL;
2365 int nx = 0;
2366 double* map = NULL;
2367 double fmin=0;
2368 double fmax=0;
2369
2370 name = cpl_frame_get_filename(frm_ima);
2371 map_ima = cpl_image_load(name, CPL_TYPE_DOUBLE, 0, 0);
2372 nx = cpl_image_get_size_x(map_ima);
2373 map = cpl_image_get_data_double(map_ima);
2374
2375
2376 xmin = xcen - 1;
2377 xmax = xcen + 1;
2378
2379 ymin = ycen - 1;
2380 ymax = ycen + 1;
2381
2382
2383 if(1==direction) {
2384 ymin = ycen - 1;
2385 ymax = ycen + 1;
2386
2387 fmin = map[nx * ymin + xcen];
2388 fmax = map[nx * ymax + xcen];
2389 } else {
2390 xmin = xcen - 1;
2391 xmax = xcen + 1;
2392
2393 fmin = map[nx * ycen + xmin];
2394 fmax = map[nx * ycen + xmax];
2395 }
2396
2397 *dif = fabs(0.5 * (fmax - fmin));
2398
2399 xsh_free_image(&map_ima);
2400
2401 return cpl_error_get_code();
2402
2403}
2404
2405
2406static cpl_error_code xsh_plist_set_spat_accuracy(cpl_propertylist* header,
2407 const double srms, const double serr, const double sys_err) {
2408 cpl_propertylist_insert_after_double(header, XSH_CUNIT1,XSH_SPATRMS, srms);
2409 cpl_propertylist_set_comment(header, XSH_SPATRMS,
2411 cpl_propertylist_insert_after_double(header, XSH_SPATRMS, XSH_CRDER2, serr);
2412 cpl_propertylist_set_comment(header, XSH_CRDER2, XSH_CRDER2_C);
2413 cpl_propertylist_insert_after_double(header, XSH_CRDER2, XSH_CSYER2, sys_err);
2414 cpl_propertylist_set_comment(header, XSH_CSYER2, XSH_CSYER2_C);
2415 cpl_propertylist_insert_after_string(header, XSH_CSYER2, XSH_CUNIT2, "arcsec");
2416 cpl_propertylist_set_comment(header, XSH_CUNIT2, XSH_CUNIT2_C);
2417
2418 return cpl_error_get_code();
2419}
2420
2421static cpl_error_code xsh_plist_set_wave_accuracy(cpl_propertylist* header,
2422 const double wrms, const double werr, const double sys_err) {
2423
2424 if (wrms > 0) { /* Only write valid LAMRMS values. */
2425 cpl_propertylist_insert_after_double(header, XSH_LAMNLIN, XSH_LAMRMS, wrms);
2426 cpl_propertylist_set_comment(header, XSH_LAMRMS, XSH_LAMRMS_C);
2427 cpl_propertylist_insert_after_double(header, XSH_LAMRMS, XSH_CRDER1, werr);
2428 } else {
2429 cpl_propertylist_insert_after_double(header, XSH_LAMNLIN, XSH_CRDER1, werr);
2430 }
2431 cpl_propertylist_set_comment(header, XSH_CRDER1, XSH_CRDER1_C);
2432 cpl_propertylist_insert_after_double(header, XSH_CRDER1, XSH_CSYER1, sys_err);
2433 cpl_propertylist_set_comment(header, XSH_CSYER1, XSH_CSYER1_C);
2434 cpl_propertylist_insert_after_string(header, XSH_CSYER1, XSH_CUNIT1, "nm");
2435 cpl_propertylist_set_comment(header, XSH_CUNIT1, XSH_CUNIT1_C);
2436
2437 return cpl_error_get_code();
2438}
2439
2440double
2442{
2443 double csyer1=0.02;
2445 csyer1 = 0.03; /* nm */
2446 }
2448 csyer1 = 0.02; /* nm */
2449 }
2451 csyer1 = 0.004; /* nm */
2452 }
2453 return csyer1;
2454}
2455
2456double
2458{
2459 double csyer2=0.16;
2461 csyer2 = 0.17; /* arcsecs */
2462 }
2464 csyer2 = 0.16; /* arcsecs */
2465 }
2467 csyer2 = 0.25; /* arcsecs */
2468 }
2469 return csyer2;
2470}
2471
2472cpl_error_code
2474 cpl_frame* slitmap,
2475 cpl_frame* order_tab_edges,
2476 cpl_frame* model_config,
2477 cpl_frame* science,
2479
2480 cpl_propertylist* plist=NULL;
2481 const char* name=NULL;
2482 const char* tag=NULL;
2483
2484 double rms_x=0;
2485 double rms_y=0;
2486 cpl_table* tab=NULL;
2487 cpl_table* ext=NULL;
2488
2489 xsh_pre* pre=NULL;
2490
2491 int xcen=0;
2492 int ycen=0;
2493
2494 double wdif;
2495 double sdif;
2496
2497 cpl_image* wmap_ima=NULL;
2498 cpl_image* smap_ima=NULL;
2499 cpl_frame* frm_tmp=NULL;
2500 xsh_spectrum* s=NULL;
2501 cpl_image* ima=NULL;
2502 cpl_propertylist* phead=NULL;
2503 cpl_propertylist* xhead=NULL;
2504 cpl_image* xima=NULL;
2505
2506 double wrms=0;
2507 double srms=0;
2508 double werr=0;
2509 double serr=0;
2510 int nline=1;
2511 //int nbext=0;
2512 double csyer1=0;
2513 double csyer2=1; /* pix */
2514
2515 XSH_ASSURE_NOT_NULL_MSG(wavemap,"Null input wavemap");
2516 XSH_ASSURE_NOT_NULL_MSG(slitmap,"Null input wavemap");
2517 XSH_ASSURE_NOT_NULL_MSG(order_tab_edges,"Null input order tab edges");
2518 XSH_ASSURE_NOT_NULL_MSG(model_config,"Null input model config");
2519 XSH_ASSURE_NOT_NULL_MSG(science,"Null input sci frame");
2520 XSH_ASSURE_NOT_NULL_MSG(instrument,"Null input instrument structure");
2522 check(xsh_get_central_xy(order_tab_edges,instrument,&xcen, &ycen));
2523 check(xsh_frame_image_get_step(wavemap,xcen,ycen,1,&wdif));
2524 check(xsh_frame_image_get_step(slitmap,xcen,ycen,0,&sdif));
2525
2526
2527
2528 name=cpl_frame_get_filename(model_config);
2529 plist=cpl_propertylist_load(name,0);
2530 if(cpl_propertylist_has(plist,XSH_QC_MODEL_ANNEAL_RESX_RMS) ){
2531 check(rms_x=cpl_propertylist_get_double(plist,XSH_QC_MODEL_ANNEAL_RESX_RMS));
2532 } else {
2533 xsh_msg_warning("Key %s not found %s, %s will be set to 0",
2535 }
2536
2537 if(cpl_propertylist_has(plist,XSH_QC_MODEL_ANNEAL_RESY_RMS) ){
2538 check(rms_y=cpl_propertylist_get_double(plist,XSH_QC_MODEL_ANNEAL_RESY_RMS));
2539 } else {
2540 xsh_msg_warning("Key %s not found %s, %s will be set to 0",
2542 }
2543
2544 if(cpl_propertylist_has(plist,XSH_QC_MODEL_NDAT) ){
2545 nline=cpl_propertylist_get_int(plist,XSH_QC_MODEL_NDAT);
2546 }
2547 xsh_free_propertylist(&plist);
2548
2549 srms=rms_x*sdif;
2550 wrms=rms_y*wdif;
2551 serr=srms/sqrt(nline);
2552 werr=wrms/sqrt(nline);
2553 name=cpl_frame_get_filename(science);
2554 tag=cpl_frame_get_tag(science);
2555 //xsh_msg("process frame %s %s",name,tag);
2556 //xsh_msg("wdif=%g wrms=%g werr=%g sdif=%g srms=%g serr=%g",wdif,wrms,werr,sdif,srms,serr);
2557
2558 if(strstr(tag,"MERGE2D")!=NULL) {
2559 //xsh_msg("MERGE2D");
2560 check(s=xsh_spectrum_load(science));
2561
2562 cpl_propertylist_insert_after_int(s->flux_header,"DATE",XSH_LAMNLIN,nline);
2563 cpl_propertylist_set_comment(s->flux_header,XSH_LAMNLIN,XSH_LAMNLIN_C);
2565 check(xsh_plist_set_wave_accuracy(s->flux_header,wrms,werr,csyer1));
2566 check(xsh_plist_set_spat_accuracy(s->flux_header,srms,serr,csyer2));
2567
2568
2569 frm_tmp=xsh_spectrum_save(s,name,tag);
2570
2571 } else if(strstr(tag,"ORDER2D")!=NULL) {
2572
2573 //xsh_msg("ORDER2D");
2574
2575
2576 int nbext=0;
2577 int i=0;
2578 char cmd[256];
2579 const char *tname = "tmp_ima.fits";
2580
2581
2582 nbext = cpl_frame_get_nextensions( science);
2583 check(phead = cpl_propertylist_load( name, 0 ));
2584 ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
2585
2586 sprintf(cmd,"mv %s %s",name,tname);
2587 system(cmd);
2588 xsh_add_temporary_file("tmp_ima.fits");
2589
2590 cpl_propertylist_insert_after_int(phead,"DATE",XSH_LAMNLIN,nline);
2591 cpl_propertylist_set_comment(phead,XSH_LAMNLIN,XSH_LAMNLIN_C);
2593 check(xsh_plist_set_wave_accuracy(phead,wrms,werr,csyer1));
2594 check(xsh_plist_set_spat_accuracy(phead,srms,serr,csyer2));
2595
2596
2597 check(cpl_image_save(ima, name, CPL_BPP_IEEE_FLOAT,
2598 phead,CPL_IO_DEFAULT));
2599 for( i = 0 ; i<=nbext ; i++ ) {
2600 int extension ;
2601 xsh_free_image( &xima) ;
2602 xsh_free_propertylist( &xhead) ;
2603 check(xima = cpl_image_load( tname, CPL_TYPE_FLOAT, 0,i ));
2604 check(xhead = cpl_propertylist_load( tname ,i));
2605 if ( i == 0 ) {
2606 extension = CPL_IO_DEFAULT ;
2607 check(cpl_image_save(xima, name, CPL_BPP_IEEE_FLOAT,
2608 phead,extension));
2609 }
2610 else {
2611 extension = CPL_IO_EXTEND ;
2612 check(cpl_image_save(xima, name, CPL_BPP_IEEE_FLOAT,xhead,extension));
2613 }
2614 }
2615 sprintf(cmd,"rm tmp_ima.fits");
2616 system(cmd);
2617 }
2618 //xsh_msg("processed frame %s",tag);
2619
2620 cleanup:
2621
2622 xsh_free_image( &xima) ;
2623 xsh_free_image( &ima) ;
2624 xsh_free_propertylist( &xhead) ;
2625 xsh_free_propertylist( &phead) ;
2626 xsh_free_frame(&frm_tmp);
2627 xsh_pre_free(&pre);
2628 xsh_free_table(&tab);
2629 xsh_free_table(&ext);
2630 xsh_free_image(&wmap_ima);
2631 xsh_free_image(&smap_ima);
2632 xsh_free_propertylist(&plist);
2634
2635 return cpl_error_get_code();
2636
2637}
2638
2639
2640cpl_error_code
2642 cpl_frame* order_tab_edges,
2643 cpl_frame* model_config,
2644 cpl_frame* science,
2646
2647 cpl_propertylist* plist=NULL;
2648 cpl_frame* frm_tmp=NULL;
2649 const char* name=NULL;
2650 const char* tag=NULL;
2651
2652 double rms_y=0;
2653 cpl_table* tab=NULL;
2654 cpl_table* ext=NULL;
2655
2656 xsh_pre* pre=NULL;
2657 //xsh_rec_list * rec_list = NULL ;
2658 int xcen=0;
2659 int ycen=0;
2660
2661 double wdif;
2662
2663 cpl_image* wmap_ima=NULL;
2664 xsh_spectrum* s=NULL;
2665 cpl_vector* vec=NULL;
2666 double wrms=0;
2667 double werr=0;
2668 int nline=1;
2669 cpl_propertylist* xhead=NULL;
2670 cpl_vector* xvec=NULL;
2671 cpl_table* xtab=NULL;
2672 cpl_propertylist* phead=NULL;
2673 double csyer1=0;
2674
2675 XSH_ASSURE_NOT_NULL_MSG(wavemap,"Null input wavemap");
2676 XSH_ASSURE_NOT_NULL_MSG(order_tab_edges,"Null input order tab edges");
2677 XSH_ASSURE_NOT_NULL_MSG(model_config,"Null input model config");
2678 XSH_ASSURE_NOT_NULL_MSG(science,"Null input sci frame");
2679 XSH_ASSURE_NOT_NULL_MSG(instrument,"Null input instrument structure");
2680
2682
2683 check(xsh_get_central_xy(order_tab_edges,instrument,&xcen, &ycen));
2684 check(xsh_frame_image_get_step(wavemap,xcen,ycen,1,&wdif));
2685
2686 name=cpl_frame_get_filename(model_config);
2687 plist=cpl_propertylist_load(name,0);
2688
2689 if (cpl_propertylist_has(plist, XSH_QC_MODEL_ANNEAL_RESY_RMS)) {
2690 check(
2691 rms_y = cpl_propertylist_get_double(plist,
2693 } else {
2694 xsh_msg_warning("Key %s not found %s, %s will be set to 0",
2696 }
2697
2698 if(cpl_propertylist_has(plist,XSH_QC_MODEL_NDAT) ){
2699 nline=cpl_propertylist_get_int(plist,XSH_QC_MODEL_NDAT);
2700 }
2701 xsh_free_propertylist(&plist);
2702
2703 wrms=rms_y*wdif;
2704 werr=wrms/sqrt(nline);
2705 name=cpl_frame_get_filename(science);
2706 tag=cpl_frame_get_tag(science);
2707
2708 xsh_msg("process frame %s %s",name,tag);
2709 if(strstr(tag,"MERGE1D")!=NULL) {
2710 xsh_msg("MERGE1D");
2711 check(s=xsh_spectrum_load(science));
2712 cpl_propertylist_insert_after_int(s->flux_header,"DATE",XSH_LAMNLIN,nline);
2713 cpl_propertylist_set_comment(s->flux_header,XSH_LAMNLIN,XSH_LAMNLIN_C);
2714 check(xsh_plist_set_wave_accuracy(s->flux_header,wrms,werr,csyer1));
2715
2716
2717 frm_tmp=xsh_spectrum_save(s,name,tag);
2718
2719 } else if( strstr(tag,"ORDER1D")!=NULL ) {
2720 xsh_msg("ORDER1D");
2721 int nbext=0;
2722 int i=0;
2723 char cmd[256];
2724 const char *tname = "tmp_ima.fits";
2725 nbext = cpl_frame_get_nextensions( science);
2726 check(phead = cpl_propertylist_load( name, 0 ));
2727 //ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
2728 vec=cpl_vector_load(name,0);
2729
2730 sprintf(cmd,"mv %s %s",name,tname);
2731 system(cmd);
2732 xsh_add_temporary_file("tmp_ima.fits");
2733 cpl_propertylist_insert_after_int(phead,"DATE",XSH_LAMNLIN,nline);
2734 cpl_propertylist_set_comment(phead,XSH_LAMNLIN,XSH_LAMNLIN_C);
2735 check(xsh_plist_set_wave_accuracy(phead,wrms,werr,csyer1));
2736
2737 check(cpl_vector_save(vec, name, CPL_BPP_IEEE_FLOAT,
2738 phead,CPL_IO_DEFAULT));
2739 for( i = 0 ; i<=nbext ; i++ ) {
2740 int extension ;
2741 xsh_free_vector( &xvec) ;
2742 xsh_free_propertylist( &xhead) ;
2743 check(xvec = cpl_vector_load( tname,i ));
2744 check(xhead = cpl_propertylist_load( tname ,i));
2745 if ( i == 0 ) {
2746 extension = CPL_IO_DEFAULT ;
2747 check(cpl_vector_save(xvec, name, CPL_BPP_IEEE_FLOAT,
2748 phead,extension));
2749 }
2750 else {
2751 extension = CPL_IO_EXTEND ;
2752 check(cpl_vector_save(xvec, name, CPL_BPP_IEEE_FLOAT,xhead,extension));
2753 }
2754 }
2755 sprintf(cmd,"rm tmp_ima.fits");
2756 system(cmd);
2757
2758 } else if(strstr(tag,"SKY_ORD1D")!=NULL) {
2759 xsh_msg("SKY_ORD1D");
2760
2761 int nbext=0;
2762 int i=0;
2763 char cmd[256];
2764 const char *tname = "tmp_tab.fits";
2765 nbext = cpl_frame_get_nextensions( science);
2766 check(phead = cpl_propertylist_load( name, 0 ));
2767 xsh_msg("name=%s",name);
2768 check(tab=cpl_table_load(name,1,0));
2769
2770 sprintf(cmd,"mv %s %s",name,tname);
2771 system(cmd);
2773 cpl_propertylist_insert_after_int(phead,"DATE",XSH_LAMNLIN,nline);
2774 cpl_propertylist_set_comment(phead,XSH_LAMNLIN,XSH_LAMNLIN_C);
2775 check(xsh_plist_set_wave_accuracy(phead,wrms,werr,csyer1));
2776
2777 check(cpl_table_save(tab, phead, NULL, name, CPL_IO_DEFAULT));
2778 for( i = 0 ; i<=nbext ; i++ ) {
2779 int extension ;
2780 xsh_free_table( &xtab) ;
2781 xsh_free_propertylist( &xhead) ;
2782 check(xtab = cpl_table_load( tname,1, i ));
2783 check(xhead = cpl_propertylist_load( tname ,i));
2784 if ( i == 0 ) {
2785 extension = CPL_IO_DEFAULT ;
2786 check(cpl_table_save(xtab, phead, NULL, name, extension));
2787 }
2788 else {
2789 extension = CPL_IO_EXTEND ;
2790 check(cpl_table_save(xtab, phead, NULL, name, extension));
2791
2792 }
2793 }
2794 sprintf(cmd,"rm tmp_tab.fits");
2795 system(cmd);
2796
2797 }
2798 xsh_msg("processed frame %s",tag);
2799 cleanup:
2800 xsh_free_frame(&frm_tmp);
2801 xsh_free_propertylist( &phead) ;
2802 xsh_free_propertylist( &xhead) ;
2803 xsh_free_vector( &xvec) ;
2804 xsh_free_vector( &vec) ;
2805 xsh_pre_free(&pre);
2806 xsh_free_table(&tab);
2807 xsh_free_table(&ext);
2808 xsh_free_image(&wmap_ima);
2809 xsh_free_propertylist(&plist);
2812 return cpl_error_get_code();
2813
2814}
2815
2816
2817/*****************************************************************************/
2831/*****************************************************************************/
2832cpl_frameset*
2833xsh_frameset_crh_single(cpl_frameset* raws,
2834 xsh_remove_crh_single_param * crh_single_par,
2835 cpl_frame* sky_map_frm,
2836 xsh_instrument* instrument,const char* prefix,const char* spec)
2837{
2838/* remove crh on frame */
2839 cpl_frameset* clean=NULL;
2840 cpl_frame* frm=NULL;
2841 int nraws=0;
2842 int i=0;
2843 char ftag[256];
2844 char fname[256];
2845 char arm_str[16] ;
2846 cpl_frame * rm_crh = NULL ;
2847 cpl_image * sky_map_ima = NULL;
2848 cpl_mask * sky_map_msk = NULL;
2849 //cpl_frameset_dump(raws,stdout);
2850
2851 if( sky_map_frm != NULL ) {
2852 sky_map_ima = cpl_image_load(cpl_frame_get_filename(sky_map_frm),CPL_TYPE_FLOAT,0,0);
2853 sky_map_msk=cpl_mask_threshold_image_create(sky_map_ima,0.1,1.1);
2854 }
2855 sprintf( arm_str, "%s", xsh_instrument_arm_tostring(instrument) ) ;
2856 nraws=cpl_frameset_get_size(raws);
2857 check( clean = cpl_frameset_new() ) ;
2858 /* AMO: Don't do CRH single on a raw frame, need to be done on a sky corrected one */
2859 if ( crh_single_par->nb_iter > 0 ) {
2860 xsh_msg( "Detect crh (single frame) as removecrhsingle_niter %d > 0", crh_single_par->nb_iter ) ;
2861 for ( i = 0 ; i < nraws ; i++ ) {
2862
2863 frm = cpl_frameset_get_frame( raws, i ) ;
2864 sprintf(ftag,"%s_%s_NO_CRH_%s_%d",prefix,spec,arm_str,i) ;
2865 sprintf(fname,"%s.fits",ftag) ;
2866
2867 rm_crh = xsh_remove_crh_single( frm,instrument,sky_map_msk,crh_single_par,ftag ) ;
2869 cpl_frameset_insert( clean, rm_crh ) ;
2870 }
2871 } else {
2872 xsh_msg_warning( "Skip Remove crh (single frame) on not sky corrected frame" ) ;
2873 cpl_frameset_delete(clean);
2874 clean=cpl_frameset_duplicate(raws);
2875 }
2876 if( sky_map_frm != NULL ) {
2877 xsh_free_image(&sky_map_ima);
2878 xsh_free_mask(&sky_map_msk);
2879 }
2880cleanup:
2881 return clean;
2882}
2883
2884
2885/*****************************************************************************/
2900/*****************************************************************************/
2901cpl_frameset*
2902xsh_frameset_mflat_divide(cpl_frameset* input, cpl_frame* mflat,
2904
2905 int nraw = 0;
2906 int i = 0;
2907
2908 cpl_frame * divided = NULL;
2909 cpl_frame * frm = NULL;
2910 char arm_str[16] ;
2911 char ftag[256];
2912 char fname[256];
2913
2914 cpl_frameset* output = NULL;
2915
2916 xsh_msg("apply flat field");
2917
2918 nraw = cpl_frameset_get_size(input);
2919 output = cpl_frameset_new();
2920 sprintf( arm_str, "%s", xsh_instrument_arm_tostring(instrument) ) ;
2921 for (i = 0; i < nraw; i++) {
2922 frm = cpl_frameset_get_frame(input, i);
2923
2924 sprintf(ftag, "FF_%d_SLIT_OFFSET_%s", i,arm_str);
2925 sprintf(fname, "%s.fits", ftag);
2926
2927 /* the following function creates a new frame: output is a new frameset.
2928 * For this reason there is no need to duplicate the frame when we insert
2929 * it in the output frameset. In the end we need to remember to cleanup
2930 * the output frameset.
2931 */
2932 divided = xsh_divide_flat( frm,mflat, ftag, instrument );
2934 cpl_frameset_insert(output, divided );
2935
2936 }
2937
2938 return output;
2939}
2940
static xsh_instrument * instrument
int binx
int biny
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
Definition: xsh_data_pre.c:849
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
xsh_rec_list * xsh_rec_list_load(cpl_frame *frame, xsh_instrument *instrument)
load an rec list from a frame
Definition: xsh_data_rec.c:289
float * xsh_rec_list_get_data1(xsh_rec_list *list, int idx)
cpl_frame * xsh_rec_list_save(xsh_rec_list *list, const char *filename, const char *tag, int is_temp)
Save a rec list in a frame.
cpl_frame * xsh_rec_list_frame_invert(cpl_frame *rec_frame, const char *tag, xsh_instrument *instrument)
Invert the rectified flux images of the input frame into a new frame.
Definition: xsh_data_rec.c:713
void xsh_rec_list_free(xsh_rec_list **list)
free memory associated to a rec_list
Definition: xsh_data_rec.c:760
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
cpl_frame * xsh_spectrum_save(xsh_spectrum *s, const char *filename, const char *tag)
save a spectrum
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
cpl_frame * xsh_divide_flat(cpl_frame *frame, cpl_frame *flat, const char *tag, xsh_instrument *instr)
divide PRE frame with the master FLAT frame
Definition: xsh_divide.c:75
#define XSH_ASSURE_NOT_NULL_MSG(pointer, msg)
Definition: xsh_error.h:103
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_reset()
Definition: xsh_error.h:87
#define xsh_error_msg(...)
Definition: xsh_error.h:94
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
void xsh_instrument_update_from_spectralformat(xsh_instrument *i, cpl_frame *spectralformat_frame)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
cpl_frame * xsh_localize_obj(cpl_frame *sci_frame, cpl_frame *skymask_frame, xsh_instrument *instrument, xsh_localize_obj_param *loc_obj_par, xsh_slit_limit_param *slit_limit_param, const char *fname)
Build the localization table.
cpl_frame * xsh_merge_ord(cpl_frame *sci_frame, xsh_instrument *instrument, int merge, const char *rec_prefix)
Merge orders of the rectified frame using merge parameters.
static SimAnneal s
Definition: xsh_model_sa.c:99
#define xsh_msg_warning(...)
Print an warning message.
Definition: xsh_msg.h:88
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define xsh_msg_dbg_low(...)
Definition: xsh_msg.h:48
#define xsh_msg_dbg_high(...)
Definition: xsh_msg.h:40
double xsh_pfits_get_ra_cumoffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3585
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
Definition: xsh_pfits.c:289
double xsh_pfits_get_dec_cumoffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3600
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
Definition: xsh_pfits.c:306
double xsh_pfits_get_dec_reloffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3543
double xsh_pfits_get_ra_reloffset(const cpl_propertylist *plist)
Definition: xsh_pfits.c:3528
cpl_frame * xsh_rectify_and_shift(cpl_frame *sci_frame, cpl_frame *orderlist_frame, cpl_frame *wavesol_frame, cpl_frame *model_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, cpl_frame *spectralformat_frame, cpl_frame *loc_frame, cpl_frame *loc0_frame, double *throw_shift, cpl_frame *disp_tab_frame, const char *res_name, cpl_frame **res_frame_ext, cpl_frame **res_frame_tab)
Definition: xsh_rectify.c:928
cpl_frame * shift_with_kw(cpl_frame *rec_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, const char *fname, cpl_frame **res_frame_ext, double **ref_ra, double **ref_dec, int flag)
This function creates a structure containing for each order the shift to be applied.
Definition: xsh_rectify.c:1974
cpl_frame * xsh_rectify(cpl_frame *sci_frame, cpl_frame *order_table_frame, cpl_frame *wavesol_frame, cpl_frame *model_config_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, cpl_frame *spectral_format, cpl_frame *disp_tab_frame, const char *fname, cpl_frame **res_frame_ext, cpl_frame **res_frame_tab, const char *prefix)
Create a grid in wavelength with the step in lambda and slit. Steps are defined in the parameters....
Definition: xsh_rectify.c:867
cpl_frame * xsh_remove_crh_multiple(cpl_frameset *rawFrames, const char *name, xsh_stack_param *stack_param, xsh_clipping_param *crh_clipping, xsh_instrument *inst, cpl_imagelist **, cpl_image **, const int save_tmp)
cpl_frame * xsh_remove_crh_single(cpl_frame *sci_frame, xsh_instrument *instrument, cpl_mask *sky_map, xsh_remove_crh_single_param *single_par, const char *name)
Remove cosmic rays from a single frame.
cpl_frame * xsh_add_sky_model(cpl_frame *sub_sky_frame, cpl_frame *sky_frame, xsh_instrument *instrument, const char *rec_prefix)
cpl_frame * xsh_normalize_spectrum(const cpl_frame *obj_frame, const cpl_frame *atm_ext_frame, cpl_boolean correct_binning, xsh_instrument *instrument, const char *tag_o)
Normalize a spectrum.
Definition: xsh_utils.c:5807
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
Definition: xsh_utils.c:2284
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
cpl_frame * xsh_normalize_spectrum_ord(const cpl_frame *obj_frame, const cpl_frame *atm_ext_frame, cpl_boolean correct_binning, xsh_instrument *instrument, const char *tag_o)
Normalize a spectrum.
Definition: xsh_utils.c:5893
cpl_frame * xsh_util_multiply_by_response_ord(cpl_frame *extracted_sci, cpl_frame *response, const char *tag_o)
Multiply input frame by response frame.
Definition: xsh_utils.c:5016
void xsh_free_mask(cpl_mask **m)
Deallocate an image mask and set the pointer to NULL.
Definition: xsh_utils.c:2149
void xsh_frame_image_save(cpl_frame *frm, const char *name_o)
save an image frame
Definition: xsh_utils.c:3983
cpl_frame * xsh_util_multiply_by_response(cpl_frame *merged_sci, cpl_frame *response, const char *tag_o)
Multiply input frame by response frame.
Definition: xsh_utils.c:4798
cpl_error_code xsh_frame_table_monitor_flux_qc(cpl_frame *frm, const char *colw, const char *colf, const char *prefix, xsh_instrument *instrument)
Computes statistics on spectrum for QC.
cpl_error_code xsh_rectify_params_set_defaults(cpl_parameterlist *pars, const char *rec_id, xsh_instrument *inst, xsh_rectify_param *rectify_par)
Definition: xsh_utils.c:6681
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
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
Definition: xsh_utils.c:1432
enum localize_method method
xsh_rec * list
Definition: xsh_data_rec.h:87
int nslit
Definition: xsh_data_rec.h:65
int nlambda
Definition: xsh_data_rec.h:64
void xsh_create_map(cpl_frame *dispsol_frame, cpl_frame *ordertab_frame, cpl_frame *pre_frame, xsh_instrument *instrument, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const char *rec_prefix)
void xsh_create_model_map(cpl_frame *model_frame, xsh_instrument *instrument, const char *wtag, const char *stag, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const int save_tmp)
@ XSH_ARM_UVB
@ XSH_ARM_NIR
@ XSH_ARM_VIS
int nx
cpl_frame * xsh_find_wavemap(cpl_frameset *frames, xsh_instrument *instr)
Find Wave Map frame. The frame returned should not be free by the caller.
Definition: xsh_dfs.c:3983
cpl_frame * xsh_find_master_dark(cpl_frameset *frames, xsh_instrument *instr)
Find master dark frame.
Definition: xsh_dfs.c:3404
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
Definition: xsh_dfs.c:4318
cpl_frame * xsh_find_disp_tab(cpl_frameset *frames, xsh_instrument *instr)
Find Dispersol tab frame. The frame returned should not be free by the caller.
Definition: xsh_dfs.c:4066
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
Definition: xsh_dfs.c:3595
cpl_frame * xsh_find_master_bias(cpl_frameset *frames, xsh_instrument *instr)
Find master bias frame.
Definition: xsh_dfs.c:3319
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
Definition: xsh_dfs.c:877
cpl_boolean xsh_mode_is_physmod(cpl_frameset *set, xsh_instrument *instrument)
Definition: xsh_dfs.c:4411
cpl_frame * xsh_find_slitmap(cpl_frameset *frames, xsh_instrument *instr)
Find a slit map.
Definition: xsh_dfs.c:3673
cpl_frame * xsh_find_wave_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D or a wave tab ARC.
Definition: xsh_dfs.c:3699
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
cpl_frame * xsh_find_master_flat(cpl_frameset *frames, xsh_instrument *instr)
Find master flat frame.
Definition: xsh_dfs.c:3426
#define XSH_NORM_ORDER2D
Definition: xsh_dfs.h:986
#define XSH_MOD_CFG_OPT_AFC
Definition: xsh_dfs.h:1256
#define XSH_WAVE_MAP
Definition: xsh_dfs.h:928
#define XSH_MASTER_FLAT
Definition: xsh_dfs.h:569
#define XSH_MOD_CFG_OPT_2D
Definition: xsh_dfs.h:1233
#define XSH_NORM_ORDER1D
Definition: xsh_dfs.h:981
#define XSH_MASTER_DARK
Definition: xsh_dfs.h:550
#define XSH_ORDER2D
Definition: xsh_dfs.h:588
#define XSH_MOD_CFG_TAB
Definition: xsh_dfs.h:1251
#define XSH_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_NORM_OXT1D
Definition: xsh_dfs.h:975
#define XSH_FLUX_ORDER2D
Definition: xsh_dfs.h:1014
#define XSH_WAVE_TAB_AFC
Definition: xsh_dfs.h:557
#define XSH_SLIT_MAP_MODEL
Definition: xsh_dfs.h:146
#define XSH_ORDER_TAB_EDGES_IFU
Definition: xsh_dfs.h:703
#define XSH_SKY_SUB_BKPTS
Definition: xsh_dfs.h:251
#define XSH_RESPONSE_MERGE1D_SLIT
Definition: xsh_dfs.h:1149
#define XSH_WAVE_MAP_MODEL
Definition: xsh_dfs.h:923
#define XSH_SLIT_MAP
Definition: xsh_dfs.h:907
#define XSH_SKY_ORDERS_CHUNKS
Definition: xsh_dfs.h:256
#define XSH_MRESPONSE_MERGE1D_SLIT
Definition: xsh_dfs.h:1159
#define XSH_SKY_LINE_LIST
Definition: xsh_dfs.h:944
#define XSH_IFU_CFG_COR
Definition: xsh_dfs.h:53
#define XSH_IFU_CFG_TAB
Definition: xsh_dfs.h:48
#define XSH_WAVE_TAB_2D
Definition: xsh_dfs.h:556
#define XSH_ORDER_OXT1D
Definition: xsh_dfs.h:1034
#define XSH_MASTER_FLAT_SLIT
Definition: xsh_dfs.h:869
#define XSH_FLUX_ORDER1D
Definition: xsh_dfs.h:1003
#define XSH_FLUX_OXT1D
Definition: xsh_dfs.h:1009
#define XSH_GET_TAG_FROM_MODE(TAG, instr)
Definition: xsh_dfs.h:1594
cpl_frame * xsh_check_subtract_sky_single(int do_subsky, cpl_frame *src_frame, cpl_frame *ordertabedges_frame, cpl_frame *slitmap_frame, cpl_frame *wavemap_frame, cpl_frame *loctab_frame, cpl_frame *definedbreakpoints_frame, xsh_instrument *instrument, int nbkpts, xsh_subtract_sky_single_param *sky_par, cpl_frame *ref_sky_list, cpl_frame *sky_orders_chunks, cpl_frame **sky_spectrum, cpl_frame **sky_spectrum_eso, cpl_frame **sky_img, const char *prefix, const int clean_tmp)
Check function sky subtraction on single frame.
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
Definition: xsh_drl_check.c:51
void xsh_check_get_map(cpl_frame *disp_tab_frame, cpl_frame *order_tab_edges, cpl_frame *crhm_frame, cpl_frame *model_config_frame, cpl_frameset *calib, xsh_instrument *instrument, int do_computemap, int recipe_use_model, const char *rec_prefix, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame)
Check function to get wave and slit maps.
DOUBLE vec[4]
cpl_error_code xsh_model_temperature_update_frame(cpl_frame **model_config_frame, cpl_frame *ref_frame, xsh_instrument *instrument, int *found_temp)
cpl_frame * xsh_util_physmod_model_THE_create(cpl_frame *config_frame, xsh_instrument *instrument, cpl_frame *wave_list, const int binx, const int biny, const int num_ph, const int sky)
int xsh_parameters_rectify_fast_get(const char *recipe_id, cpl_parameterlist *list)
cpl_parameter * xsh_parameters_find(cpl_parameterlist *list, const char *recipe_id, const char *name)
find a parameter
int xsh_parameters_get_boolean(const cpl_parameterlist *list, const char *recipe_id, const char *name)
xsh_slit_limit_param * xsh_parameters_slit_limit_get(const char *recipe_id, cpl_parameterlist *list)
xsh_localize_obj_param * xsh_parameters_localize_obj_get(const char *recipe_id, cpl_parameterlist *list)
int xsh_parameters_subtract_sky_single_get_second(const char *recipe_id, cpl_parameterlist *list)
xsh_extract_param * xsh_parameters_extract_get(const char *recipe_id, cpl_parameterlist *list)
xsh_opt_extract_param * xsh_parameters_opt_extract_get(const char *recipe_id, cpl_parameterlist *list)
Get the optimal extraction parameters in a parameters list.
xsh_rectify_param * xsh_parameters_rectify_get(const char *recipe_id, cpl_parameterlist *list)
xsh_remove_crh_single_param * xsh_parameters_remove_crh_single_get(const char *recipe_id, cpl_parameterlist *list)
int xsh_parameters_get_int(const cpl_parameterlist *list, const char *recipe_id, const char *name)
xsh_combine_nod_param * xsh_parameters_combine_nod_get(const char *recipe_id, cpl_parameterlist *list)
get the combine nod parameters in a parameters list
xsh_subtract_sky_single_param * xsh_parameters_subtract_sky_single_get(const char *recipe_id, cpl_parameterlist *list)
int xsh_parameters_subtract_sky_single_get_first(const char *recipe_id, cpl_parameterlist *list)
xsh_background_param * xsh_parameters_background_get(const char *recipe_id, cpl_parameterlist *list)
get the background parameters in a parameters list
@ LOC_MANUAL_METHOD
#define XSH_CUNIT1
Definition: xsh_pfits.h:109
#define XSH_CUNIT2
Definition: xsh_pfits.h:110
#define XSH_CSYER2_C
#define XSH_QC_MODEL_ANNEAL_RESY_RMS
#define XSH_CSYER1_C
#define XSH_SPATRMS
#define XSH_CRDER2
#define XSH_LAMNLIN
#define XSH_LAMRMS_C
#define XSH_CRDER1
#define XSH_SPATRMS_C
#define XSH_CRDER2_C
#define XSH_CUNIT1_C
#define XSH_CSYER2
#define XSH_QC_MODEL_NDAT
#define XSH_CSYER1
#define XSH_QC_MODEL_ANNEAL_RESX_RMS
#define XSH_CUNIT2_C
#define XSH_LAMRMS
#define XSH_CRDER1_C
#define XSH_LAMNLIN_C
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
cpl_frame * xsh_efficiency_compute(cpl_frame *frm_sci, cpl_frame *frm_cat, cpl_frame *frm_atmext, cpl_frame *high_abs_win, xsh_instrument *instrument)
computes efficiency
cpl_error_code xsh_scired_slit_nod_get_calibs(cpl_frameset *raws, cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **bpmap, cpl_frame **master_bias, cpl_frame **master_flat, cpl_frame **order_tab_edges, cpl_frame **wave_tab, cpl_frame **model_config_frame, cpl_frame **wavemap, cpl_frame **slitmap, cpl_frame **disp_tab_frame, cpl_frame **spectral_format, cpl_frame **skymask_frame, cpl_frame **response_ord_frame, cpl_frame **frm_atmext, int do_computemap, int use_skymask, int pscan, const char *rec_prefix, const char *recipe_id)
double xsh_get_systematic_spatial_accuracy(xsh_instrument *instrument)
static cpl_error_code xsh_plist_set_wave_accuracy(cpl_propertylist *header, const double wrms, const double werr, const double sys_err)
cpl_frameset * xsh_nod_group_by_reloff(cpl_frameset *ord_set, xsh_instrument *instrument, xsh_stack_param *stack_par)
cpl_error_code xsh_slit_offset_get_params(cpl_parameterlist *parameters, const char *rec_id, xsh_localize_obj_param **loc_obj_par, xsh_rectify_param **rectify_par, xsh_remove_crh_single_param **crh_single_par, xsh_extract_param **extract_par, xsh_combine_nod_param **combine_nod_param, int *do_flatfield, int *gen_sky, int *generate_sdp_format)
cpl_error_code xsh_get_calibs_to_flux_calibrate(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **response_ord_frame, cpl_frame **frm_atmext)
static cpl_frame * xsh_nod_median_correct_list_per_wavelength(cpl_frame *frame_i, xsh_instrument *inst)
static cpl_error_code xsh_get_central_xy(cpl_frame *order_tab_edges, xsh_instrument *instrument, int *xcen, int *ycen)
cpl_frameset * xsh_scired_slit_nod_accurate(cpl_frameset *nod_set, cpl_frame *spectral_format, cpl_frame *master_flat, cpl_frame *order_tab_edges, cpl_frame *wave_tab, cpl_frame *model_config_frame, cpl_frame *disp_tab_frame, cpl_frame *wavemap, cpl_frame *skymask_frame, xsh_instrument *instrument, xsh_remove_crh_single_param *crh_single_par, xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par, const char *throw_name, const int do_flatfield, const char *rec_prefix)
cpl_error_code xsh_get_slit_stare_calibs(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **sky_list, cpl_frame **model_cfg, cpl_frame **qc_sky, cpl_frame **sframe_sky_sub_tab, cpl_frame **sky_orders_chunks)
static cpl_error_code xsh_plist_set_spat_accuracy(cpl_propertylist *header, const double srms, const double serr, const double sys_err)
cpl_error_code xsh_stare_params_bin_scale(cpl_frameset *raws, xsh_background_param *backg, xsh_opt_extract_param *opt_extract_par, int *sub_sky_nbkpts1, int *sub_sky_nbkpts2)
Corrects parameters for binning.
cpl_error_code xsh_slit_stare_get_calibs2(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **spectralformat, cpl_frame **mbias, cpl_frame **mdark, cpl_frame **mflat, cpl_frame **otab_edges, cpl_frame **model_cfg, cpl_frame **wave_tab, cpl_frame **sky_list, cpl_frame **sky_orders_chunks, cpl_frame **qc_sky, cpl_frame **bpmap, cpl_frame **sframe_sky_sub_tab, cpl_frame **wmap, cpl_frame **smap, const char *rec_id, int *recipe_use_model, int pscan)
cpl_error_code xsh_get_dispersion_calibs(cpl_frameset *calib, xsh_instrument *instrument, const int do_computemap, cpl_frame **model_config_frame, cpl_frame **wave_tab, cpl_frame **wavemap)
cpl_error_code xsh_respon_slit_nod_get_calibs(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **bpmap, cpl_frame **master_bias, cpl_frame **master_flat, cpl_frame **order_tab_edges, cpl_frame **wave_tab, cpl_frame **model_config_frame, cpl_frame **wavemap, cpl_frame **slitmap, cpl_frame **disp_tab_frame, cpl_frame **spectral_format, cpl_frame **skymask_frame, cpl_frame **response_ord_frame, cpl_frame **frm_atmext, int do_computemap, int use_skymask, int pscan, const char *rec_prefix, const char *recipe_id)
cpl_error_code xsh_ifu_stare_get_calibs(cpl_frameset *calib, xsh_instrument *inst, cpl_frame **spectral_format, cpl_frame **mbias, cpl_frame **mdark, cpl_frame **mflat, cpl_frame **otab_edges, cpl_frame **model_cfg, cpl_frame **bpmap, cpl_frame **wmap, cpl_frame **smap, cpl_frame **ifu_cfg_tab, cpl_frame **ifu_cfg_cor, cpl_frame **wavesol, const char *rec_id, int *recipe_use_model, int pscan)
cpl_error_code xsh_slit_stare_get_params(cpl_parameterlist *parameters, const char *rec_id, int *pre_overscan_corr, xsh_background_param **backg_par, xsh_localize_obj_param **loc_obj_par, xsh_rectify_param **rectify_par, xsh_remove_crh_single_param **crh_single_par, int *sub_sky_nbkpts1, int *do_flatfield, int *sub_sky_nbkpts2, xsh_subtract_sky_single_param **sky_par, int *do_optextract, xsh_opt_extract_param **opt_extract_par, int *generate_sdp_format)
double xsh_get_systematic_wave_accuracy(xsh_instrument *instrument)
static cpl_error_code xsh_frame_image_get_step(cpl_frame *frm_ima, const int xcen, const int ycen, const int direction, double *dif)
cpl_frameset * xsh_frameset_crh_single(cpl_frameset *raws, xsh_remove_crh_single_param *crh_single_par, cpl_frame *sky_map_frm, xsh_instrument *instrument, const char *prefix, const char *spec)
Generates a new frameset with each frame CRH-single rejected from input frameset.
cpl_error_code xsh_flux_calibrate(cpl_frame *rect2D, cpl_frame *rect1D, cpl_frame *atmext, cpl_frame *response, int mpar, xsh_instrument *inst, const char *rec_prefix, cpl_frame **fcal_rect_2D, cpl_frame **fcal_rect_1D, cpl_frame **fcal_2D, cpl_frame **fcal_1D)
cpl_error_code xsh_scired_get_proper_maps(cpl_frameset *raws, cpl_frameset *calib, cpl_frame *order_tab_edges, cpl_frame *master_flat, cpl_frame *model_config_frame, cpl_frame *disp_tab, xsh_instrument *instrument, const int do_computemap, const char *rec_prefix, cpl_frame **wavemap, cpl_frame **slitmap)
cpl_error_code xsh_slit_stare_get_maps(cpl_frameset *calib, int do_compute_map, int recipe_use_model, const char *rec_prefix, xsh_instrument *instrument, cpl_frame *model_config_frame, cpl_frame *crhm_frame, cpl_frame *disp_tab_frame, cpl_frame *order_tab_edges, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame)
cpl_error_code xsh_scired_util_spectra_flux_calibrate(cpl_frame *res2D, cpl_frame *res1D, cpl_frame *response, cpl_frame *atmext, xsh_instrument *inst, const char *prefix, cpl_frame **fluxcal_2D, cpl_frame **fluxcal_1D)
cpl_frame * xsh_compute_efficiency(cpl_frame *mer1D, cpl_frame *std_cat, cpl_frame *atm_ext, cpl_frame *high_abs_win, xsh_instrument *instr)
cpl_error_code xsh_compute_resampling_accuracy(cpl_frame *wavemap, cpl_frame *slitmap, cpl_frame *order_tab_edges, cpl_frame *model_config, cpl_frame *science, xsh_instrument *instrument)
cpl_frameset * xsh_nod_group_by_reloff2(cpl_frameset *ord_set, xsh_instrument *instrument, xsh_stack_param *stack_par)
cpl_error_code xsh_get_normal_calibs(cpl_frameset *calib, xsh_instrument *instrument, const char *recipe_id, int pscan, cpl_frame **spectral_format, cpl_frame **master_bias, cpl_frame **bpmap, cpl_frame **order_tab_edges, cpl_frame **master_flat)
cpl_frameset * xsh_frameset_mflat_divide(cpl_frameset *input, cpl_frame *mflat, xsh_instrument *instrument)
Generates a new frameset with each frame mflat divided input frameset.
static cpl_error_code xsh_get_response_calibs(cpl_frameset *calib, xsh_instrument *instrument, const int use_sky_mask, cpl_frame **disp_tab_frame, cpl_frame **response_ord_frame, cpl_frame **frm_atmext, cpl_frame **skymask_frame)
static cpl_frame * xsh_frame_divide_flat(int do_flat, cpl_frame *src, cpl_frame *mflat, const char *tag, xsh_instrument *instr)
cpl_error_code xsh_compute_wavelength_resampling_accuracy(cpl_frame *wavemap, cpl_frame *order_tab_edges, cpl_frame *model_config, cpl_frame *science, xsh_instrument *instrument)
static cpl_error_code xsh_nod_rectify_and_shift_with_key(const char *nod_name, const char *qual_name, const char *rec_prefix, cpl_frame *frame2D, cpl_frame *order_tab_edges, cpl_frame *wave_tab, cpl_frame *model_config_frame, cpl_frame *spectral_format, cpl_frame *disp_tab_frame, xsh_instrument *instrument, const int corr_sky, xsh_rectify_param *rectify_par, double **ref_ra, double **ref_dec, cpl_frame **shift2_frame, cpl_frame **shift1_frame)
static cpl_error_code xsh_scired_nod_params_monitor(xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par)
monitor param values
cpl_error_code xsh_slit_stare_correct_crh_and_sky(xsh_localize_obj_param *loc_obj_par, xsh_remove_crh_single_param *crh_single_par, xsh_rectify_param *rectify_par, int do_sub_sky, const char *rec_prefix, cpl_frame *rmbkg, cpl_frame *order_tab_edges, cpl_frame *slitmap, cpl_frame *wavemap, cpl_frame *sky_map, cpl_frame *model_config, cpl_frame *single_frame_sky_sub_tab, xsh_instrument *instrument, int sub_sky_nbkpts1, xsh_subtract_sky_single_param *sky_par, cpl_frame *ref_sky_list, cpl_frame *sky_orders_chunks, cpl_frame **sky, cpl_frame **sky_eso, cpl_frame **sky_ima, cpl_frame *wave_tab, cpl_frame *disp_tab, cpl_frame *spectral_format, int nb_raw_frames, cpl_frame **loc_table, cpl_frame **clean, cpl_frame **clean_obj, const int clean_tmp)
correct CRH and sky lines (1st iteration)
cpl_error_code xsh_slit_stare_get_calibs(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **spectralformat, cpl_frame **mbias, cpl_frame **mdark, cpl_frame **mflat, cpl_frame **otab_edges, cpl_frame **model_cfg, cpl_frame **wave_tab, cpl_frame **sky_list, cpl_frame **sky_orders_chunks, cpl_frame **qc_sky, cpl_frame **bpmap, cpl_frame **sframe_sky_sub_tab, cpl_frame **wmap, cpl_frame **smap, const char *rec_id, int *recipe_use_model, int pscan)
cpl_error_code xsh_slit_offset_get_calibs(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **bpmap, cpl_frame **mbias, cpl_frame **mdark, cpl_frame **otab_edges, cpl_frame **model_cfg, cpl_frame **wave_tab, cpl_frame **mflat, cpl_frame **wmap, cpl_frame **smap, cpl_frame **spectral_format, const char *rec_id)
cpl_error_code xsh_flux_calibrate2D(cpl_frame *rect2D, cpl_frame *atmext, cpl_frame *response, int mpar, xsh_instrument *inst, const char *rec_prefix, cpl_frame **fcal_rect_2D, cpl_frame **fcal_2D)
cpl_frameset * xsh_scired_slit_nod_fast(cpl_frameset *nod_set, cpl_frame *spectral_format, cpl_frame *master_flat, cpl_frame *order_tab_edges, cpl_frame *wave_tab, cpl_frame *model_config_frame, cpl_frame *disp_tab_frame, cpl_frame *wavemap, xsh_instrument *instrument, xsh_remove_crh_single_param *crh_single_par, xsh_rectify_param *rectify_par, const int do_flatfield, const int corr_sky, const int compute_eff, const char *rec_prefix, cpl_frameset **comb_eff_set)
cpl_error_code xsh_scired_nod_get_parameters(cpl_parameterlist *parameters, xsh_instrument *instrument, xsh_remove_crh_single_param **crh_single_par, xsh_rectify_param **rectify_par, xsh_extract_param **extract_par, xsh_combine_nod_param **combine_nod_par, xsh_slit_limit_param **slit_limit_par, xsh_localize_obj_param **loc_obj_par, int *rectify_fast, int *pscan, int *generate_sdp_format, const char *rec_id)
cpl_error_code xsh_flux_calibrate1D(cpl_frame *rect1D, cpl_frame *atmext, cpl_frame *response, int mpar, xsh_instrument *inst, const char *rec_prefix, cpl_frame **fcal_rect_1D, cpl_frame **fcal_1D)