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
00037
00040
00041
00042
00043
00044 #include <math.h>
00045 #include <xsh_drl.h>
00046
00047 #include <xsh_utils_table.h>
00048 #include <xsh_badpixelmap.h>
00049 #include <xsh_data_pre.h>
00050 #include <xsh_dfs.h>
00051 #include <xsh_pfits.h>
00052 #include <xsh_error.h>
00053 #include <xsh_msg.h>
00054 #include <xsh_fit.h>
00055 #include <xsh_data_instrument.h>
00056 #include <xsh_data_localization.h>
00057 #include <xsh_data_rec.h>
00058 #include <xsh_ifu_defs.h>
00059
00060 #include <cpl.h>
00061
00062
00063
00064
00065
00066
00067
00068
00088 static cpl_frame *
00089 xsh_extract_with_tag(cpl_frame * rec_frame, cpl_frame* loc_frame,
00090 xsh_instrument* instrument, xsh_extract_param* extract_par,
00091 const char * tag, cpl_frame** res_frame_ext) {
00092 cpl_frame *res_frame = NULL;
00093 xsh_localization *loc_list = NULL;
00094 xsh_rec_list *rec_list = NULL, *result_list = NULL;
00095 int i = 0;
00096 double slit_step = 0.0;
00097 char * fname = NULL;
00098 char * fname_drl = NULL;
00099 char * tag_drl = NULL;
00100 double slit_ext_min = 0;
00101 double slit_ext_max = 0;
00102 cpl_propertylist* plist = NULL;
00103 const char* name = NULL;
00104
00105 XSH_ASSURE_NOT_NULL( rec_frame);
00106
00107 xsh_msg_dbg_medium( "Entering xsh_extract_with_tag(%s)", tag);
00108 xsh_msg_dbg_medium( "Parameters");
00109 xsh_msg_dbg_medium( " method %s", EXTRACT_METHOD_PRINT(extract_par->method));
00110
00111 if (extract_par->method == NOD_METHOD) {
00112 name = cpl_frame_get_filename(rec_frame);
00113 plist = cpl_propertylist_load(name, 0);
00114 slit_ext_min = xsh_pfits_get_extract_slit_min(plist);
00115 slit_ext_max = xsh_pfits_get_extract_slit_max(plist) - 2;
00116 xsh_free_propertylist(&plist);
00117 }
00118
00119 check( rec_list = xsh_rec_list_load( rec_frame, instrument));
00120 check( slit_step = xsh_pfits_get_rectify_bin_space( rec_list->header));
00121
00122
00123 if ((extract_par->method != FULL_METHOD)
00124 && (extract_par->method != NOD_METHOD)) {
00125 XSH_ASSURE_NOT_NULL( loc_frame);
00126 check( loc_list = xsh_localization_load( loc_frame));
00127 }check(
00128 result_list = xsh_rec_list_create_with_size( rec_list->size, instrument));
00129
00130 for (i = 0; i < rec_list->size; i++) {
00131 int order = xsh_rec_list_get_order(rec_list, i);
00132 int nslit = xsh_rec_list_get_nslit(rec_list, i);
00133 int nlambda = xsh_rec_list_get_nlambda(rec_list, i);
00134 float* slit = xsh_rec_list_get_slit(rec_list, i);
00135 double* lambda = xsh_rec_list_get_lambda(rec_list, i);
00136 float slitmin = slit[0];
00137 float slitmax = slit[nslit - 1];
00138 double lambdamin = lambda[0];
00139 double lambdamax = lambda[nlambda - 1];
00140 float *flux = xsh_rec_list_get_data1(rec_list, i);
00141 float *errs = xsh_rec_list_get_errs1(rec_list, i);
00142 int *qual = xsh_rec_list_get_qual1(rec_list, i);
00143 int ilambda, islit;
00144
00145 double *res_lambda = NULL;
00146 float *res_flux = NULL, *res_errs = NULL;
00147 int *res_qual = NULL;
00148
00149 xsh_msg_dbg_medium(
00150 "order %d nslit %d (%f,%f) nlambda %d (%f %f)", order, nslit, slitmin, slitmax, nlambda, lambdamin, lambdamax);
00151
00152 check( xsh_rec_list_set_data_size( result_list, i, order, nlambda, 1));
00153
00154 check( res_lambda = xsh_rec_list_get_lambda( result_list, i));
00155 check( res_flux = xsh_rec_list_get_data1( result_list, i));
00156 check( res_errs = xsh_rec_list_get_errs1( result_list, i));
00157 check( res_qual = xsh_rec_list_get_qual1( result_list, i));
00158
00159 for (ilambda = 0; ilambda < nlambda; ilambda++) {
00160 double slit_lo = 0.0, slit_up = 0.0;
00161 double ypix_low, ypix_up;
00162
00163 int ylow = 0, yup = 0;
00164 double y_frac_low, y_frac_up;
00165 double fluxval = 0.0;
00166 double errval = 0.0;
00167 int qualval = 0;
00168 int idx;
00169
00170
00171 if (extract_par->method == LOCALIZATION_METHOD) {
00172 check(
00173 slit_lo = cpl_polynomial_eval_1d( loc_list->edglopoly, lambda[ilambda], NULL));
00174 check(
00175 slit_up = cpl_polynomial_eval_1d( loc_list->edguppoly, lambda[ilambda], NULL));
00176
00177 xsh_msg_dbg_medium(
00178 "LOCALIZATION_METHOD get poly ok lambda %f slit_lo %f slit_up %f", lambda[ilambda], slit_lo, slit_up);
00179
00180 ypix_low = (slit_lo - slit[0]) / slit_step;
00181 ypix_up = (slit_up - slit[0]) / slit_step;
00182
00183 if (ypix_low < 0.0) {
00184 xsh_msg(
00185 "WARNING : localization give low pixel \
00186 outside of image : fix it to zero");
00187 ypix_low = 0.0;
00188 }
00189 if (ypix_up >= nslit) {
00190 xsh_msg(
00191 "WARNING : localization give up pixel \
00192 outside of image : fix it to %d", nslit-1);
00193 ypix_up = nslit - 1;
00194 }
00195 xsh_msg_dbg_medium("ypix_low %f ypix_up %f", ypix_low, ypix_up);
00196
00197 ylow = (int) (ypix_low);
00198 yup = (int) (ypix_up);
00199
00200 y_frac_up = ypix_up - yup;
00201 y_frac_low = 1 - (ypix_low - ylow);
00202
00203 xsh_msg_dbg_medium("ylow %d yup %d", ylow, yup);
00204
00205
00206 idx = ylow * nlambda + ilambda;
00207 if (idx >= (nlambda * nslit)) {
00208 xsh_msg_dbg_high(
00209 "Index Out of Image: %d >= %d (ylow: %d, ilambda: %d)", idx, nlambda*nslit, ylow, ilambda);
00210 continue;
00211 }
00212 fluxval += y_frac_low * flux[idx];
00213 errval += y_frac_low * (errs[idx] * errs[idx]);
00214 qualval |= qual[idx];
00215
00216
00217 for (islit = ylow + 1; islit < yup; islit++) {
00218 idx = islit * nlambda + ilambda;
00219 fluxval += flux[idx];
00220 errval += errs[idx]*errs[idx];
00221 qualval |= qual[idx];
00222 }
00223
00224
00225 if (yup < nslit) {
00226 idx = yup * nlambda + ilambda;
00227 fluxval += y_frac_up * flux[idx];
00228 errval += y_frac_up * errs[idx]*errs[idx];
00229 qualval |= qual[idx];
00230 }
00231
00232
00233 } else if (extract_par->method == FULL_METHOD) {
00234
00235 for (islit = 0; islit < nslit; islit++) {
00236 idx = islit * nlambda + ilambda;
00237 fluxval += flux[idx];
00238 errval += errs[idx]*errs[idx];
00239 qualval |= qual[idx];
00240 }
00241
00242
00243 } else if (extract_par->method == NOD_METHOD) {
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 ylow = slit_ext_min;
00255 yup = slit_ext_max;
00256
00257 for (islit = ylow; islit <= yup; islit++) {
00258 idx = islit * nlambda + ilambda;
00259 fluxval += flux[idx];
00260 errval += errs[idx]*errs[idx];
00261 qualval |= qual[idx];
00262 }
00263 }
00264 res_lambda[ilambda] = lambda[ilambda];
00265 res_flux[ilambda] = fluxval;
00266 res_errs[ilambda] = sqrt(errval);
00267 res_qual[ilambda] = qualval;
00268 }
00269 }
00270
00271 check( cpl_propertylist_append ( result_list->header, rec_list->header));
00272 check( xsh_pfits_set_pcatg( result_list->header, tag));
00273 fname = xsh_stringcat_any(tag, ".fits", NULL);
00274 tag_drl = xsh_stringcat_any(tag, "_DRL", NULL);
00275 fname_drl = xsh_stringcat_any(tag_drl, ".fits", NULL);
00276
00277 check( *res_frame_ext= xsh_rec_list_save2( result_list,fname, tag));
00278 check( res_frame = xsh_rec_list_save( result_list, fname_drl, tag_drl,0));
00279
00280 xsh_msg_dbg_medium("%s created", fname);
00281
00282 cleanup: xsh_rec_list_free(&result_list);
00283 xsh_rec_list_free(&rec_list);
00284 xsh_localization_free(&loc_list);
00285
00286 XSH_FREE( tag_drl);
00287 XSH_FREE( fname_drl);
00288 XSH_FREE( fname);
00289
00290 return res_frame;
00291 }
00292
00293 static cpl_error_code
00294 xsh_extraction_get_slit_minmax(xsh_localization *loc_list,
00295 const double lambda, const double slit_0, const double slit_step,
00296 const int nslit, int* ylow, int* yup,double* y_frac_up,double* y_frac_low) {
00297 double slit_lo = 0;
00298 double slit_up = 0;
00299 double ypix_low = 0;
00300 double ypix_up = 0;
00301
00302 slit_lo = cpl_polynomial_eval_1d(loc_list->edglopoly, lambda, NULL);
00303 slit_up = cpl_polynomial_eval_1d(loc_list->edguppoly, lambda, NULL);
00304
00305 xsh_msg_dbg_medium(
00306 "LOCALIZATION_METHOD get poly ok lambda %f slit_lo %f slit_up %f", lambda, slit_lo, slit_up);
00307
00308 ypix_low = (slit_lo - slit_0) / slit_step;
00309 ypix_up = (slit_up - slit_0) / slit_step;
00310
00311 if (ypix_low < 0.0) {
00312 xsh_msg(
00313 "WARNING : localization give low pixel \
00314 outside of image : fix it to zero");
00315 ypix_low = 0.0;
00316 }
00317 if (ypix_up >= nslit) {
00318 xsh_msg(
00319 "WARNING : localization give up pixel \
00320 outside of image : fix it to %d", nslit-1);
00321 ypix_up = nslit - 1;
00322 }
00323 xsh_msg_dbg_medium("ypix_low %f ypix_up %f", ypix_low, ypix_up);
00324
00325 *ylow = (int) (ypix_low);
00326 *yup = (int) (ypix_up);
00327
00328 *y_frac_up = ypix_up - *yup;
00329 *y_frac_low = 1 - (ypix_low - *ylow);
00330 return cpl_error_get_code();
00331 }
00332
00333 cpl_error_code xsh_extract_clean_slice(const float* flux, const float* errs,
00334 int* qual, const double* lambda,
00335 const int ilambda, xsh_instrument* instrument, const int slit_min,
00336 const int slit_max, const int nlambda, const int nslit,
00337 const int mask_hsize, double* fluxval, double* errval, int* qualval) {
00338
00339 int mask_size = 0;
00340
00341 int nbad = 0;
00342 int islit = 0;
00343 int idx = 0;
00344 const int slit_size = slit_max - slit_min + 1;
00345 double den_fct = 0;
00346 double num_fct = 0;
00347 int mdx = 0;
00348 int m = 0;
00349
00350 float* prof = NULL;
00351
00352 double ipol_fct = 0;
00353 cpl_vector* vec_wave_flag=NULL;
00354 double* pflag=NULL;
00355 int nflag=0;
00356 double inv_err2=0;
00357 double err2=0;
00358 int ilambda_min=0;
00359 int ilambda_max=0;
00360 int mstart=0;
00361 int mend=0;
00362
00363
00364 for (islit = slit_min; islit <= slit_max; islit++) {
00365 idx = islit * nlambda + ilambda;
00366 if ((qual[idx] & instrument->decode_bp) > 0) {
00367 nbad++;
00368 }
00369 }
00370
00371
00372 if (nbad == slit_size || nbad == 0) {
00373
00374 for (islit = slit_min; islit <= slit_max; islit++) {
00375 idx = islit * nlambda + ilambda;
00376
00377 *fluxval += flux[idx];
00378 *errval += (errs[idx] * errs[idx]);
00379 *qualval |= qual[idx];
00380 }
00381 } else {
00382 xsh_msg_debug("Found %d bad pix at lambda=%g", nbad, lambda[ilambda]);
00383
00384
00385 ilambda_min=ilambda-mask_hsize;
00386 ilambda_max=ilambda+mask_hsize;
00387 ilambda_min = (ilambda_min>=0) ? ilambda_min : 0;
00388 ilambda_max = (ilambda_max<nlambda) ? ilambda_max : nlambda-1;
00389
00390 mask_size=ilambda_max-ilambda_min+1;
00391 mstart=ilambda_min-ilambda;
00392 mend=ilambda_max-ilambda;
00393
00394
00395 xsh_free_vector(&vec_wave_flag);
00396 vec_wave_flag=cpl_vector_new(mask_size);
00397 pflag=cpl_vector_get_data(vec_wave_flag);
00398 for (m = 0; m < mask_size; m++) {
00399 pflag[m]=0;
00400 }
00401 nflag=0;
00402 for (m = mstart; m <= mend; m++) {
00403 for (islit = slit_min; islit <= slit_max; islit++) {
00404 mdx = islit * nlambda + ilambda + m;
00405
00406 if ((qual[mdx] & instrument->decode_bp) > 0) {
00407 pflag[m-mstart]=1;
00408 nflag++;
00409 break;
00410 }
00411 }
00412 }
00413
00414
00415 if (nflag == mask_size) {
00416
00417
00418 *qualval = QFLAG_MISSING_DATA;
00419
00420 } else {
00421
00422
00423
00424 prof = cpl_malloc(nslit * sizeof(float));
00425 for (islit = 0; islit < nslit; islit++) {
00426 prof[islit] = 0;
00427 }
00428
00429
00430 for (m = mstart; m <= mend; m++) {
00431 if (pflag[m-mstart] == 0) {
00432 for (islit = slit_min; islit <= slit_max; islit++) {
00433 mdx = islit * nlambda + ilambda+m;
00434 prof[islit] += flux[mdx];
00435 }
00436 }
00437 }
00438
00439
00440 num_fct = 0;
00441 den_fct = 0;
00442 for (islit = slit_min; islit <= slit_max; islit++) {
00443 idx = islit * nlambda + ilambda;
00444 if ((qual[idx] & instrument->decode_bp) == 0) {
00445 err2 = errs[idx] * errs[idx];
00446 inv_err2=1./ err2;
00447 num_fct += prof[islit] * flux[idx] * inv_err2;
00448 den_fct += prof[islit] * prof[islit] * inv_err2 ;
00449 }
00450 }
00451 ipol_fct = num_fct / den_fct;
00452
00453
00454
00455 for (islit = slit_min; islit <= slit_max; islit++) {
00456 idx = islit * nlambda + ilambda;
00457 if ((qual[idx] & instrument->decode_bp) == 0) {
00458 *fluxval += flux[idx];
00459 *errval += (errs[idx] * errs[idx]);
00460 *qualval |= qual[idx];
00461 } else {
00462 *fluxval += ipol_fct * prof[islit];
00463 *errval += (prof[islit] * prof[islit])/ den_fct;
00464 *qualval |= QFLAG_INTERPOL_FLUX;
00465 }
00466 }
00467
00468 XSH_FREE(prof);
00469 }
00470
00471 xsh_free_vector(&vec_wave_flag);
00472
00473 }
00474
00475
00476 return cpl_error_get_code();
00477
00478 }
00479
00480
00500 static cpl_frame *
00501 xsh_extract_clean_with_tag(cpl_frame * rec_frame, cpl_frame* loc_frame,
00502 xsh_instrument* instrument, xsh_extract_param* extract_par,
00503 xsh_interpolate_bp_param * ipol_bp_par, const char * tag,
00504 cpl_frame** res_frame_ext) {
00505 cpl_frame *res_frame = NULL;
00506 xsh_localization *loc_list = NULL;
00507 xsh_rec_list *rec_list = NULL, *result_list = NULL;
00508 int i = 0;
00509 double slit_step = 0.0;
00510 char * fname = NULL;
00511 char * fname_drl = NULL;
00512 char * tag_drl = NULL;
00513 double slit_ext_min = 0;
00514 double slit_ext_max = 0;
00515 cpl_propertylist* plist = NULL;
00516 const char* name = NULL;
00517
00518 XSH_ASSURE_NOT_NULL( rec_frame);
00519 xsh_msg("Extract method clean with tag");
00520
00521 xsh_msg_dbg_medium( "Entering xsh_extract_with_tag(%s)", tag);
00522 xsh_msg_dbg_medium( "Parameters");
00523 xsh_msg_dbg_medium( " method %s", EXTRACT_METHOD_PRINT(extract_par->method));
00524
00525 if (extract_par->method == NOD_METHOD) {
00526 name = cpl_frame_get_filename(rec_frame);
00527 plist = cpl_propertylist_load(name, 0);
00528 slit_ext_min = xsh_pfits_get_extract_slit_min(plist);
00529 slit_ext_max = xsh_pfits_get_extract_slit_max(plist) - 2;
00530 xsh_free_propertylist(&plist);
00531 }
00532
00533
00534 check( rec_list = xsh_rec_list_load( rec_frame, instrument));
00535 check( slit_step = xsh_pfits_get_rectify_bin_space( rec_list->header));
00536
00537
00538 if ((extract_par->method != FULL_METHOD)
00539 && (extract_par->method != NOD_METHOD)) {
00540 XSH_ASSURE_NOT_NULL( loc_frame);
00541 xsh_msg("loc_frame name=%s", cpl_frame_get_filename(loc_frame));
00542 check( loc_list = xsh_localization_load( loc_frame));
00543 }check(
00544 result_list = xsh_rec_list_create_with_size( rec_list->size, instrument));
00545 int mask_hsize = ipol_bp_par->mask_hsize;
00546
00547 xsh_msg("Number of orders=%d", rec_list->size);
00548 for (i = 0; i < rec_list->size; i++) {
00549 int order = xsh_rec_list_get_order(rec_list, i);
00550 int nslit = xsh_rec_list_get_nslit(rec_list, i);
00551 int nlambda = xsh_rec_list_get_nlambda(rec_list, i);
00552 float* slit = xsh_rec_list_get_slit(rec_list, i);
00553 double* lambda = xsh_rec_list_get_lambda(rec_list, i);
00554 float slitmin = slit[0];
00555 float slitmax = slit[nslit - 1];
00556 double lambdamin = lambda[0];
00557 double lambdamax = lambda[nlambda - 1];
00558 float *flux = xsh_rec_list_get_data1(rec_list, i);
00559 float *errs = xsh_rec_list_get_errs1(rec_list, i);
00560 int *qual = xsh_rec_list_get_qual1(rec_list, i);
00561 int ilambda, islit;
00562
00563 double *res_lambda = NULL;
00564 float *res_flux = NULL, *res_errs = NULL;
00565 int *res_qual = NULL;
00566
00567
00568
00569
00570 xsh_msg_dbg_medium(
00571 "order %d nslit %d (%f,%f) nlambda %d (%f %f)", order, nslit, slitmin, slitmax, nlambda, lambdamin, lambdamax);
00572
00573 check( xsh_rec_list_set_data_size( result_list, i, order, nlambda, 1));
00574
00575 check( res_lambda = xsh_rec_list_get_lambda( result_list, i));
00576 check( res_flux = xsh_rec_list_get_data1( result_list, i));
00577 check( res_errs = xsh_rec_list_get_errs1( result_list, i));
00578 check( res_qual = xsh_rec_list_get_qual1( result_list, i));
00579
00580
00581
00582 for (ilambda = 0; ilambda < nlambda; ilambda++) {
00583
00584 int ylow = 0, yup = 0;
00585 double y_frac_low, y_frac_up;
00586 double fluxval = 0.0;
00587 double errval = 0.0;
00588 int qualval = 0;
00589 int idx;
00590
00591 if (extract_par->method == LOCALIZATION_METHOD) {
00592
00593 xsh_extraction_get_slit_minmax(loc_list, lambda[ilambda], slit[0],
00594 slit_step, nslit, &ylow, &yup, &y_frac_up, &y_frac_low);
00595
00596 xsh_msg_dbg_medium("ylow %d yup %d", ylow, yup);
00597
00598 if (mask_hsize <= 0) {
00599
00600 idx = ylow * nlambda + ilambda;
00601 if (idx >= (nlambda * nslit)) {
00602 xsh_msg_dbg_high(
00603 "Index Out of Image: %d >= %d (ylow: %d, ilambda: %d)", idx, nlambda*nslit, ylow, ilambda);
00604 continue;
00605 }
00606 fluxval += y_frac_low * flux[idx];
00607 errval += y_frac_low * (errs[idx] * errs[idx]);
00608 qualval |= qual[idx];
00609
00610
00611 for (islit = ylow + 1; islit < yup; islit++) {
00612 idx = islit * nlambda + ilambda;
00613 fluxval += flux[idx];
00614 errval += errs[idx] * errs[idx];
00615 qualval |= qual[idx];
00616 }
00617
00618
00619 if (yup < nslit) {
00620 idx = yup * nlambda + ilambda;
00621 fluxval += y_frac_up * flux[idx];
00622 errval += y_frac_up * errs[idx] * errs[idx];
00623 qualval |= qual[idx];
00624 }
00625
00626 } else {
00627 int slit_min = ylow + 1;
00628 int slit_max = yup;
00629
00630 xsh_extract_clean_slice(flux, errs, qual, lambda,
00631 ilambda, instrument, slit_min, slit_max, nlambda, nslit,
00632 mask_hsize, &fluxval, &errval, &qualval);
00633
00634 }
00635
00636
00637 } else if (extract_par->method == NOD_METHOD) {
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649 ylow = slit_ext_min;
00650 yup = slit_ext_max;
00651
00652 if (mask_hsize <= 0) {
00653 for (islit = ylow; islit <= yup; islit++) {
00654 idx = islit * nlambda + ilambda;
00655 fluxval += flux[idx];
00656 errval += errs[idx] * errs[idx];
00657 qualval |= qual[idx];
00658 }
00659
00660 } else {
00661
00662 int slit_min = ylow + 1;
00663 int slit_max = yup;
00664
00665 xsh_extract_clean_slice(flux, errs, qual, lambda,
00666 ilambda, instrument, slit_min, slit_max, nlambda, nslit,
00667 mask_hsize, &fluxval, &errval, &qualval);
00668 }
00669 }
00670 res_lambda[ilambda] = lambda[ilambda];
00671 res_flux[ilambda] = fluxval;
00672 res_errs[ilambda] = sqrt(errval);
00673 res_qual[ilambda] = qualval;
00674 }
00675
00676 }
00677
00678 check( cpl_propertylist_append ( result_list->header, rec_list->header));
00679 check( xsh_pfits_set_pcatg( result_list->header, tag));
00680 fname = xsh_stringcat_any(tag, ".fits", NULL);
00681 tag_drl = xsh_stringcat_any(tag, "_DRL", NULL);
00682 fname_drl = xsh_stringcat_any(tag_drl, ".fits", NULL);
00683
00684 check( *res_frame_ext= xsh_rec_list_save2( result_list,fname, tag));
00685 check( res_frame = xsh_rec_list_save( result_list, fname_drl, tag_drl,0));
00686
00687 xsh_msg_dbg_medium("%s created", fname);
00688
00689 cleanup: xsh_rec_list_free(&result_list);
00690 xsh_rec_list_free(&rec_list);
00691 xsh_localization_free(&loc_list);
00692
00693 XSH_FREE( tag_drl);
00694 XSH_FREE( fname_drl);
00695 XSH_FREE( fname);
00696
00697 return res_frame;
00698 }
00699
00700
00701
00702
00703
00715 cpl_frame*
00716 xsh_extract(cpl_frame * rec_frame, cpl_frame* loc_frame,
00717 xsh_instrument* instrument, xsh_extract_param* extract_par,
00718 cpl_frame** res_frame_ext, const char* rec_prefix) {
00719 cpl_frame *res_frame = NULL;
00720 char tag[256];
00721
00722 sprintf(tag, "%s_%s", rec_prefix,
00723 XSH_GET_TAG_FROM_ARM( XSH_ORDER1D, instrument));
00724
00725 check( res_frame = xsh_extract_with_tag( rec_frame, loc_frame, instrument,
00726 extract_par, tag,res_frame_ext ) );
00727 xsh_add_temporary_file(cpl_frame_get_filename(res_frame));
00728 cleanup: return res_frame;
00729 }
00730
00743 cpl_frame*
00744 xsh_extract_clean(cpl_frame * rec_frame, cpl_frame* loc_frame,
00745 xsh_instrument* instrument, xsh_extract_param* extract_par,
00746 xsh_interpolate_bp_param * ipol_bp_par, cpl_frame** res_frame_ext,
00747 const char* rec_prefix) {
00748 cpl_frame *res_frame = NULL;
00749 char tag[256];
00750
00751 sprintf(tag, "%s_%s", rec_prefix,
00752 XSH_GET_TAG_FROM_ARM( XSH_ORDER1D, instrument));
00753
00754 check(
00755 res_frame=xsh_extract_clean_with_tag( rec_frame, loc_frame, instrument, extract_par, ipol_bp_par, tag,res_frame_ext ));
00756
00757
00758
00759
00760
00761
00762 xsh_add_temporary_file(cpl_frame_get_filename(res_frame));
00763 cleanup: return res_frame;
00764 }
00765
00776 cpl_frameset * xsh_extract_ifu(cpl_frameset * rec_frameset,
00777 cpl_frameset * loc_frameset, xsh_instrument* instrument,
00778 xsh_extract_param * extract_par, const char* rec_prefix) {
00779 cpl_frameset * result_set = NULL;
00780 int slitlet;
00781 int i;
00782
00783 xsh_msg( " Entering xsh_extract_ifu");
00784 XSH_ASSURE_NOT_NULL( rec_frameset);
00785
00786 XSH_ASSURE_NOT_NULL( instrument);
00787 XSH_ASSURE_NOT_NULL( extract_par);
00788
00789 check( result_set = cpl_frameset_new());
00790
00791
00792 for (i = 0, slitlet = LOWER_IFU_SLITLET; slitlet <= UPPER_IFU_SLITLET;
00793 slitlet++, i++) {
00794 cpl_frame * loc_frame = NULL;
00795 cpl_frame * rec_frame = NULL;
00796 cpl_frame * ext_frame = NULL;
00797 cpl_frame * ext_frame_eso = NULL;
00798 char tag[256];
00799 const char * tag_suf = NULL;
00800
00801 switch (slitlet) {
00802 case LOWER_IFU_SLITLET:
00803 tag_suf = XSH_GET_TAG_FROM_ARM( XSH_ORDER1D_DOWN_IFU,
00804 instrument);
00805 break;
00806 case CENTER_IFU_SLITLET:
00807 tag_suf = XSH_GET_TAG_FROM_ARM( XSH_ORDER1D_CEN_IFU,
00808 instrument);
00809 break;
00810 case UPPER_IFU_SLITLET:
00811 tag_suf = XSH_GET_TAG_FROM_ARM( XSH_ORDER1D_UP_IFU,
00812 instrument);
00813 break;
00814 }
00815 sprintf(tag, "%s_%s", rec_prefix, tag_suf);
00816 xsh_msg( " Slitlet %s", SlitletName[slitlet]);
00817 check( rec_frame = cpl_frameset_get_frame( rec_frameset, i ));
00818 xsh_msg( " REC Frame '%s' Got", cpl_frame_get_filename( rec_frame ));
00819
00820 if (loc_frameset != NULL) {
00821 check( loc_frame = cpl_frameset_get_frame( loc_frameset, i ));
00822 xsh_msg( " LOC Frame '%s' Got", cpl_frame_get_filename( loc_frame ));
00823 } else {
00824 xsh_msg_dbg_medium( "No localization table");
00825 }
00826
00827 xsh_msg( "Calling xsh_extract");
00828 check(
00829 ext_frame = xsh_extract_with_tag( rec_frame, loc_frame, instrument, extract_par, tag,&ext_frame_eso));
00830 xsh_msg( "Extracted frame '%s'", cpl_frame_get_filename( ext_frame ));
00831 check( cpl_frameset_insert( result_set, ext_frame_eso ));
00832 check( cpl_frameset_insert( result_set, ext_frame ));
00833 }
00834
00835 cleanup:
00836 xsh_msg( "Exit xsh_extract_ifu");
00837 return result_set;
00838 }
00839
00840
00841