29#define REGDEBUG_WAVECAL 0
74#define XSH_SPECRES_CLIP_KAPPA 3.
75#define XSH_SPECRES_CLIP_NITER 2
76#define XSH_SPECRES_CLIP_FRAC 0.5
102 float lambda,
int ordnum,
double xpix,
138 cpl_vector * pixpos = NULL ;
139 cpl_vector * pixval = NULL ;
144 if ( xpix <= 0 || xpix > pre->
nx || y <= 0 || y > pre->
ny )
148 y > 0 && y <= pre->
ny );
165 dy = ypix - follow_param->
range ;
166 nelem = (follow_param->
range*2) + 1 ;
168 check( pixpos = cpl_vector_new( nelem ) ) ;
169 check( pixval = cpl_vector_new( nelem ) ) ;
176 value = cpl_image_get( pre->
data, ix,
ny, &rej ) ;
177 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
182 cpl_vector_set( pixval, i, value ) ;
183 cpl_vector_set( pixpos, i, dy ) ;
188 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
189 xsh_msg_dbg_high(
"Failed to fit Y centroid for x %d y [%d, %d], wavelength %f",
195 FILE *debug_file = NULL;
200 sprintf( name,
"profil_%d_%f_%f.dat", ordnum, lambda, xpix);
202 debug_file = fopen( name,
"w");
203 fprintf( debug_file,
"# ypos yflux yfit\n");
204 for( idebug=0; idebug< nelem; idebug++){
208 x = cpl_vector_get( pixpos, idebug);
212 fprintf( debug_file,
"%f %f %f\n",
x, cpl_vector_get( pixval, idebug), gauss);
227static cpl_polynomial *
230 switch ( ifu_flag ) {
244static cpl_polynomial *
247 switch ( ifu_flag ) {
266find_tilt(
double yp0,
double xc,
float lambda,
int ordnum,
270 double * chisq,
double * minx,
double * maxx,
271 int * nt,
int * ng,
double * fwhm_center,
272 double * good_center,
int ifu_flag )
275 cpl_polynomial * lo_poly = NULL;
276 cpl_polynomial * up_poly = NULL;
279 double x0,
x, ycenter ;
281 cpl_vector *pos_vect =NULL, *val_vect = NULL;
283 cpl_polynomial * poly_tilt = NULL ;
288 cpl_vector *fwhm_median_vect = NULL;
289 double *median_data = NULL;
290 double fwhm_median = 0.0;
292 double tilt_kappa, tilt_frac, good_frac;
293 int ntot, no_centroid =0;
307 xsh_msg(
"Unknown Absolute Order %d", ordnum);
321 xmin += follow_param->
margin ;
322 xmax -= follow_param->
margin ;
327 xsh_msg_dbg_medium(
" Find_tilt - order %d, idx %d, xmin = %.2lf, xmax = %.2lf, yc = %.2lf",
328 ordnum, iorder, xmin, xmax, yp0 ) ;
330 if ( xmax <= xmin ) {
331 xsh_msg(
"******* Something Wrong in Edges!" ) ;
335 if ( xc <= xmin || xc >= xmax ) {
336 xsh_msg(
"lambda %f, order %d: Center (from wavesol) %lf not in ] %lf, %lf [",
337 lambda, ordnum, xc, xmin, xmax ) ;
343 csize = ceil(xmax) - floor(xmin);
353 for(
x = x0 ;
x >= xmin ;
x--) {
356 centers[ntot].
xpos =
x;
358 follow_param, 0, &fit_res);
359 if ( ok == 0 && fit_res.
peakpos > 0. ) {
361 centers[ntot].
fwhm = CPL_MATH_FWHM_SIG*fit_res.
sigma;
363 centers[ntot].
good = 0 ;
369 centers[ntot].
good = 1 ;
376 for(
x = x0+1 ;
x <= xmax ;
x++) {
379 centers[ntot].
xpos =
x;
381 follow_param, 0, &fit_res);
382 if ( ok == 0 && fit_res.
peakpos > 0. ) {
384 centers[ntot].
fwhm = CPL_MATH_FWHM_SIG*fit_res.
sigma ;
386 centers[ntot].
good = 0 ;
392 centers[ntot].
good = 1 ;
397 lambda, ordnum, ngood, ntot, no_centroid);
399 good_frac = (double)ngood/(
double) ntot;
401 if ( ngood >= 2 && good_frac >= tilt_frac){
405 check( pos_vect = cpl_vector_new( ngood));
406 check( val_vect = cpl_vector_new( ngood));
409 for( i = 0 ; i< ntot; i++ ) {
410 if ( centers[i].good == 0){
411 cpl_vector_set( pos_vect, j, centers[i].xpos);
412 cpl_vector_set( val_vect, j, centers[i].ypos);
418 tilt_frac, 1, &poly_tilt, chisq, &flags));
425 for( i = 0 ; i< ntot; i++ ) {
426 if ( centers[i].good == 0){
428 median_data[k] = centers[i].
fwhm;
438 check( fwhm_median_vect = cpl_vector_wrap( k, median_data));
440 check( fwhm_median = cpl_vector_get_median( fwhm_median_vect));
441 *fwhm_center = fwhm_median;
444 check( *good_center = cpl_polynomial_eval_1d( poly_tilt, x0, NULL));
445 check( *slope = cpl_polynomial_get_coeff( poly_tilt, °1));
448 *slope, fwhm_median, x0, *good_center);
456 FILE *fwhm_debug_file = NULL;
460 sprintf( name,
"fwhm_%d_%f.dat", ordnum, lambda);
462 if ( fwhm_debug_mode == NULL){
463 fwhm_debug_file = fopen( name,
"w");
464 fwhm_debug_mode =
"a+";
465 fprintf( fwhm_debug_file,
466 "# wavelength order xcen xcen-x0 ygauss ytilt fwhm area good\n");
469 fwhm_debug_file = fopen( name, fwhm_debug_mode);
471 for( idebug=0; idebug< ntot; idebug++){
477 fit = cpl_polynomial_eval_1d( poly_tilt, xpos, NULL);
478 fprintf( fwhm_debug_file,
"%f %d %f %f %f %f %f %f %d\n",
481 centers[idebug].ypos, fit, centers[idebug].fwhm,
482 centers[idebug].area, centers[idebug].good);
484 fclose( fwhm_debug_file);
490 xsh_msg(
"Not enough points to do the fit: Good fraction points (%f < %f)",
491 good_frac, tilt_frac);
511 return (ya*(xb-
x))/(xb_xa) + (yb*(
x-xa))/(xb_xa) ;
520 float lambda, lm, lp;
528 ym = (int) floor(
y);
531 lm =
data[(ym-1)*
nx+xpos];
532 lp =
data[(yp-1)*
nx+xpos];
537 ym, lm, yp, lp,
y, lambda ) ;
559 cpl_frame *disptab_frame,
566 double *specres_stdev)
568 cpl_array *a_specres = NULL ;
569 int i=0, j=0, status=0 ;
571 cpl_vector* positions = NULL;
572 const char *wavemap_name = NULL;
573 cpl_image *wavemap_img = NULL;
574 float *wavemap_data = NULL ;
576 int tilt_list_size =0;
581 if (disptab_frame != NULL){
584 check( positions = cpl_vector_new(2));
589 check( wavemap_name = cpl_frame_get_filename( wavemap_frame));
590 check( wavemap_img = cpl_image_load( wavemap_name, CPL_TYPE_FLOAT, 0, 0));
591 check( wavemap_data = cpl_image_get_data_float( wavemap_img));
592 nx = cpl_image_get_size_x( wavemap_img);
593 ny = cpl_image_get_size_y( wavemap_img);
597 tilt_list_size = tilt_list->
size;
598 check( a_specres = cpl_array_new( tilt_list_size, CPL_TYPE_DOUBLE));
601 for( i=0 ; i< tilt_list_size; i++) {
602 double xc=0, yc=0, yc0=0, yc1=0;
604 float lambda0=0, lambda1=0, lambdac=0;
620 yc0 = yc - (pix_width/2.);
621 yc1 = yc + (pix_width/2.);
623 if ( displist != NULL){
624 int absorder = tilt_list->
list[i]->
order;
630 cpl_vector_set( positions, 0, xc);
631 cpl_vector_set( positions, 1, yc0);
636 cpl_vector_set( positions, 1, yc1);
641 if( (yc0 >= 1) && (yc1 <=
ny-1) ) {
648 lambda0, lambda1, lambdac, pix_width);
650 if ( lambda0 != 0. && lambda1 != 0.) {
653 tilt_list->
list[i]->
specres = lambdac/fabs(lambda1 - lambda0)*
659 check( *specres_med = cpl_array_get_median( a_specres));
660 check( *specres_stdev = cpl_array_get_stdev( a_specres));
662 xsh_msg(
"---Clipping on spectral resolution");
664 frac, specres_med, specres_stdev));
666 for( j=0; j < tilt_list_size; j++){
688 cpl_propertylist *shift_header,
697 double specres_stdev,
700 cpl_array * yarr = NULL, * warr = NULL, * iarr = NULL ;
701 double avg, med, std, wavg, wstd, iavg;
702 int n=tilt_list->
size;
705 check( yarr = cpl_array_wrap_double( ypos,
n ) ) ;
706 check( warr = cpl_array_wrap_double(
width,
n ) ) ;
707 check( iarr = cpl_array_wrap_double( intens,
n ) ) ;
711 cpl_array_set_invalid(yarr,i);
712 cpl_array_set_invalid(warr,i);
713 cpl_array_set_invalid(iarr,i);
717 check( avg = cpl_array_get_mean( yarr ) ) ;
718 check( med = cpl_array_get_median( yarr ) ) ;
719 check( std = cpl_array_get_stdev( yarr ) ) ;
721 check( wstd = cpl_array_get_stdev( warr ) ) ;
722 check( wavg = cpl_array_get_mean( warr ) ) ;
724 check( iavg = cpl_array_get_mean( iarr ) ) ;
726 xsh_msg(
"diffy avg=%16.14g med=%16.14g std=%16.14g",avg,med,std);
727 xsh_msg(
"FWHM avg=%16.14g std=%16.14g",wavg,wstd);
728 xsh_msg(
"nlineint iavg=%16.14g",iavg);
756 if(isnan(specres_stdev)) {
758 specres_stdev = -999;
786 cpl_frame *arclines_frame,
788 cpl_frame *config_model_frame,
789 cpl_frame *pre_frame,
790 cpl_frame *spectralformat_frame,
804 int arclist_size =0, global_size=0;
805 cpl_vector** spectral_tab = NULL;
811 int i, j, index_loc = 0;
814 check( spectralformat_list =
818 if ( wavesol_frame != NULL) {
821 else if ( config_model_frame != NULL ) {
830 "Undefined solution type (POLY or MODEL).");
833 XSH_CALLOC( spectral_tab, cpl_vector*, arclist_size);
835 for( i=0; i< arclist_size; i++){
836 cpl_vector* res = NULL;
845 check( res_size = cpl_vector_get_size( res));
851 global_size += res_size;
852 spectral_tab[i] = res;
854 xsh_msg (
" Arc List x Order size = %d", global_size);
863 for( i=0; i< arclist_size; i++){
864 double comp_x=0.0, comp_y=0.0, comp_xmin=0.0, comp_ymin=0.0;
865 double comp_xmax=0.0, comp_ymax=0.0;
866 cpl_vector *spectral_res = NULL;
867 int spectral_res_size=0;
871 check( spectral_res = spectral_tab[i]);
873 if (spectral_res != NULL){
874 check( spectral_res_size = cpl_vector_get_size( spectral_res));
875 for( j=0; j< spectral_res_size; j++){
879 check( absorder = (
int) cpl_vector_get( spectral_res, j));
893 lambdaARC, absorder, slit, &comp_x, &comp_y));
895 lambdaARC, absorder, slit_min, &comp_xmin, &comp_ymin));
897 lambdaARC, absorder, slit_max, &comp_xmax, &comp_ymax));
902 (*lambda)[index_loc] = lambdaARC;
903 (*n)[index_loc] = absorder;
904 (*x)[index_loc] = comp_x;
905 (*y)[index_loc] = comp_y;
906 if ( comp_xmin < comp_xmax){
907 (*xmin)[index_loc] = comp_xmin;
908 (*xmax)[index_loc] = comp_xmax;
909 xsh_msg_dbg_medium(
"The relation f(s)->X is increasing, X and s axes have same direction.");
912 (*xmin)[index_loc] = comp_xmax;
913 (*xmax)[index_loc] = comp_xmin;
914 xsh_msg_dbg_medium(
"The relation f(s)->X is decreasing, X and s axes have opposite directions");
917 "lambda %f order %d slit %f smin %f smax %f x %f y %f xmin %f xmax %f",
918 lambdaARC, absorder, slit, slit_min, slit_max, comp_x, comp_y, comp_xmin, comp_xmax);
928 xsh_msg(
"Clean size %d (%d bad positions)", index_loc, bad_positions);
936 if ( spectral_tab != NULL){
937 for(i=0; i< arclist_size; i++){
942 if ( cpl_error_get_code() != CPL_ERROR_NONE){
986 cpl_frame *arclines_frame,
987 cpl_frame *wavesol_frame,
988 cpl_frame *order_frame,
989 cpl_frame *spectralformat_frame,
990 cpl_frame * config_model_frame,
991 cpl_frame *wavemap_frame,
992 cpl_frame *disptab_frame,
1000 cpl_frame **tilt_frame,
1001 cpl_frame **shift_frame,
const int clean_tmp)
1005 double * vlambdadata = NULL, *vorderdata = NULL;
1006 double * vxthedata = NULL, * vythedata = NULL;
1007 double *vxmindata = NULL, * vxmaxdata = NULL;
1009 const char* arclines_name = NULL;
1010 int s_n_low = 0, no_centroid = 0, bad_position = 0 , no_tilt=0;
1015 cpl_propertylist *tilt_header = NULL ;
1016 double *ydelta = NULL, *
width = NULL, *intensity = NULL;
1021 const char * shift_tag = NULL ;
1024 int specres_niter=0;
1025 double specres_kappa = 0, specres_frac = 1;
1026 double specres_med = 0., specres_stdev = 0 ;
1027 cpl_vector *svect = NULL;
1028 int cat_lines, match_lines, found_lines;
1053 config_model_frame, pre_frame, spectralformat_frame,
1054 &vlambdadata, &vorderdata,
1055 &vxthedata, &vythedata, &vxmindata, &vxmaxdata,
1056 &sol_size, slit, slit_min, slit_max,
instrument));
1065 check( arclines_name = cpl_frame_get_filename( arclines_frame));
1066 check( tilt_header = cpl_propertylist_load( arclines_name, 0));
1083 for ( i = 0 ; i < sol_size ; i++ ) {
1084 double lambda,
order;
1087 int nt = 0, ng = 0 ;
1090 lambda = vlambdadata[i];
1091 order = vorderdata[i];
1092 xpix = vxthedata[i];
1093 ypix = vythedata[i];
1095 xsh_msg_dbg_low(
"LAMBDA %f, ORDER %f, SLIT %f, X %lf, Y %lf", lambda,
1096 order, slit, xpix, ypix );
1099 follow_param, 1, &fit_res));
1109 if( (xpix<=pre->
nx) && (xpix>0) && (ypix<=pre->
ny) && (ypix>0)) {
1110 double flux_val, err_val;
1112 check( flux_val = cpl_image_get( pre->
data, xpix, ypix, &rej ));
1113 check( err_val = cpl_image_get( pre->
data, xpix, ypix, &rej ));
1114 check(s_n = cpl_image_get( pre->
data, xpix, ypix, &rej )/
1115 cpl_image_get( pre->
errs, xpix, ypix, &rej));
1117 if ( s_n < follow_param->s_n_min ) {
1119 flux_val, err_val, follow_param->
s_n_min);
1123 double slope = 0.0, chisq = 0.0, xmin = 0.0, xmax = 0.0;
1124 double fwhm_center = 0.0;
1125 double good_center = 0;
1133 xmin = vxmindata[i];
1134 xmax = vxmaxdata[i];
1136 follow_param, pre, orders,
1138 &xmin, &xmax, &nt, &ng,
1139 &fwhm_center, &good_center,
1140 ifu_flag )) == 0 ) {
1148 ydelta[goodlines] = good_center-ypix;
1149 width[goodlines] = CPL_MATH_FWHM_SIG*fit_res.
sigma;
1150 intensity[goodlines] = cpl_image_get( pre->
data, ix, iy, &rej);
1153 tilt_line->
slit = slit;
1154 tilt_line->
tilt = slope ;
1155 tilt_line->
chisq = chisq;
1156 tilt_line->
xmin = xmin ;
1157 tilt_line->
xmax = xmax ;
1158 tilt_line->
ntot = nt ;
1159 tilt_line->
ngood = ng ;
1160 tilt_line->
deltay = fwhm_center;
1161 tilt_line->
name = NULL ;
1166 tilt_line->
tilt_y = good_center;
1167 tilt_line->
shift_y = good_center-ypix;
1168 tilt_line->
specres = fwhm_center;
1170 tilt_line->
intensity = cpl_image_get( pre->
data, ix, iy, &rej);
1189 xsh_msg(
"No centroid %d Bad Position: %d, S/N too low: %d No tilt %d",
1190 no_centroid, bad_position, s_n_low, no_tilt);
1191 if ( goodlines == 0 ){
1192 xsh_msg(
"***** NO FITTED LINE !!!!" );
1195 xsh_msg(
" Good Fitted lines : %d/%d", goodlines, sol_size);
1198 if ( wavemap_frame != NULL || disptab_frame != NULL) {
1200 tilt_list, specres_niter,
1201 specres_kappa, specres_frac,
1202 &specres_med, &specres_stdev);
1203 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
1204 xsh_msg(
"ERROR while computing Spectral Resolution" ) ;
1207 specres_stdev = 0. ;
1211 xsh_msg_error(
"NO Wavemap (WAVE_MAP) or dispersion table (DISP_TAB), can't compute Spectral Resolution");
1214 cat_lines = sol_size;
1215 found_lines = goodlines;
1216 match_lines = tilt_list->
size;
1220 specres_med, specres_stdev,pre->
exptime);
1224 sprintf( tag,
"FOLLOW_LINETILT_%s_%s", tag_id,
1226 sprintf(fname,
"%s.fits",tag);
1229 specres_kappa, specres_niter,pre->
exptime));
1231 sprintf( tag,
"TILT_TAB_%s_%s", tag_id,
1233 check( cpl_frame_set_tag( *tilt_frame, tag));
1236 xsh_msg(
"Tilt Frame saved" ) ;
1239 xsh_msg(
"Saving shift table SLIT, %d lines", tilt_list->
size);
1241 check( svect = cpl_vector_wrap( tilt_list->
size, ydelta));
1244 check( shift_tab->
shift_y = cpl_vector_get_median( svect));
1249 sprintf( tag,
"SHIFT_TAB_%s_%s", tag_id,
1283 cpl_frame *arclines_frame,
1284 cpl_frame *wavesol_frame,
1285 cpl_frame *order_frame,
1286 cpl_frame *spectralformat_frame,
1287 cpl_frame * config_model_frame,
1288 cpl_frame *wavemap_frame,
1289 cpl_frame *slitmap_frame,
1290 cpl_frame *disptab_frame,
1293 cpl_frame **tilt_frame,
1294 cpl_frame **shift_frame)
1296 double smin=-6.0, smax=6.0;
1304 order_frame, spectralformat_frame,
1305 config_model_frame, wavemap_frame, disptab_frame,
1306 follow_param, 0.0, smin, smax,
"SLIT",
1308 tilt_frame, shift_frame,0));
1342 cpl_frame *arclines_frame,
1343 cpl_frame *wavesol_frame,
1344 cpl_frame *order_frame,
1345 cpl_frame *spectralformat_frame,
1346 cpl_frame *config_model_frame,
1347 cpl_frame *wavemap_frame,
1348 cpl_frame *slitmap_frame,
1349 cpl_frame *disptab_frame,
1352 cpl_frameset *tilt_set,
1353 cpl_frame **shift_frame)
1358 double slit_min=-6, slitcen_lo=-2.0, slitcen_up=2.0, slit_max=6;
1360 cpl_frameset *shift_ifu_set = NULL;
1361 cpl_frame *shift_tab_frame = NULL;
1365 const char* shift_tag = NULL;
1367 double shift_center=0, shift_lower=0, shift_upper=0;
1372 shift_ifu_set = cpl_frameset_new();
1376 slit_pos[0] = slit_min;
1377 slit_pos[1] = slitcen_lo;
1378 slit_pos[2] = slitcen_up;
1379 slit_pos[3] = slit_max;
1384 cpl_frame *tmp_tilt_frame = NULL;
1385 cpl_frame *tmp_shift_frame = NULL;
1386 double slitlet_min, slitlet_max, slitlet_center;
1388 slitlet_min = slit_pos[spos];
1389 slitlet_max = slit_pos[spos+1];
1390 slitlet_center = (slitlet_min+slitlet_max)/2.0;
1392 xsh_msg(
"IFU Slitlet %s: center = %f arcsec; edges = [%f, %f] arcsec",
1393 SlitletName[ifu], slitlet_center, slitlet_min, slitlet_max);
1398 order_frame, spectralformat_frame, config_model_frame, wavemap_frame,
1400 follow_param, slitlet_center, slitlet_min, slitlet_max, tag_id, ifu,
instrument,
1401 &tmp_tilt_frame, &tmp_shift_frame,1));
1404 check( cpl_frameset_insert( tilt_set, tmp_tilt_frame));
1405 check( cpl_frameset_insert( shift_ifu_set, tmp_shift_frame));
1408 check( shift_tab_frame = cpl_frameset_get_frame( shift_ifu_set, 0));
1410 cpl_frame_get_filename( shift_tab_frame));
1413 check( shift_tab_frame = cpl_frameset_get_frame( shift_ifu_set, 1));
1415 cpl_frame_get_filename( shift_tab_frame));
1418 check( shift_tab_frame = cpl_frameset_get_frame( shift_ifu_set, 2));
1420 cpl_frame_get_filename( shift_tab_frame));
1429 shift_lower, shift_center, shift_upper);
static xsh_instrument * instrument
void xsh_set_image_cpl_bpmap(cpl_image *image, cpl_image *bpmap, const int decode_bp)
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
void xsh_arclist_reject(xsh_arclist *list, int idx)
reject a line from the list
xsh_arclist * xsh_arclist_load(cpl_frame *frame)
load an arcline list frame in arclist structure
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.
double xsh_dispersol_list_eval(xsh_dispersol_list *list, cpl_polynomial *poly, cpl_vector *pos)
Evaluate the polynomial according the binning.
void xsh_linetilt_list_free(xsh_linetilt_list **list)
free memory associated to a arclist
xsh_linetilt * xsh_linetilt_new(void)
void xsh_linetilt_list_add(xsh_linetilt_list *list, xsh_linetilt *line, int idx)
xsh_linetilt_list * xsh_linetilt_list_new(int size, cpl_propertylist *header)
cpl_frame * xsh_linetilt_list_save(xsh_linetilt_list *list, xsh_instrument *instr, const char *filename, const char *tag, const double kappa, const int niter, float exptime)
save a (ks clip clean) linetilt list to a frame
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
int xsh_order_list_get_starty(xsh_order_list *list, int i)
get position on Y axis of first pixel detected on order
int xsh_order_list_get_endy(xsh_order_list *list, int i)
get position on Y axis of last pixel detected on order
int xsh_order_list_get_order(xsh_order_list *list, int absorder)
void xsh_order_list_free(xsh_order_list **list)
free memory associated to an order_list
double xsh_order_list_eval(xsh_order_list *list, cpl_polynomial *poly, double y)
Evaluate an order list poly.
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.
cpl_frame * xsh_shift_tab_save(xsh_shift_tab *tab, const char *tag, const int clean_tmp)
xsh_shift_tab * xsh_shift_tab_create(xsh_instrument *instrument)
void xsh_shift_tab_free(xsh_shift_tab **tab)
Free memory associated to a the_arcline.
xsh_shift_tab * xsh_shift_tab_load(cpl_frame *frame, xsh_instrument *instr)
Load a shift table.
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_ILLEGAL(cond)
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
#define XSH_ASSURE_NOT_NULL(pointer)
static int detect_centroid(xsh_pre *pre, float lambda, int ordnum, double xpix, double ypix, xsh_follow_arclines_param *follow_param, int is_center, XSH_GAUSSIAN_FIT *fit_res)
static cpl_polynomial * get_slit_ifu_lo_poly(xsh_order *porder, int ifu_flag)
static cpl_polynomial * get_slit_ifu_up_poly(xsh_order *porder, int ifu_flag)
static void compute_specres(cpl_frame *wavemap_frame, cpl_frame *disptab_frame, xsh_instrument *instr, xsh_linetilt_list *tilt_list, int niter, double kappa, double frac, double *specres_med, double *specres_stdev)
static float get_lambda(float *data, float x, float y, int nx, int ny)
static float linear_interpol(float xa, float ya, float xb, float yb, float x)
static void xsh_follow_arclines(cpl_frame *pre_frame, cpl_frame *arclines_frame, cpl_frame *wavesol_frame, cpl_frame *order_frame, cpl_frame *spectralformat_frame, cpl_frame *config_model_frame, cpl_frame *wavemap_frame, cpl_frame *disptab_frame, xsh_follow_arclines_param *follow_param, double slit, double slit_min, double slit_max, const char *tag_id, int ifu_flag, xsh_instrument *instrument, cpl_frame **tilt_frame, cpl_frame **shift_frame, const int clean_tmp)
Detect and follow arc lines. Computes center, width and tilt parameters. The position of the center o...
void xsh_follow_arclines_slit(cpl_frame *pre_frame, cpl_frame *arclines_frame, cpl_frame *wavesol_frame, cpl_frame *order_frame, cpl_frame *spectralformat_frame, cpl_frame *config_model_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *disptab_frame, xsh_follow_arclines_param *follow_param, xsh_instrument *instrument, cpl_frame **tilt_frame, cpl_frame **shift_frame)
static int find_tilt(double yp0, double xc, float lambda, int ordnum, xsh_follow_arclines_param *follow_param, xsh_pre *pre, xsh_order_list *orders, xsh_instrument *instrument, double *slope, double *chisq, double *minx, double *maxx, int *nt, int *ng, double *fwhm_center, double *good_center, int ifu_flag)
static void set_qc_parameters(cpl_propertylist *tilt_header, cpl_propertylist *shift_header, double *ypos, double *width, double *intens, xsh_linetilt_list *tilt_list, xsh_instrument *instrument, int nlinecat, int nb_lines, double specres_med, double specres_stdev, float exptime)
static void clean_arclist_data(cpl_frame *wavesol_frame, cpl_frame *arclines_frame, xsh_order_list *orders, cpl_frame *config_model_frame, cpl_frame *pre_frame, cpl_frame *spectralformat_frame, double **lambda, double **n, double **x, double **y, double **xmin, double **xmax, int *size, double slit, double slit_min, double slit_max, xsh_instrument *instrument)
void xsh_follow_arclines_ifu(cpl_frame *pre_frame, cpl_frame *arclines_frame, cpl_frame *wavesol_frame, cpl_frame *order_frame, cpl_frame *spectralformat_frame, cpl_frame *config_model_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *disptab_frame, xsh_follow_arclines_param *follow_param, xsh_instrument *instrument, cpl_frameset *tilt_set, cpl_frame **shift_frame)
Detect and follow arc lines. Computes center, width and tilt parameters. The position of the center o...
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
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
#define xsh_msg_dbg_medium(...)
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
#define xsh_msg_dbg_high(...)
void xsh_pfits_set_qc_slit_width(cpl_propertylist *source_list, cpl_propertylist *set_list, xsh_instrument *instrument)
void xsh_pfits_set_qc(cpl_propertylist *plist, void *value, const char *kw, xsh_instrument *instrument)
void xsh_get_slit_edges(cpl_frame *slitmap_frame, double *sdown, double *sup, double *sldown, double *slup, xsh_instrument *instrument)
Trace slit edges in a master flat.
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
void xsh_vector_fit_gaussian(cpl_vector *x, cpl_vector *y, XSH_GAUSSIAN_FIT *result)
set debug level
void xsh_free_polynomial(cpl_polynomial **p)
Deallocate a polynomial and set the pointer to NULL.
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
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
void xsh_free_array(cpl_array **m)
Deallocate an array and set the pointer to NULL.
void xsh_array_clip_poly1d(cpl_vector *pos_vect, cpl_vector *val_vect, double kappa, int niter, double frac_min, int deg, cpl_polynomial **polyp, double *chisq, int **flagsp)
clip outliers from a 1D poly fit
long xsh_round_double(double x)
Computes round(x)
void xsh_array_clip_median(cpl_array *array, double kappa, int niter, double frac_min, double *median, double *stdev)
median clip of an array
void xsh_unwrap_array(cpl_array **a)
Unwrap an array and set the pointer to NULL.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_polynomial * lambda_poly
xsh_clipping_param * tilt_clipping
xsh_clipping_param * specres_clipping
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
cpl_polynomial * slicuppoly
cpl_polynomial * sliclopoly
cpl_propertylist * data_header
cpl_propertylist * header
#define XSH_SHIFT_TAB_SLIT
#define XSH_SHIFT_TAB_IFU
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
static const char * SlitletName[]
cpl_error_code xsh_model_temperature_update_frame(cpl_frame **model_config_frame, cpl_frame *ref_frame, xsh_instrument *instrument, int *found_temp)
#define QC_WAVECAL_NLININT
#define QC_WAVECAL_DIFFYSTD
#define QC_WAVECAL_CATLINE
#define QC_WAVECAL_FOUNDLINE
#define QC_WAVECAL_DIFFYMED
#define QC_WAVECAL_MATCHLINE
#define QC_WAVECAL_FWHMAVG
#define QC_WAVECAL_FWHMRMS
#define QC_WAVECAL_DIFFYAVG
#define XSH_FREE(POINTER)
#define XSH_MALLOC(POINTER, TYPE, SIZE)
#define XSH_CALLOC(POINTER, TYPE, SIZE)