67#define MODULE_ID "XSH_COMBINE_NOD"
88 {
"slit-n",required_argument, 0,
NSLIT_OPT},
89 {
"use-localization",required_argument, 0,
USELOC_OPT},
98 puts(
"Unitary test of xsh_combine_nod" ) ;
99 puts(
"Usage: test_rectify [options] <input_files>" ) ;
101 puts(
" --kernel=<name> : Name of the rectify kernel" ) ;
102 puts(
" --radius=<nn> : Radius (default 4)" ) ;
103 puts(
" --bin-lambda=<n> : Bin in Lambda (default 0.1)" ) ;
104 puts(
" --bin-space=<n> : Bin in Slit (default 0.1)" ) ;
105 puts(
" --order-min=<n> : Minimum abs order" );
106 puts(
" --order-max=<n> : Maximum abs order" );
107 puts(
" --slit-min=<n> : Minimum slit to rectify" );
108 puts(
" --slit-n=<n> : Number of pixels in slit rectified frame" );
109 puts(
" --use-localization : 1 if tou want to use it");
110 puts(
" --nod-set=<file> : Set of rectified shifted frames with tag OBJECT_SLIT_NOD_arm");
111 puts(
" --nod-order=<n> : abs order where we analyse nod" );
112 puts(
" --help : What you see" ) ;
113 puts(
"\nInput Files" ) ;
114 puts(
"The input files argument MUST be in this order:" ) ;
115 puts(
" 1. Science frame in PRE format" ) ;
116 puts(
" 2. SOF\n" ) ;
122 double *slit_min,
int *nslit,
int *use_loc,
char** nod_set_name)
125 int option_index = 0;
127 while (( opt = getopt_long (argc, argv,
Options,
143 sscanf( optarg,
"%64d", order_min);
146 sscanf( optarg,
"%64d", order_max);
149 sscanf( optarg,
"%64lf", slit_min) ;
152 sscanf( optarg,
"%64d", nslit);
155 sscanf( optarg,
"%64d", use_loc);
158 *nod_set_name = optarg;
161 sscanf( optarg,
"%64d", order_min);
163 default:
Help() ; exit( 0 ) ;
170 const char* rec_name = NULL;
172 int ilambda=0, islit=0;
173 int nlambda = 0, nslit=0;
176 char *shortname = NULL;
177 cpl_frame *res_frame = NULL;
181 check( rec_name = cpl_frame_get_filename( rec_frame));
183 shortname = strrchr( rec_name,
'/');
185 if (shortname != NULL){
186 sprintf( name,
"ZERO_%s",shortname+1);
189 sprintf( name,
"ZERO_%s",rec_name);
200 for( islit=0; islit < nslit; islit++){
203 for(ilambda=0; ilambda < nlambda; ilambda++){
204 flux[ilambda+islit*nlambda] = val;
211 if (cpl_error_get_code() != CPL_ERROR_NONE){
224 const char* rec_name = NULL;
226 int ilambda=0, islit=0;
227 int nlambda = 0, nslit=0;
231 FILE* datfile = NULL;
232 char *shortname = NULL;
236 check( rec_name = cpl_frame_get_filename( rec_frame));
238 shortname = strrchr( rec_name,
'/');
240 if (shortname != NULL){
241 rec_name = shortname+1;
251 sprintf( name,
"%s_profil.dat",rec_name);
252 datfile = fopen( name,
"w");
253 fprintf( datfile,
"#slit flux\n");
255 for( islit=0; islit < nslit; islit++){
258 for(ilambda=0; ilambda < nlambda; ilambda++){
259 val+= flux[ilambda+islit*nlambda];
261 fprintf( datfile,
"%f %f\n", slit[islit], val);
277int main(
int argc,
char **argv)
284 char *sof_name = NULL;
285 cpl_frameset *set = NULL;
287 const char * raw_sof_name = NULL ;
288 cpl_frameset *raw_set = NULL;
290 cpl_frame *sci_frame = NULL;
291 cpl_frame *orderlist_frame = NULL;
292 cpl_frame *wavesol_frame = NULL;
293 cpl_frame *model_frame = NULL;
294 cpl_frame *spectralformat_frame = NULL;
295 cpl_frame *rec_ab_frame = NULL ;
296 cpl_frame *rec_abeso_frame = NULL ;
297 cpl_frame *rec_abtab_frame = NULL ;
298 cpl_frame *rec_ba_frame = NULL ;
299 cpl_frame *rec_bashift_frame = NULL ;
300 cpl_frame *rec_bashifteso_frame = NULL ;
301 cpl_frame *loc_ab_frame = NULL;
302 cpl_frame *loc_ba_frame = NULL;
303 cpl_frameset *nod_set = NULL;
304 cpl_frameset *zero_nod_set = NULL;
305 cpl_frameset *combine_set = NULL;
307 cpl_frame *combine_nod_frame = NULL;
308 cpl_frame *combine_nodeso_frame = NULL;
310 int order_min = -1, order_max = -1;
312 int rec_min_index=-1, rec_max_index=-1;
317 int nslit_c, nslit=-100;
319 double slit_min_c, slit_min=-100;
321 const char *tag = NULL;
323 double *ref_ra = NULL, *ref_dec = NULL;
324 const int decode_bp=2147483647;
327 cpl_msg_set_level(CPL_MSG_DEBUG);
343 HandleOptions( argc, argv, &rectify_par, &order_min, &order_max,
344 &slit_min, &nslit, &use_loc_obj, &sof_name);
346 if ( sof_name != NULL){
347 xsh_msg(
"Using nod set : %s", sof_name);
351 check( nb_frames = cpl_frameset_get_size( nod_set));
353 for ( i = 0 ; i < nb_frames ; i++ ) {
354 check( sci_frame = cpl_frameset_get_frame( nod_set, i));
355 xsh_msg(
"NOD : %s", cpl_frame_get_filename( sci_frame));
362 if ( (argc - optind) >=2 ) {
363 raw_sof_name = argv[optind];
364 sof_name = argv[optind+1];
382 check( nb_frames = cpl_frameset_get_size( raw_set));
384 for ( i = 0 ; i < nb_frames ; i++ ) {
385 check( sci_frame = cpl_frameset_get_frame( raw_set, i));
387 cpl_frame_get_filename( sci_frame));
390 cpl_frame_get_filename( orderlist_frame));
392 cpl_frame_get_filename( spectralformat_frame));
397 if ( wavesol_frame == NULL){
401 if ( wavesol_frame != NULL){
403 cpl_frame_get_filename( wavesol_frame));
407 cpl_frame_get_filename( model_frame));
419 if ( order_min != -1) {
422 xsh_msg(
"Order min %d => index %d", order_min, rec_min_index);
428 if ( order_max != -1) {
431 xsh_msg(
"Order max %d => index %d", order_max, rec_max_index);
434 rec_max_index = order_list->
size;
440 &slit_min_c, &nslit_c,
mode));
442 if (slit_min == -100){
443 slit_min = slit_min_c;
449 xsh_msg(
"SLIT min = %f and has size %d", slit_min, nslit);
454 wavesol_frame, model_frame,
instrument, &rectify_par,
455 spectralformat_frame, NULL,
"REC_A_B.fits", tag,
456 &rec_abeso_frame,&rec_abtab_frame,
457 rec_min_index, rec_max_index, slit_min, nslit, 0,NULL));
461 nod_set = cpl_frameset_new();
462 cpl_frameset_insert( nod_set, rec_ab_frame);
464 if ( use_loc_obj == 1){
466 &loc_par, NULL,
"LOC_AB.fits"));
468 &loc_par, NULL,
"LOC_BA.fits"));
472 &rectify_par,
"REC_SHIFT_B_A.fits", &rec_bashifteso_frame, &ref_ra,
475 xsh_msg(
"TEST REF RA DEC %f %f", *ref_ra, *ref_dec);
477 cpl_frameset_insert( nod_set, rec_bashift_frame);
481 zero_nod_set = cpl_frameset_new();
484 for ( i = 0 ; i < nb_frames ; i++ ) {
485 cpl_frame *new_frame = NULL;
487 check( sci_frame = cpl_frameset_get_frame( nod_set, i));
489 check( cpl_frameset_insert( zero_nod_set, new_frame));
494 for ( i = 0 ; i < nb_frames ; i++ ) {
495 cpl_frame *analyse_frame = NULL;
496 cpl_frame *orig_frame = NULL;
497 const char * orig_name = NULL;
500 combine_set = cpl_frameset_duplicate( zero_nod_set);
501 check( analyse_frame = cpl_frameset_get_frame( combine_set, i));
502 check( orig_frame = cpl_frameset_get_frame( nod_set, i));
503 check( orig_name = cpl_frame_get_filename( orig_frame));
504 check( cpl_frame_set_filename( analyse_frame, orig_name));
506 sprintf( tag,
"COMBINE_NOD%d", i);
517 "FULL_COMBINE_NOD",
instrument,&combine_nodeso_frame,0));
521 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static const char * Options
cpl_frame * create_zero_rectify(cpl_frame *rec_frame, int iorder, xsh_instrument *instr)
static void HandleOptions(int argc, char **argv, xsh_rectify_param *rectify_par, int *order_min, int *order_max, double *slit_min, int *nslit, int *use_loc, char **nod_set_name)
static struct option long_options[]
void analyse_rectify(cpl_frame *rec_frame, int iorder, xsh_instrument *instr)
static xsh_instrument * instrument
cpl_frameset * sof_to_frameset(const char *sof_name)
cpl_frame * xsh_combine_nod(cpl_frameset *nod_frames, xsh_combine_nod_param *nod_par, const char *tag, xsh_instrument *instrument, cpl_frame **res_frame_ext, const int scale_nod)
int xsh_order_list_get_index_by_absorder(xsh_order_list *list, double absorder)
xsh_order_list * xsh_order_list_load(cpl_frame *frame, xsh_instrument *instr)
load an order list from a frame
void xsh_order_list_free(xsh_order_list **list)
free memory associated to an order_list
int xsh_rec_list_get_nslit(xsh_rec_list *list, int idx)
xsh_rec_list * xsh_rec_list_load(cpl_frame *frame, xsh_instrument *instrument)
load an rec list from a frame
float * xsh_rec_list_get_data1(xsh_rec_list *list, int idx)
cpl_frame * xsh_rec_list_save(xsh_rec_list *list, const char *filename, const char *tag, int is_temp)
Save a rec list in a frame.
float * xsh_rec_list_get_slit(xsh_rec_list *list, int idx)
int xsh_rec_list_get_nlambda(xsh_rec_list *list, int idx)
cpl_frame * xsh_rec_list_frame_invert(cpl_frame *rec_frame, const char *tag, xsh_instrument *instrument)
Invert the rectified flux images of the input frame into a new frame.
void xsh_rec_list_free(xsh_rec_list **list)
free memory associated to a rec_list
#define xsh_error_dump(level)
#define XSH_ASSURE_NOT_NULL(pointer)
XSH_MODE xsh_instrument_get_mode(xsh_instrument *i)
Get a mode on instrument structure.
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.
#define xsh_msg(...)
Print a message on info level.
cpl_frame * shift_with_kw(cpl_frame *rec_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, const char *fname, cpl_frame **res_frame_ext, double **ref_ra, double **ref_dec, int flag)
This function creates a structure containing for each order the shift to be applied.
cpl_frame * xsh_rectify_orders(cpl_frame *sci_frame, xsh_order_list *orderlist_frame, cpl_frame *wavesol_frame, cpl_frame *model_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, cpl_frame *spectralformat_frame, cpl_frame *disp_tab_frame, const char *res_name, const char *tag, cpl_frame **res_frame_ext, cpl_frame **res_frame_tab, int min_index, int max_index, double slit_min, int nslit, double slit_shift, cpl_frame *slitshift_tab)
Create a grid in wavelength with the step in lambda and slit. Steps are defined in the parameters....
void xsh_rec_slit_size(xsh_rectify_param *rectify_par, double *slit_min, int *nslit, XSH_MODE mode)
rectify frame
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
enum localize_method method
#define TESTS_INIT(DRL_ID)
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
cpl_frame * xsh_find_wave_tab_2d(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D.
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
cpl_frame * xsh_find_model_config_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a model configuration table frame.
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_FREE(POINTER)