40 #include "omega_wcscor.h"
41 #include "omega_background.h"
42 #include "omega_bpm.h"
43 #include "omega_cosmic.h"
44 #include "omega_dfs.h"
45 #include "omega_flats.h"
46 #include "omega_fits.h"
47 #include "omega_pfits.h"
48 #include "omega_satellites.h"
49 #include "omega_science.h"
50 #include "omega_stats.h"
51 #include "omega_trim.h"
52 #include "omega_utils.h"
54 #define RECIPE "omega_science"
339 const cpl_image *mbias,
340 const cpl_image *mflat,
341 const cpl_image *bpm,
342 const cpl_table *photom,
343 const cpl_frame *usnoa2,
344 const cpl_image *illum,
345 const cpl_image *fringes,
346 const cpl_image *nsky,
347 double * zeropoint_final,
348 cpl_parameterlist *pars,
int ext)
356 double zeropoint = 0.0;
357 double zeropoint_error = 0.0;
358 double extinction = 0.0;
361 double exptime = 0.0;
362 double airmass = 0.0;
364 const char *smoothed =
"omega_sci_smoothed.fits";
365 const char *smoothed_weight =
"omega_sci_smoothed_weight.fits";
367 cpl_image *mask_img, *image, *trim, *reduced, *combmap;
368 cpl_image *back = NULL;
369 cpl_image *smooth = NULL;
370 cpl_mask *satu_map,*bpm_map, *mask;
371 cpl_mask *cosmic, *satellite;
372 cpl_propertylist *plist, *astrolist, *wcslist;
374 omega_fits *simplefits;
375 double mag_zpt_no_std_table=0.0;
376 double mag_zpt_err_no_std_table=0.0;
377 double ext_no_std_table=0.0;
379 if((scifits == NULL) || (mbias == NULL) || (mflat == NULL) ||
380 (bpm == NULL) || (usnoa2 == NULL) || (pars == NULL))
390 p = cpl_parameterlist_find(pars,
"omega.omega_science.OverscanMethod") ;
391 oc = cpl_parameter_get_int(p);
392 p = cpl_parameterlist_find(pars,
"omega.omega_science.SubtractBackground");
393 sub_back = cpl_parameter_get_bool(p);
396 p = cpl_parameterlist_find(pars,
"omega.omega_science.mag_zpt_no_std_table") ;
397 mag_zpt_no_std_table = cpl_parameter_get_double(p);
398 p = cpl_parameterlist_find(pars,
"omega.omega_science.mag_zpt_err_no_std_table");
399 mag_zpt_err_no_std_table = cpl_parameter_get_double(p);
400 p = cpl_parameterlist_find(pars,
"omega.omega_science.ext_no_std_table");
401 ext_no_std_table = cpl_parameter_get_double(p);
407 zeropoint = cpl_table_get_double(photom,
"ZEROPOINT",0,NULL);
408 zeropoint_error = cpl_table_get_double(photom,
"ZEROPOINT_ERR", 0, NULL);
409 extinction = cpl_table_get_double(photom,
"EXTINCTION",0,NULL);
412 zeropoint = mag_zpt_no_std_table;
413 zeropoint_error = mag_zpt_err_no_std_table;
414 extinction = ext_no_std_table;
418 cpl_msg_error(cpl_func,
"Unable to trim image");
432 ZP = zeropoint + 2.5* log10(exptime);
434 ZP -= extinction*airmass;
436 cpl_propertylist_update_double(astrolist,
"ESO QC SCI ZEROPNT",ZP);
437 cpl_propertylist_set_comment(astrolist,
"ESO QC SCI ZEROPNT",
"new zp with flux in ADU");
438 cpl_propertylist_update_double(astrolist,
"ESO QC SCI ZEROPNT ERR", zeropoint_error) ;
439 cpl_propertylist_set_comment(astrolist,
"ESO QC SCI ZEROPNT ERR",
"zp error");
445 cpl_propertylist_update_double(astrolist,
"ESO QC SCI ZEROPNT_ELECTRON",ZP+(2.5*log10(gain)));
446 cpl_propertylist_set_comment(astrolist,
"ESO QC SCI ZEROPNT_ELECTRON",
"new zp with flux in e-");
447 cpl_propertylist_update_double(astrolist,
"ESO QC SCI ZEROPNT_ELECTRON ERR", zeropoint_error) ;
448 cpl_propertylist_set_comment(astrolist,
"ESO QC SCI ZEROPNT_ELECTRON ERR",
"zp error");
457 cpl_msg_error(cpl_func,
"Error in flat correction");
467 bpm_map = cpl_mask_threshold_image_create(bpm, 0.5, 1.5) ;
468 if(satu_map != NULL){
470 cpl_mask_or(bpm_map, satu_map);
473 mask_img = cpl_image_new_from_mask(bpm_map);
475 cpl_image_reject_from_mask(trim, bpm_map);
487 median = cpl_image_get_median(back);
488 cpl_propertylist_update_double(astrolist,
"ESO DRS MEDIAN BKG", median);
491 cpl_msg_debug(cpl_func,
"Unable to create background image");
494 image = cpl_image_subtract_create(trim, back);
500 trim = cpl_image_duplicate(image);
507 satellite =
detsat(trim, pars);
519 mask = cpl_mask_threshold_image_create(combmap, 0.5, 1.5);
521 cpl_image_reject_from_mask(trim, mask);
522 median = cpl_image_get_median(trim);
523 cpl_propertylist_update_double(astrolist,
"ESO DRS MEDIAN", median);
527 if(cpl_detector_interpolate_rejected(trim) != CPL_ERROR_NONE)
528 cpl_msg_debug(cpl_func,
"Cannot clean rejected pixels. %s",cpl_error_get_message());
540 cpl_image_reject_from_mask(trim, mask);
544 cpl_propertylist_save(plist,smoothed, CPL_IO_CREATE);
545 cpl_image_save(smooth, smoothed, CPL_BPP_IEEE_FLOAT, astrolist, CPL_IO_EXTEND);
548 cpl_propertylist_save(plist,smoothed_weight, CPL_IO_CREATE);
549 cpl_image_save(combmap, smoothed_weight, CPL_BPP_IEEE_FLOAT, astrolist, CPL_IO_EXTEND);
556 wcslist =
omega_match_points(smoothed, smoothed_weight, usnoa2, pars,ext,&nmatches, &mratio);
559 cpl_msg_debug(cpl_func,
"Number matches between USNOA2 cat and stars. %d", nmatches);
560 cpl_msg_debug(cpl_func,
"ratio USNOA2 matches/detected stars. %g", mratio);
563 cpl_msg_warning(cpl_func,
"Unable to calculate WCS distortion for image. %s",
564 cpl_error_get_message());