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_drl.h>
00050 #include <xsh_pfits.h>
00051
00052 #include <xsh_badpixelmap.h>
00053
00054 #include <cpl.h>
00055 #include <math.h>
00056
00057 #include <getopt.h>
00058
00059
00060
00061
00062
00063 #define MODULE_ID "XSH_REMOVE_CRH_SINGLE"
00064
00065 static void Help( void)
00066 {
00067 puts( "Unitary test of xsh_remove_crh_single");
00068 puts( "Usage: test_xsh_remove_crh_single [options] <input_files>");
00069
00070 puts( "Options" ) ;
00071 puts( " --sigma_lim=<n> : Sigma limit (5.0]" ) ;
00072 puts( " --f_lim=<n> : F limit [2.0]" ) ;
00073 puts( " --iter=<n> : Number of iteration [4]" ) ;
00074 puts( " --frac_max=<n> : Maximum rejected fraction [0.1]");
00075 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
00076 puts( " --help : What you see" ) ;
00077 puts( "\nInput Files" ) ;
00078 puts( "The input files argument MUST be in this order:" ) ;
00079 puts( " 1. Science frame in PRE format sky subtracted" ) ;
00080 puts( " 2. SOF [WAVE_MAP]\n" ) ;
00081 TEST_END();
00082 }
00083
00084 enum {
00085 SIGMA_LIM_OPT,
00086 F_LIM_OPT,
00087 ITER_OPT,
00088 FRAC_MAX_OPT,
00089 DEBUG_OPT,
00090 HELP_OPT
00091 } ;
00092
00093 static struct option long_options[] = {
00094 {"sigma_lim", required_argument, 0, SIGMA_LIM_OPT},
00095 {"f_lim", required_argument, 0, F_LIM_OPT},
00096 {"iter", required_argument, 0, ITER_OPT},
00097 {"frac_max", required_argument, 0, FRAC_MAX_OPT},
00098 {"debug", required_argument, 0, DEBUG_OPT},
00099 {"help", 0, 0,HELP_OPT},
00100 {0, 0, 0, 0}
00101 };
00102
00103 static void HandleOptions( int argc, char **argv,
00104 xsh_remove_crh_single_param *single_par)
00105 {
00106 int opt ;
00107 int option_index = 0;
00108
00109 while (( opt = getopt_long (argc, argv, "sigma_lim:f_lim",
00110 long_options, &option_index)) != EOF ){
00111 switch ( opt ) {
00112 case SIGMA_LIM_OPT:
00113 single_par->sigma_lim = atof(optarg);
00114 break ;
00115 case F_LIM_OPT:
00116 single_par->f_lim = atof(optarg);
00117 break ;
00118 case FRAC_MAX_OPT:
00119 single_par->crh_frac_max = atof(optarg);
00120 break;
00121 case ITER_OPT:
00122 sscanf( optarg, "%d", &single_par->nb_iter ) ;
00123 break ;
00124 case DEBUG_OPT:
00125 if ( strcmp( optarg, "LOW")==0){
00126 xsh_debug_level_set( XSH_DEBUG_LEVEL_LOW);
00127 }
00128 else if ( strcmp( optarg, "HIGH")==0){
00129 xsh_debug_level_set( XSH_DEBUG_LEVEL_HIGH);
00130 }
00131 break;
00132 default:
00133 Help();
00134 exit(-1);
00135 }
00136 }
00137 return;
00138 }
00139
00140
00141
00142
00143
00152 int main( int argc, char **argv)
00153 {
00154
00155 int ret = 0 ;
00156 char name[256];
00157 char sof_name[256];
00158 char res_name[64] ;
00159
00160 cpl_frameset* raw = NULL;
00161 cpl_frameset *set = NULL;
00162 cpl_frame* sciraw_frame = NULL;
00163 cpl_frame* sci_frame = NULL;
00164 cpl_frame* wavemap_frame = NULL;
00165 cpl_frame* frame_rmcrh = NULL;
00166 xsh_instrument* instrument = NULL;
00167 xsh_remove_crh_single_param single_par = { 0.1,2.5,2.0, 4 } ;
00168 XSH_INSTRCONFIG* iconfig = NULL;
00169 cpl_image* test_image = NULL;
00170 cpl_propertylist * header = NULL ;
00171
00172
00173 TESTS_INIT(MODULE_ID);
00174 cpl_msg_set_level( CPL_MSG_DEBUG);
00175 xsh_debug_level_set( XSH_DEBUG_LEVEL_MEDIUM) ;
00176
00177
00178
00179 single_par.sigma_lim = 5.0;
00180 single_par.f_lim = 2.0;
00181 single_par.nb_iter = 4;
00182
00183 HandleOptions( argc, argv, &single_par);
00184
00185 if (argc-optind > 1){
00186 sprintf(name, argv[optind]);
00187 sprintf( sof_name, argv[optind+1]);
00188
00189 TESTS_XSH_FRAME_CREATE( sci_frame, "OBJECT_SLIT_STARE_arm", name);
00190
00191 check( set = sof_to_frameset( sof_name));
00192
00193
00194 check( instrument = xsh_dfs_set_groups( set));
00195 check( wavemap_frame = xsh_find_wavemap( set, instrument));
00196 }
00197 else{
00198 xsh_msg("-------------------------------------------");
00199 xsh_msg("Execute default test : do --help for option");
00200 xsh_msg("-------------------------------------------");
00201
00202 instrument = xsh_instrument_new() ;
00203 xsh_instrument_set_mode( instrument, XSH_MODE_IFU ) ;
00204 xsh_instrument_set_arm( instrument, XSH_ARM_UVB) ;
00205 xsh_instrument_set_lamp( instrument, XSH_LAMP_QTH ) ;
00206 iconfig = xsh_instrument_get_config( instrument ) ;
00207
00208
00209 test_image = cpl_image_fill_test_create(10,10);
00210 sprintf(name, "remove_crh_single_sci_UVB.fits");
00211 header = mkHeader( iconfig, 10, 10, 1.) ;
00212 cpl_image_save(test_image, name, CPL_BPP_IEEE_DOUBLE, header,
00213 CPL_IO_DEFAULT);
00214 sciraw_frame = cpl_frame_new();
00215 cpl_frame_set_filename( sciraw_frame, name) ;
00216 cpl_frame_set_tag( sciraw_frame, "BIAS_UVB");
00217 cpl_frame_set_level( sciraw_frame, CPL_FRAME_LEVEL_TEMPORARY);
00218 cpl_frame_set_group( sciraw_frame, CPL_FRAME_GROUP_RAW);
00219
00220 raw = cpl_frameset_new();
00221 check( cpl_frameset_insert( raw, sciraw_frame));
00222
00223 check( xsh_prepare( raw, NULL, NULL, "BIAS_UVB", instrument,0,CPL_FALSE));
00224 check( sci_frame = cpl_frame_duplicate( cpl_frameset_get_first( raw)));
00225 }
00226
00227 xsh_msg("---Input Frames");
00228 xsh_msg("sky subtracted frame : %s", name);
00229 if ( wavemap_frame != NULL){
00230 xsh_msg("Wave map frame : %s", cpl_frame_get_filename( wavemap_frame));
00231 }
00232
00233 xsh_msg("---Parameters");
00234 xsh_msg(" frac max : %f", single_par.crh_frac_max);
00235 xsh_msg(" sigma_lim : %f", single_par.sigma_lim);
00236 xsh_msg(" f_lim : %f", single_par.f_lim);
00237 xsh_msg(" niter : %d", single_par.nb_iter);
00238
00239
00240 sprintf( res_name, "NOCRH_%s.fits",
00241 xsh_instrument_arm_tostring( instrument));
00242
00243
00244 xsh_instrument_set_recipe_id( instrument, "xsh_mdark" ) ;
00245
00246 check(frame_rmcrh = xsh_remove_crh_single( sci_frame,
00247 instrument, &single_par, res_name));
00248
00249
00250 cleanup:
00251 xsh_instrument_free( &instrument);
00252 xsh_free_frameset( &raw);
00253 xsh_free_frameset( &set);
00254 xsh_free_propertylist( &header);
00255 xsh_free_image ( &test_image);
00256 xsh_free_frame( &frame_rmcrh);
00257 xsh_free_frame( &sci_frame);
00258
00259 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00260 xsh_error_dump(CPL_MSG_ERROR);
00261 ret=1;
00262 }
00263 TEST_END();
00264 return ret ;
00265 }