80 cpl_frame **slitmap_frame,
const char* rec_prefix)
84 char wavemap_tag[256];
85 char slitmap_tag[256];
98 sprintf(wavemap_tag,
"%s_%s",
100 sprintf(slitmap_tag,
"%s_%s",
104 ordertab_frame, pre,
instrument,wavemap_tag));
128 const char* wtag,
const char* stag,
129 cpl_frame **wavemap_frame,
130 cpl_frame **slitmap_frame,
const int save_tmp)
135 XSH_ASSURE_NOT_NULL_MSG( model_frame,
"If model-scenario is 0 make sure that the input model cfg has at least one parameter with Compute_Flag set to 1 and High_Limit>Low_limit");
153 wavemap_frame,slitmap_frame,save_tmp));
197 cpl_frame *wave_tab_2d_frame,
198 cpl_frame *order_tab_frame,
199 cpl_frame *spectral_format_frame,
203 cpl_frame **dispersol_frame,
204 cpl_frame** slitmap_frame)
209 cpl_frame *result = NULL ;
214 float sol_min_slit, sol_max_slit;
216 int i, idx,
size, slit_size;
218 double *vlambda = NULL, *vslit = NULL, *vorder = NULL;
219 double *pos_x = NULL, *pos_y = NULL;
235 if (pre_frame != NULL){
254 sol_min_slit = wave_tab_2d->
min_slit;
255 sol_max_slit = wave_tab_2d->
max_slit;
262 slit_size = (int)((sol_max_slit-sol_min_slit)/
slit_step)+1;
265 for( i=0; i< spec_list->
size; i++){
266 float lambda_min, lambda_max;
272 "lambda_max< lambda_min!! Check input spectralformat table, columns WLMAXFUL and WLMINFUL");
273 lambda_size = (int)((lambda_max-lambda_min)/
lambda_step)+1;
274 size += lambda_size*slit_size;
285 for( i=0; i< spec_list->
size; i++){
287 float lambda_min, lambda_max;
292 xsh_msg(
"order %f lambda %f-%f",absorder, lambda_min, lambda_max);
294 for(j=lambda_min; j <= lambda_max; j+=
lambda_step){
295 for( k=sol_min_slit; k <= sol_max_slit; k+=
slit_step){
300 vorder[idx] = absorder;
315 test = fopen(
"wavemap_grid.log",
"w");
316 for( itest=0; itest <
size; itest++){
317 fprintf(test,
"%f %f\n", pos_x[itest], pos_y[itest]);
326 vorder, wm_par, wm_list));
335 vorder, dispsol_par, wm_list));
337 sprintf(wm_name,
"%s.fits",wm_tag);
339 pre,
instrument, wm_tag, dispersol_frame, slitmap_frame));
342 check( cpl_frame_set_tag( result,wm_tag));
343 check( cpl_frame_set_tag( *slitmap_frame,
364 cpl_frame *order_tab_frame,
365 cpl_frame* mod_cfg_frame,
366 cpl_frame* wave_map_frame,
367 cpl_frame* slit_map_frame,
369 cpl_frame* spectral_format_frame,
376 cpl_frame* disp_frame=NULL;
386 float sol_min_slit=0, sol_max_slit=0;
387 int sol_min_order=0, sol_max_order=0;
388 cpl_image* wmap_ima=NULL;
389 cpl_image* smap_ima=NULL;
390 cpl_frame* loc_slit_map_frame=NULL;
391 const char* name=NULL;
397 double *vlambda = NULL, *vslit = NULL, *vorder = NULL;
398 double *pos_x = NULL, *pos_y = NULL;
403 cpl_frame* result=NULL;
412 if (pre_frame != NULL){
425 name=cpl_frame_get_filename(wave_map_frame);
426 wmap_ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
428 name=cpl_frame_get_filename(slit_map_frame);
429 smap_ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
436 sol_min_slit = cpl_image_get_min(smap_ima);
437 sol_max_slit = cpl_image_get_max(smap_ima);
441 slit_size = (int)((sol_max_slit-sol_min_slit)/
slit_step)+1;
444 for( i=0; i< spec_list->
size; i++){
445 float lambda_min, lambda_max;
449 sol_max_order = (sol_max_order < spec_list->list[i].absorder) ? spec_list->
list[i].
absorder : sol_max_order;
454 "lambda_max< lambda_min!! Check input spectralformat table, columns WLMAXFUL and WLMINFUL");
455 lambda_size = (int)((lambda_max-lambda_min)/
lambda_step)+1;
456 size += lambda_size*slit_size;
470 for( i=0; i< spec_list->
size; i++){
472 float lambda_min, lambda_max;
479 xsh_msg(
"order %f lambda %f-%f",absorder, lambda_min, lambda_max);
481 for(j=lambda_min; j <= lambda_max; j+=
lambda_step){
482 for( k=sol_min_slit; k <= sol_max_slit; k+=
slit_step){
485 vorder[idx] = absorder;
500 test = fopen(
"wavemap_grid.log",
"w");
501 for( itest=0; itest <
size; itest++){
502 fprintf(test,
"%f %f\n", pos_x[itest], pos_y[itest]);
511 vorder, dispsol_param, wm_list));
514 sprintf(wm_name,
"%s.fits",wm_tag);
517 &disp_frame,&loc_slit_map_frame));
574 const char* name_tab=NULL;
575 const char* name_map=NULL;
578 cpl_propertylist* plist=NULL;
590 check(name_tab=cpl_frame_get_filename(frm_tab));
591 check(tab=cpl_table_load(name_tab,2,0));
592 check(ord_min=cpl_table_get_column_min(tab,
"ABSORDER"));
593 check(ord_max=cpl_table_get_column_max(tab,
"ABSORDER"));
596 name_map=cpl_frame_get_filename(frm_map);
597 ima=cpl_image_load(name_map,CPL_TYPE_DOUBLE,0,0);
598 pima=cpl_image_get_data_double(ima);
599 sx=cpl_image_get_size_x(ima);
601 plist=cpl_propertylist_load(name_map,0);
602 for(i=ord_min;i<=ord_max;i++) {
603 next=cpl_table_and_selected_int(tab,
"ABSORDER",CPL_EQUAL_TO,i);;
604 ext=cpl_table_extract_selected(tab);
605 cx=cpl_table_get_data_double(ext,
"CENTER_X");
606 cy=cpl_table_get_data_double(ext,
"CENTER_Y");
611 cpl_propertylist_append_double(plist,qc_wlen,wlen);
613 cpl_table_select_all(tab);
624 return cpl_error_get_code();
647 const char* name_tab=NULL;
655 cpl_vector* loc_vec=NULL;
657 double* ptab_all_ord=NULL;
661 double ymin_all=FLT_MAX;
662 double ymax_all=FLT_MIN;
667 cpl_propertylist* plist=NULL;
668 cpl_table* tab_all_ord=NULL;
674 check(name_tab=cpl_frame_get_filename(frm_tab));
675 check(tab=cpl_table_load(name_tab,1,0));
676 check(ord_min=cpl_table_get_column_min(tab,
"Order"));
677 check(ord_max=cpl_table_get_column_max(tab,
"Order"));
678 check(plist=cpl_propertylist_load(name_tab,0));
680 check(nsel=cpl_table_and_selected_int(tab,
"Slit_index",CPL_EQUAL_TO,4));
681 check(ext=cpl_table_extract_selected(tab));
682 tab_all_ord=cpl_table_new(ord_max-ord_min+1);
683 cpl_table_new_column(tab_all_ord,
"data",CPL_TYPE_DOUBLE);
684 cpl_table_fill_column_window_double(tab_all_ord,
"data",0,ord_max-ord_min+1,0);
685 check(ptab_all_ord=cpl_table_get_data_double(tab_all_ord,
"data"));
687 for(i=ord_min;i<=ord_max;i++) {
688 check(nsel=cpl_table_and_selected_int(ext,
"Order",CPL_EQUAL_TO,i));
689 check(tbl=cpl_table_extract_selected(ext));
692 check(loc_vec=cpl_vector_new(nsel-1));
693 check(pvec=cpl_vector_get_data(loc_vec));
696 py=cpl_table_get_data_double(tbl,
"Ypoly");
698 py=cpl_table_get_data_double(tbl,
"Ythanneal");
701 for(j=0;j<nsel-1;j++) {
702 pvec[j]=fabs(py[j+1]-py[j]);
704 if(pvec[j]>ymax_all) {
708 if(pvec[j]<ymin_all) {
716 check(ymin=cpl_vector_get_min(loc_vec));
717 check(ymax=cpl_vector_get_max(loc_vec));
718 check(ymed=cpl_vector_get_median(loc_vec));
719 check(yavg=cpl_vector_get_mean(loc_vec));
720 check(ptab_all_ord[i-ord_min]=yavg);
725 check(cpl_propertylist_append_double(plist,qc_line,ymin));
729 check(cpl_propertylist_append_double(plist,qc_line,ymax));
733 check(cpl_propertylist_append_double(plist,qc_line,ymed));
737 check(cpl_propertylist_append_double(plist,qc_line,yavg));
744 check(cpl_table_set_invalid(tab_all_ord,
"data",i-ord_min));
746 check(cpl_table_select_all(ext));
749 cpl_table_erase_invalid(tab_all_ord);
752 check(yavg=cpl_table_get_column_mean(tab_all_ord,
"data"));
753 check(ymax=cpl_table_get_column_max(tab_all_ord,
"data"));
754 check(ymed=cpl_table_get_column_median(tab_all_ord,
"data"));
755 check(ymin=cpl_table_get_column_min(tab_all_ord,
"data"));
761 check(cpl_propertylist_append_double(plist,qc_line,ymin_all));
765 check(cpl_propertylist_append_int(plist,qc_line,ymin_all_ord));
769 check(cpl_propertylist_append_double(plist,qc_line,ymax_all));
773 check(cpl_propertylist_append_int(plist,qc_line,ymax_all_ord));
777 check(cpl_propertylist_append_double(plist,qc_line,ymed));
781 check(cpl_propertylist_append_double(plist,qc_line,yavg));
784 check(cpl_table_select_all(tab));
785 check(cpl_table_save(tab, plist, NULL,name_tab, CPL_IO_DEFAULT));
796 return cpl_error_get_code();
static xsh_instrument * instrument
xsh_dispersol_list * xsh_dispersol_list_load(cpl_frame *frame, xsh_instrument *instrument)
Load a dispersion list from a frame.
void xsh_dispersol_list_free(xsh_dispersol_list **list)
Free the dispersion list.
cpl_frame * xsh_dispersol_list_to_slitmap(xsh_dispersol_list *list, cpl_frame *order_frame, xsh_pre *pre, xsh_instrument *instr, const char *tag)
Save a SLIT MAP image.
cpl_frame * xsh_dispersol_list_to_wavemap(xsh_dispersol_list *list, cpl_frame *order_frame, xsh_pre *pre, xsh_instrument *instr, const char *tag)
Save a WAVE MAP image.
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
void xsh_wavemap_list_compute_poly(double *vlambda, double *vslit, double *xpos, double *ypos, int nitems, double *orders, xsh_dispersol_param *dispsol_param, xsh_wavemap_list *wmap)
compute a wave-map-list
void xsh_wavemap_list_free(xsh_wavemap_list **list)
free memory associated to a wavemap_list
cpl_frame * xsh_wavemap_list_save_poly(xsh_wavemap_list *wmap, cpl_frame *order_frame, xsh_pre *pre, xsh_instrument *instr, const char *prefix, cpl_frame **dispersol_frame, cpl_frame **slitmap_frame)
Save the wave_map slit_map and disp_tab.
void xsh_wavemap_list_compute(double *vlambda, double *xpos, double *ypos, int nitems, double *orders, xsh_dispersol_param *dispsol_param, xsh_wavemap_list *wmap)
compute a wave-map-list
xsh_wavemap_list * xsh_wavemap_list_create(xsh_instrument *instr)
create an empty order list
void xsh_wavesol_set_bin_y(xsh_wavesol *wsol, int bin)
Set the bin of wave table in y.
void xsh_wavesol_set_bin_x(xsh_wavesol *wsol, int bin)
Set the bin of wave table in x.
xsh_wavesol * xsh_wavesol_load(cpl_frame *frame, xsh_instrument *instrument)
load a wavelength solution
double xsh_wavesol_eval_poly(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in Y
void xsh_wavesol_free(xsh_wavesol **w)
free wavelength solution structure
double xsh_wavesol_eval_polx(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in X
#define XSH_ASSURE_NOT_NULL_MSG(pointer, msg)
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
#define XSH_ASSURE_NOT_NULL(pointer)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
int xsh_instrument_get_binx(xsh_instrument *instrument)
cpl_error_code xsh_model_config_load_best(cpl_frame *config_frame, xsh_xs_3 *p_xs_3)
Load the config model table and fill the struct.
void xsh_model_get_xy(xsh_xs_3 *p_xs_3, xsh_instrument *instr, double lambda_nm, int morder, double ent_slit_pos, double *x, double *y)
Compute the detector location (floating point pixels) of a given wavelength/entrance slit position.
void xsh_model_binxy(xsh_xs_3 *p_xs_3, int bin_X, int bin_Y)
corrects model for detector's binning
cpl_error_code xsh_model_maps_create(xsh_xs_3 *p_xs_3, xsh_instrument *instr, const char *wtag, const char *stag, cpl_frame **wmap_frame, cpl_frame **smap_frame, const int save_tmp)
Compute the wavelength and slit maps.
#define xsh_msg_warning(...)
Print an warning message.
#define xsh_msg_dbg_medium(...)
#define xsh_msg(...)
Print a message on info level.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
int xsh_debug_level_get(void)
get debug level
cpl_error_code xsh_update_pheader_in_image_multi(cpl_frame *frame, const cpl_propertylist *pheader)
Update FITS header.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_error_code xsh_wavetab_qc(cpl_frame *frm_tab, const int is_poly)
Monitor min/max/med/avg distance between detected lines on each ordee.
cpl_frame * xsh_create_dispersol_physmod(cpl_frame *pre_frame, cpl_frame *order_tab_frame, cpl_frame *mod_cfg_frame, cpl_frame *wave_map_frame, cpl_frame *slit_map_frame, xsh_dispersol_param *dispsol_param, cpl_frame *spectral_format_frame, xsh_instrument *instrument, const int clean_tmp)
cpl_error_code xsh_wavemap_qc(cpl_frame *frm_map, const cpl_frame *frm_tab)
Monitor Flux level along the orders traces given by an input table.
void xsh_create_map(cpl_frame *dispsol_frame, cpl_frame *ordertab_frame, cpl_frame *pre_frame, xsh_instrument *instrument, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const char *rec_prefix)
void xsh_create_model_map(cpl_frame *model_frame, xsh_instrument *instrument, const char *wtag, const char *stag, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const int save_tmp)
cpl_frame * xsh_create_poly_wavemap(cpl_frame *pre_frame, cpl_frame *wave_tab_2d_frame, cpl_frame *order_tab_frame, cpl_frame *spectral_format_frame, xsh_dispersol_param *dispsol_par, xsh_instrument *instrument, const char *wm_tag, cpl_frame **dispersol_frame, cpl_frame **slitmap_frame)
#define XSH_SLIT_MAP_POLY
#define XSH_WAVE_MAP_POLY
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_QC_LINE_DIFMIN_ORD
#define XSH_QC_WMAP_WAVEC
#define XSH_QC_LINE_DIFMAX_C
#define XSH_QC_LINE_DIFMED_C
#define XSH_QC_LINE_DIFAVG
#define XSH_QC_LINE_DIFMIN
#define XSH_QC_LINE_DIFMAX
#define XSH_QC_LINE_DIFMAX_ORD
#define XSH_QC_LINE_DIFAVG_C
#define XSH_QC_LINE_DIFMED
#define XSH_QC_LINE_DIFMIN_C
#define XSH_FREE(POINTER)
#define XSH_MALLOC(POINTER, TYPE, SIZE)