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
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "crires_recipe.h"
00037
00038 #include "crires_model_kernel.h"
00039 #include "crires_combine.h"
00040 #include "crires_extract.h"
00041 #include "crires_photom.h"
00042 #include "crires_wlcalib.h"
00043
00044
00045
00046
00047
00048 #define RECIPE_STRING "crires_spec_astro"
00049
00050
00051
00052
00053
00054 static int crires_spec_astro_compare(const cpl_frame *, const cpl_frame *) ;
00055 static cpl_imagelist ** crires_spec_astro_reduce(cpl_frameset *,
00056 const char *, const char *, const char *, const char *, const char *,
00057 const char *, const char *, const char *, cpl_imagelist **,
00058 cpl_imagelist **, cpl_imagelist **, cpl_imagelist **,
00059 cpl_table **, cpl_table **, cpl_table **, cpl_table **) ;
00060 static int crires_spec_astro_save(const cpl_imagelist **,
00061 const cpl_imagelist *, const cpl_imagelist *, const cpl_table **,
00062 const cpl_imagelist *, const cpl_imagelist *, int,
00063 const cpl_frameset *, const cpl_parameterlist *, cpl_frameset *) ;
00064
00065 static char crires_spec_astro_description[] =
00066 "crires_spec_astro -- Astrometry recipe\n"
00067 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00068 "raw-file.fits "CRIRES_SPEC_ASTRO_RAW" or\n"
00069 "flat-file.fits "CRIRES_CALPRO_FLAT" or\n"
00070 "bpm-file.fits "CRIRES_CALPRO_BPM" or\n"
00071 "dark-file.fits "CRIRES_CALPRO_DARK" or\n"
00072 "detlin-file.fits "CRIRES_CALPRO_COEFFS_CUBE" or\n"
00073 "wavecal-file.fits "CRIRES_CALPRO_WAVE" or\n"
00074 "catalog-file.fits "CRIRES_CALPRO_OH_CAT" or\n"
00075 "catalog-file.fits "CRIRES_CALPRO_HITRAN_CAT" or\n"
00076 "model-config-file.fits "CRIRES_CALPRO_MODEL_CONFIG".\n"
00077 "\n"
00078 "The input data set is a series of nodding observations using different\n"
00079 " derotator position angles. The data are reduced separately for each\n"
00080 " of those positions. In order not to degrade the instrument high\n"
00081 " resolution, the combined images using only NODA or NODB nodding\n"
00082 " positions can be produced on request. (see --onlyA/B)\n"
00083 " In this case, the following spectrum extraction can be applied \n"
00084 " either on the usual combined image or on those NODA/B combined\n"
00085 " images (see --comb_used).\n"
00086 "\n"
00087 "This recipe produces 6 to 11 files per rotation angle:\n"
00088 " The combined image (PRO TYPE = "CRIRES_PROTYPE_COMBINED")\n"
00089 " The contribution map (PRO TYPE = "CRIRES_PROTYPE_CONTRIB")\n"
00090 " The combined image using only Nodding A frames (optional)\n"
00091 " (PRO TYPE = "CRIRES_PROTYPE_COMBINED")\n"
00092 " The contribution map using only Nodding A frames (optional)\n"
00093 " (PRO TYPE = "CRIRES_PROTYPE_CONTRIB")\n"
00094 " The combined image using only Nodding B frames (optional)\n"
00095 " (PRO TYPE = "CRIRES_PROTYPE_COMBINED")\n"
00096 " The contribution map using only Nodding B frames (optional)\n"
00097 " (PRO TYPE = "CRIRES_PROTYPE_CONTRIB")\n"
00098 " The table with the extracted spectrum\n"
00099 " (PRO TYPE = "CRIRES_PROTYPE_SPEC_WL")\n"
00100 " The profile image (PRO TYPE = "CRIRES_PROTYPE_PROFILE")\n"
00101 " The background map (PRO TYPE = "CRIRES_PROTYPE_BGD_MAP")\n"
00102 " The wavelength map (PRO TYPE = "CRIRES_PROTYPE_WL_MAP")\n"
00103 " The wavelength map from the model (optional)\n"
00104 " (PRO TYPE = "CRIRES_PROTYPE_WL_MAP")\n" ;
00105
00106 CRIRES_RECIPE_DEFINE(crires_spec_astro,
00107 CRIRES_PARAM_WAVES |
00108 CRIRES_PARAM_DISPLAY |
00109 CRIRES_PARAM_REFINE |
00110 CRIRES_PARAM_ONLYA |
00111 CRIRES_PARAM_ONLYB |
00112 CRIRES_PARAM_COMB_USED |
00113 CRIRES_PARAM_BLIND |
00114 CRIRES_PARAM_HOR_SIZE |
00115 CRIRES_PARAM_SPEC_HSIZE |
00116 CRIRES_PARAM_KAPPA |
00117 CRIRES_PARAM_CLOSING_HSIZE |
00118 CRIRES_PARAM_CLEAN_RATE |
00119 CRIRES_PARAM_REJECT |
00120 CRIRES_PARAM_SPEC_ZONE |
00121 CRIRES_PARAM_WL_ERROR |
00122 CRIRES_PARAM_XC_LIMIT |
00123 CRIRES_PARAM_WL_LOG |
00124 CRIRES_PARAM_WL_NOLIMIT |
00125 CRIRES_PARAM_WL_NBSAMPLES |
00126 CRIRES_PARAM_WL_STARTY |
00127 CRIRES_PARAM_WL_STOPY |
00128 CRIRES_PARAM_DEGREE |
00129 CRIRES_PARAM_WL_CLEAN,
00130 "Astrometry recipe",
00131 crires_spec_astro_description) ;
00132
00133
00134
00135
00136
00137 static struct {
00138
00139 int comb_blind ;
00140 int comb_refine ;
00141 int comb_onlyA ;
00142 int comb_onlyB ;
00143 crires_comb_method comb_used ;
00144 double wstart[CRIRES_NB_DETECTORS] ;
00145 double wstop[CRIRES_NB_DETECTORS] ;
00146 int wl_nolimit ;
00147 int wl_log ;
00148 int wl_starty ;
00149 int wl_stopy ;
00150 double wl_fwhm ;
00151 double wl_slitw ;
00152 int wl_degree ;
00153 double wl_err ;
00154 int wl_samples ;
00155 int wl_clean ;
00156 double wl_xclimit ;
00157 int wl_ppm ;
00158 int extr_box_hor_size ;
00159 int extr_spec_hsize ;
00160 double extr_kappa ;
00161 int extr_closing_hs ;
00162 int extr_clean_rate ;
00163 int extr_rej_left ;
00164 int extr_rej_right ;
00165 int extr_spec_starty ;
00166 int extr_spec_stopy ;
00167 int display ;
00168
00169 crires_illum_period period ;
00170 int qc_specpos[CRIRES_NB_DETECTORS] ;
00171 int qc_specwrec[CRIRES_NB_DETECTORS] ;
00172 int qc_specwopt[CRIRES_NB_DETECTORS] ;
00173 double qc_specoptmed[CRIRES_NB_DETECTORS] ;
00174 double qc_s2nmed[CRIRES_NB_DETECTORS] ;
00175 double qc_wlxc[CRIRES_NB_DETECTORS] ;
00176 double qc_wlcent[CRIRES_NB_DETECTORS] ;
00177 double qc_wldisp[CRIRES_NB_DETECTORS] ;
00178 double qc_fwhm_comb_pix[CRIRES_NB_DETECTORS] ;
00179 double qc_fwhm_comb_as[CRIRES_NB_DETECTORS] ;
00180 double qc_fwhm_prof_pix[CRIRES_NB_DETECTORS] ;
00181 double qc_fwhm_prof_as[CRIRES_NB_DETECTORS] ;
00182 double qc_fwhm_diff[CRIRES_NB_DETECTORS] ;
00183 } crires_spec_astro_config ;
00184
00185
00186
00187
00188
00189
00196
00197 static int crires_spec_astro(
00198 cpl_frameset * frameset,
00199 const cpl_parameterlist * parlist)
00200 {
00201 cpl_frameset * raw_one ;
00202 const char * sval ;
00203 cpl_frameset * rawframes ;
00204 const char * flat ;
00205 const char * dark ;
00206 const char * bpm ;
00207 const char * detlin ;
00208 const char * wavecal ;
00209 const char * oh_cat ;
00210 const char * hitran_cat ;
00211 const char * cfg_model ;
00212 int * labels ;
00213 int nlabels ;
00214 cpl_imagelist ** comblist ;
00215 cpl_table * extr_tab[CRIRES_NB_DETECTORS] ;
00216 cpl_imagelist * prof_list ;
00217 cpl_imagelist * bgmap_list ;
00218 cpl_imagelist * wl_map ;
00219 cpl_imagelist * wl_map_model ;
00220 int i, j ;
00221
00222
00223 rawframes = NULL ;
00224 crires_spec_astro_config.wl_ppm = 0 ;
00225 crires_spec_astro_config.wl_slitw = 2.0 ;
00226 crires_spec_astro_config.wl_fwhm = 2.0 ;
00227
00228
00229 crires_spec_astro_config.display = crires_parameterlist_get_int(parlist,
00230 RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00231 crires_spec_astro_config.comb_refine = crires_parameterlist_get_bool(
00232 parlist, RECIPE_STRING, CRIRES_PARAM_REFINE) ;
00233 crires_spec_astro_config.comb_onlyA = crires_parameterlist_get_bool(
00234 parlist, RECIPE_STRING, CRIRES_PARAM_ONLYA) ;
00235 crires_spec_astro_config.comb_onlyB = crires_parameterlist_get_bool(
00236 parlist, RECIPE_STRING, CRIRES_PARAM_ONLYB) ;
00237 sval = crires_parameterlist_get_string(parlist, RECIPE_STRING,
00238 CRIRES_PARAM_COMB_USED) ;
00239 if (!strcmp(sval, "NODA"))
00240 crires_spec_astro_config.comb_used = CRIRES_COMB_METHOD_NODA ;
00241 else if (!strcmp(sval, "NODB"))
00242 crires_spec_astro_config.comb_used = CRIRES_COMB_METHOD_NODB ;
00243 else if (!strcmp(sval, "COMB"))
00244 crires_spec_astro_config.comb_used = CRIRES_COMB_METHOD_COMB ;
00245 else {
00246 cpl_msg_error(__func__, "Invalid combination method specified");
00247 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00248 return -1;
00249 }
00250 crires_spec_astro_config.comb_blind = crires_parameterlist_get_bool(
00251 parlist, RECIPE_STRING, CRIRES_PARAM_BLIND) ;
00252 sval = crires_parameterlist_get_string(parlist, RECIPE_STRING,
00253 CRIRES_PARAM_WAVES) ;
00254 if (sscanf(sval, "%lg,%lg,%lg,%lg,%lg,%lg,%lg,%lg",
00255 &crires_spec_astro_config.wstart[0],
00256 &crires_spec_astro_config.wstop[0],
00257 &crires_spec_astro_config.wstart[1],
00258 &crires_spec_astro_config.wstop[1],
00259 &crires_spec_astro_config.wstart[2],
00260 &crires_spec_astro_config.wstop[2],
00261 &crires_spec_astro_config.wstart[3],
00262 &crires_spec_astro_config.wstop[3])!=2*CRIRES_NB_DETECTORS){
00263 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00264 return -1 ;
00265 }
00266 crires_spec_astro_config.wl_log = crires_parameterlist_get_bool(parlist,
00267 RECIPE_STRING, CRIRES_PARAM_WL_LOG) ;
00268 crires_spec_astro_config.wl_nolimit = crires_parameterlist_get_bool(
00269 parlist, RECIPE_STRING, CRIRES_PARAM_WL_NOLIMIT) ;
00270 crires_spec_astro_config.wl_degree = crires_parameterlist_get_int(parlist,
00271 RECIPE_STRING, CRIRES_PARAM_DEGREE) ;
00272 crires_spec_astro_config.wl_err = crires_parameterlist_get_double(parlist,
00273 RECIPE_STRING, CRIRES_PARAM_WL_ERROR) ;
00274 crires_spec_astro_config.wl_xclimit = crires_parameterlist_get_double(
00275 parlist, RECIPE_STRING, CRIRES_PARAM_XC_LIMIT) ;
00276 crires_spec_astro_config.wl_samples = crires_parameterlist_get_int(parlist,
00277 RECIPE_STRING, CRIRES_PARAM_WL_NBSAMPLES) ;
00278 crires_spec_astro_config.wl_clean = crires_parameterlist_get_bool(parlist,
00279 RECIPE_STRING, CRIRES_PARAM_WL_CLEAN) ;
00280 crires_spec_astro_config.wl_starty = crires_parameterlist_get_int(parlist,
00281 RECIPE_STRING, CRIRES_PARAM_WL_STARTY) ;
00282 crires_spec_astro_config.wl_stopy = crires_parameterlist_get_int(parlist,
00283 RECIPE_STRING, CRIRES_PARAM_WL_STOPY) ;
00284 crires_spec_astro_config.extr_box_hor_size = crires_parameterlist_get_int(
00285 parlist, RECIPE_STRING, CRIRES_PARAM_HOR_SIZE) ;
00286 crires_spec_astro_config.extr_spec_hsize = crires_parameterlist_get_int(
00287 parlist, RECIPE_STRING, CRIRES_PARAM_SPEC_HSIZE) ;
00288 crires_spec_astro_config.extr_kappa = crires_parameterlist_get_double(
00289 parlist, RECIPE_STRING, CRIRES_PARAM_KAPPA) ;
00290 crires_spec_astro_config.extr_closing_hs = crires_parameterlist_get_int(
00291 parlist, RECIPE_STRING, CRIRES_PARAM_CLOSING_HSIZE) ;
00292 crires_spec_astro_config.extr_clean_rate = crires_parameterlist_get_double(
00293 parlist, RECIPE_STRING, CRIRES_PARAM_CLEAN_RATE) ;
00294 sval = crires_parameterlist_get_string(parlist, RECIPE_STRING,
00295 CRIRES_PARAM_REJECT) ;
00296 if (sscanf(sval, "%d,%d",
00297 &crires_spec_astro_config.extr_rej_left,
00298 &crires_spec_astro_config.extr_rej_right)!=2) {
00299 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00300 return -1 ;
00301 }
00302 sval = crires_parameterlist_get_string(parlist, RECIPE_STRING,
00303 CRIRES_PARAM_SPEC_ZONE) ;
00304 if (sscanf(sval, "%d,%d",
00305 &crires_spec_astro_config.extr_spec_starty,
00306 &crires_spec_astro_config.extr_spec_stopy)!=2) {
00307 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00308 return -1 ;
00309 }
00310
00311
00312 if (crires_dfs_set_groups(frameset, "crires_spec_astro")) {
00313 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00314 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00315 return -1 ;
00316 }
00317
00318
00319 flat = crires_extract_filename(frameset, CRIRES_CALPRO_FLAT) ;
00320 dark = crires_extract_filename(frameset, CRIRES_CALPRO_DARK) ;
00321 bpm = crires_extract_filename(frameset, CRIRES_CALPRO_BPM) ;
00322 detlin = crires_extract_filename(frameset, CRIRES_CALPRO_COEFFS_CUBE) ;
00323 wavecal = crires_extract_filename(frameset, CRIRES_CALPRO_WAVE) ;
00324 oh_cat = crires_extract_filename(frameset, CRIRES_CALPRO_OH_CAT) ;
00325 hitran_cat = crires_extract_filename(frameset, CRIRES_CALPRO_HITRAN_CAT) ;
00326 cfg_model = crires_extract_filename(frameset, CRIRES_CALPRO_MODEL_CONFIG);
00327
00328
00329 if ((rawframes = crires_extract_frameset(frameset,
00330 CRIRES_SPEC_ASTRO_RAW)) == NULL) {
00331 cpl_msg_error(__func__, "No raw frame in input") ;
00332 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00333 return -1 ;
00334 }
00335
00336
00337 if ((crires_spec_astro_config.comb_used == CRIRES_COMB_METHOD_NODA)
00338 && (crires_spec_astro_config.comb_onlyA == 0)) {
00339 cpl_msg_warning(__func__,
00340 "You forgot to require the NODA image to be produced !") ;
00341 crires_spec_astro_config.comb_onlyA = 1 ;
00342 }
00343 if ((crires_spec_astro_config.comb_used == CRIRES_COMB_METHOD_NODB)
00344 && (crires_spec_astro_config.comb_onlyB == 0)) {
00345 cpl_msg_warning(__func__,
00346 "You forgot to require the NODB image to be produced !") ;
00347 crires_spec_astro_config.comb_onlyB = 1 ;
00348 }
00349
00350
00351 crires_spec_astro_config.period =
00352 crires_get_detector_illum_period(
00353 cpl_frame_get_filename(cpl_frameset_get_frame(rawframes, 0))) ;
00354 if (crires_spec_astro_config.period == CRIRES_ILLUM_UNKNOWN) {
00355 cpl_msg_error(__func__,
00356 "Cannot determine the detector illumination period") ;
00357 cpl_frameset_delete(rawframes) ;
00358 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00359 return -1 ;
00360 } else {
00361 crires_display_detector_illum(crires_spec_astro_config.period) ;
00362 }
00363
00364
00365 if ((labels = cpl_frameset_labelise(rawframes, crires_spec_astro_compare,
00366 &nlabels)) == NULL) {
00367 cpl_msg_error(__func__, "Cannot labelise input frames") ;
00368 cpl_frameset_delete(rawframes) ;
00369 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
00370 return -1 ;
00371 }
00372
00373
00374 for (i=0 ; i<nlabels ; i++) {
00375
00376
00377 for (j=0 ; j<CRIRES_NB_DETECTORS ; j++) {
00378 crires_spec_astro_config.qc_specpos[j] = -1 ;
00379 crires_spec_astro_config.qc_specwrec[j] = -1 ;
00380 crires_spec_astro_config.qc_specwopt[j] = -1 ;
00381 crires_spec_astro_config.qc_specoptmed[j] = -1.0 ;
00382 crires_spec_astro_config.qc_s2nmed[j] = -1.0 ;
00383 crires_spec_astro_config.qc_wlxc[j] = -1.0 ;
00384 crires_spec_astro_config.qc_wlcent[j] = -1.0 ;
00385 crires_spec_astro_config.qc_wldisp[j] = -1.0 ;
00386 crires_spec_astro_config.qc_fwhm_comb_pix[j] = -1.0 ;
00387 crires_spec_astro_config.qc_fwhm_comb_as[j] = -1.0 ;
00388 crires_spec_astro_config.qc_fwhm_prof_pix[j] = -1.0 ;
00389 crires_spec_astro_config.qc_fwhm_prof_as[j] = -1.0 ;
00390 crires_spec_astro_config.qc_fwhm_diff[j] = -1.0 ;
00391 }
00392
00393
00394 raw_one = cpl_frameset_extract(rawframes, labels, i) ;
00395
00396
00397 cpl_msg_info(__func__, "Reduce data set %d / %d", i+1, nlabels);
00398 cpl_msg_indent_more() ;
00399
00400
00401 if ((comblist = crires_spec_astro_reduce(raw_one, flat, dark, bpm,
00402 detlin, wavecal, oh_cat, hitran_cat, cfg_model,
00403 &wl_map,
00404 &wl_map_model,
00405 &prof_list,
00406 &bgmap_list,
00407 &(extr_tab[0]),
00408 &(extr_tab[1]),
00409 &(extr_tab[2]),
00410 &(extr_tab[3]))) == NULL) {
00411 cpl_msg_error(__func__, "Cannot reduce setting") ;
00412 cpl_frameset_delete(rawframes) ;
00413 cpl_frameset_delete(raw_one) ;
00414 cpl_msg_indent_less() ;
00415 return -1 ;
00416 }
00417
00418
00419 cpl_msg_info(__func__, "Save the products") ;
00420 cpl_msg_indent_more() ;
00421 if (crires_spec_astro_save((const cpl_imagelist **)comblist,
00422 prof_list, bgmap_list,
00423 (const cpl_table **)extr_tab, wl_map, wl_map_model,
00424 i+1, raw_one, parlist, frameset)) {
00425 cpl_msg_error(__func__, "Cannot save the product") ;
00426 cpl_imagelist_delete(prof_list) ;
00427 cpl_imagelist_delete(bgmap_list) ;
00428 for (j=0 ; j<CRIRES_NB_DETECTORS ; j++)
00429 if (extr_tab[j] != NULL) cpl_table_delete(extr_tab[j]) ;
00430 cpl_imagelist_delete(comblist[0]) ;
00431 cpl_imagelist_delete(comblist[1]) ;
00432 if (crires_spec_astro_config.comb_onlyA) {
00433 cpl_imagelist_delete(comblist[2]) ;
00434 cpl_imagelist_delete(comblist[3]) ;
00435 }
00436 if (crires_spec_astro_config.comb_onlyB) {
00437 cpl_imagelist_delete(comblist[4]) ;
00438 cpl_imagelist_delete(comblist[5]) ;
00439 }
00440 cpl_free(comblist) ;
00441 cpl_imagelist_delete(wl_map) ;
00442 if (wl_map_model) cpl_imagelist_delete(wl_map_model) ;
00443 cpl_msg_indent_less() ;
00444 return -1 ;
00445 }
00446 cpl_imagelist_delete(comblist[0]) ;
00447 cpl_imagelist_delete(comblist[1]) ;
00448 if (crires_spec_astro_config.comb_onlyA) {
00449 cpl_imagelist_delete(comblist[2]) ;
00450 cpl_imagelist_delete(comblist[3]) ;
00451 }
00452 if (crires_spec_astro_config.comb_onlyB) {
00453 cpl_imagelist_delete(comblist[4]) ;
00454 cpl_imagelist_delete(comblist[5]) ;
00455 }
00456 cpl_free(comblist) ;
00457
00458 cpl_imagelist_delete(wl_map) ;
00459 if (wl_map_model) cpl_imagelist_delete(wl_map_model) ;
00460 cpl_imagelist_delete(prof_list) ;
00461 cpl_imagelist_delete(bgmap_list) ;
00462 for (j=0 ; j<CRIRES_NB_DETECTORS ; j++)
00463 if (extr_tab[j] != NULL) cpl_table_delete(extr_tab[j]) ;
00464 cpl_msg_indent_less() ;
00465
00466 cpl_frameset_delete(raw_one) ;
00467 cpl_msg_indent_less() ;
00468 }
00469
00470 cpl_frameset_delete(rawframes) ;
00471 cpl_free(labels) ;
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 if (cpl_error_get_code()) return -1 ;
00485 else return 0 ;
00486 }
00487
00488
00493
00494 static cpl_imagelist ** crires_spec_astro_reduce(
00495 cpl_frameset * rawframes,
00496 const char * flat,
00497 const char * dark,
00498 const char * bpm,
00499 const char * detlin,
00500 const char * wavecal,
00501 const char * oh_cat,
00502 const char * hitran_cat,
00503 const char * cfg_model,
00504 cpl_imagelist ** wl_map,
00505 cpl_imagelist ** wl_map_model,
00506 cpl_imagelist ** prof_list,
00507 cpl_imagelist ** bgmap_list,
00508 cpl_table ** extr_tab1,
00509 cpl_table ** extr_tab2,
00510 cpl_table ** extr_tab3,
00511 cpl_table ** extr_tab4)
00512 {
00513 cpl_frame * fr ;
00514 const char * fname ;
00515 cpl_propertylist * plist ;
00516 double wmin, wmax ;
00517 double tot_ndit ;
00518 cpl_imagelist ** comblist ;
00519 int comblist_offset ;
00520 cpl_table * wave_tab ;
00521 cpl_polynomial * wave_poly[CRIRES_NB_DETECTORS] ;
00522 cpl_image * profiles[CRIRES_NB_DETECTORS] ;
00523 cpl_image * bg_maps[CRIRES_NB_DETECTORS] ;
00524 cpl_table ** wl_tab ;
00525 cpl_imagelist * wl_map_loc ;
00526 cpl_imagelist * wl_map_model_loc ;
00527 cpl_imagelist * prof_list_loc ;
00528 cpl_imagelist * bgmap_list_loc ;
00529 cpl_table * extr_tab[CRIRES_NB_DETECTORS] ;
00530 int power ;
00531 double wl_dx1, wl_dx2 ;
00532 cpl_vector ** wavelengths ;
00533 int i, j ;
00534
00535
00536 if (crires_spec_astro_config.comb_used == CRIRES_COMB_METHOD_COMB)
00537 comblist_offset = 0 ;
00538 else if (crires_spec_astro_config.comb_used == CRIRES_COMB_METHOD_NODA)
00539 comblist_offset = 1 ;
00540 else if (crires_spec_astro_config.comb_used == CRIRES_COMB_METHOD_NODB)
00541 comblist_offset = 2 ;
00542
00543
00544 fr = cpl_frameset_get_frame(rawframes, 0);
00545 tot_ndit = crires_get_totndit(cpl_frame_get_filename(fr)) ;
00546 if (tot_ndit < 0) {
00547 cpl_msg_error(__func__, "Cannot get the total number of NDIT") ;
00548 return NULL ;
00549 }
00550 tot_ndit *= cpl_frameset_get_size(rawframes) ;
00551
00552
00553 cpl_msg_info(__func__, "Images combination") ;
00554 cpl_msg_indent_more() ;
00555 if ((comblist = crires_combine_imagelist(rawframes, NULL,
00556 crires_spec_astro_config.period,
00557 flat, dark, bpm, detlin, 1,
00558 crires_spec_astro_config.comb_blind,
00559 crires_spec_astro_config.comb_refine,
00560 crires_spec_astro_config.comb_onlyA,
00561 crires_spec_astro_config.comb_onlyB)) == NULL) {
00562 cpl_msg_error(__func__, "Cannot combine the images") ;
00563 cpl_msg_indent_less() ;
00564 return NULL ;
00565 }
00566 cpl_msg_indent_less() ;
00567
00568
00569 cpl_msg_info(__func__, "Wavelength Calibration") ;
00570 cpl_msg_indent_more() ;
00571 if (wavecal != NULL) {
00572
00573 cpl_msg_info(__func__, "Use the provided solution") ;
00574 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00575 if ((wave_tab = crires_load_table_check(wavecal, i+1,
00576 CRIRES_PROTYPE_WL_POLY, -1, -1, 0)) == NULL) {
00577 cpl_msg_error(__func__, "Cannot load the wavelength table") ;
00578 cpl_msg_indent_less() ;
00579 cpl_imagelist_delete(comblist[0]) ;
00580 cpl_imagelist_delete(comblist[1]) ;
00581 if (crires_spec_astro_config.comb_onlyA) {
00582 cpl_imagelist_delete(comblist[2]) ;
00583 cpl_imagelist_delete(comblist[3]) ;
00584 }
00585 if (crires_spec_astro_config.comb_onlyB) {
00586 cpl_imagelist_delete(comblist[4]) ;
00587 cpl_imagelist_delete(comblist[5]) ;
00588 }
00589 cpl_free(comblist) ;
00590 return NULL ;
00591 }
00592
00593 wave_poly[i] = crires_wlcalib_gen_wlpoly(wave_tab) ;
00594 cpl_table_delete(wave_tab) ;
00595 }
00596 } else {
00597
00598 cpl_msg_info(__func__, "Use the science frame sky to calibrate") ;
00599
00600
00601 fname = cpl_frame_get_filename(cpl_frameset_get_frame(rawframes,0)) ;
00602
00603
00604 if (crires_spec_astro_config.wl_nolimit == 0) {
00605 plist = cpl_propertylist_load(fname, 0) ;
00606 wmin = crires_pfits_get_wlen_min(plist) ;
00607 wmax = crires_pfits_get_wlen_max(plist) ;
00608 cpl_propertylist_delete(plist) ;
00609 if (cpl_error_get_code()) {
00610 wmin = wmax = -1.0 ;
00611 cpl_error_reset() ;
00612 }
00613 } else {
00614 wmin = wmax = -1.0 ;
00615 }
00616
00617
00618 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00619 cpl_msg_info(__func__, "Calibrate chip number %d", i+1) ;
00620 cpl_msg_indent_more() ;
00621 wave_poly[i] = crires_wlcalib_sky(fname,
00622 crires_spec_astro_config.period,
00623 oh_cat, flat, dark, bpm, detlin,
00624 crires_spec_astro_config.wstart[i],
00625 crires_spec_astro_config.wstop[i],
00626 wmin, wmax,
00627 crires_spec_astro_config.wl_log,
00628 hitran_cat, i+1,
00629 crires_spec_astro_config.wl_starty,
00630 crires_spec_astro_config.wl_stopy,
00631 crires_spec_astro_config.wl_degree,
00632 crires_spec_astro_config.wl_slitw,
00633 crires_spec_astro_config.wl_fwhm,
00634 crires_spec_astro_config.wl_err,
00635 crires_spec_astro_config.wl_samples,
00636 crires_spec_astro_config.wl_clean,
00637 crires_spec_astro_config.wl_xclimit,
00638 crires_spec_astro_config.wl_ppm,
00639 (i+1==crires_spec_astro_config.display),
00640 &(crires_spec_astro_config.qc_wlxc[i])) ;
00641 cpl_msg_indent_less() ;
00642 }
00643 }
00644
00645
00646 for (i=1 ; i<CRIRES_NB_DETECTORS ; i++) {
00647 if (wave_poly[i-1] != NULL && wave_poly[i] != NULL) {
00648 power = 1 ;
00649 wl_dx1 = cpl_polynomial_get_coeff(wave_poly[i-1], &power) ;
00650 wl_dx2 = cpl_polynomial_get_coeff(wave_poly[i], &power) ;
00651 if (wl_dx1<wl_dx2) {
00652 cpl_msg_warning(__func__,
00653 "The linear coefficient is increasing from chip %d to chip %d : %g -> %g",
00654 i, i+1, wl_dx1, wl_dx2) ;
00655 }
00656 }
00657 }
00658 cpl_msg_indent_less() ;
00659
00660
00661 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00662 if (wave_poly[i] != NULL) {
00663 crires_spec_astro_config.qc_wlcent[i] =
00664 cpl_polynomial_eval_1d(wave_poly[i], (double)512, NULL) ;
00665 crires_spec_astro_config.qc_wldisp[i] =
00666 (cpl_polynomial_eval_1d(wave_poly[i], (double)1024, NULL) -
00667 cpl_polynomial_eval_1d(wave_poly[i], (double)1, NULL)) / 1024 ;
00668 }
00669 }
00670
00671
00672 wl_tab = crires_wlcalib_gen_wltab((const cpl_polynomial **)wave_poly) ;
00673 wl_map_loc = crires_wlcalib_gen_wlmap((const cpl_table **)wl_tab) ;
00674 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(wl_tab[i]) ;
00675 cpl_free(wl_tab) ;
00676
00677
00678 fname = cpl_frame_get_filename(cpl_frameset_get_frame(rawframes,0)) ;
00679 if ((cfg_model != NULL) && (!crires_model_off()) &&
00680 (crires_model_config_check(cfg_model, fname) == 0)) {
00681 cpl_msg_info(__func__, "Call the model to get the wavelength map") ;
00682 cpl_msg_indent_more() ;
00683 wl_map_model_loc = crires_model_wavpix( fname, cfg_model, -1) ;
00684 if (wl_map_model_loc == NULL) {
00685 cpl_msg_warning(__func__, "Model function returns NULL") ;
00686 cpl_error_reset() ;
00687 }
00688 cpl_msg_indent_less() ;
00689 } else {
00690 wl_map_model_loc = NULL ;
00691 }
00692
00693
00694 cpl_msg_info(__func__, "Spectrum extraction") ;
00695 cpl_msg_indent_more() ;
00696 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00697 cpl_msg_info(__func__, "Chip number %d extraction", i+1) ;
00698 cpl_msg_indent_more() ;
00699 if ((extr_tab[i] = crires_extract_spectrum(
00700 cpl_imagelist_get(comblist[0+2*comblist_offset], i),
00701 cpl_imagelist_get(comblist[1+2*comblist_offset], i),
00702 crires_spec_astro_config.extr_box_hor_size,
00703 crires_spec_astro_config.extr_spec_hsize,
00704 crires_spec_astro_config.extr_kappa,
00705 crires_spec_astro_config.extr_closing_hs,
00706 crires_spec_astro_config.extr_clean_rate,
00707 crires_spec_astro_config.extr_rej_left,
00708 crires_spec_astro_config.extr_rej_right,
00709 crires_spec_astro_config.extr_spec_starty,
00710 crires_spec_astro_config.extr_spec_stopy,
00711 i+1,
00712 tot_ndit,
00713 crires_spec_astro_config.period,
00714 &(crires_spec_astro_config.qc_specpos[i]),
00715 &(crires_spec_astro_config.qc_specwrec[i]),
00716 &(crires_spec_astro_config.qc_specwopt[i]),
00717 &(crires_spec_astro_config.qc_specoptmed[i]),
00718 &(crires_spec_astro_config.qc_s2nmed[i]),
00719 &(profiles[i]),
00720 &(bg_maps[i]))) == NULL) {
00721 cpl_msg_error(__func__, "Cannot extract the spectrum") ;
00722 cpl_msg_indent_less() ;
00723 cpl_msg_indent_less() ;
00724 for (j=0 ; j<CRIRES_NB_DETECTORS ; j++)
00725 if (wave_poly[j] != NULL) cpl_polynomial_delete(wave_poly[j]);
00726 for (j=0 ; j<i ; j++)
00727 cpl_table_delete(extr_tab[j]) ;
00728 for (j=0 ; j<i ; j++)
00729 cpl_image_delete(profiles[j]) ;
00730 for (j=0 ; j<i ; j++)
00731 cpl_image_delete(bg_maps[j]) ;
00732 cpl_imagelist_delete(comblist[0]) ;
00733 cpl_imagelist_delete(comblist[1]) ;
00734 if (crires_spec_astro_config.comb_onlyA) {
00735 cpl_imagelist_delete(comblist[2]) ;
00736 cpl_imagelist_delete(comblist[3]) ;
00737 }
00738 if (crires_spec_astro_config.comb_onlyB) {
00739 cpl_imagelist_delete(comblist[4]) ;
00740 cpl_imagelist_delete(comblist[5]) ;
00741 }
00742 cpl_free(comblist) ;
00743 cpl_imagelist_delete(wl_map_loc) ;
00744 if (wl_map_model_loc) cpl_imagelist_delete(wl_map_model_loc) ;
00745 return NULL ;
00746 }
00747 cpl_msg_info(__func__, "Chip number %d FWHM Computation", i+1) ;
00748 if (crires_extract_qc_fwhm(
00749 cpl_imagelist_get(comblist[0+2*comblist_offset], i),
00750 profiles[i],
00751 &(crires_spec_astro_config.qc_fwhm_comb_pix[i]),
00752 &(crires_spec_astro_config.qc_fwhm_comb_as[i]),
00753 &(crires_spec_astro_config.qc_fwhm_prof_pix[i]),
00754 &(crires_spec_astro_config.qc_fwhm_prof_as[i]),
00755 &(crires_spec_astro_config.qc_fwhm_diff[i])) == -1) {
00756 cpl_msg_warning(__func__, "Failed for FWHM computation") ;
00757 crires_spec_astro_config.qc_fwhm_comb_pix[i] = -1.0 ;
00758 crires_spec_astro_config.qc_fwhm_comb_as[i] = -1.0 ;
00759 crires_spec_astro_config.qc_fwhm_prof_pix[i] = -1.0 ;
00760 crires_spec_astro_config.qc_fwhm_prof_as[i] = -1.0 ;
00761 crires_spec_astro_config.qc_fwhm_diff[i] = -1.0 ;
00762 }
00763 cpl_msg_indent_less() ;
00764 }
00765
00766
00767 prof_list_loc = cpl_imagelist_new() ;
00768 bgmap_list_loc = cpl_imagelist_new() ;
00769 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00770 cpl_imagelist_set(prof_list_loc, profiles[i], i) ;
00771 cpl_imagelist_set(bgmap_list_loc, bg_maps[i], i) ;
00772 }
00773
00774
00775 for (i=1 ; i<CRIRES_NB_DETECTORS ; i++) {
00776 if (crires_spec_astro_config.qc_specpos[i-1] > 0 &&
00777 crires_spec_astro_config.qc_specpos[i] > 0 &&
00778 fabs(crires_spec_astro_config.qc_specpos[i-1] -
00779 crires_spec_astro_config.qc_specpos[i]) >
00780 CRIRES_SPEC_POS_TOLERANCE) {
00781 cpl_msg_warning(__func__,
00782 "The spectrum positions in chip %d and chip %d are too different: %d -> %d",
00783 i, i+1, crires_spec_astro_config.qc_specpos[i-1],
00784 crires_spec_astro_config.qc_specpos[i]) ;
00785 }
00786 }
00787 cpl_msg_indent_less() ;
00788
00789
00790 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00791 cpl_table_new_column(extr_tab[i], CRIRES_COL_WAVELENGTH,
00792 CPL_TYPE_DOUBLE) ;
00793 for (j=0 ; j<cpl_table_get_nrow(extr_tab[i]) ; j++) {
00794 if (wave_poly[i] != NULL) {
00795 cpl_table_set_double(extr_tab[i], CRIRES_COL_WAVELENGTH, j,
00796 cpl_polynomial_eval_1d(wave_poly[i], (double)(j+1), NULL));
00797 } else {
00798 cpl_table_set_double(extr_tab[i], CRIRES_COL_WAVELENGTH, j,
00799 0.0);
00800 }
00801 }
00802 }
00803 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++)
00804 if (wave_poly[i] != NULL) cpl_polynomial_delete(wave_poly[i]);
00805
00806
00807 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00808 cpl_table_new_column(extr_tab[i], CRIRES_COL_WAVELENGTH_MODEL,
00809 CPL_TYPE_DOUBLE) ;
00810 cpl_table_fill_column_window_double(extr_tab[i],
00811 CRIRES_COL_WAVELENGTH_MODEL, 0,
00812 cpl_table_get_nrow(extr_tab[i]), -1.0) ;
00813 }
00814 if ((cfg_model != NULL) && (!crires_model_off()) && (1)) {
00815 cpl_msg_info(__func__, "Call the model to get the wavelengths") ;
00816 cpl_msg_indent_more() ;
00817 wavelengths = crires_model_wavelengths(
00818 cpl_frame_get_filename(cpl_frameset_get_frame(rawframes,0)),
00819 cfg_model, -1,
00820 (double)(crires_spec_astro_config.qc_specpos[0]),
00821 wl_map_model_loc) ;
00822 if (wavelengths != NULL) {
00823
00824 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00825
00826 for (j=0 ; j<cpl_vector_get_size(wavelengths[i]) ; j++) {
00827 cpl_table_set_double(extr_tab[i],
00828 CRIRES_COL_WAVELENGTH_MODEL, j,
00829 cpl_vector_get(wavelengths[i], j)) ;
00830 }
00831 }
00832 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++)
00833 cpl_vector_delete(wavelengths[i]) ;
00834 cpl_free(wavelengths) ;
00835 } else {
00836 cpl_msg_warning(__func__, "Model function returns NULL") ;
00837 cpl_error_reset() ;
00838 }
00839 cpl_msg_indent_less() ;
00840 }
00841
00842
00843 if (wl_map != NULL) *wl_map = wl_map_loc ;
00844 else cpl_imagelist_delete(wl_map_loc) ;
00845 if (wl_map_model != NULL) *wl_map_model = wl_map_model_loc ;
00846 else cpl_imagelist_delete(wl_map_model_loc) ;
00847 if (prof_list != NULL) *prof_list = prof_list_loc ;
00848 else cpl_imagelist_delete(prof_list_loc) ;
00849 if (bgmap_list != NULL) *bgmap_list = bgmap_list_loc ;
00850 else cpl_imagelist_delete(bgmap_list_loc) ;
00851 if (extr_tab1 != NULL) *extr_tab1 = extr_tab[0] ;
00852 else cpl_table_delete(extr_tab[0]) ;
00853 if (extr_tab2 != NULL) *extr_tab2 = extr_tab[1] ;
00854 else cpl_table_delete(extr_tab[1]) ;
00855 if (extr_tab3 != NULL) *extr_tab3 = extr_tab[2] ;
00856 else cpl_table_delete(extr_tab[2]) ;
00857 if (extr_tab4 != NULL) *extr_tab4 = extr_tab[3] ;
00858 else cpl_table_delete(extr_tab[3]) ;
00859 return comblist ;
00860 }
00861
00862
00878
00879 static int crires_spec_astro_save(
00880 const cpl_imagelist ** images,
00881 const cpl_imagelist * prof,
00882 const cpl_imagelist * bgmap,
00883 const cpl_table ** extr_tab,
00884 const cpl_imagelist * wl_map,
00885 const cpl_imagelist * wl_map_model,
00886 int setting,
00887 const cpl_frameset * cur_set,
00888 const cpl_parameterlist * parlist,
00889 cpl_frameset * set)
00890 {
00891 cpl_propertylist ** qclists ;
00892 const cpl_frame * ref_frame ;
00893 char * filename ;
00894 cpl_propertylist * inputlist ;
00895 const char * recipe_name = "crires_spec_astro" ;
00896 int i ;
00897
00898
00899 ref_frame = irplib_frameset_get_first_from_group(cur_set,
00900 CPL_FRAME_GROUP_RAW) ;
00901
00902
00903 qclists = cpl_malloc(CRIRES_NB_DETECTORS * sizeof(cpl_propertylist*)) ;
00904 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00905 qclists[i] = cpl_propertylist_new() ;
00906 cpl_propertylist_append_int(qclists[i], "ESO QC SPECPOS",
00907 crires_spec_astro_config.qc_specpos[i]) ;
00908 cpl_propertylist_append_int(qclists[i], "ESO QC SPECWREC",
00909 crires_spec_astro_config.qc_specwrec[i]) ;
00910 cpl_propertylist_append_int(qclists[i], "ESO QC SPECWOPT",
00911 crires_spec_astro_config.qc_specwopt[i]) ;
00912 cpl_propertylist_append_double(qclists[i], "ESO QC SIGNAL MED",
00913 crires_spec_astro_config.qc_specoptmed[i]) ;
00914 cpl_propertylist_append_double(qclists[i], "ESO QC S2NMED",
00915 crires_spec_astro_config.qc_s2nmed[i]) ;
00916 cpl_propertylist_append_double(qclists[i], "ESO QC XCORR",
00917 crires_spec_astro_config.qc_wlxc[i]) ;
00918 cpl_propertylist_append_double(qclists[i], "ESO QC CENTWL",
00919 crires_spec_astro_config.qc_wlcent[i]) ;
00920 cpl_propertylist_append_double(qclists[i], "ESO QC DISPWL",
00921 crires_spec_astro_config.qc_wldisp[i]) ;
00922 cpl_propertylist_append_double(qclists[i], "ESO QC FWHMPIX COMBINED",
00923 crires_spec_astro_config.qc_fwhm_comb_pix[i]) ;
00924 cpl_propertylist_append_double(qclists[i], "ESO QC FWHMARC COMBINED",
00925 crires_spec_astro_config.qc_fwhm_comb_as[i]) ;
00926 cpl_propertylist_append_double(qclists[i], "ESO QC FWHMPIX PROFILE",
00927 crires_spec_astro_config.qc_fwhm_prof_pix[i]) ;
00928 cpl_propertylist_append_double(qclists[i], "ESO QC FWHMARC PROFILE",
00929 crires_spec_astro_config.qc_fwhm_prof_as[i]) ;
00930 cpl_propertylist_append_double(qclists[i], "ESO QC FWHM DIFF",
00931 crires_spec_astro_config.qc_fwhm_diff[i]) ;
00932
00933 inputlist = cpl_propertylist_load_regexp(
00934 cpl_frame_get_filename(ref_frame), i+1,
00935 CRIRES_HEADER_EXT_FORWARD, 0) ;
00936 cpl_propertylist_copy_property_regexp(qclists[i], inputlist,
00937 CRIRES_HEADER_EXT_FORWARD, 0) ;
00938 cpl_propertylist_delete(inputlist) ;
00939 }
00940
00941
00942 filename = cpl_sprintf("%s_comb_set%02d.fits", recipe_name, setting) ;
00943 crires_image_save(set,
00944 parlist,
00945 cur_set,
00946 images[0],
00947 recipe_name,
00948 CRIRES_ASTRO_COMBINED_IMA,
00949 CRIRES_PROTYPE_COMBINED,
00950 crires_spec_astro_config.period,
00951 NULL,
00952 (const cpl_propertylist **)qclists,
00953 PACKAGE "/" PACKAGE_VERSION,
00954 filename) ;
00955 cpl_free(filename) ;
00956
00957
00958 filename = cpl_sprintf("%s_contrib_set%02d.fits", recipe_name, setting) ;
00959 crires_image_save(set,
00960 parlist,
00961 cur_set,
00962 images[1],
00963 recipe_name,
00964 CRIRES_ASTRO_CONTRIBUTION_IMA,
00965 CRIRES_PROTYPE_CONTRIB,
00966 crires_spec_astro_config.period,
00967 NULL,
00968 (const cpl_propertylist **)qclists,
00969 PACKAGE "/" PACKAGE_VERSION,
00970 filename) ;
00971 cpl_free(filename) ;
00972
00973
00974 if (crires_spec_astro_config.comb_onlyA) {
00975
00976 filename = cpl_sprintf("%s_comb_noddedA_set%02d.fits",
00977 recipe_name, setting) ;
00978 crires_image_save(set,
00979 parlist,
00980 cur_set,
00981 images[2],
00982 recipe_name,
00983 CRIRES_ASTRO_COMBINED_IMA,
00984 CRIRES_PROTYPE_COMBINED,
00985 crires_spec_astro_config.period,
00986 NULL,
00987 (const cpl_propertylist **)qclists,
00988 PACKAGE "/" PACKAGE_VERSION,
00989 filename) ;
00990 cpl_free(filename) ;
00991
00992
00993 filename = cpl_sprintf("%s_contrib_noddedA_set%02d.fits",
00994 recipe_name, setting) ;
00995 crires_image_save(set,
00996 parlist,
00997 cur_set,
00998 images[3],
00999 recipe_name,
01000 CRIRES_ASTRO_CONTRIBUTION_IMA,
01001 CRIRES_PROTYPE_CONTRIB,
01002 crires_spec_astro_config.period,
01003 NULL,
01004 (const cpl_propertylist **)qclists,
01005 PACKAGE "/" PACKAGE_VERSION,
01006 filename) ;
01007 cpl_free(filename) ;
01008 }
01009
01010
01011 if (crires_spec_astro_config.comb_onlyB) {
01012
01013 filename = cpl_sprintf("%s_comb_noddedB_set%02d.fits",
01014 recipe_name, setting) ;
01015 crires_image_save(set,
01016 parlist,
01017 cur_set,
01018 images[4],
01019 recipe_name,
01020 CRIRES_ASTRO_COMBINED_IMA,
01021 CRIRES_PROTYPE_COMBINED,
01022 crires_spec_astro_config.period,
01023 NULL,
01024 (const cpl_propertylist **)qclists,
01025 PACKAGE "/" PACKAGE_VERSION,
01026 filename) ;
01027 cpl_free(filename) ;
01028
01029
01030 filename = cpl_sprintf("%s_contrib_noddedB_set%02d.fits",
01031 recipe_name, setting) ;
01032 crires_image_save(set,
01033 parlist,
01034 cur_set,
01035 images[5],
01036 recipe_name,
01037 CRIRES_ASTRO_CONTRIBUTION_IMA,
01038 CRIRES_PROTYPE_CONTRIB,
01039 crires_spec_astro_config.period,
01040 NULL,
01041 (const cpl_propertylist **)qclists,
01042 PACKAGE "/" PACKAGE_VERSION,
01043 filename) ;
01044 cpl_free(filename) ;
01045 }
01046
01047
01048 filename = cpl_sprintf("%s_prof_set%02d.fits", recipe_name, setting) ;
01049 crires_image_save(set,
01050 parlist,
01051 cur_set,
01052 prof,
01053 recipe_name,
01054 CRIRES_ASTRO_EXTRACT_PROFILE_IMA,
01055 CRIRES_PROTYPE_PROFILE,
01056 crires_spec_astro_config.period,
01057 NULL,
01058 (const cpl_propertylist **)qclists,
01059 PACKAGE "/" PACKAGE_VERSION,
01060 filename) ;
01061 cpl_free(filename) ;
01062
01063
01064 filename = cpl_sprintf("%s_bgmap_set%02d.fits", recipe_name, setting) ;
01065 crires_image_save(set,
01066 parlist,
01067 cur_set,
01068 bgmap,
01069 recipe_name,
01070 CRIRES_ASTRO_EXTRACT_BGMAP_IMA,
01071 CRIRES_PROTYPE_BGD_MAP,
01072 crires_spec_astro_config.period,
01073 NULL,
01074 (const cpl_propertylist **)qclists,
01075 PACKAGE "/" PACKAGE_VERSION,
01076 filename) ;
01077 cpl_free(filename) ;
01078
01079
01080 filename = cpl_sprintf("%s_wlmap_set%02d.fits", recipe_name, setting) ;
01081 crires_image_save(set,
01082 parlist,
01083 cur_set,
01084 wl_map,
01085 recipe_name,
01086 CRIRES_ASTRO_WL_MAP_IMA,
01087 CRIRES_PROTYPE_WL_MAP,
01088 crires_spec_astro_config.period,
01089 NULL,
01090 (const cpl_propertylist **)qclists,
01091 PACKAGE "/" PACKAGE_VERSION,
01092 filename) ;
01093 cpl_free(filename) ;
01094
01095 if (wl_map_model != NULL) {
01096
01097 filename = cpl_sprintf("%s_wlmap_model_set%02d.fits", recipe_name,
01098 setting) ;
01099 crires_image_save(set,
01100 parlist,
01101 cur_set,
01102 wl_map_model,
01103 recipe_name,
01104 CRIRES_ASTRO_WL_MAP_MODEL_IMA,
01105 CRIRES_PROTYPE_WL_MAP,
01106 crires_spec_astro_config.period,
01107 NULL,
01108 (const cpl_propertylist **)qclists,
01109 PACKAGE "/" PACKAGE_VERSION,
01110 filename) ;
01111 cpl_free(filename) ;
01112 }
01113
01114
01115 filename = cpl_sprintf("%s_extracted_set%02d.fits", recipe_name, setting);
01116 crires_table_save(set,
01117 parlist,
01118 cur_set,
01119 extr_tab,
01120 recipe_name,
01121 CRIRES_ASTRO_EXTRACT_WL_TAB,
01122 CRIRES_PROTYPE_SPEC_WL,
01123 NULL,
01124 (const cpl_propertylist **)qclists,
01125 PACKAGE "/" PACKAGE_VERSION,
01126 filename) ;
01127 cpl_free(filename) ;
01128
01129
01130 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
01131 cpl_propertylist_delete(qclists[i]) ;
01132 }
01133 cpl_free(qclists) ;
01134 return 0;
01135 }
01136
01137
01144
01145 static int crires_spec_astro_compare(
01146 const cpl_frame * frame1,
01147 const cpl_frame * frame2)
01148 {
01149 int comparison ;
01150 cpl_propertylist * plist1 ;
01151 cpl_propertylist * plist2 ;
01152 double dval1, dval2 ;
01153 int ival1, ival2 ;
01154
01155
01156 if (frame1==NULL || frame2==NULL) return -1 ;
01157
01158
01159 if ((plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0))==NULL){
01160 cpl_msg_error(__func__, "getting header from reference frame");
01161 return -1 ;
01162 }
01163 if ((plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0))==NULL){
01164 cpl_msg_error(__func__, "getting header from reference frame");
01165 cpl_propertylist_delete(plist1) ;
01166 return -1 ;
01167 }
01168
01169
01170 if (cpl_error_get_code()) {
01171 cpl_propertylist_delete(plist1) ;
01172 cpl_propertylist_delete(plist2) ;
01173 return -1 ;
01174 }
01175
01176 comparison = 1 ;
01177
01178
01179 dval1 = crires_pfits_get_dit(plist1) ;
01180 dval2 = crires_pfits_get_dit(plist2) ;
01181 if (cpl_error_get_code()) {
01182 cpl_msg_error(__func__, "Cannot get the POSANG");
01183 cpl_propertylist_delete(plist1) ;
01184 cpl_propertylist_delete(plist2) ;
01185 return -1 ;
01186 }
01187 if (fabs(dval1-dval2) > 1e-3) comparison = 0 ;
01188
01189
01190 ival1 = crires_pfits_get_expno(plist1) ;
01191 ival2 = crires_pfits_get_expno(plist2) ;
01192 if (cpl_error_get_code()) {
01193 cpl_msg_error(__func__, "Cannot get the EXPNO");
01194 cpl_propertylist_delete(plist1) ;
01195 cpl_propertylist_delete(plist2) ;
01196 return -1 ;
01197 }
01198 if (fabs(ival2-ival1) != 1.0) comparison = 0 ;
01199
01200 cpl_propertylist_delete(plist1) ;
01201 cpl_propertylist_delete(plist2) ;
01202 return comparison ;
01203 }