00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00036
00039
00040
00041
00042
00043 #include <xsh_data_instrument.h>
00044 #include <xsh_badpixelmap.h>
00045 #include <xsh_pfits.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_utils.h>
00048 #include <tests.h>
00049 #include <cpl.h>
00050 #include <math.h>
00051 #include <stdlib.h>
00052 #include <getopt.h>
00053
00054
00055
00056
00057 #define MODULE_ID "XSH_DETECT_ARLINES"
00058
00059 #define SYNTAX "Test the detect_arclines function\n"\
00060 "use : ./test_xsh_detect_arclines OPTIONS FMTCHK_FRAME LINE_LIST THEMAP "\
00061 "[GUESS_WAVE_TAB]\n"\
00062 "FMTCHK_FRAME => the frame to detect arclines (PRE format)\n"\
00063 "LINE_LIST => the line list\n"\
00064 "THEMAP => the theoretical map\n"\
00065 "GUESS_WAVE_TAB => the guess wave solution\n"\
00066 "SPECTRAL_FORMAT_TAB => the spectral format table \n"\
00067 "OPTIONS => \n"\
00068 " --half_window_size : half window size (HWS) in pixel around the"\
00069 " position to fit the gaussian (total window size = 2*HWS+1)\n"\
00070 " --half_window_size_for_max : half window size (HWS) in pixel around the"\
00071 " theoritical position to find the maximum flux\n"\
00072 " --half_window_size_running_median : half window size of running "\
00073 "median\n"\
00074 " --deg_lambda : lambda degree in polynomial wavelength solution fit\n"\
00075 " --deg_order : order degree in polynomial wavelength solution fit\n"\
00076 " --deg_slit : slit degree in polynomial wavelength solution fit\n"\
00077 " --poly_degree : Polynomial degree\n"\
00078 " --min_sn : minimal S/N allowed\n"\
00079 " --clip_sigma : multiple of sigma in sigma clipping\n"\
00080 " --clip_niter : number of iterations in sigma clipping\n"\
00081 " --clip_frac : minimal fractions of bad pixel allowed\n"
00082
00083 enum {
00084 HALF_WINDOW_SIZE_OPT, HALF_WINDOW_SIZE_FOR_MAX_OPT, DEG_LAMBDA_OPT,
00085 DEG_ORDER_OPT, DEG_SLIT_OPT, POLY_DEGREE_OPT, MIN_SN_OPT, CLIP_SIGMA_OPT,
00086 CLIP_NITER_OPT, CLIP_FRAC_OPT, INITIAL_CENTER_OPT,
00087 HALF_WINDOW_SIZE_RUNNING_MEDIAN_OPT
00088 } ;
00089
00090 static struct option long_options[] = {
00091 {"half_window_size", required_argument, 0, HALF_WINDOW_SIZE_OPT},
00092 {"half_window_size_for_max", required_argument, 0,
00093 HALF_WINDOW_SIZE_FOR_MAX_OPT},
00094 {"half_window_size_running_median", required_argument, 0,
00095 HALF_WINDOW_SIZE_RUNNING_MEDIAN_OPT},
00096 {"deg_lambda", required_argument, 0, DEG_LAMBDA_OPT},
00097 {"deg_order", required_argument, 0, DEG_ORDER_OPT},
00098 {"deg_slit", required_argument, 0, DEG_SLIT_OPT},
00099 {"poly_degree", required_argument, 0, POLY_DEGREE_OPT},
00100 {"min_sn", required_argument, 0, MIN_SN_OPT},
00101 {"clip_sigma", required_argument, 0, CLIP_SIGMA_OPT},
00102 {"clip_niter", required_argument, 0, CLIP_NITER_OPT},
00103 {"clip_frac", required_argument, 0, CLIP_FRAC_OPT},
00104 {0, 0, 0, 0}
00105 };
00106
00107 static void HandleOptions( int argc, char **argv,
00108 xsh_detect_arclines_param *det_arc_par, xsh_clipping_param* clip_par)
00109 {
00110 int opt ;
00111 int option_index = 0;
00112
00113
00114 det_arc_par->fit_window_hsize = 10;
00115 det_arc_par->search_window_hsize = 30;
00116 det_arc_par->running_median_hsize = 1;
00117 det_arc_par->wavesol_deg_lambda = 2;
00118 det_arc_par->wavesol_deg_order = 2;
00119 det_arc_par->wavesol_deg_slit = 0;
00120 det_arc_par->ordertab_deg_y = 2;
00121 det_arc_par->min_sn = 0.2;
00122 clip_par->sigma = 1.0;
00123 clip_par->niter = 5;
00124 clip_par->frac = 0.7;
00125
00126
00127 while (( opt = getopt_long (argc, argv, "half_window_size:deg_lambda:"\
00128 "deg_order:deg_slit:poly_degree:min_sn:"\
00129 "clip_sigma:clip_niter:clip_frac:half_window_size_for_max:"\
00130 "half_window_size_running_median",
00131 long_options, &option_index)) != EOF ){
00132
00133 switch ( opt ) {
00134 case HALF_WINDOW_SIZE_OPT :
00135 det_arc_par->fit_window_hsize = atoi(optarg);
00136 break ;
00137 case HALF_WINDOW_SIZE_FOR_MAX_OPT :
00138 det_arc_par->search_window_hsize = atoi(optarg);
00139 break;
00140 case HALF_WINDOW_SIZE_RUNNING_MEDIAN_OPT :
00141 det_arc_par->running_median_hsize = atoi(optarg);
00142 break;
00143 case DEG_LAMBDA_OPT:
00144 det_arc_par->wavesol_deg_lambda = atoi(optarg);
00145 break;
00146 case DEG_ORDER_OPT:
00147 det_arc_par->wavesol_deg_order = atoi(optarg);
00148 break;
00149 case DEG_SLIT_OPT:
00150 det_arc_par->wavesol_deg_slit = atoi(optarg);
00151 break;
00152 case POLY_DEGREE_OPT:
00153 det_arc_par->ordertab_deg_y = atoi(optarg);
00154 break;
00155 case MIN_SN_OPT:
00156 det_arc_par->min_sn = atof(optarg);
00157 break;
00158 case CLIP_SIGMA_OPT:
00159 clip_par->sigma = atof(optarg);
00160 break;
00161 case CLIP_NITER_OPT:
00162 clip_par->niter = atoi(optarg);
00163 break;
00164 case CLIP_FRAC_OPT:
00165 clip_par->frac = atof(optarg);
00166 break;
00167 default:
00168 printf(SYNTAX);
00169 exit(0);
00170 }
00171 }
00172 return;
00173 }
00174
00175
00176
00177
00178
00185
00186
00187 int main(int argc, char** argv)
00188 {
00189
00190 cpl_frame* predict = NULL;
00191 cpl_frame* theoretical_map = NULL;
00192 cpl_frame* arclines = NULL;
00193 cpl_frame* clean_arclines = NULL;
00194
00195 cpl_frame* resid_tab_orders=NULL;
00196 cpl_frame* guess_tab = NULL;
00197 cpl_frame* wave_sol = NULL;
00198 cpl_frame* twodmap_resid = NULL;
00199 cpl_frame* spectral_format = NULL;
00200 xsh_instrument* instrument = NULL;
00201 xsh_detect_arclines_param da ;
00202 xsh_clipping_param dac ;
00203 char *fmtchk_name = NULL;
00204 char *linelist_name = NULL;
00205 char *themap_name = NULL;
00206 char *guess_tab_name = NULL;
00207 char *spectral_format_name = NULL;
00208 int nb_frames = 0;
00209 int decode_bp=QFLAG_OUTSIDE_DATA_RANGE;
00210
00211 TESTS_INIT(MODULE_ID);
00212
00213 cpl_msg_set_level(CPL_MSG_DEBUG);
00214 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00215
00216
00217 HandleOptions( argc, argv, &da, &dac);
00218
00219 nb_frames = argc - optind;
00220 if ( nb_frames > 2 ) {
00221 fmtchk_name = argv[optind];
00222 linelist_name = argv[optind+1];
00223 themap_name = argv[optind+2];
00224 if ( nb_frames > 3){
00225 guess_tab_name = argv[optind+3];
00226 TESTS_XSH_FRAME_CREATE( guess_tab, "GUESS_WAVE_TAB_UVB",
00227 guess_tab_name);
00228 if ( nb_frames > 4){
00229 spectral_format_name = argv[optind+4];
00230 TESTS_XSH_FRAME_CREATE( spectral_format, "SPECTRAL_FORMAT_TAB_UVB",
00231 spectral_format_name);
00232
00233 }
00234 }
00235 }
00236 else{
00237 xsh_msg( "********** NOT ENOUGH INPUT FRAMES **********" ) ;
00238 printf(SYNTAX);
00239 exit(0);
00240 }
00241 TESTS_XSH_INSTRUMENT_CREATE( instrument, XSH_MODE_IFU,
00242 XSH_ARM_UVB, XSH_LAMP_QTH, "xsh_predict");
00243
00244 TESTS_XSH_FRAME_CREATE( predict, "FMTCHK_UVB", fmtchk_name);
00245 TESTS_XSH_FRAME_CREATE( theoretical_map, "THEORETICAL_MAP_SLIT_UVB",
00246 themap_name);
00247 TESTS_XSH_FRAME_CREATE( arclines, "ARC_LINE_LIST_UVB",
00248 linelist_name);
00249
00250 xsh_msg("--------------------------------------------------------");
00251 xsh_msg("PARAMETERS");
00252 xsh_msg("--------------------------------------------------------");
00253 xsh_msg(" fit window half size : %d", da.fit_window_hsize);
00254 xsh_msg(" search window half size : %d", da.search_window_hsize);
00255 xsh_msg(" running median half size : %d", da.running_median_hsize);
00256 xsh_msg(" wave solution order degree : %d", da.wavesol_deg_order);
00257 xsh_msg(" wave solution lambda degree : %d", da.wavesol_deg_lambda);
00258 xsh_msg(" wave solution slit degree : %d", da.wavesol_deg_slit);
00259 xsh_msg(" order tab y degree : %d", da.ordertab_deg_y);
00260 xsh_msg(" min S/N : %f", da.min_sn);
00261 xsh_msg(" clip sigma : %f", dac.sigma);
00262 xsh_msg(" clip niter : %d", dac.niter);
00263 xsh_msg(" clip frac : %f", dac.frac);
00264 xsh_msg("--------------------------------------------------------");
00265 xsh_msg("FRAMES");
00266 xsh_msg("--------------------------------------------------------");
00267 xsh_msg(" FMTCHK frame : %s", fmtchk_name);
00268 xsh_msg(" LINE_LIST frame : %s", linelist_name);
00269 xsh_msg(" THEMAP frame : %s", themap_name);
00270 if (guess_tab_name != NULL){
00271 xsh_msg(" GUESS_TAB frame : %s", guess_tab_name);
00272 }
00273 if (spectral_format_name != NULL){
00274 xsh_msg(" SPECTRAL FORMAT TAB frame : %s", spectral_format_name);
00275 }
00276 xsh_msg("--------------------------------------------------------");
00277 xsh_msg("Function call");
00278 xsh_msg("--------------------------------------------------------");
00279
00280 check( xsh_detect_arclines ( predict,
00281 theoretical_map,
00282 arclines,
00283 guess_tab,
00284 NULL,
00285 NULL,
00286 spectral_format,
00287 &resid_tab_orders, &clean_arclines,
00288 &wave_sol, &twodmap_resid,
00289 XSH_SOLUTION_RELATIVE,
00290 &da, &dac,
00291 instrument,
00292 "xsh_predict",decode_bp,0));
00293
00294
00295 xsh_msg("--------------------------------------------------------");
00296 xsh_msg("CLEANUP");
00297 xsh_msg("--------------------------------------------------------");
00298 cleanup:
00299 cpl_frame_delete(predict);
00300 cpl_frame_delete(theoretical_map);
00301 cpl_frame_delete(arclines);
00302 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00303 xsh_error_dump(CPL_MSG_ERROR);
00304 return 1;
00305 }
00306 else {
00307 return 0;
00308 }
00309 }
00310