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