66#define MODULE_ID "XSH_LOCALIZE_OBJ"
80 {
"kappa", required_argument, 0,
KAPPA_OPT},
81 {
"niter", required_argument, 0,
NITER_OPT},
89 puts(
"Unitary test of Localization");
90 puts(
"Usage: test_xsh_localize_obj [options] REC_FRAME [LOC_TABLE]");
93 puts(
" --help : What you see" ) ;
94 puts(
" --method= : MANUAL | AUTO | GAUSSIAN [GAUSSIAN]");
95 puts(
" MANUAL options");
96 puts(
" --slit_position=<n>: (MANUAL only) the reference slit position in arcsec [0]");
97 puts(
" --slit_hheight=<n> : (MANUAL only) the half size of slit height in arcsec [0.5]");
98 puts(
" AUTO or GAUSSIAN options");
99 puts(
" --deg_poly=<n> : (AUTO, GAUSSIAN) polynomial degree of fit [0]");
100 puts(
" --niter=<n> : (AUTO, GAUSSIAN) Number of iterations for sigma clipping[3]");
101 puts(
" --kappa=<n> : (AUTO, GAUSSIAN) Kappa for sigma clipping [1.0]");
102 puts(
" --nbchunk=<n> : (AUTO, GAUSSIAN) Number of chunk [10]");
103 puts(
" --skymask=<file> : (AUTO, GAUSSIAN) Sky mask file");
104 puts(
" AUTO options");
105 puts(
" --threshold=<n> : (AUTO) Threshold to find edges [10]");
106 puts(
"\nInput Files" ) ;
107 puts(
"The input files argument MUST be in this order:" ) ;
108 puts(
" 1. DRL rectified 2D frame tag DRL_ORDER2D" ) ;
109 puts(
" 2. (optional] Localization table" );
118 int option_index = 0;
120 while (( opt = getopt_long (argc, argv,
121 "nbchunk:threshold:deg_poly:method:slit_position:slit_hheight",
145 xsh_msg(
"WRONG method %s", optarg);
157 loc_par->
kappa = atof( optarg);
160 loc_par->
niter = atoi( optarg);
164 *skymask_name = optarg;
186 const char* rec_name = NULL;
187 cpl_frame* merge_frame = NULL;
188 const char* loc_name = NULL;
192 FILE *loc_regfile = NULL ;
193 FILE *loc_datfile = NULL;
199 check( rec_name = cpl_frame_get_filename( rec_frame));
200 check( loc_name = cpl_frame_get_filename( loc_frame));
202 xsh_msg(
"---Dump the localization");
203 printf(
"DRL RECTIFY frame : %s\n", rec_name);
204 printf(
"LOCALIZE frame : %s\n", loc_name);
212 loc_regfile = fopen(
"LOCALIZATION.reg",
"w");
213 fprintf(loc_regfile,
"# Region file format: DS9 version 4.0\n"\
214 "#red center, blue low, green up\n"\
215 "global color=red font=\"helvetica 4 normal\""\
216 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0"\
219 loc_datfile = fopen(
"LOCALIZATION.dat",
"w");
220 fprintf( loc_datfile,
"#lambda slow scen sup\n");
222 for( ilambda=0; ilambda < spectrum->
size_lambda; ilambda++){
223 double slit_cen = 0.0, slit_low= 0.0, slit_up = 0.0;
227 check( slit_cen = cpl_polynomial_eval_1d( loc_list->
cenpoly,
233 fprintf( loc_regfile,
"point(%f,%f) "\
234 "#point=cross color=red font=\"helvetica 4 normal\"\n", lambda, slit_cen);
235 fprintf( loc_regfile,
"point(%f,%f) "\
236 "#point=cross color=blue font=\"helvetica 4 normal\"\n", lambda, slit_low);
237 fprintf( loc_regfile,
"point(%f,%f) "\
238 "#point=cross color=green font=\"helvetica 4 normal\"\n", lambda, slit_up);
239 fprintf( loc_datfile,
"%f %f %f %f\n", lambda, slit_low, slit_cen, slit_up);
242 xsh_msg(
"Produce ds9 region file : LOCALIZATION.reg");
243 xsh_msg(
"Produce data file : LOCALIZATION.dat");
244 xsh_msg(
" Produce MERGE frame : %s", cpl_frame_get_filename( merge_frame));
247 if(loc_regfile != NULL) {
248 fclose( loc_regfile);
251 if(loc_datfile != NULL) {
252 fclose( loc_datfile);
268int main(
int argc,
char **argv)
275 char* rec_name = NULL;
276 cpl_frame *rec_frame = NULL;
278 const char *tag = NULL;
279 char* loc_name = NULL;
280 cpl_frame* loc_frame = NULL;
281 cpl_propertylist *plist = NULL;
283 char * skymask_name = NULL;
284 cpl_frame *skymask_frame = NULL;
285 const int decode_bp=2147483647;
289 cpl_msg_set_level(CPL_MSG_DEBUG);
301 if ( (argc - optind) > 0 ) {
302 rec_name = argv[optind];
303 if ((argc - optind) > 1){
304 loc_name = argv[optind+1];
312 check( plist = cpl_propertylist_load( rec_name, 0));
323 xsh_msg(
"DRL RECTIFY frame : %s tag %s", rec_name, tag);
325 if (loc_name == NULL){
326 xsh_msg(
"---Localize parameters");
341 xsh_msg(
" skymask : %s", skymask_name);
347 NULL,
"LOCALIZE_TABLE.fits"));
365 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static void analyse_localization(cpl_frame *merge_frame, cpl_frame *loc_frame, xsh_instrument *instr)
static void HandleOptions(int argc, char **argv, xsh_localize_obj_param *loc_par, char **skymask_name)
static struct option long_options[]
static xsh_instrument * instrument
xsh_localization * xsh_localization_load(cpl_frame *frame)
Load a localization list from a frame.
void xsh_localization_free(xsh_localization **list)
free memory associated to a localization_list
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
#define xsh_error_dump(level)
#define XSH_ASSURE_NOT_NULL(pointer)
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
cpl_frame * xsh_localize_obj(cpl_frame *sci_frame, cpl_frame *skymask_frame, xsh_instrument *instrument, xsh_localize_obj_param *loc_obj_par, xsh_slit_limit_param *slit_limit_param, const char *fname)
Build the localization table.
cpl_frame * xsh_merge_ord(cpl_frame *sci_frame, xsh_instrument *instrument, int merge, const char *rec_prefix)
Merge orders of the rectified frame using merge parameters.
#define xsh_msg(...)
Print a message on info level.
XSH_ARM xsh_pfits_get_arm(const cpl_propertylist *plist)
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
enum localize_method method
#define TESTS_XSH_INSTRUMENT_CREATE(instr, mode, arm, lamp, recipe)
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
#define TESTS_INIT(DRL_ID)
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_SKY_LINE_LIST
#define LOCALIZE_METHOD_PRINT(method)