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
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00039
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <xsh_error.h>
00051
00052 #include <xsh_utils_image.h>
00053 #include <xsh_msg.h>
00054
00055 #include <xsh_dfs.h>
00056 #include <xsh_pfits.h>
00057 #include <xsh_ifu_defs.h>
00058 #include <xsh_model_io.h>
00059
00060 #include <xsh_drl.h>
00061
00062 #include <cpl.h>
00063
00064
00065
00066
00067
00068
00069 #define RECIPE_ID "xsh_util_ifu_build_cube"
00070 #define RECIPE_AUTHOR "A. Modigliani"
00071 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 static int xsh_util_ifu_build_cube_create(cpl_plugin *);
00082 static int xsh_util_ifu_build_cube_exec(cpl_plugin *);
00083 static int xsh_util_ifu_build_cube_destroy(cpl_plugin *);
00084
00085
00086 static void xsh_util_ifu_build_cube(cpl_parameterlist *, cpl_frameset *);
00087
00088
00089
00090
00091 static char xsh_util_ifu_build_cube_description_short[] =
00092 "Produces the spatial geometry of the IFU pattern on the sky";
00093
00094 static char xsh_util_ifu_build_cube_description[] =
00095 "This recipe Produces the spatial geometry of the IFU pattern on the sky\n\
00096 Input Frames : \n\
00097 - A set of n Science frames ( n == 1 or >=3, \
00098 Tag = OBJECT_IFU_STARE_UVB)\n\
00099 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
00100 - A master dark frame (Tag = MASTER_DARK_arm)\n\
00101 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
00102 - An order table frame(Tag = ORDER_TABLE_arm)\n\
00103 - 3 wave solution frames, one per slitlet(Tag = WAVE_SOLUTION_IFU_slitlet_arm)\n\
00104 where 'slitlet' is DOWN, CEN or UP\n\
00105 - [OPTIONAL] A badpixel map (Tag = BADPIXEL_MAP_arm)\n\
00106 Products : \n\
00107 - A Slice Offset Table (similar to a localization table)\n\
00108 Tag = SLICE_OFFSET_TABLE_arm\n" ;
00109
00110
00111
00112
00113
00122
00123
00124 int cpl_plugin_get_info(cpl_pluginlist *list) {
00125 cpl_recipe *recipe = NULL;
00126 cpl_plugin *plugin = NULL;
00127
00128 recipe = cpl_calloc(1, sizeof(*recipe));
00129 if ( recipe == NULL ){
00130 return -1;
00131 }
00132
00133 plugin = &recipe->interface ;
00134
00135 cpl_plugin_init(plugin,
00136 CPL_PLUGIN_API,
00137 XSH_BINARY_VERSION,
00138 CPL_PLUGIN_TYPE_RECIPE,
00139 RECIPE_ID,
00140 xsh_util_ifu_build_cube_description_short,
00141 xsh_util_ifu_build_cube_description,
00142 RECIPE_AUTHOR,
00143 RECIPE_CONTACT,
00144 xsh_get_license(),
00145 xsh_util_ifu_build_cube_create,
00146 xsh_util_ifu_build_cube_exec,
00147 xsh_util_ifu_build_cube_destroy);
00148
00149 cpl_pluginlist_append(list, plugin);
00150
00151 return (cpl_error_get_code() != CPL_ERROR_NONE);
00152 }
00153
00154
00164
00165
00166 static int xsh_util_ifu_build_cube_create(cpl_plugin *plugin){
00167 cpl_recipe *recipe = NULL;
00168
00169
00170 xsh_init();
00171
00172
00173 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00174
00175
00176 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00177 CPL_ERROR_TYPE_MISMATCH,
00178 "Plugin is not a recipe");
00179
00180 recipe = (cpl_recipe *)plugin;
00181
00182
00183 recipe->parameters = cpl_parameterlist_new();
00184 assure( recipe->parameters != NULL,
00185 CPL_ERROR_ILLEGAL_OUTPUT,
00186 "Memory allocation failed!");
00187
00188
00189 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00190
00191
00192 cleanup:
00193 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00194 xsh_error_dump(CPL_MSG_ERROR);
00195 return 1;
00196 }
00197 else {
00198 return 0;
00199 }
00200 }
00201
00209
00210
00211
00217
00218
00219 static int xsh_util_ifu_build_cube_exec(cpl_plugin *plugin) {
00220 cpl_recipe *recipe = NULL;
00221
00222
00223
00224 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00225
00226
00227 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00228 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00229
00230 recipe = (cpl_recipe *)plugin;
00231
00232
00233 xsh_util_ifu_build_cube(recipe->parameters, recipe->frames);
00234
00235 cleanup:
00236 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00237 xsh_error_dump(CPL_MSG_ERROR);
00238 xsh_error_reset();
00239 return 1;
00240 }
00241 else {
00242 return 0;
00243 }
00244 }
00245
00246
00252
00253 static int xsh_util_ifu_build_cube_destroy(cpl_plugin *plugin)
00254 {
00255 cpl_recipe *recipe = NULL;
00256
00257
00258 xsh_error_reset();
00259
00260 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00261
00262
00263 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00264 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00265
00266 recipe = (cpl_recipe *)plugin;
00267
00268 xsh_free_parameterlist(&recipe->parameters);
00269
00270 cleanup:
00271 if (cpl_error_get_code() != CPL_ERROR_NONE)
00272 {
00273 return 1;
00274 }
00275 else
00276 {
00277 return 0;
00278 }
00279 }
00280
00281
00282
00283
00291
00292 static void xsh_util_ifu_build_cube(cpl_parameterlist* parameters,
00293 cpl_frameset* frameset)
00294 {
00295 const char* recipe_tags[1] = {XSH_RAW_IMA_IFU};
00296 int recipe_tags_size = 1;
00297
00298
00299 cpl_frameset *raws = NULL;
00300 cpl_frameset *calib = NULL;
00301
00302
00303
00304 cpl_frame *sci_frame=NULL;
00305 cpl_frame *spectral_format_frame = NULL;
00306 cpl_frame *model_config_frame = NULL ;
00307 cpl_frame *ifu_config_frame = NULL ;
00308
00309
00310 xsh_instrument* instrument=NULL;
00311 char rec_prefix[80];
00312
00313 cpl_image* data_img=NULL;
00314 cpl_image* errs_img=NULL;
00315 cpl_image* qual_img=NULL;
00316
00317 cpl_image* data_tmp=NULL;
00318 cpl_image* errs_tmp=NULL;
00319 cpl_image* qual_tmp=NULL;
00320 cpl_image* mask_tmp=NULL;
00321 cpl_frame* qc_trace_frame=NULL;
00322 cpl_frame* qc_trace_merged_frame=NULL;
00323 cpl_frame* frame_cube=NULL;
00324 cpl_frame* frame_merged_cube=NULL;
00325
00326
00327 cpl_propertylist* data_plist=NULL;
00328 cpl_propertylist* errs_plist=NULL;
00329 cpl_propertylist* qual_plist=NULL;
00330
00331
00332
00333
00334 XSH_ARM arm;
00335 xsh_xs_3 model_config ;
00336 xsh_rec_list * rec_list = NULL ;
00337
00338 cpl_table* ifu_cfg_tab=NULL;
00339 cpl_table* sp_fmt_tab=NULL;
00340 cpl_vector* profile=NULL;
00341 cpl_imagelist* data_cube=NULL;
00342 cpl_imagelist* errs_cube=NULL;
00343 cpl_imagelist* qual_cube=NULL;
00344
00345 cpl_imagelist* data_cube_merge=NULL;
00346 cpl_imagelist* errs_cube_merge=NULL;
00347 cpl_imagelist* qual_cube_merge=NULL;
00348 cpl_imagelist* mask_cube_merge=NULL;
00349
00350
00351 float* pima=NULL;
00352 float* perr=NULL;
00353 int* pqua=NULL;
00354 int* pmsk=NULL;
00355 int nord=0;
00356 int save_size_uvb=4;
00357 int save_size_vis=4;
00358 int save_size_nir=2;
00359 int save_size=0;
00360 const int peack_search_hsize=5;
00361 int method=0;
00362
00363 const char* sci_name=NULL;
00364 const char* sp_fmt_name=NULL;
00365 const char* ifu_cfg_name=NULL;
00366
00367
00368 char tag[256];
00369 char name[256];
00370
00371 int recipe_use_model=0;
00372
00373 int binx=1;
00374 int biny=1;
00375
00376 double flux_upp=0;
00377 double flux_cen=0;
00378 double flux_low=0;
00379
00380
00381 double errs_upp=0;
00382 double errs_cen=0;
00383 double errs_low=0;
00384 double cube_wave_min=0;
00385 double cube_wave_max=0;
00386
00387
00388 int qual_upp=0;
00389 int qual_cen=0;
00390 int qual_low=0;
00391
00392 double cube_wmin=550;
00393 double cube_wmax=1000;
00394 double cube_wstep=0;
00395 double cube_sstep=0;
00396
00397 int is=0;
00398
00399 int ord=0;
00400 int ord_min=0;
00401 int ord_max=0;
00402
00403 double wave=0;
00404 double wave_min=0;
00405 double wave_max=0;
00406 double wave_step=0;
00407
00408 double wave_min_old=0;
00409 double wave_max_old=0;
00410
00411 int nstep_off=0;
00412
00413 double s=0;
00414 double s_min=-2;
00415 double s_max=2;
00416 double s_step=0;
00417
00418 double x=0;
00419 double y=0;
00420 double s_upp=0;
00421 double s_low=0;
00422
00423
00424 int radius=4;
00425
00426 double confidence=0;
00427 int naxis1=0;
00428 int naxis2=0;
00429 int naxis3=0;
00430 int ik=0;
00431
00432
00433
00434
00435
00436
00437
00438
00439 double w_low_coeff1=0;
00440 double w_low_coeff2=0;
00441
00442 double w_upp_coeff1=0;
00443 double w_upp_coeff2=0;
00444
00445 double w_low_coeff1_uvb=-0.002972;
00446 double w_low_coeff2_uvb=2.26497e-6;
00447 double w_upp_coeff1_uvb=8.3355331e-5;
00448 double w_upp_coeff2_uvb=-1.0682e-6;
00449
00450
00451
00452 double w_low_coeff1_vis=-0.0016549569;
00453 double w_low_coeff2_vis=1.183805e-6;
00454 double w_upp_coeff1_vis=-0.0016610719;
00455 double w_upp_coeff2_vis=1.0823013e-6;
00456
00457 double w_low_coeff1_nir=0;
00458 double w_low_coeff2_nir=0;
00459 double w_upp_coeff1_nir=0;
00460 double w_upp_coeff2_nir=0;
00461
00462 double s_upp_off_uvb=4.0514429+0.16;
00463 double s_upp_off_vis=5.2504895+0.16;
00464 double s_upp_off_nir=3.5452+0.31;
00465 double s_upp_off=0;
00466
00467 double s_low_off_uvb=-3.4636662+0.16;
00468 double s_low_off_vis=-2.9428071+0.16;
00469 double s_low_off_nir=-4.451682+0.21;
00470 double s_low_off=0;
00471
00472 int w_step_fct=10;
00473
00474 int status=0;
00475 int mk=0;
00476
00477
00478
00479
00480 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00481 recipe_tags, recipe_tags_size,RECIPE_ID,
00482 XSH_BINARY_VERSION,
00483 xsh_util_ifu_build_cube_description_short));
00484
00485 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
00486 "Instrument NOT in IFU Mode");
00487
00488
00489 check(strcpy(rec_prefix,
00490 xsh_set_recipe_file_prefix(raws,"xsh_util_ifu_build_cube")));
00491
00492
00493
00494 check(sci_frame = xsh_find_frame_with_tag(raws,XSH_RAW_IMA_IFU, instrument));
00495
00496
00497 check( spectral_format_frame = xsh_find_frame_with_tag( calib,
00498 XSH_SPECTRAL_FORMAT,
00499 instrument));
00500
00501
00502
00503 check(model_config_frame = xsh_find_model_config( calib, instrument));
00504
00505 check(ifu_config_frame=xsh_find_frame_with_tag(calib,XSH_IFU_CFG_TAB,instrument));
00506
00507
00508
00509
00510
00511 recipe_use_model = ( model_config_frame != NULL);
00512
00513
00514
00515
00516
00517 sci_name=cpl_frame_get_filename(sci_frame);
00518 data_plist=cpl_propertylist_load(sci_name,0);
00519 arm=instrument->arm;
00520
00521
00522
00523
00524 if(arm == XSH_ARM_UVB) {
00525 cube_wmin=300;
00526 cube_wmax=550;
00527 cube_wstep=XSH_WAVE_BIN_SIZE_NARROW_SLIT_UVB; ;
00528 cube_sstep=XSH_SLIT_BIN_SIZE_NARROW_SLIT_UVB;
00529 binx=xsh_pfits_get_binx(data_plist);
00530 biny=xsh_pfits_get_biny(data_plist);
00531
00532 s_low_off=s_low_off_uvb;
00533 s_upp_off=s_upp_off_uvb;
00534 w_low_coeff1=w_low_coeff1_uvb;
00535 w_low_coeff2=w_low_coeff2_uvb;
00536
00537 w_upp_coeff1=w_upp_coeff1_uvb;
00538 w_upp_coeff2=w_upp_coeff2_uvb;
00539 save_size=save_size_uvb;
00540
00541
00542
00543 } else if(arm == XSH_ARM_VIS) {
00544 cube_wmin=550;
00545 cube_wmax=1000;
00546 cube_wstep=XSH_WAVE_BIN_SIZE_NARROW_SLIT_VIS;
00547 cube_sstep=XSH_SLIT_BIN_SIZE_NARROW_SLIT_VIS;
00548
00549 binx=xsh_pfits_get_binx(data_plist);
00550 biny=xsh_pfits_get_biny(data_plist);
00551
00552 s_low_off=s_low_off_vis;
00553 s_upp_off=s_upp_off_vis;
00554
00555 w_low_coeff1=w_low_coeff1_vis;
00556 w_low_coeff2=w_low_coeff2_vis;
00557
00558 w_upp_coeff1=w_upp_coeff1_vis;
00559 w_upp_coeff2=w_upp_coeff2_vis;
00560 save_size=save_size_vis;
00561
00562
00563 } else if(arm == XSH_ARM_NIR) {
00564 cube_wmin=1000;
00565 cube_wmax=2500;
00566 cube_wstep=XSH_WAVE_BIN_SIZE_NARROW_SLIT_NIR; ;
00567 cube_sstep=XSH_SLIT_BIN_SIZE_NARROW_SLIT_NIR;
00568
00569
00570 s_low_off=s_low_off_nir;
00571 s_upp_off=s_upp_off_nir;
00572
00573
00574 w_low_coeff1=w_low_coeff1_nir;
00575 w_low_coeff2=w_low_coeff2_nir;
00576
00577 w_upp_coeff1=w_upp_coeff1_nir;
00578 w_upp_coeff2=w_upp_coeff2_nir;
00579 save_size=save_size_nir;
00580
00581 }
00582
00583
00584
00585 if(ifu_config_frame) {
00586
00587 ifu_cfg_name=cpl_frame_get_filename(ifu_config_frame);
00588 ifu_cfg_tab=cpl_table_load(ifu_cfg_name,1,0);
00589 s_upp_off=cpl_table_get_double(ifu_cfg_tab,"S_UPP_OFF",arm,&status);
00590 s_low_off=cpl_table_get_double(ifu_cfg_tab,"S_LOW_OFF",arm,&status);
00591
00592 w_upp_coeff1=cpl_table_get_double(ifu_cfg_tab,"W_UPP_COEF1",arm,&status);
00593 w_low_coeff1=cpl_table_get_double(ifu_cfg_tab,"W_LOW_COEF1",arm,&status);
00594 w_upp_coeff2=cpl_table_get_double(ifu_cfg_tab,"W_UPP_COEF2",arm,&status);
00595 w_low_coeff2=cpl_table_get_double(ifu_cfg_tab,"W_LOW_COEF2",arm,&status);
00596
00597 w_step_fct=cpl_table_get_int(ifu_cfg_tab,"W_STEP_FCT",arm,&status);
00598 xsh_msg("s_upp_off=%10.8g",s_upp_off);
00599 xsh_msg("s_low_off=%10.8g",s_low_off);
00600
00601
00602 xsh_msg("w_upp_coeff1=%10.8g",w_upp_coeff1);
00603 xsh_msg("w_upp_coeff2=%10.8g",w_upp_coeff2);
00604 xsh_msg("w_low_coeff1=%10.8g",w_low_coeff1);
00605 xsh_msg("w_low_coeff2=%10.8g",w_low_coeff2);
00606
00607 xsh_msg("w_step_fct=%d",w_step_fct);
00608
00609 }
00610 cube_wstep*=w_step_fct; ;
00611
00612 check( xsh_model_config_load_best( model_config_frame, &model_config));
00613 xsh_model_binxy(&model_config,binx,biny);
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626 check( rec_list = xsh_rec_list_create( instrument));
00627 check( profile = cpl_vector_new( CPL_KERNEL_DEF_SAMPLES));
00628 check(cpl_vector_fill_kernel_profile( profile,CPL_KERNEL_DEFAULT,
00629 CPL_KERNEL_DEF_WIDTH));
00630 check(sci_name=cpl_frame_get_filename(sci_frame));
00631 check(data_img=cpl_image_load(sci_name,XSH_PRE_DATA_TYPE,0,0));
00632 check(errs_img=cpl_image_load(sci_name,XSH_PRE_ERRS_TYPE,0,1));
00633 check(qual_img=cpl_image_load(sci_name,XSH_PRE_QUAL_TYPE,0,2));
00634
00635 check(sp_fmt_name=cpl_frame_get_filename(spectral_format_frame));
00636 check(sp_fmt_tab=cpl_table_load(sp_fmt_name,1,0));
00637 check(ord_min=cpl_table_get_column_min(sp_fmt_tab,"ORDER"));
00638 check(ord_max=cpl_table_get_column_max(sp_fmt_tab,"ORDER"));
00639 nord=ord_max-ord_min+1;
00640
00641 check(cube_wave_min=cpl_table_get(sp_fmt_tab,"WLMIN",nord-1,&status));
00642 check(cube_wave_max=cpl_table_get(sp_fmt_tab,"WLMAX",0,&status));
00643
00644 xsh_msg("cube_wave_min=%10.8g cube_wave_max=%10.8g",cube_wave_min,cube_wave_max);
00645
00646
00647 naxis1=3;
00648 xsh_msg("ord_min=%d ord_max=%d",ord_min,ord_max);
00649 wave_step= cube_wstep;
00650 s_step= cube_sstep;
00651 xsh_free_imagelist(&data_cube_merge);
00652 xsh_free_imagelist(&errs_cube_merge);
00653 xsh_free_imagelist(&qual_cube_merge);
00654 xsh_free_imagelist(&mask_cube_merge);
00655
00656 data_cube_merge=cpl_imagelist_new();
00657 errs_cube_merge=cpl_imagelist_new();
00658 qual_cube_merge=cpl_imagelist_new();
00659 mask_cube_merge=cpl_imagelist_new();
00660
00661
00662 xsh_free_image(&data_tmp);
00663 xsh_free_image(&errs_tmp);
00664 xsh_free_image(&qual_tmp);
00665 xsh_free_image(&mask_tmp);
00666
00667 mk=0;
00668 for( ord = ord_max; ord >= ord_min; ord-- ) {
00669
00670 naxis2=(int)((s_max-s_min)/s_step+0.5)+1;
00671 xsh_free_imagelist(&data_cube);
00672 xsh_free_imagelist(&errs_cube);
00673 xsh_free_imagelist(&qual_cube);
00674
00675 data_cube=cpl_imagelist_new();
00676 errs_cube=cpl_imagelist_new();
00677 qual_cube=cpl_imagelist_new();
00678
00679
00680 data_tmp=cpl_image_new(naxis1,naxis2,XSH_PRE_DATA_TYPE);
00681 errs_tmp=cpl_image_new(naxis1,naxis2,XSH_PRE_ERRS_TYPE);
00682 qual_tmp=cpl_image_new(naxis1,naxis2,XSH_PRE_QUAL_TYPE);
00683 mask_tmp=cpl_image_new(naxis1,naxis2,XSH_PRE_QUAL_TYPE);
00684
00685 check(pima=cpl_image_get_data_float(data_tmp));
00686 check(perr=cpl_image_get_data_float(errs_tmp));
00687 check(pqua=cpl_image_get_data_int(qual_tmp));
00688 check(pmsk=cpl_image_get_data_int(mask_tmp));
00689
00690
00691
00692 check(wave_min=cpl_table_get(sp_fmt_tab,"WLMIN",ord-ord_min,&status));
00693 check(wave_max=cpl_table_get(sp_fmt_tab,"WLMAX",ord-ord_min,&status));
00694
00695 naxis3=(wave_max-wave_min)/wave_step+1;
00696 xsh_msg("order=%d naxis1=%d,naxis2=%d naxis3=%d, wave_min=%g wave_max=%g",
00697 ord,naxis1,naxis2,naxis3,wave_min,wave_max);
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 if(ord<ord_max) {
00719
00720
00721
00722
00723 nstep_off=(int)((wave_min-wave_min_old)/wave_step+0.5);
00724
00725
00726
00727
00728
00729 wave_min=wave_min_old+nstep_off*wave_step;
00730
00731
00732
00733
00734
00735
00736 }
00737
00738 ik=0;
00739
00740 for( wave = wave_min; wave <= wave_max; wave+=wave_step) {
00741 is=0;
00742 for( s = s_min; s <= s_max; s+=s_step ) {
00743
00744
00745
00746
00747
00748 s_upp=-s+s_upp_off+w_upp_coeff1*wave+w_upp_coeff2*wave*wave;
00749
00750 check(xsh_model_get_xy(&model_config,instrument,wave,ord,s_upp,
00751 &x,&y));
00752 check(flux_upp=cpl_image_get_interpolated(data_img,x,y,
00753 profile,radius,
00754 profile,radius,
00755 &confidence));
00756 check(errs_upp=cpl_image_get_interpolated(errs_img,x,y,
00757 profile,radius,
00758 profile,radius,
00759 &confidence));
00760 check(qual_upp=cpl_image_get_interpolated(qual_img,x,y,
00761 profile,radius,
00762 profile,radius,
00763 &confidence));
00764
00765 pima[is*naxis1+0]=flux_upp;
00766 perr[is*naxis1+0]=errs_upp;
00767 pqua[is*naxis1+0]=qual_upp;
00768 pmsk[is*naxis1+0]=1;
00769
00770
00771
00772
00773
00774 check(xsh_model_get_xy(&model_config,instrument,wave,ord,s,&x,&y));
00775 check(flux_cen=cpl_image_get_interpolated(data_img,x,y,
00776 profile,radius,
00777 profile,radius,
00778 &confidence));
00779
00780 check(errs_cen=cpl_image_get_interpolated(errs_img,x,y,
00781 profile,radius,
00782 profile,radius,
00783 &confidence));
00784
00785 check(qual_cen=cpl_image_get_interpolated(qual_img,x,y,
00786 profile,radius,
00787 profile,radius,
00788 &confidence));
00789
00790 pima[is*naxis1+1]=flux_cen;
00791 perr[is*naxis1+1]=errs_cen;
00792 pqua[is*naxis1+1]=qual_cen;
00793 pmsk[is*naxis1+1]=1;
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803 s_low=-s+s_low_off+w_low_coeff1*wave+w_low_coeff2*wave*wave;
00804 check(xsh_model_get_xy(&model_config,instrument,wave,ord,s_low,
00805 &x,&y));
00806
00807 check(flux_low=cpl_image_get_interpolated(data_img,x,y,
00808 profile,radius,
00809 profile,radius,
00810 &confidence));
00811 check(errs_low=cpl_image_get_interpolated(errs_img,x,y,
00812 profile,radius,
00813 profile,radius,
00814 &confidence));
00815 check(qual_low=cpl_image_get_interpolated(qual_img,x,y,
00816 profile,radius,
00817 profile,radius,
00818 &confidence));
00819
00820 pima[is*naxis1+2]=flux_low;
00821 perr[is*naxis1+2]=errs_low;
00822 pqua[is*naxis1+2]=qual_low;
00823 pmsk[is*naxis1+2]=1;
00824
00825
00826 is++;
00827 }
00828 wave_max_old=wave_max;
00829 wave_min_old=wave_min;
00830
00831 check(cpl_imagelist_set(data_cube,cpl_image_duplicate(data_tmp),ik));
00832 check(cpl_imagelist_set(errs_cube,cpl_image_duplicate(errs_tmp),ik));
00833 check(cpl_imagelist_set(qual_cube,cpl_image_duplicate(qual_tmp),ik));
00834
00835
00836
00837
00838 check(xsh_iml_merge_avg(&data_cube_merge,&mask_cube_merge,
00839 data_tmp,mask_tmp,mk));
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 ik++;
00859 if(ord==ord_max) {
00860 mk++;
00861 } else {
00862 mk=(int)((wave-cube_wave_min)/wave_step+0.5);
00863 }
00864 }
00865 xsh_msg("mk=%d",mk);
00866 sprintf(tag,"CUBE_DATA_IFU_%s",xsh_arm_tostring(arm));
00867 sprintf(name,"%s_%2.2d.fits",tag,ord);
00868
00869 xsh_pfits_set_crval1(data_plist,wave_min);
00870 xsh_pfits_set_cdelt1(data_plist,wave_step);
00871
00872 cpl_imagelist_save(data_cube,name,CPL_BPP_IEEE_FLOAT,data_plist,CPL_IO_DEFAULT);
00873
00874 xsh_free_frame(&frame_cube);
00875 frame_cube=xsh_frame_product(name,tag,CPL_FRAME_TYPE_IMAGE,CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL);
00876 xsh_free_frame(&qc_trace_frame);
00877 sprintf(tag,"ORD%2.2d",ord);
00878 check(qc_trace_frame=xsh_cube_qc_trace_window(frame_cube,instrument,tag,
00879 RECIPE_ID,
00880 save_size+1,
00881 naxis2-save_size,
00882 peack_search_hsize,method));
00883
00884
00885
00886
00887
00888
00889 sprintf(tag,"CUBE_ERRS_IFU_%s",xsh_arm_tostring(arm));
00890 sprintf(name,"%s_%2.2d.fits",tag,ord);
00891 cpl_imagelist_save(errs_cube,name,CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
00892
00893 sprintf(tag,"CUBE_QUAL_IFU_%s",xsh_arm_tostring(arm));
00894 sprintf(name,"%s_%2.2d.fits",tag,ord);
00895 cpl_imagelist_save(qual_cube,name,CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
00896
00897
00898 sprintf(name,"QC%s_%2.2d.fits",tag,ord);
00899
00900
00901 xsh_free_image(&data_tmp);
00902 xsh_free_image(&errs_tmp);
00903 xsh_free_image(&qual_tmp);
00904 xsh_free_image(&mask_tmp);
00905
00906 }
00907
00908 sprintf(tag,"MERGE_CUBE_DATA_IFU_%s",xsh_arm_tostring(arm));
00909 sprintf(name,"%s.fits",tag);
00910 xsh_pfits_set_crval1(data_plist,cube_wave_min);
00911 xsh_pfits_set_cdelt1(data_plist,wave_step);
00912
00913 cpl_imagelist_save(data_cube_merge,name,CPL_BPP_IEEE_FLOAT,data_plist,CPL_IO_DEFAULT);
00914
00915
00916 xsh_msg("merge cube size=%d",cpl_imagelist_get_size(data_cube_merge));
00917
00918 frame_merged_cube=xsh_frame_product(name,tag,CPL_FRAME_TYPE_IMAGE,
00919 CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL);
00920
00921 xsh_add_product_imagelist(frame_merged_cube,frameset,parameters,RECIPE_ID,
00922 instrument,tag);
00923
00924 check(qc_trace_merged_frame=xsh_cube_qc_trace_window(frame_merged_cube,instrument,
00925 "MERGED", RECIPE_ID,
00926 save_size+1,
00927 naxis2-save_size,
00928 peack_search_hsize,method));
00929
00930 check( xsh_add_product_table_multi( qc_trace_merged_frame, frameset,
00931 parameters, RECIPE_ID, instrument));
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964 cleanup:
00965 xsh_msg("cleanup");
00966 xsh_end( RECIPE_ID, frameset, parameters );
00967
00968 xsh_free_propertylist(&data_plist);
00969 xsh_free_propertylist(&errs_plist);
00970 xsh_free_propertylist(&qual_plist);
00971 xsh_free_vector(&profile);
00972
00973 xsh_free_image(&data_tmp);
00974 xsh_free_image(&errs_tmp);
00975 xsh_free_image(&qual_tmp);
00976 xsh_free_image(&mask_tmp);
00977
00978 xsh_free_image(&data_img);
00979 xsh_free_image(&errs_img);
00980 xsh_free_image(&qual_img);
00981
00982
00983 xsh_free_table(&sp_fmt_tab);
00984
00985 xsh_free_imagelist(&data_cube);
00986 xsh_free_imagelist(&errs_cube);
00987 xsh_free_imagelist(&qual_cube);
00988
00989
00990 xsh_free_imagelist(&data_cube_merge);
00991 xsh_free_imagelist(&errs_cube_merge);
00992 xsh_free_imagelist(&qual_cube_merge);
00993 xsh_free_imagelist(&mask_cube_merge);
00994
00995 xsh_rec_list_free(&rec_list);
00996 xsh_free_frame(&qc_trace_frame);
00997 xsh_free_frame(&qc_trace_merged_frame);
00998 xsh_free_frame(&frame_cube);
00999 xsh_free_frame(&frame_merged_cube);
01000
01001
01002
01003
01004
01005 xsh_instrument_free( &instrument);
01006 xsh_free_frameset( &raws);
01007 xsh_free_frameset( &calib);
01008
01009
01010 return;
01011 }
01012