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 <tests.h>
00044
00045 #include <xsh_data_pre.h>
00046 #include <xsh_error.h>
00047 #include <xsh_msg.h>
00048 #include <xsh_data_instrument.h>
00049 #include <xsh_data_the_map.h>
00050 #include <xsh_data_localization.h>
00051 #include <xsh_data_spectralformat.h>
00052
00053 #include <xsh_drl.h>
00054 #include <xsh_pfits.h>
00055
00056 #include <xsh_badpixelmap.h>
00057
00058 #include <cpl.h>
00059 #include <math.h>
00060
00061 #include <getopt.h>
00062
00063
00064
00065
00066
00067 #define MODULE_ID "XSH_DETECT_ORDER"
00068
00069
00070
00071
00072 enum {
00073 SEARCH_WINDOW_HSIZE_OPT, FLUX_THRESH_OPT, MIN_SN_OPT,
00074 MIN_ORDER_SIZE_X_OPT, CHUNK_HSIZE_OPT, SLITLET_LOW_FACTOR_OPT,
00075 SLITLET_UP_FACTOR_OPT, FIXED_SLICE_OPT, METHOD_OPT, HELP_OPT
00076 } ;
00077
00078 static const char * Options = "";
00079
00080 static struct option long_options[] = {
00081 {"search-window-hsize", required_argument, 0, SEARCH_WINDOW_HSIZE_OPT},
00082 {"flux-thresh", required_argument, 0, FLUX_THRESH_OPT},
00083 {"min-sn", required_argument, 0, MIN_SN_OPT},
00084 {"min-order-size-x", required_argument, 0, MIN_ORDER_SIZE_X_OPT},
00085 {"chunk-hsize", required_argument, 0, CHUNK_HSIZE_OPT},
00086 {"slitlet-low-factor", required_argument, 0, SLITLET_LOW_FACTOR_OPT},
00087 {"slitlet-up-factor",required_argument, 0, SLITLET_UP_FACTOR_OPT},
00088 {"fixed-slice",required_argument, 0, FIXED_SLICE_OPT},
00089 {"method",required_argument, 0, METHOD_OPT},
00090 {"help", 0, 0, HELP_OPT},
00091 {0, 0, 0, 0}
00092 };
00093
00094 static void Help( void )
00095 {
00096 puts( "Unitary test of xsh_detect_order" ) ;
00097 puts( "Usage: test_xsh_detect_order [options] <input_files>" ) ;
00098 puts( "Options" ) ;
00099 puts( " --search-window-hsize=<n> : Half size of the search box" ) ;
00100 puts( " --flux-thresh=<nn> : Threshold in flux" ) ;
00101 puts( " --min-sn=<n> : Minimum s/n ratio" ) ;
00102 puts( " --min-order-size-x=<n> : Minimum pixel size of an order in cross dispersion" ) ;
00103 puts( " --chunk-hsize=<n> : Pixel half size of chunk of an order in dispersion" );
00104 puts( " --slitlet-low-factor=<n> : ????" );
00105 puts( " --slitlet-up-factor=<n> : ????" );
00106 puts( " --fixed-slice=<n> : if TRUE used slitlet ratio" );
00107 puts( " --method=<n> : ????" );
00108 puts( " --help : What you see" ) ;
00109 puts( "\nInput Files" ) ;
00110 puts( "The input files argument MUST be in this order:" ) ;
00111 puts( " 1. Science frame FLAT" ) ;
00112 puts( " 2. SOF (ORDER_TAB_CEN]\n" ) ;
00113 TEST_END();
00114 }
00115
00116 static void HandleOptions( int argc, char **argv,
00117 xsh_detect_order_param* detectorder_par)
00118 {
00119 int opt ;
00120 int option_index = 0;
00121
00122 while (( opt = getopt_long (argc, argv, Options,
00123 long_options, &option_index)) != EOF )
00124 switch ( opt ) {
00125 case SEARCH_WINDOW_HSIZE_OPT:
00126 detectorder_par->search_window_hsize = atoi( optarg);
00127 break ;
00128 case FLUX_THRESH_OPT:
00129 detectorder_par->flux_thresh = atof( optarg);
00130 break ;
00131 case MIN_SN_OPT:
00132 detectorder_par->min_sn = atof( optarg);
00133 break ;
00134 case MIN_ORDER_SIZE_X_OPT:
00135 detectorder_par->min_order_size_x = atoi( optarg);
00136 break ;
00137 case CHUNK_HSIZE_OPT:
00138 detectorder_par->chunk_hsize = atoi( optarg);
00139 break;
00140 case SLITLET_LOW_FACTOR_OPT:
00141 detectorder_par->slitlet_low_factor = atof( optarg);
00142 break;
00143 case SLITLET_UP_FACTOR_OPT:
00144 detectorder_par->slitlet_up_factor = atof( optarg);
00145 break ;
00146 case FIXED_SLICE_OPT:
00147 detectorder_par->fixed_slice = atoi( optarg);
00148 break ;
00149 case METHOD_OPT:
00150 detectorder_par->method = optarg;
00151 break;
00152 default: Help() ; exit( 0);
00153 }
00154 }
00155
00164 int main( int argc, char **argv)
00165 {
00166
00167 int ret = 0 ;
00168
00169 xsh_instrument* instrument = NULL;
00170
00171 const char *sof_name = NULL;
00172 cpl_frameset *set = NULL;
00173
00174 const char * sci_name = NULL ;
00175
00176 cpl_frame *sci_frame = NULL;
00177 cpl_frame *orderlist_frame = NULL;
00178 cpl_frame *edges_order_tab_frame = NULL;
00179 xsh_detect_order_param detectorder_par;
00180 const int decode_bp=2147483647;
00181
00182 TESTS_INIT(MODULE_ID);
00183 cpl_msg_set_level(CPL_MSG_DEBUG);
00184 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00185
00186
00187 detectorder_par.search_window_hsize = 50;
00188 detectorder_par.flux_thresh = 0.05;
00189 detectorder_par.min_sn = 35.;
00190 detectorder_par.min_order_size_x = 60;
00191 detectorder_par.chunk_hsize = 1;
00192 detectorder_par.slitlet_low_factor = 1.0;
00193 detectorder_par.slitlet_up_factor = 1.0;
00194 detectorder_par.fixed_slice = CPL_TRUE;
00195 detectorder_par.method = "fixed";
00196
00197 HandleOptions( argc, argv, &detectorder_par);
00198
00199 if ( (argc - optind) >=2 ) {
00200 sci_name = argv[optind];
00201 sof_name = argv[optind+1];
00202 }
00203 else {
00204 Help();
00205 exit(0);
00206 }
00207
00208 check( set = sof_to_frameset( sof_name));
00209
00210 check( instrument = xsh_dfs_set_groups( set));
00211 xsh_instrument_set_decode_bp( instrument, decode_bp ) ;
00212 check( orderlist_frame = xsh_find_order_tab_centr( set, instrument));
00213
00214 TESTS_XSH_FRAME_CREATE( sci_frame, "FLAT_arm", sci_name);
00215
00216 xsh_msg("SCI : %s",
00217 cpl_frame_get_filename( sci_frame));
00218 xsh_msg("ORDERLIST : %s",
00219 cpl_frame_get_filename( orderlist_frame));
00220
00221 xsh_msg(" Parameters ");
00222 xsh_msg(" search window half size %d", detectorder_par.search_window_hsize);
00223 xsh_msg(" flux threshold %f", detectorder_par.flux_thresh);
00224 xsh_msg(" min S/N %f", detectorder_par.min_sn);
00225 xsh_msg(" min order size cross dispersion %d", detectorder_par.min_order_size_x);
00226 xsh_msg(" chunk hsize %d", detectorder_par.chunk_hsize);
00227 xsh_msg(" slitlet low factor %f", detectorder_par.slitlet_low_factor);
00228 xsh_msg(" slitlet up factor %f", detectorder_par.slitlet_up_factor);
00229 xsh_msg(" fixed slice %d", detectorder_par.fixed_slice);
00230 xsh_msg(" detect method %s",detectorder_par.method);
00231
00232
00233 check( edges_order_tab_frame = xsh_detect_order_edge( sci_frame,
00234 orderlist_frame, &detectorder_par, instrument));
00235
00236 cleanup:
00237 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00238 xsh_error_dump(CPL_MSG_ERROR);
00239 ret = 1;
00240 }
00241 xsh_free_frame( &sci_frame);
00242 xsh_free_frame( &edges_order_tab_frame);
00243 xsh_free_frameset( &set);
00244 xsh_instrument_free( &instrument);
00245 TEST_END();
00246 return ret;
00247 }