00001 /* $Id: omega_stare.c,v 1.11 2011/08/30 14:09:14 agabasch Exp $ 00002 * 00003 * This file is part of the OMEGA Pipeline 00004 * Copyright (C) 2002,2003 European Southern Observatory 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 /* 00022 * $Author: agabasch $ 00023 * $Date: 2011/08/30 14:09:14 $ 00024 * $Revision: 1.11 $ 00025 * $Name: omega-0_9_8 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 /*----------------------------------------------------------------------------- 00033 Includes 00034 -----------------------------------------------------------------------------*/ 00035 00036 #include <string.h> 00037 #include <math.h> 00038 #include <stdlib.h> 00039 00040 #include "omega_wcscor.h" 00041 #include "omega_background.h" 00042 #include "omega_bpm.h" 00043 #include "omega_cosmic.h" 00044 #include "omega_dfs.h" 00045 #include "omega_flats.h" 00046 #include "omega_fits.h" 00047 #include "omega_pfits.h" 00048 #include "omega_satellites.h" 00049 #include "omega_science.h" 00050 #include "omega_stats.h" 00051 #include "omega_trim.h" 00052 #include "omega_utils.h" 00053 00054 #define RECIPE "omega_science" 00055 00092 /*int omega_science_process(cpl_parameterlist *pars, int nraw, int ext) 00093 { 00094 00095 int i = 0; 00096 double exptime = 0.0; 00097 const char *tmpreduced = "omega_stare_reduced_temp.fits"; 00098 const char *bckname = "omega_stare_back_temp.fits"; 00099 const char *weight_name = "omega_stare_weight_temp.fits"; 00100 const char *starename = "omega_stare_temp.fits"; 00101 const char *smoothed = "omega_stare_smoothed.fits"; 00102 const char *refname,*monit_name, *extname; 00103 const char *colname = NULL; 00104 00105 cpl_image *bpm_img, *mask_img, *image, *weight, *weight_img; 00106 cpl_image *illum_img = NULL; 00107 cpl_image *backimg = NULL; 00108 cpl_image *reduced = NULL; 00109 cpl_image *smooth = NULL; 00110 cpl_mask *satu_map,*bpm_map; 00111 cpl_mask *cosmic_map, *satellite_map; 00112 cpl_propertylist *plist; 00113 cpl_table *phototbl, *exttbl; 00114 const cpl_frame *stareframe; 00115 00116 All member of ps structure are deallocated in main recipe 00117 00118 Load master flat 00119 ps.mflat = cpl_image_load(cpl_frame_get_filename(ps.mflatfr),CPL_TYPE_FLOAT,0,ext); 00120 if (ps.mflat == NULL){ 00121 cpl_msg_error(cpl_func,"Cannot load Master Flat image",cpl_error_get_message()); 00122 return -1; 00123 } 00124 if(cpl_image_get_mean(ps.mflat) < 0.1){ 00125 cpl_msg_error(cpl_func,"Master Flat image is NULL"); 00126 return -1; 00127 } 00128 00129 Load bad pixels map 00130 bpm_img = cpl_image_load(cpl_frame_get_filename(ps.bpmfr), CPL_TYPE_INT, 0, ext); 00131 if(bpm_img == NULL){ 00132 cpl_msg_error(cpl_func, "Cannot load BPM", cpl_error_get_message()); 00133 return -1; 00134 } 00135 00136 Load optional illumination map 00137 if(ps.illumfr != NULL) 00138 illum_img = cpl_image_load(cpl_frame_get_filename(ps.illumfr),CPL_TYPE_FLOAT,0,ext); 00139 00140 Loop through all science frames in frame set 00141 stareframe = cpl_frameset_get_first_const(ps.scilist); 00142 00143 for (i = 0; i < nraw; i++){ 00144 cpl_msg_info(cpl_func,"Reducing image %s", cpl_frame_get_filename(stareframe)); 00145 00146 Create a Saturated Pixels Map 00147 satu_map = create_saturated_map(stareframe, omega_science_config.oc, ext, pars); 00148 if (satu_map == NULL) 00149 cpl_msg_warning(cpl_func,"Null saturation map"); 00150 00151 Create logical mask from saturated map and input bad pixels map 00152 bpm_map = cpl_mask_threshold_image_create(bpm_img, 0.5, 1.5) ; 00153 if(satu_map != NULL){ 00154 cpl_mask_and(bpm_map, satu_map); 00155 freemask(satu_map); 00156 } 00157 mask_img = cpl_image_new_from_mask(bpm_map); 00158 freemask(bpm_map); 00159 00160 Create Reduced image 00161 reduced = omega_reduce_science(stareframe, mask_img, pars, ext); 00162 if(reduced == NULL){ 00163 freeimage(ps.mflat); 00164 ps.mflat = NULL; 00165 freeimage(mask_img); 00166 freeimage(bpm_img); 00167 freeimage(illum_img); 00168 cpl_msg_error(cpl_func,"Cannot reduce image"); 00169 return -1; 00170 } 00171 00172 Create Cosmic Rays Map 00173 image = cpl_image_cast(mask_img,CPL_TYPE_FLOAT); 00174 weight = cpl_image_multiply_create(ps.mflat,image); 00175 freeimage(image); 00176 00177 if(ps.illumfr != NULL) 00178 cpl_image_divide(weight,illum_img); 00179 00180 cpl_image_power(weight, 0.5); 00181 cpl_image_save(reduced, tmpreduced, BITPIX, NULL, CPL_IO_DEFAULT); 00182 omega_create_background(pars, tmpreduced, bckname); 00183 backimg = cpl_image_load(bckname,CPL_TYPE_FLOAT, 0, 0); 00184 image = cpl_image_subtract_create(reduced,backimg); 00185 cpl_image_multiply(image,weight); 00186 freeimage(backimg); 00187 freeimage(weight); 00188 00189 cosmic_map = detcosmic(image, pars); 00190 if(cosmic_map == NULL) 00191 cpl_msg_warning(cpl_func,"Cannot create cosmic rays map"); 00192 00193 Create Satellite Tracks Map 00194 FIXME: revise this function 00195 satellite_map = detsat(image, pars); 00196 if(satellite_map == NULL) 00197 cpl_msg_warning(cpl_func,"Cannot create satellite tracks map"); 00198 00199 freeimage(image); 00200 00201 Create Weight Map 00202 weight_img = create_weightframe(ps.mflat, mask_img, cosmic_map, satellite_map); 00203 if(weight_img == NULL){ 00204 cpl_msg_warning(cpl_func,"Cannot create weight map"); 00205 weight_img = NULL; 00206 } 00207 00208 if((illum_img != NULL) && (weight_img != NULL)) { 00209 cpl_image_divide(weight_img, illum_img); 00210 } 00211 00212 freeimage(mask_img); 00213 freemask(cosmic_map); 00214 freemask(satellite_map); 00215 00216 Multiply each science by its weight frame 00217 // cpl_image_save(weight_img, weight_name, BITPIX, NULL, CPL_IO_DEFAULT); 00218 cpl_image_multiply(reduced, weight_img); 00219 00220 if(i == 0){ 00221 ps.reduced = cpl_image_duplicate(reduced); 00222 ps.weight = cpl_image_duplicate(weight_img); 00223 } 00224 else{ 00225 cpl_image_add(ps.reduced, reduced); 00226 cpl_image_add(ps.weight, weight_img); 00227 } 00228 freeimage(reduced); 00229 freeimage(weight_img); 00230 00231 Get next frame 00232 stareframe = cpl_frameset_get_next_const(ps.scilist); 00233 } 00234 00235 freeimage(ps.mflat); 00236 ps.mflat = NULL; 00237 freeimage(bpm_img); 00238 freeimage(illum_img); 00239 00240 Weighted average of STARE frames 00241 if(cpl_image_divide(ps.reduced, ps.weight) != CPL_ERROR_NONE){ 00242 cpl_msg_error(cpl_func,"Cannot create weighted average of images. %s", cpl_error_get_message()); 00243 // freeimage(sumwght); 00244 dummy = 1; 00245 return 1; 00246 } 00247 00248 Cast weight map to INT 00249 ps.weight = cpl_image_cast(ps.weight,CPL_TYPE_INT); 00250 00251 Correct coordinates after trimming 00252 ps.astrolist = cpl_propertylist_duplicate(ps.eh); 00253 if(omega_shift_refpix(ps.firstframe, ext, ps.astrolist) != 0){ 00254 cpl_msg_warning(cpl_func,"Cannot shift reference pixel of trimmed image"); 00255 freeplist(ps.astrolist); 00256 ps.astrolist = NULL; 00257 dummy = 1; 00258 return 1; 00259 } 00260 00261 00262 * Calculate new zeropoint using photometric table 00263 00264 photom_tbl = cpl_table_load(cpl_frame_get_filename(ps.photomfr),ext,0); 00265 if(photom_tbl == NULL){ 00266 cpl_msg_error(cpl_func,"Cannot load photometric table. %s",cpl_error_get_message()); 00267 return -1; 00268 } 00269 00270 zeropoint = cpl_table_get_float(photom_tbl,"ZEROPOINT",0,NULL); 00271 extinction = cpl_table_get_float(photom_tbl,"EXTINCTION",0,NULL); 00272 omega_sci_qc.ZP = zeropoint + 2.5* log10 (omega_pfits_get_exptime(ps.eh)); 00273 omega_sci_qc.ZP -= extinction*omega_pfits_get_mean_airmass(ps.ph,&airmass); 00274 freetable(photom_tbl); 00275 00276 Add newZP to header of product 00277 cpl_propertylist_update_float(ps.astrolist,"ESO QC SCI ZEROPNT",omega_sci_qc.ZP); 00278 cpl_propertylist_set_comment(ps.astrolist,"ESO QC SCI ZEROPNT", "new zeropoint"); 00279 00280 00281 * Use pattern matching to detect stars. 00282 * Smooth image before creating catalogue 00283 00284 smooth = omega_smooth_image(ps.reduced, 7); 00285 00286 Save star as intermediate product 00287 cpl_propertylist_save(NULL,smoothed, CPL_IO_CREATE); 00288 cpl_image_save(smooth, smoothed, BITPIX, ps.astrolist, CPL_IO_EXTEND); 00289 freeimage(smooth); 00290 00291 00292 * Calculate WCS distortion for image 00293 00294 plist = omega_match_points(smoothed, ps.usnoa2, pars, 00295 &omega_sci_qc.nmatches, &omega_sci_qc.mratio); 00296 00297 if(plist == NULL){ 00298 cpl_msg_warning(cpl_func,"Error in astrometric calculation"); 00299 freeplist(plist); 00300 dummy = 0; 00301 return 1; 00302 } 00303 00304 Append WCS header to extension header 00305 if(omega_pfits_update_header(&ps.astrolist, plist) != 0) 00306 cpl_msg_debug(cpl_func,"Cannot append WCS header to extension header"); 00307 00308 freeplist(plist); 00309 00310 00311 * NOTE: Need a secondary standard star catalogue to 00312 * calculate ZP for all science frames!!! 00313 00314 00315 return 0; 00316 }*/ 00317 00318 00338 omega_fits *omega_jitter_process(omega_fits *scifits, 00339 const cpl_image *mbias, 00340 const cpl_image *mflat, 00341 const cpl_image *bpm, 00342 const cpl_table *photom, 00343 const cpl_frame *usnoa2, 00344 const cpl_image *illum, 00345 const cpl_image *fringes, 00346 const cpl_image *nsky, 00347 double * zeropoint_final, 00348 cpl_parameterlist *pars, int ext) 00349 { 00350 00351 int i = 0; 00352 int oc = 0; 00353 int sub_back = 0; 00354 int nmatches = 0; 00355 double ZP = 0.0; 00356 double zeropoint = 0.0; 00357 double zeropoint_error = 0.0; 00358 double extinction = 0.0; 00359 double median = 1.0; 00360 double mratio = 0.0; 00361 double exptime = 0.0; 00362 double airmass = 0.0; 00363 double gain = 1.0; 00364 const char *smoothed = "omega_sci_smoothed.fits"; 00365 const char *smoothed_weight = "omega_sci_smoothed_weight.fits"; 00366 00367 cpl_image *mask_img, *image, *trim, *reduced, *combmap; 00368 cpl_image *back = NULL; 00369 cpl_image *smooth = NULL; 00370 cpl_mask *satu_map,*bpm_map, *mask; 00371 cpl_mask *cosmic, *satellite; 00372 cpl_propertylist *plist, *astrolist, *wcslist; 00373 cpl_parameter *p; 00374 omega_fits *simplefits; 00375 00376 00377 if((scifits == NULL) || (mbias == NULL) || (mflat == NULL) || 00378 (bpm == NULL) || (photom == NULL) || (usnoa2 == NULL) || (pars == NULL)) 00379 return NULL; 00380 00381 /* if(cpl_image_get_mean(mflat) < 0.1){ 00382 cpl_msg_error(cpl_func,"Master Flat image is NULL"); 00383 return NULL; 00384 }*/ 00385 00386 /* Get a few parameters */ 00387 p = cpl_parameterlist_find(pars, "omega.omega_science.OverscanMethod") ; 00388 oc = cpl_parameter_get_int(p); 00389 p = cpl_parameterlist_find(pars,"omega.omega_science.SubtractBackground"); 00390 sub_back = cpl_parameter_get_bool(p); 00391 00392 /* Calculate new zeropoint using photometric table */ 00393 zeropoint = cpl_table_get_double(photom,"ZEROPOINT",0,NULL); 00394 zeropoint_error = cpl_table_get_double(photom, "ZEROPOINT_ERR", 0, NULL); 00395 extinction = cpl_table_get_double(photom,"EXTINCTION",0,NULL); 00396 00397 00398 /* Trim and overscan correct all images */ 00399 if((trim = omega_trim_oscan_correct(scifits, oc)) == NULL){ 00400 cpl_msg_error(cpl_func,"Unable to trim image"); 00401 return NULL; 00402 } 00403 00404 /* Correct coordinates after trimming */ 00405 astrolist = omega_fits_get_ehu(scifits); 00406 omega_shift_refpix(omega_fits_get_frame(scifits), ext, astrolist); 00407 00408 /* Add newZP to header of product */ 00409 plist = omega_fits_get_phu(scifits); 00410 if((exptime = omega_pfits_get_exptime(astrolist)) <= 0.0) 00411 exptime = omega_pfits_get_exptime(plist); 00412 00413 00414 ZP = zeropoint + 2.5* log10(exptime); 00415 omega_pfits_get_mean_airmass(plist,&airmass); 00416 ZP -= extinction*airmass; 00417 00418 cpl_propertylist_update_double(astrolist,"ESO QC SCI ZEROPNT",ZP); 00419 cpl_propertylist_set_comment(astrolist,"ESO QC SCI ZEROPNT", "new zp with flux in ADU"); 00420 cpl_propertylist_update_double(astrolist, "ESO QC SCI ZEROPNT ERR", zeropoint_error) ; 00421 cpl_propertylist_set_comment(astrolist, "ESO QC SCI ZEROPNT ERR", "zp error"); 00422 00423 00424 /*Get gain*/ 00425 omega_pfits_get_conad(astrolist,&gain); 00426 00427 cpl_propertylist_update_double(astrolist,"ESO QC SCI ZEROPNT_ELECTRON",ZP+(2.5*log10(gain))); 00428 cpl_propertylist_set_comment(astrolist,"ESO QC SCI ZEROPNT_ELECTRON", "new zp with flux in e-"); 00429 cpl_propertylist_update_double(astrolist, "ESO QC SCI ZEROPNT_ELECTRON ERR", zeropoint_error) ; 00430 cpl_propertylist_set_comment(astrolist, "ESO QC SCI ZEROPNT_ELECTRON ERR", "zp error"); 00431 00432 *zeropoint_final=ZP; 00433 00434 /* Subtract the bias */ 00435 omega_biascor(trim, mbias); 00436 00437 /* Divide by the flat */ 00438 if(omega_flatcor(trim, mflat, nsky) != 0){ 00439 cpl_msg_error(cpl_func,"Error in flat correction"); 00440 freeimage(trim); 00441 plist = NULL; 00442 astrolist = NULL; 00443 return NULL; 00444 } 00445 00446 /* Create BPM+SATURATION mask */ 00447 satu_map = omega_saturated_map(trim, oc, pars); 00448 00449 bpm_map = cpl_mask_threshold_image_create(bpm, 0.5, 1.5) ; 00450 if(satu_map != NULL){ 00451 // cpl_mask_and(bpm_map, satu_map); 00452 cpl_mask_or(bpm_map, satu_map); 00453 freemask(satu_map); 00454 } 00455 mask_img = cpl_image_new_from_mask(bpm_map); 00456 freemask(bpm_map); 00457 00458 /* Correct for fringing */ 00459 if(fringes != NULL){ 00460 omega_fringecor(trim, fringes, mask_img, pars); 00461 } 00462 00463 /* Get background */ 00464 back = omega_background(trim, pars); 00465 00466 if(back != NULL){ 00467 median = cpl_image_get_median(back); 00468 cpl_propertylist_update_double(astrolist, "ESO DRS MEDIAN BKG", median); 00469 } 00470 if(back == NULL) 00471 cpl_msg_debug(cpl_func,"Unable to create background image"); 00472 00473 /* Detect cosmic rays */ 00474 image = cpl_image_subtract_create(trim, back); 00475 cosmic = omega_cosmic_rays(image,mflat,illum,mask_img,pars); 00476 00477 /* Subtract background from science */ 00478 if(sub_back == 1){ 00479 freeimage(trim); 00480 trim = cpl_image_duplicate(image); 00481 } 00482 00483 freeimage(image); 00484 freeimage(back); 00485 00486 /* Detect satellite tracks in background subtracted image */ 00487 satellite = detsat(trim, pars); 00488 00489 /* Create combination map (BPM,saturated,cosmic,satellite) */ 00490 /* The bad pixels are set to CPL_BINARY_0 in combmap */ 00491 combmap = create_weightframe(mflat,mask_img,cosmic,satellite); 00492 // cpl_image_save(combmap,"combmap.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_CREATE); 00493 00494 freemask(satellite); 00495 freemask(cosmic); 00496 freeimage(mask_img); 00497 00498 /* Save median value of image in header */ 00499 mask = cpl_mask_threshold_image_create(combmap, 0.5, 1.5); 00500 cpl_mask_not(mask); 00501 cpl_image_reject_from_mask(trim, mask); 00502 median = cpl_image_get_median(trim); 00503 cpl_propertylist_update_double(astrolist, "ESO DRS MEDIAN", median); 00504 00505 00506 /* Clean bad pixels */ 00507 if(cpl_detector_interpolate_rejected(trim) != CPL_ERROR_NONE) 00508 cpl_msg_debug(cpl_func,"Cannot clean rejected pixels. %s",cpl_error_get_message()); 00509 00510 /*The image should remember the bad pixels even after interpolation!*/ 00511 00512 00513 /* 00514 * Use pattern matching to detect stars. 00515 */ 00516 00517 /* Smooth image before creating catalogue */ 00518 smooth = omega_smooth_image(trim, 1); 00519 00520 cpl_image_reject_from_mask(trim, mask); 00521 freemask(mask); 00522 00523 /* Save star as intermediate product */ 00524 cpl_propertylist_save(plist,smoothed, CPL_IO_CREATE); 00525 cpl_image_save(smooth, smoothed, CPL_BPP_IEEE_FLOAT, astrolist, CPL_IO_EXTEND); 00526 00527 /* Save weight map as intermediate product */ 00528 cpl_propertylist_save(plist,smoothed_weight, CPL_IO_CREATE); 00529 cpl_image_save(combmap, smoothed_weight, CPL_BPP_IEEE_FLOAT, astrolist, CPL_IO_EXTEND); 00530 00531 freeimage(smooth); 00532 freeimage(combmap); 00533 /* 00534 * Calculate WCS distortion for simple image 00535 */ 00536 wcslist = omega_match_points(smoothed, smoothed_weight, usnoa2, pars,ext,&nmatches, &mratio); 00537 00538 /* Debugging information */ 00539 cpl_msg_debug(cpl_func,"Number matches between USNOA2 cat and stars. %d", nmatches); 00540 cpl_msg_debug(cpl_func,"ratio USNOA2 matches/detected stars. %g", mratio); 00541 00542 if(wcslist == NULL){ 00543 cpl_msg_warning(cpl_func,"Unable to calculate WCS distortion for image. %s", 00544 cpl_error_get_message()); 00545 } 00546 00547 /* Append WCS header to extension header */ 00548 omega_pfits_update_header(astrolist, wcslist); 00549 freeplist(wcslist); 00550 00551 /* Wrap product into omega fits structure using 1st frame headers */ 00552 simplefits = omega_fits_wrap(trim,NULL,plist,astrolist); 00553 00554 // plist = NULL; 00555 // astrolist = NULL; 00556 00557 return simplefits; 00558 00559 } 00560 00561 /* 00562 * Copied from omega_reduce_std() 00563 */ 00564 /* 00565 cpl_image *omega_reduce_science(const cpl_frame *sciframe, cpl_image *mask_img, 00566 cpl_parameterlist *pars, int ext) 00567 { 00568 00569 const char *cpl_func = "make_std_reduced"; 00570 const char *bckname = "omega_background_temp.fits"; 00571 const char *tempname1111 = "omega_reduced_temp.fits"; 00572 cpl_image *trim_img, *mbias_img, *mflat_img, *nsky_img; 00573 cpl_image *back_img = NULL; 00574 cpl_image *illum_img = NULL; 00575 cpl_image *fringe_img = NULL; 00576 cpl_image *reduced = NULL; 00577 cpl_mask *bpmtemp_map; 00578 00579 00580 Trim and overscan correct image 00581 trim_img = TrimOscanCorrect(sciframe, omega_science_config.oc, ext); 00582 if (trim_img == NULL) { 00583 cpl_msg_error(cpl_func,"Cannot trim image %s",cpl_error_get_message()); 00584 return NULL; 00585 } 00586 00587 Subtract the bias 00588 mbias_img = cpl_image_load(cpl_frame_get_filename(ps.mbiasfr), CPL_TYPE_FLOAT,0,ext); 00589 if (mbias_img == NULL) { 00590 cpl_msg_error(cpl_func,"Cannot load master bias %s", cpl_error_get_message()); 00591 freeimage(trim_img); 00592 return NULL; 00593 } 00594 cpl_image_subtract(trim_img, mbias_img); 00595 freeimage(mbias_img); 00596 00597 00598 Correct for flat field. If there is a night sky flat, use it. 00599 if(ps.nskyfr != NULL){ 00600 nsky_img = cpl_image_load(cpl_frame_get_filename(ps.nskyfr), CPL_TYPE_FLOAT, 0, ext); 00601 if(nsky_img != NULL){ 00602 mflat_img = cpl_image_multiply_create(ps.mflat, nsky_img); 00603 cpl_image_divide(trim_img, mflat_img); 00604 freeimage(nsky_img); 00605 freeimage(mflat_img); 00606 } 00607 else { 00608 cpl_image_divide(trim_img, ps.mflat); 00609 } 00610 } 00611 else { 00612 cpl_image_divide(trim_img, ps.mflat); 00613 } 00614 00615 Correct for fringing. Check if filter really requires fringing correction 00616 FIXME: should this be a fatal error or a warning? 00617 if(ps.fringesfr != NULL){ 00618 fringe_img = cpl_image_load(cpl_frame_get_filename(ps.fringesfr),CPL_TYPE_FLOAT,0,ext); 00619 if(fringe_img == NULL) { 00620 cpl_msg_warning(cpl_func,"Cannot load Master Fringe image"); 00621 reduced = cpl_image_duplicate(trim_img); 00622 } 00623 else { 00624 bpmtemp_map = cpl_mask_threshold_image_create(mask_img, 0.5, 1.5); 00625 cpl_msg_info(cpl_func,"Applying fringing correction"); 00626 reduced = omega_fringecor(trim_img,fringe_img, bpmtemp_map, pars); 00627 if(reduced == NULL) { 00628 cpl_msg_warning(cpl_func,"Cannot apply fringing correction"); 00629 reduced = cpl_image_duplicate(trim_img); 00630 } 00631 freemask(bpmtemp_map); 00632 freeimage(fringe_img); 00633 } 00634 00635 } 00636 else { 00637 reduced = cpl_image_duplicate(trim_img); 00638 } 00639 00640 freeimage(trim_img); 00641 00642 FIXME: review this 00643 Illumination Correction and Background subtraction 00644 // iillum = (illum == NULL) ? 0 : 1; 00645 00646 if((ps.illumfr != NULL) && (omega_science_config.bckg == 0)){ 00647 00648 // if (!(iillum == 0 && bckg == 1)) { 00649 Save temporary image to create a background in Sextractor 00650 cpl_image_save(reduced, tempname1111, BITPIX, NULL, CPL_IO_DEFAULT); 00651 00652 cpl_msg_info("","Measuring statistics with background"); 00653 00654 stats = omega_iter_stat_opts(reduced_img, 5.0, 5); 00655 cpl_msg_info("","Mean :%10.3f",cpl_stats_get_mean(stats)); 00656 cpl_msg_info("","Median :%10.3f",cpl_stats_get_median(stats)); 00657 cpl_msg_info("","Stdev :%10.3f",cpl_stats_get_stdev(stats)); 00658 00659 cpl_msg_info(cpl_func,"Doing background subtraction"); 00660 if(omega_create_background(pars, tempname1111, bckname) != 0){ 00661 cpl_msg_error(cpl_func,"Cannot create background image"); 00662 freeimage(reduced); 00663 return NULL; 00664 } 00665 00666 back_img = cpl_image_load(bckname, CPL_TYPE_FLOAT, 0, 0); 00667 if(back_img == NULL) { 00668 cpl_msg_warning(cpl_func,"Cannot load background image %s", bckname); 00669 freeimage(reduced); 00670 return NULL; 00671 } 00672 00673 cpl_image_subtract(reduced, back_img); 00674 cpl_stats_delete(stats); 00675 } 00676 00677 00678 // if(iillum == 1) { 00679 if (ps.illumfr != NULL){ 00680 illum_img = cpl_image_load(cpl_frame_get_filename(ps.illumfr),CPL_TYPE_FLOAT, 0, ext); 00681 if(illum_img != NULL) { 00682 cpl_msg_info(cpl_func,"Applying illumination correction"); 00683 cpl_image_multiply(reduced, illum_img); 00684 freeimage(illum_img); 00685 } 00686 else{ 00687 cpl_msg_warning(cpl_func,"Cannot load Illumination Correction image"); 00688 } 00689 if(omega_std_config.bckg == 1) { 00690 cpl_msg_info("","Restoring background to image"); 00691 cpl_image_add(reduced, back_img); 00692 } 00693 } 00694 00695 00696 if (back_img != NULL){ 00697 freeimage(back_img); 00698 } 00699 00700 return reduced; 00701 00702 00703 } 00704 */ 00705 00706