39 #include "omega_background.h"
40 #include "omega_cosmic.h"
41 #include "omega_dfs.h"
42 #include "omega_utils.h"
63 static cpl_mask *detcosmic(cpl_image *nscience, cpl_parameterlist *spars);
75 static cpl_mask *detcosmic(cpl_image *nscience, cpl_parameterlist *spars)
85 const char *cosmiccat =
"omega_cosmic.cat";
86 const char *cosmicname =
"omega_cosmic.fits";
87 const char *path = NULL;
88 const char *sex_conf = NULL;
89 const char *sex_conv = NULL;
90 const char *sex_nnw = NULL;
91 const char *sex_par = NULL;
92 const char *text = NULL;
93 const char *tmpname23 =
"temp0023.fits";
98 cpl_propertylist *plist;
106 par = cpl_parameterlist_get_first(spars);
107 npars = cpl_parameterlist_get_size(spars);
109 for(i=0; i<npars; i++) {
110 text = cpl_parameter_get_alias(par, CPL_PARAMETER_MODE_CLI);
111 if(strcmp(
"bin-path", text) == 0) {
112 path = cpl_parameter_get_string(par) ;
114 else if(strcmp(
"sex-cosmic", text) == 0) {
115 sex_conf = cpl_parameter_get_string(par);
117 else if(strcmp(
"sex-cosfilt", text) == 0) {
118 sex_conv = cpl_parameter_get_string(par);
120 else if(strcmp(
"sex-cosmic-param", text) == 0) {
121 sex_par = cpl_parameter_get_string(par);
123 else if(strcmp(
"sex-nnw", text) == 0) {
124 sex_nnw = cpl_parameter_get_string(par);
126 else if(strcmp(
"sex-cosmic-det", text) == 0) {
127 thre = cpl_parameter_get_double(par);
129 par = cpl_parameterlist_get_next(spars);
135 cpl_image_save(nscience, tmpname23,BITPIX, NULL, CPL_IO_CREATE);
142 cmd = cpl_sprintf(
"%s/sex %s -c %s -PARAMETERS_NAME %s -FILTER_NAME %s -STARNNW_NAME %s "
146 "-CATALOG_TYPE FITS_1.0 "
147 "-CHECKIMAGE_NAME %s 2>/dev/null",
159 if (system(cmd) != 0) {
161 cpl_msg_debug(cpl_func,
"Failed to run Sextractor");
166 img = cpl_image_load(cosmicname, CPL_TYPE_INT, 0, 0);
168 cpl_msg_debug(cpl_func,
"Cannot load cosmic rays image");
172 cosmic_map = cpl_mask_threshold_image_create(img, -0.5, 0.5);
176 cpl_mask_not(cosmic_map);
177 count = cpl_mask_count(cosmic_map);
183 plist = cpl_propertylist_load(cosmiccat, 1);
185 cpl_msg_debug(cpl_func,
"Cannot load header of %s",cosmiccat);
187 freemask(cosmic_map);
192 count = cpl_propertylist_get_int(plist,
"NAXIS2");
193 cpl_msg_debug(cpl_func,
"Detected %d cosmic ray events",count);
213 cpl_mask *
omega_cosmic_rays(
const cpl_image *sci,
const cpl_image *flat,
const cpl_image *illum,
214 const cpl_image *bpm, cpl_parameterlist *pars)
217 cpl_mask *cosmic_map = NULL;
218 cpl_mask *bpm_map = NULL;
219 cpl_image *weight, *fbpm, *image;
221 if((sci == NULL) || (flat == NULL) || (bpm == NULL) || (pars == NULL))
226 bpm_map=cpl_mask_threshold_image_create(bpm,-0.5,0.5);
227 fbpm=cpl_image_new_from_mask(bpm_map);
230 weight = cpl_image_multiply_create(flat,fbpm);
234 cpl_image_divide(weight,illum);
236 cpl_image_power(weight, 0.5);
238 image = cpl_image_multiply_create(sci, weight);
242 cosmic_map = detcosmic(image, pars);
245 if(cosmic_map == NULL){
246 cpl_msg_debug(cpl_func,
"NULL cosmic rays map");