86 double *slit,
double* sn,
int *slit_index,
87 double *thpre_x,
double *thpre_y,
88 double*corr_x,
double* corr_y,
89 double *gaussian_norm,
90 double *gaussian_fit_x,
double *gaussian_fit_y,
91 double *gaussian_sigma_x,
double *gaussian_sigma_y,
92 double *gaussian_fwhm_x,
double *gaussian_fwhm_y,
int* flag,
145 if (wavesol != NULL) {
152 for( i=0; i<
size; i++){
154 result->
lambda[i] = lambda[i];
156 result->
slit[i] = slit[i];
158 result->
sn[i] = sn[i];
163 result->
thpre_x[i] = thpre_x[i];
164 result->
thpre_y[i] = thpre_y[i];
165 result->
thcor_x[i] = thpre_x[i]+corr_x[i];
166 result->
thcor_y[i] = thpre_y[i]+corr_y[i];
167 result->
xgauss[i] = gaussian_fit_x[i];
168 result->
ygauss[i] = gaussian_fit_y[i];
175 result->
flag[i] = flag[i];
184 result->
xpoly[i] = polx;
185 result->
ypoly[i] = poly;
194 result->
xpoly[i] = 0.0;
195 result->
ypoly[i] = 0.0;
208 if ( cpl_error_get_code() != CPL_ERROR_NONE){
218 double *slit,
double* sn,
int *slit_index,
double *thpre_x,
double *thpre_y,
219 double*corr_x,
double* corr_y,
double *gaussian_norm,
220 double *gaussian_fit_x,
double *gaussian_fit_y,
double *gaussian_sigma_x,
221 double *gaussian_sigma_y,
double *gaussian_fwhm_x,
double *gaussian_fwhm_y,
230 for (i = 0; i <
size; i++) {
232 if (flag != NULL && flag[i] == 0) {
282 result->
size = ngood;
285 if (wavesol != NULL) {
295 for (i = 0; i <
size; i++) {
296 if (flag != NULL && flag[i] == 0) {
297 result->
lambda[k] = lambda[i];
299 result->
slit[k] = slit[i];
301 result->
sn[k] = sn[i];
306 result->
thpre_x[k] = thpre_x[i];
307 result->
thpre_y[k] = thpre_y[i];
308 result->
thcor_x[k] = thpre_x[i] + corr_x[i];
309 result->
thcor_y[k] = thpre_y[i] + corr_y[i];
310 result->
xgauss[k] = gaussian_fit_x[i];
311 result->
ygauss[k] = gaussian_fit_y[i];
318 result->
flag[k] = flag[i];
327 result->
xpoly[k] = polx;
328 result->
ypoly[k] = poly;
335 result->
xpoly[k] = 0.0;
336 result->
ypoly[k] = 0.0;
342 cleanup:
if (cpl_error_get_code() != CPL_ERROR_NONE) {
352 cpl_frame* result = NULL;
353 cpl_table* tab = NULL;
354 cpl_table* ext = NULL;
355 const char* fname = NULL;
357 cpl_propertylist* header=NULL;
360 result=cpl_frame_duplicate(resid);
361 check( fname = cpl_frame_get_filename( resid));
362 tab=cpl_table_load(fname,1,0);
363 header=cpl_propertylist_load(fname,0);
366 cpl_table_erase_selected(tab);
367 cpl_table_save(tab,header,NULL,name,CPL_IO_DEFAULT);
368 cpl_frame_set_filename(result,name);
392 cpl_table* table = NULL;
393 const char* tablename = NULL;
396 double *lambda = NULL;
397 double *
order = NULL;
399 int *slit_index = NULL;
402 double *thcorx = NULL;
403 double *thcory = NULL;
404 double *xgauss = NULL;
405 double *ygauss = NULL;
406 double *sig_xgauss = NULL;
407 double *sig_ygauss = NULL;
408 double *fwhm_xgauss = NULL;
409 double *fwhm_ygauss = NULL;
410 double *norm_gauss = NULL;
411 double *xpoly = NULL;
412 double *ypoly = NULL;
413 double *thanneal_x = NULL;
414 double *thanneal_y = NULL;
422 check( tablename = cpl_frame_get_filename( resid_tab_frame));
426 check(
size = cpl_table_get_nrow(table));
429 check (result->
header = cpl_propertylist_load( tablename, 0));
431 if (cpl_error_get_code() == CPL_ERROR_NONE){
468 for(i=0; i<
size;i++){
469 int orderv, slit_indexv;
470 double lambdav, slitv, thxv, thyv;
471 double thcorxv=0, thcoryv=0;
472 double xgaussv, ygaussv, xpolyv, ypolyv;
473 double sig_xgaussv, sig_ygaussv;
474 double fwhm_xgaussv, fwhm_ygaussv;
480 CPL_TYPE_DOUBLE, i, &lambdav));
484 CPL_TYPE_INT, i, &orderv));
488 CPL_TYPE_DOUBLE, i, &slitv));
492 CPL_TYPE_INT, i, &slit_indexv));
496 CPL_TYPE_DOUBLE, i, &thxv));
500 CPL_TYPE_DOUBLE, i, &thyv));
513 CPL_TYPE_DOUBLE, i, &xgaussv));
517 CPL_TYPE_DOUBLE, i, &ygaussv));
521 CPL_TYPE_DOUBLE, i, &sig_xgaussv));
525 CPL_TYPE_DOUBLE, i, &sig_ygaussv));
530 CPL_TYPE_DOUBLE, i, &fwhm_xgaussv));
534 CPL_TYPE_DOUBLE, i, &fwhm_ygaussv));
538 CPL_TYPE_DOUBLE, i, &norm_gaussv));
543 CPL_TYPE_DOUBLE, i, &xpolyv));
544 thanneal_x[i] = xpolyv;
547 CPL_TYPE_DOUBLE, i, &ypolyv));
548 thanneal_y[i] = ypolyv;
553 CPL_TYPE_DOUBLE, i, &xpolyv));
557 CPL_TYPE_DOUBLE, i, &ypolyv));
563 CPL_TYPE_INT, i, &flagv));
566 order[i] = (double) orderv;
568 slit_index[i] = slit_indexv;
575 sig_xgauss[i] = sig_xgaussv;
576 sig_ygauss[i] = sig_ygaussv;
577 fwhm_xgauss[i] = fwhm_xgaussv;
578 fwhm_ygauss[i] = fwhm_ygaussv;
579 norm_gauss[i] = norm_gaussv;
603 result->
xpoly = xpoly;
604 result->
ypoly = ypoly;
609 if (cpl_error_get_code () != CPL_ERROR_NONE) {
611 cpl_frame_get_filename(resid_tab_frame));
630 if ( resid && *resid) {
651 if( (*resid)->sn)
XSH_FREE( (*resid)->sn) ;
673 FILE* logfile = NULL;
679 logfile = fopen(filename,
"w");
683 "# lambda order slit thx, thy, gaussx, gaussy, xpoly, ypoly");
684 for ( i=0; i< resid->
size; i++){
685 double lambda,
order, slit;
687 lambda = resid->
lambda[i];
689 slit = resid->
slit[i];
691 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
700 "# lambda order slit thx, thy, gaussx, gaussy, thanneal_x, thanneal_y");
701 for ( i=0; i< resid->
size; i++){
702 double lambda,
order, slit;
704 lambda = resid->
lambda[i];
706 slit = resid->
slit[i];
708 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
736 cpl_frame *result = NULL ;
737 cpl_table *table = NULL;
738 cpl_propertylist *header = NULL;
853 check(cpl_table_set_size( table, resid->
size));
856 for (i=0; i<resid->
size; i++) {
857 double lambda,
order, slit,sn;
859 double thpre_x, thpre_y;
861 double xgauss, ygauss;
863 double sig_xgauss, sig_ygauss;
864 double fwhm_xgauss, fwhm_ygauss;
867 lambda = resid->
lambda[i];
869 slit = resid->
slit[i];
877 xgauss = resid->
xgauss[i];
878 ygauss = resid->
ygauss[i];
884 xpoly = resid->
xpoly[i];
885 ypoly = resid->
ypoly[i];
887 flag = resid->
flag[i];
957 cpl_propertylist_append_double(header,
"ESO QC POLY RESX_MIN",residx_min);
958 cpl_propertylist_append_double(header,
"ESO QC POLY RESX_MAX",residx_max);
959 cpl_propertylist_append_double(header,
"ESO QC POLY RESX_RMS",residx_rms);
962 cpl_propertylist_append_double(header,
"ESO QC POLY RESY_MIN",residy_min);
963 cpl_propertylist_append_double(header,
"ESO QC POLY RESY_MAX",residy_max);
964 cpl_propertylist_append_double(header,
"ESO QC POLY RESY_RMS",residy_rms);
970 size = cpl_propertylist_get_size( header);
973 size = cpl_propertylist_get_size( header);
992 cpl_table_select_all(table);
995 check( cpl_table_save(table, header,NULL,filename, CPL_IO_DEFAULT));
1000 CPL_FRAME_TYPE_TABLE,
1001 CPL_FRAME_GROUP_PRODUCT,
1002 CPL_FRAME_LEVEL_TEMPORARY));
1009 if (cpl_error_get_code() != CPL_ERROR_NONE){
1037 double * result = NULL ;
1040 result = resid->lambda ;
1056 double * result = NULL ;
1059 result = resid->
order ;
1075 double * result = NULL ;
1078 result = resid->
slit ;
1104 double * result = NULL ;
1107 result = resid->thpre_x ;
1123 double * result = NULL ;
1142 double * result = NULL ;
1161 double * result = NULL ;
1174 const int solution_type)
1176 cpl_table* stab=NULL;
1177 cpl_table* rtab=NULL;
1178 cpl_propertylist* shead=NULL;
1179 cpl_propertylist* rhead=NULL;
1180 cpl_propertylist* qc_head=NULL;
1181 const char* sname=NULL;
1182 const char* rname=NULL;
1189 double* pWaveSelf=NULL;
1190 int* pFlagSelf=NULL;
1192 int* pSlitIndexSelf=NULL;
1193 int* pOrderSelf=NULL;
1194 double* pXThAnnealSelf=NULL;
1195 double* pYThAnnealSelf=NULL;
1196 double* pXpolySelf=NULL;
1197 double* pYpolySelf=NULL;
1199 double* pResidXpolySelf=NULL;
1200 double* pResidYpolySelf=NULL;
1201 double* pResidXmodelSelf=NULL;
1202 double* pResidYmodelSelf=NULL;
1205 double* pWaveRight=NULL;
1206 int* pSlitIndexRight=NULL;
1207 int* pOrderRight=NULL;
1208 double* pXThAnnealRight=NULL;
1209 double* pYThAnnealRight=NULL;
1210 double* pXpolyRight=NULL;
1211 double* pYpolyRight=NULL;
1213 double* pResidXpolyRight=NULL;
1214 double* pResidYpolyRight=NULL;
1215 double* pResidXmodelRight=NULL;
1216 double* pResidYmodelRight=NULL;
1220 sname=cpl_frame_get_filename(self);
1221 rname=cpl_frame_get_filename(right);
1224 shead=cpl_propertylist_load(sname,0);
1225 rhead=cpl_propertylist_load(rname,0);
1226 qc_head=cpl_propertylist_load_regexp(sname,0,
"^ESO QC",0);
1228 cpl_propertylist_append(rhead,qc_head);
1229 stab=cpl_table_load(sname,1,0);
1230 rtab=cpl_table_load(rname,1,0);
1231 srow=cpl_table_get_nrow(stab);
1232 rrow=cpl_table_get_nrow(rtab);
1266 for(i=0;i<srow;i++) {
1268 for (k = 0; k < rrow; k++) {
1269 if ((fabs(pWaveSelf[i] - pWaveRight[k]) < wtol)
1270 && (fabs(pSlitIndexSelf[i] - pSlitIndexRight[k]) < itol)
1271 && (fabs(pOrderSelf[i] - pOrderRight[k]) < itol)
1272 && pFlagSelf[i] == 0) {
1274 pXThAnnealSelf[i] = pXThAnnealRight[k];
1275 pYThAnnealSelf[i] = pYThAnnealRight[k];
1276 pResidXmodelSelf[i] = pResidXmodelRight[k];
1277 pResidYmodelSelf[i] = pResidYmodelRight[k];
1279 pXpolySelf[i] = pXpolyRight[k];
1280 pYpolySelf[i] = pYpolyRight[k];
1281 pResidXpolySelf[i] = pResidXpolyRight[k];
1282 pResidYpolySelf[i] = pResidYpolyRight[k];
1289 check(cpl_table_save(stab,rhead,NULL,sname,CPL_IO_DEFAULT));
1299 return cpl_error_get_code();
double * xsh_resid_tab_get_lambda_data(xsh_resid_tab *resid)
Get the size of the residual tab.
double * xsh_resid_tab_get_ygauss_data(xsh_resid_tab *resid)
Get the ygauss array of the residual tab.
void xsh_resid_tab_free(xsh_resid_tab **resid)
Free memory associated to a resid_tab.
cpl_frame * xsh_resid_tab_erase_flagged(cpl_frame *resid, const char *name)
xsh_resid_tab * xsh_resid_tab_load(cpl_frame *resid_tab_frame)
Load a residual tab from a frame.
xsh_resid_tab * xsh_resid_tab_create(int size, double *lambda, double *order, double *slit, double *sn, int *slit_index, double *thpre_x, double *thpre_y, double *corr_x, double *corr_y, double *gaussian_norm, double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x, double *gaussian_sigma_y, double *gaussian_fwhm_x, double *gaussian_fwhm_y, int *flag, xsh_wavesol *wavesol, int wavesol_type)
Create a residual tab structure.
double * xsh_resid_tab_get_thpre_y_data(xsh_resid_tab *resid)
Get the thpre_y array of the residual tab.
double * xsh_resid_tab_get_slitpos_data(xsh_resid_tab *resid)
Get the slit_pos array of the residual tab.
double * xsh_resid_tab_get_thpre_x_data(xsh_resid_tab *resid)
Get the slit_index array of the residual tab.
cpl_error_code xsh_frame_table_resid_merge(cpl_frame *self, cpl_frame *right, const int solution_type)
xsh_resid_tab * xsh_resid_tab_create_not_flagged(int size, double *lambda, double *order, double *slit, double *sn, int *slit_index, double *thpre_x, double *thpre_y, double *corr_x, double *corr_y, double *gaussian_norm, double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x, double *gaussian_sigma_y, double *gaussian_fwhm_x, double *gaussian_fwhm_y, int *flag, xsh_wavesol *wavesol, int wavesol_type)
void xsh_resid_tab_log(xsh_resid_tab *resid, const char *filename)
Log the residual tab in a ASCII file
cpl_frame * xsh_resid_tab_save(xsh_resid_tab *resid, const char *filename, xsh_instrument *instr, const char *tag)
Save a residual tab to a frame.
double * xsh_resid_tab_get_order_data(xsh_resid_tab *resid)
Get the Orders array of the residual tab.
double * xsh_resid_tab_get_xgauss_data(xsh_resid_tab *resid)
Get the xgauss array of the residual tab.
double xsh_wavesol_eval_poly(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in Y
double xsh_wavesol_eval_polx(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in X
enum wavesol_type xsh_wavesol_get_type(xsh_wavesol *wsol)
get the type of the wave table
#define XSH_REGDEBUG(...)
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define xsh_error_msg(...)
#define XSH_ASSURE_NOT_NULL(pointer)
#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_pfits_set_wavesoltype(cpl_propertylist *plist, const char *value)
Write the WAVESOL TYPE value.
const char * xsh_pfits_get_wavesoltype(const cpl_propertylist *plist)
Find out the WAVESOL TYPE.
void xsh_pfits_set_qc_nlinefound_fib4(cpl_propertylist *plist, double value)
void xsh_pfits_set_qc_nlinefound_clean_fib4(cpl_propertylist *plist, double value)
void xsh_pfits_set_qc(cpl_propertylist *plist, void *value, const char *kw, xsh_instrument *instrument)
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.
cpl_error_code xsh_get_table_value(const cpl_table *table, const char *colname, cpl_type coltype, int i, void *result)
Read a table value from a fits table.
double median_diff_poly_fit_x
double mean_diff_poly_fit_y
cpl_propertylist * header
double stdev_diff_poly_fit_y
double mean_diff_poly_fit_x
double stdev_diff_poly_fit_x
double median_diff_poly_fit_y
#define XSH_RESID_TAB_TABLE_UNIT_RESIDYPOLY
#define XSH_RESID_TAB_TABLE_UNIT_YPOLY
#define XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION
#define XSH_RESID_TAB_TABLE_COLNAME_FWHMYGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL
#define XSH_RESID_TAB_TABLE_COLNAME_ORDER
#define XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_YPOLY
#define XSH_RESID_TAB_TABLE_UNIT_WAVELENGTH
#define XSH_RESID_TAB_TABLE_COLNAME_NORMGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_YTHPRE
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY
#define XSH_RESID_TAB_TABLE_COLNAME_YTHPRE
#define XSH_RESID_TAB_TABLE_COLNAME_SN
#define XSH_RESID_TAB_TABLE_UNIT_SN
#define XSH_RESID_TAB_TABLE_COLNAME_FWHMXGAUSS
#define XSH_RESID_TAB_TABLE_NB_COL
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY
#define XSH_RESID_TAB_TABLE_UNIT_ORDER
#define XSH_RESID_TAB_TABLE_UNIT_FLAG
#define XSH_RESID_TAB_TABLE_COLNAME_XGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH
#define XSH_RESID_TAB_TABLE_COLNAME_YGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_XGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_XPOLY
#define XSH_RESID_TAB_TABLE_UNIT_SLITINDEX
#define XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL
#define RESID_TAB_PROPERTY_GET(PROPERTY, TYPE, DEFAULT)
#define XSH_RESID_TAB_TABLE_COLNAME_XPOLY
#define XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX
#define XSH_RESID_TAB_TABLE_COLNAME_FLAG
#define XSH_RESID_TAB_TABLE_UNIT_SLITPOSITION
#define XSH_RESID_TAB_TABLE_UNIT_NORMGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_YGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL
#define XSH_RESID_TAB_TABLE_UNIT_XTHPRE
#define XSH_RESID_TAB_TABLE_UNIT_YTHANNEAL
#define XSH_RESID_TAB_TABLE_UNIT_XTHANNEAL
#define XSH_RESID_TAB_TABLE_UNIT_RESIDYMODEL
#define XSH_RESID_TAB_TABLE_UNIT_RESIDXMODEL
#define XSH_RESID_TAB_TABLE_COLNAME_XTHPRE
#define XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS
#define XSH_RESID_TAB_TABLE_UNIT_RESIDXPOLY
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
#define XSH_DETECT_ARCLINES_TYPE_POLY
#define XSH_DETECT_ARCLINES_TYPE_MODEL
#define XSH_WAVESOLTYPE_POLYNOMIAL
#define XSH_WAVESOLTYPE_MODEL
#define XSH_QC_FMTCHK_POLY_DIFFXMED
#define XSH_QC_FMTCHK_POLY_DIFFYMED
#define XSH_QC_FMTCHK_POLY_DIFFXAVG
#define XSH_QC_FMTCHK_POLY_DIFFYAVG
#define XSH_QC_FMTCHK_POLY_DIFFYSTD
#define XSH_QC_FMTCHK_POLY_DIFFXSTD
#define XSH_TABLE_NEW_COL(TABLE, NAME, UNIT, TYPE)
#define XSH_FREE(POINTER)
#define XSH_CALLOC(POINTER, TYPE, SIZE)
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)