92 cpl_frame *wave_tab_frame,
93 cpl_frame *model_config_frame,
94 cpl_frame *order_tab_frame,
95 cpl_frame *attresidtab_frame,
96 int afc_xmin,
int afc_ymin,
98 cpl_frame **afc_order_tab_frame,
99 cpl_frame **afc_model_config_frame)
101 char result_name[256];
102 cpl_frame *result = NULL;
103 cpl_frame *afc_order_tab_result = NULL;
104 cpl_table *trace = NULL;
105 float xshift = 0.0, yshift = 0.0;
106 float T_effect_x = 0.0, T_effect_y = 0.0;
108 int residtab_size, iline;
109 const char *tag = NULL;
112 double lambda,
order, slit=0.0;
115 double cal_no_T_corr_x, cal_no_T_corr_y;
121 cpl_table *model_tab = NULL;
122 cpl_propertylist *model_header = NULL;
123 cpl_propertylist *afc_header = NULL;
124 cpl_vector *shiftx_vect = NULL;
125 cpl_vector *shifty_vect = NULL;
126 cpl_vector *T_effect_x_vect = NULL;
127 cpl_vector *T_effect_y_vect = NULL;
128 const char* afc_name=NULL;
130 cpl_frame* MODEL_CONF_OPT_frame=NULL;
131 cpl_propertylist* qc_head2copy=NULL;
146 check(afc_name=cpl_frame_get_filename(afc_frame));
147 check(afc_header=cpl_propertylist_load(afc_name,0));
149 if ( wave_tab_frame != NULL){
160 check( shiftx_vect = cpl_vector_new( residtab_size));
161 check( shifty_vect = cpl_vector_new( residtab_size));
162 check( T_effect_x_vect = cpl_vector_new( residtab_size));
163 check( T_effect_y_vect = cpl_vector_new( residtab_size));
167 for( iline=0; iline < residtab_size; iline++){
169 lambda = attresid_tab->
lambda[iline];
171 att_x = attresid_tab->
xgauss[iline];
172 att_y = attresid_tab->
ygauss[iline];
174 if ( wavesol != NULL){
182 &cal_no_T_corr_x, &cal_no_T_corr_y));
185 attresid_tab->
thpre_x[iline]=cal_x;
186 attresid_tab->
thpre_y[iline]=cal_y;
190 T_effect_x=cal_x-cal_no_T_corr_x;
191 T_effect_y=cal_y-cal_no_T_corr_y;
192 xsh_msg(
" T_effect_x %f T_effect_y %f", T_effect_x,T_effect_y);
193 check( cpl_vector_set( T_effect_x_vect, iline, T_effect_x));
194 check( cpl_vector_set( T_effect_y_vect, iline, T_effect_y));
197 cal_x = cal_x-afc_xmin+1.0;
198 cal_y =cal_y-afc_ymin+1.0;
200 xshift = att_x-cal_x;
201 yshift = att_y-cal_y;
202 xsh_msg(
"lambda %f order %f slit %f calx %f caly %f shiftx %f shifty %f TeffX %f TeffY %f",
203 lambda,
order,slit,cal_x, cal_y,xshift,yshift, T_effect_x,T_effect_y);
205 check( cpl_vector_set( shiftx_vect, iline, xshift));
206 check( cpl_vector_set( shifty_vect, iline, yshift));
209 check( xshift = cpl_vector_get_median( shiftx_vect));
210 check( yshift = cpl_vector_get_median( shifty_vect));
211 check( T_effect_x = cpl_vector_get_median( T_effect_x_vect));
212 check( T_effect_y = cpl_vector_get_median( T_effect_y_vect));
214 xsh_msg(
"Measured shift IN X %f Y %f", xshift, yshift);
215 if ( wavesol == NULL){
216 xsh_msg(
"Temperature effect at (mean) reference line in X %f Y %f",
217 T_effect_x,T_effect_y);
221 if ( wavesol != NULL){
223 cpl_propertylist* plist=NULL;
227 sprintf( result_name,
"%s.fits", tag);
229 tab=cpl_table_load(result_name,1,0);
230 plist=cpl_propertylist_load(result_name,0);
235 check( cpl_table_save(tab,plist, NULL, result_name,CPL_IO_DEFAULT));
264 xsh_msg(
"file name=%s",cpl_frame_get_filename(model_config_frame));
265 qc_head2copy=cpl_propertylist_load_regexp(cpl_frame_get_filename(model_config_frame),0,
"^ESO QC MODEL",0);
269 sprintf( result_name,
"%s.fits", tag);
270 check( model_header = cpl_propertylist_new());
277 if(cpl_propertylist_has(afc_header,
"ESO ADA ABSROT START") &&
278 cpl_propertylist_has(afc_header,
"ESO ADA ABSROT END")){
279 double absrot_avg = 0.5*(cpl_propertylist_get_double(afc_header,
"ESO ADA ABSROT START") +
280 cpl_propertylist_get_double(afc_header,
"ESO ADA ABSROT END"));
281 cpl_propertylist_append_double(model_header,
"ESO QC ABSROT",absrot_avg);
284 for(cpl_size row=0;row<cpl_table_get_nrow(model_tab);row++){
288 if(!strcmp(fld,
"chipx")){
289 cpl_propertylist_update_double(model_header,
"ESO QC CHIP X",val);
291 if(!strcmp(fld,
"chipy")){
292 cpl_propertylist_update_double(model_header,
"ESO QC CHIP Y",val);
298 cpl_propertylist_append(model_header,qc_head2copy);
301 check( cpl_table_save( model_tab, model_header, NULL, result_name,
303 check( *afc_model_config_frame = cpl_frame_new());
304 check( cpl_frame_set_filename( *afc_model_config_frame, result_name));
305 check( cpl_frame_set_tag( *afc_model_config_frame, tag));
310 sprintf( result_name,
"%s.fits", tag);
314 result_name, tag, config->
ny));
316 *afc_order_tab_frame = afc_order_tab_result;
319 if( cpl_error_get_code() != CPL_ERROR_NONE) {
364 cpl_frame *model_config_frame,
366 cpl_frame *spectralformat_frame,
367 cpl_frame *arclines_frame,
374 cpl_frame *result = NULL;
377 float lambda, slit_position;
380 int size, iline, iorder, ithe=0;
384 cpl_vector* orders = NULL;
399 if ( spectralformat_frame != NULL){
401 spectralformat_frame, instr));
403 for( iline=0; iline <
size; iline++){
408 check( orders_size = cpl_vector_get_size( orders));
409 the_size += orders_size;
419 xsh_msg(
"THE SIZE %d", the_size);
422 if (wave_tab_frame != NULL){
431 for( iline=0; iline <
size; iline++){
435 if ( spectrallist != NULL){
440 orders = cpl_vector_new(1);
441 cpl_vector_set( orders, 0,
order);
444 check( orders_size = cpl_vector_get_size( orders));
446 for( iorder=0; iorder < orders_size; iorder++){
449 check( cur_order = cpl_vector_get( orders, iorder));
451 if (wavesol != NULL){
459 slit_position, &
x, &
y));
465 slit_index, slit_position,
x,
y));
471 sprintf( thename,
"AFC_THEOTAB_%s.fits",
479 if( cpl_error_get_code() != CPL_ERROR_NONE) {
float xsh_arclist_get_wavelength(xsh_arclist *list, int idx)
get wavelength of a line in the arcline list
void xsh_arclist_free(xsh_arclist **list)
free memory associated to a arclist
int xsh_arclist_get_size(xsh_arclist *list)
get size of arcline list
xsh_arclist * xsh_arclist_load(cpl_frame *frame)
load an arcline list frame in arclist structure
void xsh_order_list_apply_shift(xsh_order_list *list, double xshift, double yshift)
Shift a order list.
cpl_frame * xsh_order_list_save(xsh_order_list *order_list, xsh_instrument *instrument, const char *filename, const char *tag, const int ny)
Save an order list to a frame.
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
void xsh_resid_tab_free(xsh_resid_tab **resid)
Free memory associated to a resid_tab.
xsh_resid_tab * xsh_resid_tab_load(cpl_frame *resid_tab_frame)
Load a residual tab from a frame.
void xsh_the_map_free(xsh_the_map **list)
free memory associated to a the_map
void xsh_the_map_set_arcline(xsh_the_map *list, int idx, float wavelength, int order, int slit_index, float slit_position, double detx, double dety)
xsh_the_map * xsh_the_map_create(int size)
Create an empty theoretical map.
cpl_frame * xsh_the_map_save(xsh_the_map *list, const char *filename)
save a the_map to a frame
void xsh_wavesol_apply_shift(xsh_wavesol *wsol, float shift_x, float shift_y)
Apply a shift on X and Y to wave solution.
cpl_table * xsh_wavesol_trace(xsh_wavesol *wsol, double *lambda, double *order, double *slit, int size)
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
cpl_frame * xsh_wavesol_save(xsh_wavesol *w, cpl_table *trace, const char *filename, const char *tag)
save a wavelength solution
#define XSH_REGDEBUG(...)
#define XSH_ASSURE_NOT_NULL(pointer)
cpl_frame * xsh_afcthetab_create(cpl_frame *wave_tab_frame, cpl_frame *model_config_frame, int order, cpl_frame *spectralformat_frame, cpl_frame *arclines_frame, int xmin, int ymin, xsh_instrument *instr, const int clean_tmp)
Create a The tab for AFC.
cpl_frame * xsh_flexcor(cpl_frame *afc_frame, cpl_frame *wave_tab_frame, cpl_frame *model_config_frame, cpl_frame *order_tab_frame, cpl_frame *attresidtab_frame, int afc_xmin, int afc_ymin, xsh_instrument *instr, cpl_frame **afc_order_tab_frame, cpl_frame **afc_model_config_frame)
This function applies the computed shift betwwen AFC CAL and AFC ATT frame.
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_INSTRCONFIG * xsh_instrument_get_config(xsh_instrument *i)
Get the instrument default set of keywords.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
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.
cpl_table * xsh_model_io_output_cfg(struct xs_3 *p_xs_3)
int xsh_model_offset(DOUBLE slit_pix_shift, DOUBLE disp_pix_shift, struct xs_3 *p_xs_3)
convert a pixel shift measured on the detector to a shift in detector centroid
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.
cpl_frame * xsh_model_pipe_anneal(cpl_frame *cfg_frame, cpl_frame *resid_frame, int maxit, double ann_fac, int scenario, int rec_id)
Run the annealing (optimisation) algoritm to improve the fit of the model parameter set to a given wa...
#define xsh_msg(...)
Print a message on info level.
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
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.
int xsh_resid_tab_get_size(xsh_resid_tab *resid)
#define XSH_MOD_CFG_OPT_AFC
#define XSH_COL_MODEL_CONF_BEST
#define XSH_ORDER_TAB_AFC
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_COL_MODEL_CONF_NAME
#define XSH_GET_TAG_FROM_MODE(TAG, instr)
cpl_error_code xsh_model_temperature_update_frame(cpl_frame **model_config_frame, cpl_frame *ref_frame, xsh_instrument *instrument, int *found_temp)
#define XSH_QC_AFC_XSHIFT_C
#define XSH_QC_AFC_YSHIFT
#define XSH_QC_AFC_XSHIFT
#define XSH_QC_AFC_YSHIFT_C