00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030
00031
00032
00033 #include <xsh_utils_scired_slit.h>
00034 #include <xsh_dfs.h>
00035 #include <xsh_utils.h>
00036 #include <xsh_error.h>
00037 #include <xsh_drl_check.h>
00038 #include <xsh_pfits.h>
00039 #include <xsh_model_utils.h>
00040 static int
00041 xsh_frame_has_same_nod_pos(cpl_frame* ref, cpl_frame* cmp)
00042 {
00043 int result=0;
00044
00045 cpl_propertylist* href=NULL;
00046 cpl_propertylist* hcmp=NULL;
00047
00048 const char* name_ref=NULL;
00049 const char* name_cmp=NULL;
00050
00051 double ref_yoff=0;
00052 double ref_ra=0;
00053 double ref_dec=0;
00054
00055 double cmp_yoff=0;
00056 double cmp_ra=0;
00057 double cmp_dec=0;
00058
00059 name_ref=cpl_frame_get_filename(ref);
00060 name_cmp=cpl_frame_get_filename(cmp);
00061 href=cpl_propertylist_load(name_ref,0);
00062 hcmp=cpl_propertylist_load(name_cmp,0);
00063
00064 if(cpl_propertylist_has(href, XSH_NOD_CUMULATIVE_OFFSETY)){
00065
00066 check(ref_yoff=xsh_pfits_get_cumoffsety(href));
00067 check(cmp_yoff=xsh_pfits_get_cumoffsety(hcmp));
00068
00069 if(ref_yoff==cmp_yoff) {
00070 result=1;
00071 }
00072
00073 } else {
00074
00075 check(ref_ra=xsh_pfits_get_ra_cumoffset(href));
00076 check(ref_dec=xsh_pfits_get_dec_cumoffset(href));
00077
00078 check(cmp_ra=xsh_pfits_get_ra_cumoffset(hcmp));
00079 check(cmp_dec=xsh_pfits_get_dec_cumoffset(hcmp));
00080
00081 if((ref_ra==cmp_ra) && (ref_ra==cmp_ra)) {
00082 result=1;
00083 }
00084
00085 }
00086 cleanup:
00087 xsh_free_propertylist(&href);
00088 xsh_free_propertylist(&hcmp);
00089
00090 return result;
00091
00092 }
00093
00094 cpl_frameset* xsh_nod_group_by_reloff( cpl_frameset *ord_set,
00095 xsh_instrument *instrument, xsh_clipping_param *crh_clipping_par)
00096 {
00097
00098 cpl_frameset *result = NULL;
00099 cpl_frameset *rmcrh_set = NULL;
00100 cpl_frame *frame = NULL;
00101 cpl_propertylist *header = NULL;
00102
00103 const char* nod_name = NULL;
00104
00105 double rel_ra=0;
00106 double rel_dec=0;
00107 double A_cum_ra=0;
00108 double A_cum_dec=0;
00109 int A_number=1, B_number =1;
00110 int nod_number;
00111 char ftag[40];
00112 cpl_frame *crhm_frame = NULL;
00113
00114 XSH_ASSURE_NOT_NULL( ord_set);
00115 XSH_ASSURE_NOT_NULL( instrument);
00116 XSH_ASSURE_NOT_NULL( crh_clipping_par);
00117
00118 check( result=cpl_frameset_new());
00119
00120 check( frame = cpl_frameset_get_first( ord_set));
00121 check( nod_name = cpl_frame_get_filename( frame));
00122 check( header = cpl_propertylist_load( nod_name, 0));
00123
00124 check( A_cum_ra = xsh_pfits_get_ra_cumoffset( header));
00125 check( A_cum_dec = xsh_pfits_get_dec_cumoffset( header));
00126
00127 xsh_free_propertylist( &header);
00128
00129 while( frame != NULL){
00130 double cum_ra=0;
00131 double cum_dec=0;
00132 double nrel_ra, nrel_dec;
00133 const char *type= NULL;
00134
00135 check( nod_name = cpl_frame_get_filename( frame));
00136 check( header = cpl_propertylist_load( nod_name, 0));
00137 check( cum_ra = xsh_pfits_get_ra_cumoffset( header));
00138 check( cum_dec = xsh_pfits_get_dec_cumoffset( header));
00139 check( rel_ra = xsh_pfits_get_ra_reloffset( header));
00140 check( rel_dec = xsh_pfits_get_dec_reloffset( header));
00141
00142 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
00143 type = "A";
00144 nod_number = A_number;
00145 }
00146 else{
00147 type = "B";
00148 nod_number = B_number;
00149 }
00150
00151 xsh_msg("name %s cumoffset %f %f reloffset %f %f nod_seq_number : %s%d", nod_name,
00152 cum_ra, cum_dec, rel_ra, rel_dec, type, nod_number);
00153
00154 xsh_free_propertylist( &header);
00155
00156 check( rmcrh_set = cpl_frameset_new());
00157 cpl_frameset_insert( rmcrh_set, cpl_frame_duplicate( frame));
00158
00159 check( frame = cpl_frameset_get_next( ord_set));
00160
00161 while( frame != NULL){
00162 check( nod_name = cpl_frame_get_filename( frame));
00163 check( header = cpl_propertylist_load( nod_name, 0));
00164 check( nrel_ra = xsh_pfits_get_ra_reloffset( header));
00165 check( nrel_dec = xsh_pfits_get_dec_reloffset( header));
00166 xsh_free_propertylist( &header);
00167
00168 if ( rel_ra == nrel_ra && nrel_dec == rel_dec){
00169 cpl_frameset_insert( rmcrh_set, cpl_frame_duplicate( frame));
00170 }
00171 else{
00172 break;
00173 }
00174 check( frame = cpl_frameset_get_next( ord_set));
00175 }
00176
00177
00178 sprintf( ftag,"med_%s%d", type, nod_number);
00179 check( crhm_frame = xsh_remove_crh_multiple( rmcrh_set, ftag, crh_clipping_par,
00180 instrument, NULL,NULL ));
00181
00182 check( cpl_frameset_insert( result, crhm_frame));
00183
00184 if ( cum_ra == A_cum_ra && cum_dec == A_cum_dec){
00185 A_number++;
00186 }
00187 else{
00188 B_number++;
00189 }
00190 xsh_free_frameset( &rmcrh_set);
00191 }
00192
00193 cleanup:
00194 if ( cpl_error_get_code() != CPL_ERROR_NONE){
00195 xsh_free_propertylist( &header);
00196 xsh_free_frameset( &rmcrh_set);
00197 xsh_free_frameset( &result);
00198 }
00199 return result;
00200 }
00201
00202 static cpl_frameset*
00203 xsh_nod_prepare_set( cpl_frameset *ord_set,
00204 xsh_instrument* instrument,
00205 xsh_clipping_param* crh_clipping_par)
00206 {
00207
00208 int nraw=0;
00209 int i=0;
00210 int k=0;
00211
00212 cpl_frameset* result=NULL;
00213 cpl_frameset* set_tmp=NULL;
00214 cpl_frame* frm=NULL;
00215 cpl_frame* frm_tmp=NULL;
00216 cpl_frame* crhm_frame=NULL;
00217 char ftag[40];
00218
00219 result=cpl_frameset_new();
00220 frm=cpl_frameset_get_frame(ord_set,0);
00221 set_tmp=cpl_frameset_new();
00222 cpl_frameset_insert(set_tmp,cpl_frame_duplicate(frm));
00223
00224 nraw=cpl_frameset_get_size( ord_set);
00225
00226 for(i=1;i<nraw;i++) {
00227
00228 frm_tmp=cpl_frameset_get_frame(ord_set,i);
00229
00230 if(xsh_frame_has_same_nod_pos(frm,frm_tmp)) {
00231 cpl_frameset_insert(set_tmp,cpl_frame_duplicate(frm_tmp));
00232
00233 } else {
00234 sprintf(ftag,"crh_mean_%d",k);
00235 check(crhm_frame = xsh_remove_crh_multiple(set_tmp,
00236 ftag,
00237 crh_clipping_par,
00238 instrument, NULL,NULL ));
00239 xsh_free_frameset(&set_tmp);
00240 cpl_frameset_insert(result,crhm_frame);
00241 set_tmp=cpl_frameset_new();
00242 frm=cpl_frameset_get_frame(ord_set,i);
00243 cpl_frameset_insert(set_tmp,cpl_frame_duplicate(frm));
00244 k++;
00245
00246
00247 }
00248
00249 }
00250 sprintf(ftag,"crh_mean_%d",k);
00251 check(crhm_frame = xsh_remove_crh_multiple(set_tmp,
00252 ftag,
00253 crh_clipping_par,
00254 instrument, NULL,NULL ));
00255
00256 cpl_frameset_insert(result,crhm_frame);
00257
00258 cleanup:
00259 xsh_free_frameset(&set_tmp);
00260 return result;
00261
00262 }
00263
00270
00271 static cpl_vector *
00272 xsh_get_offsets(const cpl_frameset * rawframes)
00273 {
00274 int nraw = 0;
00275 cpl_vector * offsets = NULL;
00276 cpl_propertylist * plist = NULL;
00277 int i;
00278
00279 double ra_off=0;
00280 double dec_off=0;
00281 double posang=0;
00282
00283 XSH_ASSURE_NOT_NULL_MSG (rawframes,"null input frameset");
00284
00285 nraw = cpl_frameset_get_size(rawframes);
00286 XSH_ASSURE_NOT_ILLEGAL_MSG(nraw > 0,"Provide at least a raw frame");
00287
00288 offsets = cpl_vector_new(nraw);
00289
00290
00291 for (i=0; i < nraw; i++) {
00292 const cpl_frame * cur_frame=NULL;
00293 const char * filename = NULL;
00294 double yoff;
00295 check(cur_frame= cpl_frameset_get_frame_const(rawframes, i));
00296 check(filename=cpl_frame_get_filename(cur_frame));
00297
00298 xsh_free_propertylist(&plist);
00299 plist=cpl_propertylist_load(filename,0);
00300 if(cpl_propertylist_has(plist,XSH_NOD_CUMULATIVE_OFFSETY)) {
00301 check(yoff=xsh_pfits_get_cumoffsety(plist));
00302 } else {
00303 ra_off=xsh_pfits_get_ra_cumoffset(plist);
00304 dec_off=xsh_pfits_get_dec_cumoffset(plist);
00305 posang = xsh_pfits_get_posang(plist);
00306 posang = posang/180.0* M_PI;
00307
00308
00309
00310
00311 yoff=(cos(-posang)*dec_off+
00312 sin(-posang)*ra_off);
00313 xsh_msg_dbg_medium("ra_off=%f,dec_off=%f,yoff=%f,posang=%f",
00314 ra_off,dec_off,yoff,posang);
00315
00316 }
00317
00318
00319 check((cpl_vector_set(offsets, i, yoff)));
00320 }
00321
00322 cleanup:
00323
00324 xsh_free_propertylist(&plist);
00325
00326 if (cpl_error_get_code()) {
00327 xsh_free_vector(&offsets);
00328 offsets = NULL;
00329 }
00330
00331 return offsets;
00332 }
00333
00334 static
00335 cpl_vector* xsh_get_noffsets(cpl_vector * offsets)
00336 {
00337
00338 int size=0;
00339 cpl_vector* result=NULL;
00340 cpl_table* tv=NULL;
00341 int nrow=0;
00342 double* values=NULL;
00343 double val=0;
00344 int null=0;
00345 int noffsets=0;
00346 XSH_ASSURE_NOT_NULL_MSG (offsets,"null input offsets");
00347
00348 size=cpl_vector_get_size(offsets);
00349 values=cpl_vector_get_data(offsets);
00350 tv=cpl_table_new(size);
00351 cpl_table_wrap_double(tv,values,"VALUES");
00352
00353 nrow=cpl_table_get_nrow(tv);
00354 result=cpl_vector_new(nrow);
00355 while(nrow>0){
00356 val=cpl_table_get_double(tv,"VALUES",0,&null);
00357 cpl_table_and_selected_double(tv,"VALUES",CPL_EQUAL_TO,val);
00358 cpl_table_erase_selected(tv);
00359 nrow=cpl_table_get_nrow(tv);
00360 cpl_vector_set(result,noffsets,val);
00361 noffsets++;
00362 }
00363 cpl_vector_set_size(result,noffsets);
00364 cleanup:
00365 xsh_free_table(&tv);
00366
00367 return result;
00368 }
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 static cpl_frame* xsh_frame_divide_flat( int do_flat, cpl_frame* src,
00447 cpl_frame *mflat, const char* tag, xsh_instrument* instr)
00448 {
00449 cpl_frame *result = NULL;
00450
00451 if ( do_flat == CPL_TRUE){
00452 xsh_msg( "Divide by flat");
00453 check( result = xsh_divide_flat( src, mflat, tag, instr));
00454 }
00455 else{
00456 check( result = cpl_frame_duplicate( src));
00457 }
00458
00459 cleanup:
00460 return result;
00461 }
00462
00463 static cpl_error_code
00464 xsh_nod_rectify_and_shift_with_key(const char* nod_name,
00465 const char* qual_name,
00466 const char* rec_prefix,
00467 cpl_frame* frame2D,
00468 cpl_frame* order_tab_edges,
00469 cpl_frame* wave_tab,
00470 cpl_frame* model_config_frame,
00471 cpl_frame* spectral_format,
00472 cpl_frame* disp_tab_frame,
00473 xsh_instrument* instrument,
00474 xsh_rectify_param *rectify_par,
00475 double** ref_ra,
00476 double** ref_dec,
00477 cpl_frame **shift2_frame,
00478 cpl_frame **shift1_frame)
00479
00480 {
00481
00482
00483 char file_name[80];
00484 cpl_frame * rec2_frame = NULL ;
00485 cpl_frame * rec2eso_frame = NULL ;
00486 cpl_frame * rec2tab_frame = NULL ;
00487 cpl_frame *shift2eso_frame = NULL;
00488 cpl_frame * rec1_frame = NULL ;
00489 cpl_frame *shift1eso_frame = NULL;
00490
00491
00492 sprintf(file_name,"REC2_%s_%s",qual_name,nod_name);
00493 check(rec2_frame = xsh_rectify( frame2D,order_tab_edges,
00494 wave_tab,model_config_frame,instrument,
00495 rectify_par,spectral_format,disp_tab_frame,
00496 file_name,&rec2eso_frame,&rec2tab_frame,
00497 rec_prefix));
00498
00499 sprintf(file_name,"SHIFT2_%s_%s",qual_name,nod_name);
00500
00501 check( *shift2_frame = shift_with_kw( rec2_frame, instrument,rectify_par,
00502 file_name, &shift2eso_frame,
00503 ref_ra,ref_dec, 0));
00504
00505 sprintf(file_name,"REC1_FAST_%s_%s",qual_name,nod_name);
00506 check( rec1_frame = xsh_rec_list_frame_invert( rec2_frame, file_name,
00507 instrument));
00508
00509 sprintf(file_name,"SHIFT1_FAST_%s_%s",qual_name,nod_name);
00510 check( *shift1_frame = shift_with_kw( rec1_frame, instrument,
00511 rectify_par, file_name,
00512 &shift1eso_frame, ref_ra,
00513 ref_dec, 1));
00514 cleanup:
00515
00516 xsh_free_frame( &rec1_frame);
00517 xsh_free_frame( &rec2_frame);
00518 xsh_free_frame( &shift1eso_frame);
00519 xsh_free_frame( &shift2eso_frame);
00520 xsh_free_frame( &rec2eso_frame);
00521 xsh_free_frame( &rec2tab_frame);
00522
00523 return cpl_error_get_code();
00524 }
00525
00526 cpl_error_code
00527 xsh_scired_slit_nod_fast(
00528 cpl_frameset *nod_set,
00529 cpl_frame* spectral_format,
00530 cpl_frame* master_flat,
00531 cpl_frame* order_tab_edges,
00532 cpl_frame* wave_tab,
00533 cpl_frame* model_config_frame,
00534 cpl_frame* disp_tab_frame,
00535 cpl_frame* wavemap,
00536 cpl_frame* slitmap,
00537 xsh_instrument* instrument,
00538 xsh_remove_crh_single_param *crh_single_par,
00539 xsh_rectify_param *rectify_par,
00540 const int do_flatfield,
00541 const int compute_eff,
00542 const char* rec_prefix,
00543 cpl_frameset **comb_set,
00544 cpl_frameset **comb_eff_set)
00545
00546 {
00547
00548 cpl_frame *rm_crh = NULL;
00549 cpl_frame * div2_frame = NULL ;
00550 cpl_frame * eff2_frame = NULL ;
00551 cpl_frame *shift1_frame = NULL;
00552 cpl_frame *shift2_frame = NULL;
00553 cpl_frame *shift1_eff_frame = NULL;
00554 cpl_frame *shift2_eff_frame = NULL;
00555 double* ref_ra=NULL;
00556 double* ref_dec=NULL;
00557 double* ref_eff_ra=NULL;
00558 double* ref_eff_dec=NULL;
00559
00560
00561 int i=0;
00562 int nb_pairs=0;
00563
00564 xsh_msg("Method fast");
00565 check( *comb_set = cpl_frameset_new());
00566
00567 if(compute_eff) {
00568 check( *comb_eff_set = cpl_frameset_new());
00569 }
00570
00571
00572 check( nb_pairs = cpl_frameset_get_size( nod_set));
00573
00574 for( i = 0; i< nb_pairs; i++){
00575 cpl_frame *nod_frame = NULL;
00576 const char* nod_name = NULL;
00577 char tag[80];
00578
00579 nod_frame = cpl_frameset_get_frame( nod_set, i);
00580 nod_name = cpl_frame_get_filename( nod_frame);
00581 xsh_msg_dbg_high( "***** Frame %s", nod_name);
00582
00583
00584
00585
00586
00587
00588
00589
00590 sprintf(tag,"NOCRH_%s", xsh_instrument_arm_tostring( instrument ));
00591
00592 check( rm_crh = xsh_abs_remove_crh_single( nod_frame, wavemap,instrument,
00593 crh_single_par, tag));
00594
00595
00596
00597 sprintf(tag,"DIV2_FLATFIELD_%s", xsh_instrument_arm_tostring(instrument)) ;
00598 check( div2_frame =xsh_frame_divide_flat( do_flatfield, rm_crh, master_flat,
00599 tag, instrument));
00600
00601
00602 check(xsh_nod_rectify_and_shift_with_key(nod_name,"RECTIFIED",rec_prefix,
00603 div2_frame,order_tab_edges,
00604 wave_tab,model_config_frame,
00605 spectral_format,
00606 disp_tab_frame,
00607 instrument,
00608 rectify_par,&ref_ra,&ref_dec,
00609 &shift1_frame,&shift2_frame));
00610
00611 cpl_frameset_insert( *comb_set, shift2_frame);
00612 cpl_frameset_insert( *comb_set, shift1_frame);
00613
00614 if(compute_eff) {
00615 if(disp_tab_frame != NULL) {
00616 int conserve_flux=rectify_par->conserve_flux;
00617
00618 sprintf(tag,"NOCRH_EFF_%s",xsh_instrument_arm_tostring(instrument)) ;
00619 check( eff2_frame =xsh_frame_divide_flat(0, rm_crh, master_flat,
00620 tag, instrument));
00621 rectify_par->conserve_flux=1;
00622 check(xsh_nod_rectify_and_shift_with_key(nod_name,"EFF",rec_prefix,
00623 eff2_frame,order_tab_edges,
00624 wave_tab,model_config_frame,
00625 spectral_format,
00626 disp_tab_frame,
00627 instrument,
00628 rectify_par,
00629 &ref_eff_ra,&ref_eff_dec,
00630 &shift1_eff_frame,
00631 &shift2_eff_frame));
00632 rectify_par->conserve_flux=conserve_flux;
00633 cpl_frameset_insert( *comb_eff_set, shift2_eff_frame);
00634 cpl_frameset_insert( *comb_eff_set, shift1_eff_frame);
00635 xsh_free_frame( &eff2_frame);
00636
00637 }
00638 }
00639 xsh_free_frame( &rm_crh);
00640 xsh_free_frame( &div2_frame);
00641
00642
00643 }
00644
00645 cleanup:
00646 XSH_FREE( ref_ra);
00647 XSH_FREE( ref_dec);
00648 XSH_FREE( ref_eff_ra);
00649 XSH_FREE( ref_eff_dec);
00650 xsh_free_frame( &eff2_frame);
00651 xsh_free_frame( &div2_frame);
00652 return cpl_error_get_code();
00653 }
00654
00655
00656
00657
00658 cpl_frameset*
00659 xsh_scired_slit_nod_accurate(
00660 cpl_frameset *nod_set,
00661 cpl_frame* spectral_format,
00662 cpl_frame* master_flat,
00663 cpl_frame* order_tab_edges,
00664 cpl_frame* wave_tab,
00665 cpl_frame* model_config_frame,
00666 cpl_frame* disp_tab_frame,
00667 cpl_frame* wavemap,
00668 cpl_frame* slitmap,
00669 cpl_frame *skymask_frame,
00670 xsh_instrument* instrument,
00671 xsh_remove_crh_single_param *crh_single_par,
00672 xsh_rectify_param *rectify_par,
00673 xsh_localize_obj_param *loc_obj_par,
00674 xsh_slit_limit_param *slit_limit_par,
00675 const char *throw_name,
00676 const int do_flatfield,
00677 const char* rec_prefix
00678 )
00679 {
00680 int i=0;
00681 cpl_frame * a_b = NULL;
00682
00683
00684 char file_tag[40];
00685 char file_name[80];
00686
00687 int nb_nod=0;
00688 double *throw_shift = NULL;
00689 double *throw_tab = NULL;
00690
00691 cpl_frame * loc_a_b = NULL, * loc_b_a = NULL ;
00692 cpl_frame * loc_a_b_0 = NULL;
00693
00694 cpl_frameset *comb_set = NULL;
00695
00696
00697 xsh_msg("Method accurate");
00698 check( comb_set = cpl_frameset_new());
00699
00700 check( nb_nod = cpl_frameset_get_size( nod_set));
00701
00702
00703 if ( strcmp( throw_name, "") != 0){
00704 FILE* throw_file = NULL;
00705 char throw_line[200];
00706 int iline;
00707
00708 xsh_msg("Load Throw shifts from file %s", throw_name);
00709 throw_file = fopen( throw_name, "r");
00710
00711 XSH_CALLOC( throw_tab, double, nb_nod);
00712
00713 iline=0;
00714
00715 while (fgets( throw_line, 200, throw_file) != NULL){
00716 char shiftval[200];
00717
00718 sscanf( throw_line, "%s",shiftval);
00719 if (iline < nb_nod){
00720 throw_tab[iline] = atof( shiftval);
00721 }
00722 iline++;
00723 }
00724 if (iline != nb_nod){
00725 xsh_error_msg("Invalid number of lines in ASCII file %s : %d - expected number : %d",
00726 throw_name, iline, nb_nod);
00727 }
00728 fclose( throw_file);
00729 }
00730
00731
00732 for( i = 0; i<nb_nod ; i++) {
00733 cpl_frame * rm_crh = NULL ;
00734 cpl_frame * divided = NULL ;
00735 cpl_frame * shifted_a_b = NULL;
00736 cpl_frame * shifted_a_b_eso = NULL;
00737 cpl_frame * shifted_a_b_tab = NULL;
00738 cpl_frame *inv_shifted_a_b = NULL;
00739 cpl_frame *loc_rec = NULL;
00740 cpl_frame *loc_rec_eso = NULL;
00741 cpl_frame *loc_rec_tab = NULL;
00742 cpl_frame *inv_loc_rec = NULL;
00743 char str[16] ;
00744 int mode =0;
00745
00746 if (throw_tab != NULL){
00747 throw_shift = &throw_tab[i];
00748 }
00749
00750 if (i%2 == 0){
00751 sprintf( str, "AB_%d_%s", i/2, xsh_instrument_arm_tostring(instrument)) ;
00752 mode =0;
00753 }
00754 else{
00755 sprintf( str, "BA_%d_%s", i/2, xsh_instrument_arm_tostring(instrument)) ;
00756 mode=1;
00757 }
00758 check( a_b = cpl_frameset_get_frame( nod_set, i));
00759 xsh_msg_dbg_high( "***** Frame %s", cpl_frame_get_filename( a_b ) ) ;
00760
00761
00762 xsh_msg( "Remove crh (single frame)" ) ;
00763 sprintf(file_tag, "SLIT_NOD_NOCRH_%s",str) ;
00764
00765 check( rm_crh = xsh_abs_remove_crh_single(a_b, wavemap, instrument,
00766 crh_single_par, file_tag));
00767
00768
00769 sprintf(file_tag,"SLIT_NOD_NOCRH_FF_%s", str);
00770 check( divided = xsh_frame_divide_flat( do_flatfield, rm_crh,master_flat, file_tag,
00771 instrument));
00772
00773 if ( i > 1 && throw_shift == NULL){
00774 if (i%2 == 0){
00775 xsh_msg("TEST %d : on fait loc_ab et loc_ba", i);
00776 sprintf(file_name,"LOC_REC_%s.fits", str);
00777 check( loc_rec = xsh_rectify( divided, order_tab_edges,
00778 wave_tab, model_config_frame, instrument,
00779 rectify_par, spectral_format, disp_tab_frame,
00780 file_name, &loc_rec_eso, &loc_rec_tab, rec_prefix));
00781 xsh_msg( "Localize the object (A%d)", i/2);
00782 sprintf( file_name,"LOCALIZE_%s.fits", str);
00783 check( loc_a_b = xsh_localize_obj( loc_rec, skymask_frame, instrument, loc_obj_par,
00784 NULL, file_name));
00785
00786 xsh_msg( "Negative rectify");
00787 sprintf(file_name,"DRL_INV_LOC_REC_%s", str);
00788 check( inv_loc_rec = xsh_rec_list_frame_invert( loc_rec,
00789 file_name, instrument));
00790
00791 xsh_msg( "Localize the object (B%d)", i/2);
00792 sprintf(file_name,"INV_LOCALIZE_%s.fits", str);
00793 check( loc_b_a = xsh_localize_obj( inv_loc_rec, skymask_frame, instrument, loc_obj_par,
00794 NULL, file_name));
00795 }
00796 else{
00797 xsh_msg("TEST %d : loc_ab = loc_ba", i);
00798 loc_a_b = loc_b_a;
00799 }
00800 }
00801
00802 xsh_msg( "Rectify and shift");
00803 sprintf(file_name,"SHIFT_REC_NOCRH_%s.fits", str);
00804
00805 check( shifted_a_b = xsh_rectify_and_shift( divided,order_tab_edges,
00806 wave_tab,
00807 model_config_frame,
00808 instrument,
00809 rectify_par,
00810 spectral_format,
00811 loc_a_b,
00812 loc_a_b_0,
00813 throw_shift,
00814 disp_tab_frame,
00815 file_name,
00816 &shifted_a_b_eso,
00817 &shifted_a_b_tab));
00818 xsh_free_frame( &loc_a_b);
00819
00820 if ( i==0 && throw_shift == NULL){
00821 xsh_msg( "Localize the object (A0)");
00822 sprintf(file_name,"LOCALIZE_%s.fits", str);
00823 check( loc_a_b_0 = xsh_localize_obj( shifted_a_b, skymask_frame, instrument, loc_obj_par,
00824 NULL, file_name));
00825
00826 xsh_msg( "Negative rectify");
00827 sprintf(file_name,"DRL_INV_LOC_REC_%s", str);
00828 check( inv_shifted_a_b = xsh_rec_list_frame_invert( shifted_a_b,
00829 file_name, instrument));
00830 xsh_msg( "Localize the object (B0)");
00831 sprintf(file_name,"INV_LOCALIZE_%s.fits", str);
00832 check( loc_a_b = xsh_localize_obj( inv_shifted_a_b, skymask_frame, instrument, loc_obj_par,
00833 NULL, file_name));
00834 }
00835 check( cpl_frameset_insert( comb_set, shifted_a_b));
00836
00837 xsh_free_frame( &rm_crh);
00838 xsh_free_frame( ÷d);
00839 xsh_free_frame( &shifted_a_b_eso);
00840 xsh_free_frame( &shifted_a_b_tab);
00841 xsh_free_frame( &inv_shifted_a_b);
00842 xsh_free_frame( &loc_rec);
00843 xsh_free_frame( &loc_rec_eso);
00844 xsh_free_frame( &loc_rec_tab);
00845 xsh_free_frame( &inv_loc_rec);
00846 }
00847
00848 cleanup:
00849 if ( cpl_error_get_code() != CPL_ERROR_NONE){
00850 xsh_free_frameset( &comb_set);
00851 }
00852 xsh_free_frame( &loc_a_b_0);
00853 xsh_free_frame( &loc_a_b);
00854 XSH_FREE( throw_tab);
00855 return comb_set;
00856
00857
00858 }
00859
00860
00861 void
00862 xsh_scired_slit_nod_get_calibs(cpl_frameset* raws,
00863 cpl_frameset* calib,
00864 xsh_instrument* instrument,
00865 cpl_frame** bpmap,
00866 cpl_frame** master_bias,
00867 cpl_frame** master_flat,
00868 cpl_frame** order_tab_edges,
00869 cpl_frame** wave_tab,
00870 cpl_frame** model_config_frame,
00871 cpl_frame** wavemap,
00872 cpl_frame** slitmap,
00873 cpl_frame** disp_tab_frame,
00874 cpl_frame** spectral_format,
00875 cpl_frame** skymask_frame,
00876 cpl_frame** response_ord_frame,
00877 cpl_frame** frm_atmext,
00878 int do_computemap,
00879 int use_skymask,
00880 const char* rec_prefix
00881 )
00882
00883 {
00884 int recipe_use_model=FALSE;
00885 *bpmap = xsh_find_master_bpmap( calib);
00886 cpl_frame* ref_frame=NULL;
00887
00888
00889 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00890
00891 check(*master_bias = xsh_find_master_bias( calib, instrument));
00892 }
00893
00894 check( *order_tab_edges = xsh_find_order_tab_edges( calib, instrument));
00895
00896
00897 if((*model_config_frame = xsh_find_frame_with_tag(calib,
00898 XSH_MOD_CFG_OPT_2D,
00899 instrument)) == NULL) {
00900
00901 xsh_error_reset();
00902 if ((*model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
00903 instrument)) == NULL) {
00904 xsh_error_reset();
00905
00906 if ((*model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
00907 instrument)) == NULL) {
00908 xsh_error_reset();
00909 }
00910 }
00911
00912 }
00913 if ( *model_config_frame == NULL){
00914 xsh_msg("RECIPE USE WAVE SOLUTION");
00915 check( *wave_tab = xsh_find_wave_tab( calib, instrument));
00916 recipe_use_model = FALSE;
00917 }
00918 else{
00919 xsh_msg("RECIPE USE MODEL");
00920 recipe_use_model = TRUE;
00921 }
00922 cpl_error_reset() ;
00923
00924 XSH_ASSURE_NOT_ILLEGAL( model_config_frame != NULL || wave_tab != NULL);
00925
00926 check( *master_flat = xsh_find_master_flat( calib, instrument));
00927 if(do_computemap && recipe_use_model==FALSE) {
00928 check( *wavemap = xsh_find_wavemap( calib, instrument));
00929 }
00930
00931 if(NULL == (*disp_tab_frame = xsh_find_disp_tab( calib, instrument))) {
00932 xsh_msg("To compute efficiency, you must provide a DISP_TAB_ARM input");
00933 }
00934
00935 if ( recipe_use_model){
00936 ref_frame=cpl_frameset_get_first(raws);
00937 }
00938 else{
00939 ref_frame = *master_flat;
00940 }
00941 check( xsh_check_get_map( *disp_tab_frame, *order_tab_edges,
00942 ref_frame, *model_config_frame, calib, instrument,
00943 do_computemap, recipe_use_model, rec_prefix,
00944 wavemap, slitmap));
00945
00946 check( *spectral_format = xsh_find_spectral_format( calib, instrument));
00947
00948 if ( use_skymask == TRUE){
00949 xsh_msg("Using sky mask");
00950 check( *skymask_frame = xsh_find_frame_with_tag( calib, XSH_SKY_LINE_LIST,
00951 instrument));
00952 }
00953
00954 check( *response_ord_frame = xsh_find_frame_with_tag(calib,
00955 XSH_RESPONSE_MERGE1D_SLIT,
00956 instrument));
00957
00958 if(*response_ord_frame != NULL) {
00959 *frm_atmext=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00960 if(*frm_atmext==NULL) {
00961 xsh_msg_error("Provide atmospheric extinction frame");
00962 }
00963 }
00964
00965 cleanup:
00966 return;
00967 }
00968
00975 static cpl_error_code
00976 xsh_scired_nod_params_set_defaults(cpl_parameterlist* pars,
00977 xsh_instrument* inst,
00978 xsh_rectify_param * rectify_par,
00979 const char* rec_id)
00980 {
00981 cpl_parameter* p=NULL;
00982
00983 if (xsh_instrument_get_arm(inst) == XSH_ARM_NIR){
00984
00985 check(p=xsh_parameters_find(pars,rec_id,"rectify-bin-slit"));
00986 if(xsh_parameter_get_default_flag(p) == 0) {
00987
00988 rectify_par->rectif_bin_space=XSH_SLIT_BIN_SIZE_PIPE_NIR;
00989 cpl_parameter_set_double(p,XSH_SLIT_BIN_SIZE_PIPE_NIR);
00990 }
00991
00992 check(p=xsh_parameters_find(pars,rec_id,"rectify-bin-lambda"));
00993 if(xsh_parameter_get_default_flag(p) == 0) {
00994
00995 rectify_par->rectif_bin_lambda=XSH_WAVE_BIN_SIZE_PIPE_NIR;
00996 cpl_parameter_set_double(p,XSH_WAVE_BIN_SIZE_PIPE_NIR);
00997 }
00998
00999
01000
01001 } else {
01002
01003
01004 check(p=xsh_parameters_find(pars,rec_id,"rectify-bin-slit"));
01005 if(xsh_parameter_get_default_flag(p) == 0) {
01006
01007 rectify_par->rectif_bin_space=XSH_SLIT_BIN_SIZE_PIPE_UVB;
01008 cpl_parameter_set_double(p,XSH_SLIT_BIN_SIZE_PIPE_UVB);
01009 }
01010
01011 check(p=xsh_parameters_find(pars,rec_id,"rectify-bin-lambda"));
01012 if(xsh_parameter_get_default_flag(p) == 0) {
01013
01014 rectify_par->rectif_bin_lambda=XSH_WAVE_BIN_SIZE_PIPE_UVB;
01015 cpl_parameter_set_double(p,XSH_WAVE_BIN_SIZE_PIPE_UVB);
01016 }
01017
01018
01019 }
01020
01021 cleanup:
01022
01023 return cpl_error_get_code();
01024
01025 }
01026
01027
01028
01034 static cpl_error_code
01035 xsh_scired_nod_params_monitor(xsh_rectify_param * rectify_par,
01036 xsh_localize_obj_param * loc_obj_par)
01037 {
01038
01039
01040
01041 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
01042 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
01043 rectify_par->rectif_bin_space);
01044
01045 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
01046 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
01047
01048 return cpl_error_get_code();
01049
01050 }
01051
01052
01053
01054
01055 cpl_error_code
01056 xsh_scired_nod_get_parameters(cpl_parameterlist* parameters,
01057 xsh_instrument* instrument,
01058 xsh_remove_crh_single_param** crh_single_par,
01059 xsh_rectify_param** rectify_par,
01060 xsh_merge_param** merge_par,
01061 xsh_extract_param** extract_par,
01062 xsh_combine_nod_param** combine_nod_par,
01063 xsh_slit_limit_param** slit_limit_par,
01064 xsh_localize_obj_param** loc_obj_par,
01065 int* rectify_fast,
01066 int binx,int biny,const char* rec_id
01067 )
01068
01069
01070 {
01071 check( *loc_obj_par = xsh_parameters_localize_obj_get(rec_id,
01072 parameters));
01073 check( *rectify_par = xsh_parameters_rectify_get(rec_id,
01074 parameters));
01075 check( *rectify_fast = xsh_parameters_rectify_fast_get(rec_id,
01076 parameters));
01077 check( *crh_single_par = xsh_parameters_remove_crh_single_get(rec_id,
01078 parameters));
01079 check( *merge_par = xsh_parameters_merge_ord_get(rec_id,
01080 parameters));
01081 check( *extract_par=xsh_parameters_extract_get(rec_id, parameters));
01082 check( *combine_nod_par = xsh_parameters_combine_nod_get(rec_id,
01083 parameters)) ;
01084 check( *slit_limit_par = xsh_parameters_slit_limit_get(rec_id,
01085 parameters));
01086 check(xsh_scired_nod_params_set_defaults(parameters,instrument,*rectify_par,rec_id));
01087
01088
01089
01090
01091
01092
01093
01094 check( xsh_scired_nod_params_monitor(*rectify_par,*loc_obj_par));
01095
01096 cleanup:
01097 return cpl_error_get_code();
01098 }
01099
01100
01101
01102 cpl_error_code
01103 xsh_flux_calibrate(cpl_frame* rect2D,
01104 cpl_frame* rect1D,
01105 cpl_frame* atmext,
01106 cpl_frame* response,
01107 xsh_merge_param * mpar,
01108 xsh_instrument* inst,
01109 const char* rec_prefix,
01110 cpl_frame** fcal_rect_2D,
01111 cpl_frame** fcal_rect_1D,
01112 cpl_frame** fcal_2D,
01113 cpl_frame** fcal_1D)
01114 {
01115 char file_tag[80];
01116 char arm_str[8] ;
01117 cpl_frame* nrm_2D=NULL;
01118 cpl_frame* nrm_1D=NULL;
01119
01120 sprintf(arm_str,"%s",xsh_instrument_arm_tostring(inst));
01121
01122 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_NORM_ORDER2D,arm_str);
01123 check(nrm_2D=xsh_normalize_spectrum_ord(rect2D,atmext,0,inst,file_tag));
01124 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_FLUX_ORDER2D,arm_str);
01125 check(*fcal_rect_2D=xsh_util_multiply_by_response_ord(nrm_2D,response,file_tag));
01126 check(*fcal_2D = xsh_merge_ord(*fcal_rect_2D, inst,mpar,rec_prefix ));
01127
01128
01129 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_NORM_ORDER1D,arm_str);
01130 check(nrm_1D=xsh_normalize_spectrum_ord(rect1D,atmext,0,inst,file_tag));
01131 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_FLUX_ORDER1D,arm_str);
01132 check(*fcal_rect_1D=xsh_util_multiply_by_response_ord(nrm_1D,response,file_tag));
01133 check(*fcal_1D= xsh_merge_ord(*fcal_rect_1D,inst,mpar,rec_prefix ));
01134
01135 cleanup:
01136 xsh_free_frame(&nrm_2D);
01137 xsh_free_frame(&nrm_1D);
01138
01139 return cpl_error_get_code();
01140 }
01141
01142
01143 cpl_error_code
01144 xsh_slit_stare_get_calibs(cpl_frameset* calib,
01145 xsh_instrument* instrument,
01146 cpl_frame** spectralformat,
01147 cpl_frame** mbias,
01148 cpl_frame** mdark,
01149 cpl_frame** mflat,
01150 cpl_frame** otab_edges,
01151 cpl_frame** model_cfg,
01152 cpl_frame** wave_tab,
01153 cpl_frame** sky_list,
01154 cpl_frame** qc_sky,
01155 cpl_frame** bpmap,
01156 cpl_frame** sframe_sky_sub_tab,
01157 cpl_frame** wmap,
01158 cpl_frame** smap,
01159 int * recipe_use_model)
01160 {
01161
01162
01163 int binx=1;
01164 int biny=1;
01165 cpl_propertylist* plist=NULL;
01166
01167 check(*spectralformat =xsh_find_frame_with_tag(calib,XSH_SPECTRAL_FORMAT,
01168 instrument));
01169
01170 XSH_ASSURE_NOT_NULL_MSG(*spectralformat,"Null input spectral format frame");
01171 check(xsh_instrument_update_from_spectralformat(instrument,*spectralformat));
01172
01173
01174 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
01175
01176 if((*mbias = xsh_find_master_bias( calib, instrument)) == NULL) {
01177 xsh_msg_error("You must give a MASTER_BIAS_ARM frame");
01178 return CPL_ERROR_DATA_NOT_FOUND;
01179 }
01180 }
01181
01182 if((*mdark = xsh_find_master_dark( calib, instrument))==NULL) {
01183 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
01184 xsh_error_reset();
01185 }
01186
01187 check( *mflat = xsh_find_master_flat( calib, instrument ));
01188 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR) {
01189 check(plist=cpl_propertylist_load(cpl_frame_get_filename(*mflat),0));
01190 check(binx=xsh_pfits_get_binx(plist));
01191 check(biny=xsh_pfits_get_biny(plist));
01192 xsh_free_propertylist(&plist);
01193 }
01194 check(*otab_edges = xsh_find_order_tab_edges(calib,instrument));
01195
01196
01197 if((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_2D,
01198 instrument)) == NULL) {
01199 xsh_error_reset();
01200 if ((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
01201 instrument)) == NULL) {
01202 xsh_error_reset();
01203
01204 if ((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
01205 instrument)) == NULL) {
01206 xsh_error_reset();
01207 }
01208 }
01209 }
01210 xsh_error_reset();
01211 cpl_error_reset();
01212
01213 if ( *model_cfg == NULL){
01214 xsh_msg("RECIPE USE WAVE SOLUTION");
01215 check( *wave_tab = xsh_find_wave_tab( calib, instrument));
01216 *recipe_use_model = FALSE;
01217 }
01218 else{
01219 xsh_msg("RECIPE USE MODEL");
01220 *recipe_use_model = TRUE;
01221 }
01222
01223 if ( *model_cfg != NULL){
01224 check(*sky_list = xsh_find_frame_with_tag( calib, XSH_SKY_LINE_LIST,
01225 instrument));
01226 if ( *sky_list != NULL){
01227
01228 check(*qc_sky=xsh_util_physmod_model_THE_create(*model_cfg,instrument,
01229 *sky_list,1,1,9,1));
01230 }
01231 }
01232
01233
01234 *bpmap = xsh_find_master_bpmap(calib);
01235 if ((*sframe_sky_sub_tab = xsh_find_frame_with_tag(calib,XSH_SKY_SUB_BKPTS,
01236 instrument)) == NULL) {
01237 xsh_error_reset();
01238 } else {
01239 xsh_msg_warning("Data reduction with user defined break points number from file %s",
01240 cpl_frame_get_filename(*sframe_sky_sub_tab));
01241 }
01242
01243
01244 check(*wmap = xsh_find_frame_with_tag(calib,XSH_WAVE_MAP,instrument));
01245 check(*smap = xsh_find_frame_with_tag(calib,XSH_SLIT_MAP,instrument));
01246
01247 cleanup:
01248 xsh_free_propertylist(&plist);
01249 return cpl_error_get_code();
01250 }
01251
01252 cpl_error_code
01253 xsh_slit_offset_get_calibs(cpl_frameset* calib,xsh_instrument* instrument,
01254 cpl_frame** bpmap,cpl_frame** mbias,
01255 cpl_frame** mdark, cpl_frame** otab_edges,
01256 cpl_frame** model_cfg, cpl_frame** wave_tab,
01257 cpl_frame** mflat, cpl_frame** wmap,
01258 cpl_frame** spectral_format)
01259 {
01260
01261
01262
01263 check(*bpmap = xsh_find_master_bpmap( calib));
01264
01265
01266 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
01267
01268 check( *mbias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,instrument));
01269 }
01270
01271
01272 if((*mdark=xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,instrument))==NULL){
01273 xsh_error_reset();
01274 }
01275
01276
01277 check( *otab_edges = xsh_find_order_tab_edges( calib, instrument));
01278 if((*model_cfg=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_2D,instrument)) == NULL) {
01279 xsh_error_reset();
01280 if ((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
01281 instrument)) == NULL) {
01282 xsh_error_reset();
01283
01284 if ((*model_cfg = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
01285 instrument)) == NULL) {
01286 xsh_error_reset();
01287 }
01288 }
01289 }
01290 cpl_error_reset() ;
01291
01292 *wave_tab = xsh_find_wave_tab( calib, instrument ) ;
01293 cpl_error_reset() ;
01294 XSH_ASSURE_NOT_ILLEGAL( *model_cfg != NULL || *wave_tab != NULL ) ;
01295
01296 check( *mflat = xsh_find_master_flat( calib, instrument));
01297
01298 check( *wmap = xsh_find_wavemap( calib, instrument));
01299 check( *spectral_format = xsh_find_spectral_format( calib, instrument));
01300
01301
01302 cleanup:
01303 return cpl_error_get_code();
01304
01305 }
01306
01307 cpl_error_code
01308 xsh_slit_stare_get_params(cpl_parameterlist* parameters,
01309 const char* rec_id,
01310 int* pre_overscan_corr,
01311 xsh_clipping_param** crh_clipping_par,
01312 xsh_background_param** backg_par,
01313 xsh_localize_obj_param** loc_obj_par,
01314 xsh_rectify_param** rectify_par,
01315 xsh_remove_crh_single_param** crh_single_par,
01316 int* sub_sky_nbkpts1,
01317 int* do_flatfield,
01318 int* sub_sky_nbkpts2,
01319 xsh_subtract_sky_single_param** sky_par,
01320 xsh_extract_param** extract_par,
01321 int* do_optextract,
01322 xsh_merge_param** merge_par,
01323 xsh_opt_extract_param** opt_extract_par,
01324 int* do_trace_obj)
01325 {
01326
01327 check( *pre_overscan_corr = xsh_parameters_get_int( parameters, rec_id,
01328 "pre-overscan-corr"));
01329
01330 check( *crh_clipping_par = xsh_parameters_clipping_crh_get(rec_id,parameters));
01331 check( *backg_par = xsh_parameters_background_get(rec_id,parameters));
01332
01333 check( *loc_obj_par = xsh_parameters_localize_obj_get(rec_id,parameters));
01334 check( *rectify_par = xsh_parameters_rectify_get(rec_id,parameters));
01335 check( *crh_single_par = xsh_parameters_remove_crh_single_get(rec_id,parameters));
01336
01337 check( *sub_sky_nbkpts1 = xsh_parameters_subtract_sky_single_get_first(
01338 rec_id,parameters));
01339 check( *do_flatfield = xsh_parameters_get_boolean( parameters, rec_id,
01340 "do-flatfield"));
01341 check( *sub_sky_nbkpts2 = xsh_parameters_subtract_sky_single_get_second(
01342 rec_id,parameters));
01343 check( *sky_par= xsh_parameters_subtract_sky_single_get(rec_id,parameters));
01344
01345 check( *extract_par = xsh_parameters_extract_get( rec_id, parameters));
01346 check( *do_optextract = xsh_parameters_get_boolean( parameters, rec_id,
01347 "do-optextract"));
01348 check( *opt_extract_par = xsh_parameters_opt_extract_get(rec_id,parameters));
01349
01350 check( *merge_par = xsh_parameters_merge_ord_get(rec_id,parameters));
01351
01352 check( *do_trace_obj = xsh_parameters_get_boolean( parameters,rec_id,
01353 "trace-obj"));
01354
01355
01356 cleanup:
01357 return cpl_error_get_code();
01358 }
01359
01360
01361 cpl_error_code
01362 xsh_slit_offset_get_params(cpl_parameterlist* parameters,
01363 const char* rec_id,
01364 xsh_clipping_param** crh_clipping_par,
01365 xsh_background_param** backg_par,
01366 xsh_localize_obj_param** loc_obj_par,
01367 xsh_rectify_param** rectify_par,
01368 xsh_remove_crh_single_param** crh_single_par,
01369 double* opt_kappa,
01370 xsh_merge_param** merge_par,
01371 xsh_extract_param**extract_par,
01372 xsh_combine_nod_param** combine_nod_param,
01373 int* do_flatfield,
01374 int* gen_sky)
01375 {
01376
01377
01378 check( *crh_clipping_par = xsh_parameters_clipping_crh_get(rec_id,parameters));
01379 check( *backg_par = xsh_parameters_background_get(rec_id,parameters));
01380
01381 check( *loc_obj_par = xsh_parameters_localize_obj_get(rec_id,parameters));
01382 check( *rectify_par = xsh_parameters_rectify_get(rec_id,parameters));
01383 check( *crh_single_par = xsh_parameters_remove_crh_single_get(rec_id,parameters));
01384 if ( (*rectify_par)->rectify_full_slit == 1 ){
01385
01386 xsh_msg( "Use Full Slit" ) ;
01387 }
01388 else {
01389 xsh_msg( "Use Max Possible Slit" ) ;
01390 }
01391
01392 check( *opt_kappa = xsh_parameters_optimal_extract_get_kappa(rec_id,parameters));
01393
01394 check( *merge_par = xsh_parameters_merge_ord_get(rec_id,parameters));
01395
01396 check(*extract_par=xsh_parameters_extract_get(rec_id, parameters )) ;
01397
01398 check(*combine_nod_param = xsh_parameters_combine_nod_get(rec_id,parameters )) ;
01399
01400 check( *do_flatfield = xsh_parameters_get_boolean( parameters,rec_id,
01401 "do-flatfield"));
01402
01403 check( *gen_sky = xsh_parameters_get_boolean( parameters, rec_id,
01404 "gen-sky"));
01405
01406 cleanup:
01407 return cpl_error_get_code();
01408
01409 }
01410
01411
01412 cpl_error_code
01413 xsh_slit_stare_correct_crh_and_sky(xsh_localize_obj_param * loc_obj_par,
01414 xsh_remove_crh_single_param* crh_single_par,
01415 xsh_rectify_param* rectify_par,
01416 int do_sub_sky,
01417 const char* rec_prefix,
01418 cpl_frame* rmbkg,
01419 cpl_frame* order_tab_edges,
01420 cpl_frame* slitmap,
01421 cpl_frame* wavemap,
01422 cpl_frame* model_config,
01423 cpl_frame* single_frame_sky_sub_tab,
01424 xsh_instrument* instrument,
01425 int sub_sky_nbkpts1,
01426 xsh_subtract_sky_single_param* sky_par,
01427 cpl_frame** sky,
01428 cpl_frame** sky_eso,
01429 cpl_frame** sky_ima,
01430 cpl_frame* wave_tab,
01431 cpl_frame* disp_tab,
01432 cpl_frame* spectral_format,
01433 int nb_raw_frames,
01434 cpl_frame** loc_table,
01435 cpl_frame** clean,
01436 cpl_frame** clean_obj)
01437 {
01438
01439 char sky_tag[80];
01440 char rec_name[80];
01441 cpl_frame * sub_sky = NULL ;
01442 cpl_frame * rect = NULL ;
01444 if( (loc_obj_par->method != LOC_MANUAL_METHOD) ||
01445 (nb_raw_frames == 1 && crh_single_par->nb_iter > 0)){
01446 xsh_msg("Preliminary sky subtraction for CRH single or automatic localization");
01447 xsh_msg("Sky will be put back later");
01448
01449 sprintf(sky_tag,"%s_TMPSKY",rec_prefix);
01450 if(do_sub_sky) {
01451 check( sub_sky = xsh_check_subtract_sky_single( CPL_TRUE, rmbkg,
01452 order_tab_edges,
01453 slitmap,
01454 wavemap,
01455 NULL, NULL,
01456 single_frame_sky_sub_tab,
01457 instrument,
01458 sub_sky_nbkpts1,
01459 sky_par,
01460 sky,
01461 sky_eso,
01462 sky_ima,
01463 sky_tag));
01464 } else {
01465 sub_sky = cpl_frame_duplicate(rmbkg);
01466 }
01467 if( loc_obj_par->method != LOC_MANUAL_METHOD){
01468 xsh_msg("Localize auto");
01469 sprintf(rec_name,"%s_%s_%s.fits",
01470 rec_prefix,XSH_ORDER2D,
01471 xsh_instrument_arm_tostring(instrument));
01472
01473
01474
01475 check( rect = xsh_rectify( sub_sky, order_tab_edges,
01476 wave_tab, model_config,
01477 instrument, rectify_par,
01478 spectral_format, disp_tab,
01479 rec_name, NULL, NULL,rec_prefix));
01480
01481
01482 check( *loc_table = xsh_localize_obj( rect, NULL, instrument,
01483 loc_obj_par, NULL, NULL));
01484 xsh_free_frame( &rect);
01485 }
01486 else{
01487 check( *loc_table = xsh_localize_obj( NULL, NULL,
01488 instrument, loc_obj_par, NULL, NULL));
01489 }
01490
01491
01492 check( *clean = xsh_check_remove_crh_single( nb_raw_frames, sub_sky,
01493 crh_single_par, wavemap, instrument, rec_prefix));
01494 if(do_sub_sky) {
01495 check( *clean_obj = xsh_add_sky_model( *clean, *sky_ima,
01496 instrument, rec_prefix));
01497 } else {
01498 *clean_obj=cpl_frame_duplicate(*clean);
01499 }
01500
01501 xsh_free_frame( &sub_sky);
01502 xsh_free_frame( sky);
01503 xsh_free_frame( sky_eso);
01504 xsh_free_frame( sky_ima);
01505 }
01506 else {
01507
01508 check( *clean_obj=cpl_frame_duplicate(rmbkg));
01509 check( *loc_table = xsh_localize_obj( NULL, NULL,
01510 instrument, loc_obj_par, NULL, NULL));
01511 }
01512
01513
01514 cleanup:
01515
01516 xsh_free_frame(&sub_sky) ;
01517 xsh_free_frame(&rect) ;
01518
01519 return cpl_error_get_code();
01520
01521 }
01522
01523
01524 cpl_error_code
01525 xsh_slit_stare_get_maps(cpl_frameset* calib,
01526 int do_compute_map,int recipe_use_model,
01527 const char* rec_prefix,xsh_instrument* instrument,
01528 cpl_frame* model_config_frame,cpl_frame* crhm_frame,
01529 cpl_frame* disp_tab_frame, cpl_frame* order_tab_edges,
01530 cpl_frame** wavemap_frame, cpl_frame** slitmap_frame)
01531 {
01532 char wave_map_tag[80];
01533 char slit_map_tag[80];
01534 int found_temp=1;
01535
01536 if ( do_compute_map){
01537 if (recipe_use_model){
01538 sprintf(wave_map_tag,"%s_%s_%s",rec_prefix,XSH_WAVE_MAP_MODEL,
01539 xsh_instrument_arm_tostring( instrument ));
01540 sprintf(slit_map_tag,"%s_%s_%s",rec_prefix,XSH_SLIT_MAP_MODEL,
01541 xsh_instrument_arm_tostring( instrument ));
01542
01543 check(xsh_model_temperature_update_frame(&model_config_frame,crhm_frame,
01544 instrument,&found_temp));
01545
01546 check( xsh_create_model_map( model_config_frame, instrument,
01547 wave_map_tag,slit_map_tag,
01548 wavemap_frame, slitmap_frame));
01549 }
01550 else{
01551 xsh_msg("Compute the wave map and the slit map");
01552 check( xsh_create_map( disp_tab_frame, order_tab_edges,
01553 crhm_frame, instrument,
01554 wavemap_frame, slitmap_frame,
01555 rec_prefix));
01556 }
01557 }
01558 else {
01559 xsh_msg( "Get the wave map and the slit map from sof" ) ;
01560 check( *slitmap_frame = xsh_find_slitmap(calib, instrument));
01561 check( *wavemap_frame = xsh_find_wavemap(calib, instrument));
01562 }
01563
01564 cleanup:
01565 return cpl_error_get_code();
01566 }
01567
01568
01569 cpl_error_code
01570 xsh_scired_util_spectra_flux_calibrate(cpl_frame* res2D,cpl_frame* res1D,
01571 cpl_frame* response,cpl_frame* atmext,
01572 xsh_instrument* inst,
01573 const char* prefix,
01574 cpl_frame** fluxcal_2D,
01575 cpl_frame** fluxcal_1D)
01576 {
01577 char file_tag[40];
01578 cpl_frame* nrm_1D=NULL;
01579 cpl_frame* nrm_2D=NULL;
01580
01581 sprintf(file_tag,"%s_NORM2D_%s",prefix,xsh_instrument_arm_tostring(inst));
01582 check(nrm_2D=xsh_normalize_spectrum(res2D,atmext,0,inst,file_tag));
01583 sprintf(file_tag,"%s_FLUXCAL2D_%s",prefix,xsh_instrument_arm_tostring(inst));
01584 check(*fluxcal_2D=xsh_util_multiply_by_response(nrm_2D,response,file_tag));
01585 sprintf(file_tag,"%s_NORM1D_%s",prefix,xsh_instrument_arm_tostring(inst));
01586 check(nrm_1D=xsh_normalize_spectrum(res1D,atmext,0,inst,file_tag));
01587 sprintf(file_tag,"%s_FLUXCAL1D_%s",prefix,xsh_instrument_arm_tostring(inst));
01588 check(*fluxcal_1D=xsh_util_multiply_by_response(nrm_1D,response,file_tag));
01589
01590 cleanup:
01591 xsh_free_frame(&nrm_1D);
01592 xsh_free_frame(&nrm_2D);
01593
01594 return cpl_error_get_code();
01595
01596 }
01597