00001 /* $Id: omega_stare.c,v 1.12 2012/03/29 12:17:12 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: 2012/03/29 12:17:12 $ 00024 * $Revision: 1.12 $ 00025 * $Name: omega-1_0_2 $ 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 double mag_zpt_no_std_table=0.0; 00376 double mag_zpt_err_no_std_table=0.0; 00377 double ext_no_std_table=0.0; 00378 00379 if((scifits == NULL) || (mbias == NULL) || (mflat == NULL) || 00380 (bpm == NULL) || (usnoa2 == NULL) || (pars == NULL)) 00381 return NULL; 00382 00383 00384 /* if(cpl_image_get_mean(mflat) < 0.1){ 00385 cpl_msg_error(cpl_func,"Master Flat image is NULL"); 00386 return NULL; 00387 }*/ 00388 00389 /* Get a few parameters */ 00390 p = cpl_parameterlist_find(pars, "omega.omega_science.OverscanMethod") ; 00391 oc = cpl_parameter_get_int(p); 00392 p = cpl_parameterlist_find(pars,"omega.omega_science.SubtractBackground"); 00393 sub_back = cpl_parameter_get_bool(p); 00394 00395 00396 p = cpl_parameterlist_find(pars, "omega.omega_science.mag_zpt_no_std_table") ; 00397 mag_zpt_no_std_table = cpl_parameter_get_double(p); 00398 p = cpl_parameterlist_find(pars,"omega.omega_science.mag_zpt_err_no_std_table"); 00399 mag_zpt_err_no_std_table = cpl_parameter_get_double(p); 00400 p = cpl_parameterlist_find(pars,"omega.omega_science.ext_no_std_table"); 00401 ext_no_std_table = cpl_parameter_get_double(p); 00402 00403 00404 /* Calculate new zeropoint using photometric table or use default values*/ 00405 00406 if(photom != NULL){ 00407 zeropoint = cpl_table_get_double(photom,"ZEROPOINT",0,NULL); 00408 zeropoint_error = cpl_table_get_double(photom, "ZEROPOINT_ERR", 0, NULL); 00409 extinction = cpl_table_get_double(photom,"EXTINCTION",0,NULL); 00410 } 00411 else { 00412 zeropoint = mag_zpt_no_std_table; 00413 zeropoint_error = mag_zpt_err_no_std_table; 00414 extinction = ext_no_std_table; 00415 } 00416 /* Trim and overscan correct all images */ 00417 if((trim = omega_trim_oscan_correct(scifits, oc)) == NULL){ 00418 cpl_msg_error(cpl_func,"Unable to trim image"); 00419 return NULL; 00420 } 00421 00422 /* Correct coordinates after trimming */ 00423 astrolist = omega_fits_get_ehu(scifits); 00424 omega_shift_refpix(omega_fits_get_frame(scifits), ext, astrolist); 00425 00426 /* Add newZP to header of product */ 00427 plist = omega_fits_get_phu(scifits); 00428 if((exptime = omega_pfits_get_exptime(astrolist)) <= 0.0) 00429 exptime = omega_pfits_get_exptime(plist); 00430 00431 00432 ZP = zeropoint + 2.5* log10(exptime); 00433 omega_pfits_get_mean_airmass(plist,&airmass); 00434 ZP -= extinction*airmass; 00435 00436 cpl_propertylist_update_double(astrolist,"ESO QC SCI ZEROPNT",ZP); 00437 cpl_propertylist_set_comment(astrolist,"ESO QC SCI ZEROPNT", "new zp with flux in ADU"); 00438 cpl_propertylist_update_double(astrolist, "ESO QC SCI ZEROPNT ERR", zeropoint_error) ; 00439 cpl_propertylist_set_comment(astrolist, "ESO QC SCI ZEROPNT ERR", "zp error"); 00440 00441 00442 /*Get gain*/ 00443 omega_pfits_get_conad(astrolist,&gain); 00444 00445 cpl_propertylist_update_double(astrolist,"ESO QC SCI ZEROPNT_ELECTRON",ZP+(2.5*log10(gain))); 00446 cpl_propertylist_set_comment(astrolist,"ESO QC SCI ZEROPNT_ELECTRON", "new zp with flux in e-"); 00447 cpl_propertylist_update_double(astrolist, "ESO QC SCI ZEROPNT_ELECTRON ERR", zeropoint_error) ; 00448 cpl_propertylist_set_comment(astrolist, "ESO QC SCI ZEROPNT_ELECTRON ERR", "zp error"); 00449 00450 *zeropoint_final=ZP; 00451 00452 /* Subtract the bias */ 00453 omega_biascor(trim, mbias); 00454 00455 /* Divide by the flat */ 00456 if(omega_flatcor(trim, mflat, nsky) != 0){ 00457 cpl_msg_error(cpl_func,"Error in flat correction"); 00458 freeimage(trim); 00459 plist = NULL; 00460 astrolist = NULL; 00461 return NULL; 00462 } 00463 00464 /* Create BPM+SATURATION mask */ 00465 satu_map = omega_saturated_map(trim, oc, pars); 00466 00467 bpm_map = cpl_mask_threshold_image_create(bpm, 0.5, 1.5) ; 00468 if(satu_map != NULL){ 00469 // cpl_mask_and(bpm_map, satu_map); 00470 cpl_mask_or(bpm_map, satu_map); 00471 freemask(satu_map); 00472 } 00473 mask_img = cpl_image_new_from_mask(bpm_map); 00474 freemask(bpm_map); 00475 00476 /* Correct for fringing */ 00477 if(fringes != NULL){ 00478 omega_fringecor(trim, fringes, mask_img, pars); 00479 } 00480 00481 /* Get background */ 00482 back = omega_background(trim, pars); 00483 00484 if(back != NULL){ 00485 median = cpl_image_get_median(back); 00486 cpl_propertylist_update_double(astrolist, "ESO DRS MEDIAN BKG", median); 00487 } 00488 if(back == NULL) 00489 cpl_msg_debug(cpl_func,"Unable to create background image"); 00490 00491 /* Detect cosmic rays */ 00492 image = cpl_image_subtract_create(trim, back); 00493 cosmic = omega_cosmic_rays(image,mflat,illum,mask_img,pars); 00494 00495 /* Subtract background from science */ 00496 if(sub_back == 1){ 00497 freeimage(trim); 00498 trim = cpl_image_duplicate(image); 00499 } 00500 00501 freeimage(image); 00502 freeimage(back); 00503 00504 /* Detect satellite tracks in background subtracted image */ 00505 satellite = detsat(trim, pars); 00506 00507 /* Create combination map (BPM,saturated,cosmic,satellite) */ 00508 /* The bad pixels are set to CPL_BINARY_0 in combmap */ 00509 combmap = create_weightframe(mflat,mask_img,cosmic,satellite); 00510 // cpl_image_save(combmap,"combmap.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_CREATE); 00511 00512 freemask(satellite); 00513 freemask(cosmic); 00514 freeimage(mask_img); 00515 00516 /* Save median value of image in header */ 00517 mask = cpl_mask_threshold_image_create(combmap, 0.5, 1.5); 00518 cpl_mask_not(mask); 00519 cpl_image_reject_from_mask(trim, mask); 00520 median = cpl_image_get_median(trim); 00521 cpl_propertylist_update_double(astrolist, "ESO DRS MEDIAN", median); 00522 00523 00524 /* Clean bad pixels */ 00525 if(cpl_detector_interpolate_rejected(trim) != CPL_ERROR_NONE) 00526 cpl_msg_debug(cpl_func,"Cannot clean rejected pixels. %s",cpl_error_get_message()); 00527 00528 /*The image should remember the bad pixels even after interpolation!*/ 00529 00530 00531 /* 00532 * Use pattern matching to detect stars. 00533 */ 00534 00535 /* Smooth image before creating catalogue */ 00536 smooth = omega_smooth_image(trim, 1); 00537 00538 cpl_image_reject_from_mask(trim, mask); 00539 freemask(mask); 00540 00541 /* Save star as intermediate product */ 00542 cpl_propertylist_save(plist,smoothed, CPL_IO_CREATE); 00543 cpl_image_save(smooth, smoothed, CPL_BPP_IEEE_FLOAT, astrolist, CPL_IO_EXTEND); 00544 00545 /* Save weight map as intermediate product */ 00546 cpl_propertylist_save(plist,smoothed_weight, CPL_IO_CREATE); 00547 cpl_image_save(combmap, smoothed_weight, CPL_BPP_IEEE_FLOAT, astrolist, CPL_IO_EXTEND); 00548 00549 freeimage(smooth); 00550 freeimage(combmap); 00551 /* 00552 * Calculate WCS distortion for simple image 00553 */ 00554 wcslist = omega_match_points(smoothed, smoothed_weight, usnoa2, pars,ext,&nmatches, &mratio); 00555 00556 /* Debugging information */ 00557 cpl_msg_debug(cpl_func,"Number matches between USNOA2 cat and stars. %d", nmatches); 00558 cpl_msg_debug(cpl_func,"ratio USNOA2 matches/detected stars. %g", mratio); 00559 00560 if(wcslist == NULL){ 00561 cpl_msg_warning(cpl_func,"Unable to calculate WCS distortion for image. %s", 00562 cpl_error_get_message()); 00563 } 00564 00565 /* Append WCS header to extension header */ 00566 omega_pfits_update_header(astrolist, wcslist); 00567 freeplist(wcslist); 00568 00569 /* Wrap product into omega fits structure using 1st frame headers */ 00570 simplefits = omega_fits_wrap(trim,NULL,plist,astrolist); 00571 00572 // plist = NULL; 00573 // astrolist = NULL; 00574 00575 return simplefits; 00576 00577 } 00578 00579 /* 00580 * Copied from omega_reduce_std() 00581 */ 00582 /* 00583 cpl_image *omega_reduce_science(const cpl_frame *sciframe, cpl_image *mask_img, 00584 cpl_parameterlist *pars, int ext) 00585 { 00586 00587 const char *cpl_func = "make_std_reduced"; 00588 const char *bckname = "omega_background_temp.fits"; 00589 const char *tempname1111 = "omega_reduced_temp.fits"; 00590 cpl_image *trim_img, *mbias_img, *mflat_img, *nsky_img; 00591 cpl_image *back_img = NULL; 00592 cpl_image *illum_img = NULL; 00593 cpl_image *fringe_img = NULL; 00594 cpl_image *reduced = NULL; 00595 cpl_mask *bpmtemp_map; 00596 00597 00598 Trim and overscan correct image 00599 trim_img = TrimOscanCorrect(sciframe, omega_science_config.oc, ext); 00600 if (trim_img == NULL) { 00601 cpl_msg_error(cpl_func,"Cannot trim image %s",cpl_error_get_message()); 00602 return NULL; 00603 } 00604 00605 Subtract the bias 00606 mbias_img = cpl_image_load(cpl_frame_get_filename(ps.mbiasfr), CPL_TYPE_FLOAT,0,ext); 00607 if (mbias_img == NULL) { 00608 cpl_msg_error(cpl_func,"Cannot load master bias %s", cpl_error_get_message()); 00609 freeimage(trim_img); 00610 return NULL; 00611 } 00612 cpl_image_subtract(trim_img, mbias_img); 00613 freeimage(mbias_img); 00614 00615 00616 Correct for flat field. If there is a night sky flat, use it. 00617 if(ps.nskyfr != NULL){ 00618 nsky_img = cpl_image_load(cpl_frame_get_filename(ps.nskyfr), CPL_TYPE_FLOAT, 0, ext); 00619 if(nsky_img != NULL){ 00620 mflat_img = cpl_image_multiply_create(ps.mflat, nsky_img); 00621 cpl_image_divide(trim_img, mflat_img); 00622 freeimage(nsky_img); 00623 freeimage(mflat_img); 00624 } 00625 else { 00626 cpl_image_divide(trim_img, ps.mflat); 00627 } 00628 } 00629 else { 00630 cpl_image_divide(trim_img, ps.mflat); 00631 } 00632 00633 Correct for fringing. Check if filter really requires fringing correction 00634 FIXME: should this be a fatal error or a warning? 00635 if(ps.fringesfr != NULL){ 00636 fringe_img = cpl_image_load(cpl_frame_get_filename(ps.fringesfr),CPL_TYPE_FLOAT,0,ext); 00637 if(fringe_img == NULL) { 00638 cpl_msg_warning(cpl_func,"Cannot load Master Fringe image"); 00639 reduced = cpl_image_duplicate(trim_img); 00640 } 00641 else { 00642 bpmtemp_map = cpl_mask_threshold_image_create(mask_img, 0.5, 1.5); 00643 cpl_msg_info(cpl_func,"Applying fringing correction"); 00644 reduced = omega_fringecor(trim_img,fringe_img, bpmtemp_map, pars); 00645 if(reduced == NULL) { 00646 cpl_msg_warning(cpl_func,"Cannot apply fringing correction"); 00647 reduced = cpl_image_duplicate(trim_img); 00648 } 00649 freemask(bpmtemp_map); 00650 freeimage(fringe_img); 00651 } 00652 00653 } 00654 else { 00655 reduced = cpl_image_duplicate(trim_img); 00656 } 00657 00658 freeimage(trim_img); 00659 00660 FIXME: review this 00661 Illumination Correction and Background subtraction 00662 // iillum = (illum == NULL) ? 0 : 1; 00663 00664 if((ps.illumfr != NULL) && (omega_science_config.bckg == 0)){ 00665 00666 // if (!(iillum == 0 && bckg == 1)) { 00667 Save temporary image to create a background in Sextractor 00668 cpl_image_save(reduced, tempname1111, BITPIX, NULL, CPL_IO_DEFAULT); 00669 00670 cpl_msg_info("","Measuring statistics with background"); 00671 00672 stats = omega_iter_stat_opts(reduced_img, 5.0, 5); 00673 cpl_msg_info("","Mean :%10.3f",cpl_stats_get_mean(stats)); 00674 cpl_msg_info("","Median :%10.3f",cpl_stats_get_median(stats)); 00675 cpl_msg_info("","Stdev :%10.3f",cpl_stats_get_stdev(stats)); 00676 00677 cpl_msg_info(cpl_func,"Doing background subtraction"); 00678 if(omega_create_background(pars, tempname1111, bckname) != 0){ 00679 cpl_msg_error(cpl_func,"Cannot create background image"); 00680 freeimage(reduced); 00681 return NULL; 00682 } 00683 00684 back_img = cpl_image_load(bckname, CPL_TYPE_FLOAT, 0, 0); 00685 if(back_img == NULL) { 00686 cpl_msg_warning(cpl_func,"Cannot load background image %s", bckname); 00687 freeimage(reduced); 00688 return NULL; 00689 } 00690 00691 cpl_image_subtract(reduced, back_img); 00692 cpl_stats_delete(stats); 00693 } 00694 00695 00696 // if(iillum == 1) { 00697 if (ps.illumfr != NULL){ 00698 illum_img = cpl_image_load(cpl_frame_get_filename(ps.illumfr),CPL_TYPE_FLOAT, 0, ext); 00699 if(illum_img != NULL) { 00700 cpl_msg_info(cpl_func,"Applying illumination correction"); 00701 cpl_image_multiply(reduced, illum_img); 00702 freeimage(illum_img); 00703 } 00704 else{ 00705 cpl_msg_warning(cpl_func,"Cannot load Illumination Correction image"); 00706 } 00707 if(omega_std_config.bckg == 1) { 00708 cpl_msg_info("","Restoring background to image"); 00709 cpl_image_add(reduced, back_img); 00710 } 00711 } 00712 00713 00714 if (back_img != NULL){ 00715 freeimage(back_img); 00716 } 00717 00718 return reduced; 00719 00720 00721 } 00722 */ 00723 00724