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
00051 #include <getopt.h>
00052
00053
00054
00055 #define MODULE_ID "XSH_SUBTRACT_BACKGROUND"
00056
00057
00058 enum {
00059 NB_Y_OPT, RADIUS_X_OPT, RADIUS_Y_OPT, HELP_OPT, MAX_FRAC_GRID_OPT,
00060 METHOD_OPT, SMOOTH_X_OPT, SMOOTH_Y_OPT, MIN_FRAC_OPT
00061 };
00062
00063 static const char * Options = "" ;
00064
00065 static struct option long_options[] = {
00066 {"nb-y", required_argument, 0, NB_Y_OPT},
00067 {"radius-x", required_argument, 0, RADIUS_X_OPT},
00068 {"radius-y", required_argument, 0, RADIUS_Y_OPT},
00069 {"help", 0, 0, HELP_OPT},
00070 {0, 0, 0, 0}
00071 };
00072
00073
00074
00075 static void Help( void )
00076 {
00077 puts( "Unitary test of xsh_subtract_background" ) ;
00078 puts( "Usage: test_xsh_subtract_background [options] <input_files>" ) ;
00079 puts( "Options" ) ;
00080 puts( " --nb-y=<n> : Number of points of the grid in y direction" ) ;
00081 puts( " --radius-x=<n> : Half size of the subwindow in x direction" ) ;
00082 puts( " --radius-y=<n> : Half size of the subwindow in y direction" ) ;
00083 puts( " --help : What you see" ) ;
00084 puts( "\nInput Files" ) ;
00085 puts( "The input files argument MUST be in this order:" ) ;
00086 puts( " 1. Science frame in PRE format" ) ;
00087 puts( " 2. SOF [ORDER_TAB_EDGES]\n" ) ;
00088 TEST_END();
00089 }
00090
00091 static void HandleOptions( int argc, char **argv,
00092 xsh_background_param *backg_par)
00093 {
00094 int opt ;
00095 int option_index = 0;
00096
00097
00098 while (( opt = getopt_long (argc, argv, Options,
00099 long_options, &option_index)) != EOF ){
00100 switch ( opt ) {
00101 case NB_Y_OPT:
00102 backg_par->sampley = atoi( optarg);
00103 break;
00104 case RADIUS_X_OPT:
00105 backg_par->radius_x = atoi( optarg);
00106 break;
00107 case RADIUS_Y_OPT:
00108 backg_par->radius_y = atoi( optarg);
00109 break;
00110 default: Help() ; exit( 0 ) ;
00111 }
00112 }
00113 }
00114
00115
00116
00117
00118
00125
00126
00127 int main( int argc, char **argv)
00128 {
00129 int ret = 0;
00130
00131 xsh_instrument* instrument = NULL;
00132
00133 const char *sof_name = NULL;
00134 cpl_frameset *set = NULL;
00135 const char * sci_name = NULL ;
00136
00137 cpl_frame* flat_frame = NULL;
00138 cpl_frame* flat_rmbckg = NULL;
00139 cpl_frame* guess_order_tab_frame = NULL;
00140
00141 xsh_background_param backg;
00142 cpl_frame* frame_grid=NULL;
00143 cpl_frame* frame_back=NULL;
00144
00145
00146 TESTS_INIT(MODULE_ID);
00147 cpl_msg_set_level(CPL_MSG_DEBUG);
00148 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00149
00150 backg.sampley = 800;
00151 backg.radius_x = 2;
00152 backg.radius_y = 2;
00153 backg.debug = CPL_TRUE;
00154
00155 HandleOptions( argc, argv, &backg);
00156
00157 if ( (argc - optind) >=2 ) {
00158 sci_name = argv[optind];
00159 sof_name = argv[optind+1];
00160 }
00161 else {
00162 Help();
00163 exit(0);
00164 }
00165
00166
00167 check( set = sof_to_frameset( sof_name));
00168
00169 check( instrument = xsh_dfs_set_groups( set));
00170
00171 check( guess_order_tab_frame = xsh_find_order_tab_edges( set, instrument));
00172 TESTS_XSH_FRAME_CREATE( flat_frame, "FLAT", sci_name);
00173
00174 xsh_msg("FRAME : %s",
00175 cpl_frame_get_filename( flat_frame));
00176 xsh_msg("ORDERLIST : %s",
00177 cpl_frame_get_filename( guess_order_tab_frame));
00178
00179 xsh_msg(" Parameters ");
00180 xsh_msg(" sample Y %d", backg.sampley);
00181 xsh_msg(" radius X %d", backg.radius_x);
00182 xsh_msg(" radius Y %d", backg.radius_y);
00183
00184 check( flat_rmbckg = xsh_subtract_background( flat_frame,
00185 guess_order_tab_frame, &backg, instrument, "",
00186 &frame_grid, &frame_back,1,1,1));
00187
00188 cleanup:
00189 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00190 xsh_error_dump(CPL_MSG_ERROR);
00191 ret = 1;
00192 }
00193 xsh_free_frameset( &set);
00194 xsh_instrument_free( &instrument);
00195 xsh_free_frame( &flat_frame);
00196 xsh_free_frame( &flat_rmbckg);
00197 xsh_free_frame( &frame_grid);
00198 xsh_free_frame( &frame_back);
00199
00200 TEST_END();
00201 return ret;
00202 }
00203