39 #include "omega_background.h"
40 #include "omega_dfs.h"
41 #include "omega_utils.h"
78 const char *path = NULL;
79 const char *sex_conf = NULL;
80 const char *sex_conv = NULL;
81 const char *sex_nnw = NULL;
82 const char *sex_par = NULL;
83 const char *text = NULL;
93 cpl_msg_error (cpl_func,
"Sextractor parameters list not found");
97 npars = cpl_parameterlist_get_size(parlist);
99 cpl_msg_error (cpl_func,
"Sextractor parameters list is NULL");
109 par = cpl_parameterlist_get_first(parlist);
111 for(i=0; i<npars; i++) {
112 text = cpl_parameter_get_alias(par, CPL_PARAMETER_MODE_CLI);
113 if(strcmp(
"bin-path", text) == 0) {
114 path = cpl_parameter_get_string(par) ;
116 else if(strcmp(
"sex-config", text) == 0) {
117 sex_conf = cpl_parameter_get_string(par) ;
119 else if(strcmp(
"sex-conv", text) == 0) {
120 sex_conv = cpl_parameter_get_string(par) ;
122 else if(strcmp(
"sex-param", text) == 0) {
123 sex_par = cpl_parameter_get_string(par) ;
125 else if(strcmp(
"sex-nnw", text) == 0) {
126 sex_nnw = cpl_parameter_get_string(par) ;
128 else if(strcmp(
"backthre", text) == 0) {
129 dthre = cpl_parameter_get_double(par) ;
131 else if(strcmp(
"backsize", text) == 0){
132 backsize = cpl_parameter_get_int(par);
134 par = cpl_parameterlist_get_next(parlist);
141 cmd = cpl_sprintf(
"%s/sex %s -c %s -PARAMETERS_NAME %s -FILTER_NAME %s -STARNNW_NAME %s "
145 "-CHECKIMAGE_TYPE BACKGROUND "
146 "-CHECKIMAGE_NAME %s",
157 if (system(cmd) != 0) {
159 cpl_msg_error(cpl_func,
"Failed to run Sextractor for background creation");
185 const char *sciname =
"omega_sci4back.fits";
186 const char *weightname =
"omega_sci4back_weight.fits";
187 const char *out_name =
"omega_back.fits";
188 const char *path = NULL;
189 const char *sex_conf = NULL;
190 const char *sex_conv = NULL;
191 const char *sex_nnw = NULL;
192 const char *sex_par = NULL;
193 const char *text = NULL;
199 if((sci == NULL) || (parlist == NULL))
207 npars = cpl_parameterlist_get_size(parlist);
208 par = cpl_parameterlist_get_first(parlist);
210 for(i=0; i<npars; i++) {
211 text = cpl_parameter_get_alias(par, CPL_PARAMETER_MODE_CLI);
212 if(strcmp(
"bin-path", text) == 0) {
213 path = cpl_parameter_get_string(par) ;
215 else if(strcmp(
"sex-config", text) == 0) {
216 sex_conf = cpl_parameter_get_string(par) ;
218 else if(strcmp(
"sex-conv", text) == 0) {
219 sex_conv = cpl_parameter_get_string(par) ;
221 else if(strcmp(
"sex-param", text) == 0) {
222 sex_par = cpl_parameter_get_string(par) ;
224 else if(strcmp(
"sex-nnw", text) == 0) {
225 sex_nnw = cpl_parameter_get_string(par) ;
227 else if(strcmp(
"backthre", text) == 0) {
228 dthre = cpl_parameter_get_double(par) ;
230 par = cpl_parameterlist_get_next(parlist);
234 cpl_image_save(sci, sciname, BITPIX, NULL, CPL_IO_CREATE);
237 cpl_mask * sci_bpm=cpl_mask_duplicate(cpl_image_get_bpm_const(sci));
238 cpl_mask_not(sci_bpm);
239 cpl_mask_save(sci_bpm, weightname, NULL, CPL_IO_CREATE);
240 cpl_mask_delete(sci_bpm);
244 cmd = cpl_sprintf(
"%s/sex %s "
245 " -WEIGHT_TYPE MAP_WEIGHT -WEIGHT_IMAGE %s "
246 "-c %s -PARAMETERS_NAME %s -FILTER_NAME %s -STARNNW_NAME %s "
249 "-CHECKIMAGE_TYPE BACKGROUND "
250 "-CHECKIMAGE_NAME %s 2>/dev/null",
260 cpl_msg_debug(cpl_func,
"Sextractor call for Background subtraction:\n "
262 if (system(cmd) != 0) {
264 cpl_msg_error(cpl_func,
"Failed to run Sextractor for background detection");
270 back = cpl_image_load(out_name,CPL_TYPE_FLOAT,0,0);