62#define combine_nod_old 0
80 for( i=0; i<
size; i++){
82 float* nod_slit = NULL;
464 const int nlambda,
const int nslit,
const int no,
const double smin,
468 cpl_imagelist* scale_factors = cpl_imagelist_new();
474 int nb_frames=cpl_imagelist_get_size(scaled);
476 int slit_min = (int) smin;
477 int slit_max = (int) smax;
480 const cpl_mask* mask;
481 for (
int nf = 0; nf < nb_frames; nf++) {
482 scale=cpl_image_new(1,nslit,CPL_TYPE_DOUBLE);
483 cpl_image_add_scalar(scale,1.);
484 pscale=cpl_image_get_data_double(scale);
487 ima_tmp=cpl_imagelist_get(scaled,nf);
488 mask=cpl_image_get_bpm_const(ima_tmp);
489 nbad=cpl_mask_count_window(mask,1,slit_min,nlambda,slit_max);
491 if( nbad < nlambda * (slit_max-slit_min) ) {
493 med=cpl_image_get_median_window(ima_tmp,1,slit_min,nlambda,slit_max);
501 for (
int ns = slit_min; ns <= slit_max; ns++) {
505 cpl_imagelist_set(scale_factors,scale,nf);
509 sprintf(fname,
"scale_factors_obj_%d.fits",no);
510 cpl_imagelist_save(scale_factors,fname,CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
512 return scale_factors;
518 const int nlambda,
const int nslit,
const int no)
521 cpl_imagelist* scale_factors = cpl_imagelist_new();
527 int nb_frames=cpl_imagelist_get_size(scaled);
530 const cpl_mask* mask;
531 for (
int nf = 0; nf < nb_frames; nf++) {
532 scale=cpl_image_new(1,nslit,CPL_TYPE_DOUBLE);
533 cpl_image_add_scalar(scale,1.);
534 pscale=cpl_image_get_data_double(scale);
535 for (
int ns = 0; ns < nslit; ns++) {
537 ima_tmp=cpl_imagelist_get(scaled,nf);
538 mask=cpl_image_get_bpm_const(ima_tmp);
539 nbad=cpl_mask_count_window(mask,1,ns+1,nlambda,ns+1);
543 med=cpl_image_get_median_window(ima_tmp,1,ns+1,nlambda,ns+1);
553 cpl_imagelist_set(scale_factors,scale,nf);
557 sprintf(fname,
"scale_factors_slices_%d.fits",no);
558 cpl_imagelist_save(scale_factors,fname,CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
561 return scale_factors;
568 const int nlambda,
const int nslit,
const int no)
571 cpl_imagelist* scale_factors = cpl_imagelist_new();
577 cpl_binary* pbpm=NULL;
579 int nb_frames=cpl_imagelist_get_size(scaled);
582 const cpl_mask* mask;
590 for (
int nf = 0; nf < nb_frames; nf++) {
591 ima_tmp=cpl_imagelist_get(scaled,nf);
592 mask=cpl_image_get_bpm_const(ima_tmp);
596 scale=cpl_image_new(nlambda,nslit,CPL_TYPE_DOUBLE);
597 cpl_image_add_scalar(scale,1.);
598 pscale=cpl_image_get_data_double(scale);
599 bpm=cpl_image_get_bpm(scale);
600 pbpm=cpl_mask_get_data(bpm);
602 for (
int ns = 0; ns < nslit; ns++) {
604 for (
int nl = hbox_sz; nl < nlambda-hbox_sz; nl++) {
614 check(nbad=cpl_mask_count_window(mask,lmin,ns+1,lmax,ns+1));
618 med=cpl_image_get_median_window(ima_tmp,lmin,ns+1,lmax,ns+1);
635 pscale[ns*nlambda+nl]=med;
637 pbpm[ns*nlambda+nl]=CPL_BINARY_1;
652 for (
int nl = 0; nl < hbox_sz; nl++) {
655 lmax=(lmax < nlambda) ? lmax : nlambda-1;
657 lmin=(lmin < lmax) ? lmin : lmax-1;
664 nbad=cpl_mask_count_window(mask,lmin,ns+1,lmax,ns+1);
668 med=cpl_image_get_median_window(ima_tmp,lmin,ns+1,lmax,ns+1);
679 pscale[ns*nlambda+nl]=med;
681 pbpm[ns*nlambda+nl]=CPL_BINARY_1;
686 for (
int nl = nlambda-1; nl > nlambda-hbox_sz-1; nl--) {
689 lmin=(lmin > 0) ? lmin : 1;
690 lmax=(lmax > lmin) ? lmax : lmin+1;
692 check(nbad=cpl_mask_count_window(mask,lmin,ns+1,lmax,ns+1));
696 med=cpl_image_get_median_window(ima_tmp,lmin,ns+1,lmax,ns+1);
706 pscale[ns*nlambda+nl]=med;
708 pbpm[ns*nlambda+nl]=CPL_BINARY_1;
714 cpl_imagelist_set(scale_factors,scale,nf);
719 sprintf(fname,
"scale_factors_pix_pix_%d.fits",no);
724 return scale_factors;
746 int *from_qual1 = NULL;
752 const int size=nlambda*nslit;
753 cpl_table* xy_pos=cpl_table_new(
size);
754 cpl_table_new_column(xy_pos,
"x",CPL_TYPE_INT);
755 cpl_table_new_column(xy_pos,
"y",CPL_TYPE_INT);
756 cpl_table_new_column(xy_pos,
"ngood",CPL_TYPE_INT);
759 for(
int i=0; i < nframes;i++) {
760 sprintf(cname,
"f%d",i);
761 cpl_table_new_column(xy_pos,cname,CPL_TYPE_INT);
763 int* px=cpl_table_get_data_int(xy_pos,
"x");
764 int* py=cpl_table_get_data_int(xy_pos,
"y");
765 int* pg=cpl_table_get_data_int(xy_pos,
"ngood");
769 for (ns = 0; ns < nslit; ns++) {
770 for (nl = 0; nl < nlambda; nl++) {
771 int dest_idx = nl + ns * nlambda;
772 for(nf=0;nf<nframes;nf++) {
773 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
776 if ( (dest_qual1[dest_idx] & code) > 0) {
777 xsh_msg(
"found bad pixel at [%d,%d]",nl,ns);
781 sprintf(cname,
"f%d",nf);
782 int* pq=cpl_table_get_data_int(xy_pos,cname);
783 from_idx = nl + (ns - slit_index[nf]) * nlambda;
785 if ( (from_qual1[from_idx] & code) > 0) {
796 cpl_table_set_size(xy_pos,
m);
798 sprintf(fname,
"bad_pix_ord_%d.fits",no);
799 cpl_table_save(xy_pos,NULL,NULL,fname,CPL_IO_DEFAULT);
805 int *slit_index,
int nb_frames,
int no,
806 int method,
const int decode_bp,
int scale_method)
809 cpl_image* scale=NULL;
811 int nslit, from_slit, nlambda;
817 float *dest_data1 = NULL;
818 float *dest_errs1 = NULL;
820 int *dest_qual1 = NULL;
831 cpl_imagelist* scaled = cpl_imagelist_new();
832 cpl_imagelist*
data = cpl_imagelist_new();
833 cpl_imagelist* qual = cpl_imagelist_new();
836 for (nf = 0; nf < nb_frames; nf++) {
837 ima_tmp=cpl_image_new(nlambda,nslit,CPL_TYPE_FLOAT);
838 cpl_imagelist_set(scaled,ima_tmp,nf);
839 ima_tmp2=cpl_image_new(nlambda,nslit,CPL_TYPE_FLOAT);
840 cpl_imagelist_set(
data,ima_tmp2,nf);
841 ima_tmp3=cpl_image_new(nlambda,nslit,CPL_TYPE_INT);
842 cpl_imagelist_set(qual,ima_tmp3,nf);
850 float *from_data1 = NULL;
851 float *from_errs1 = NULL;
852 int *from_qual1 = NULL;
855 for (ns = 0; ns < nslit; ns++) {
856 for (nl = 0; nl < nlambda; nl++) {
859 dest_idx = nl + ns * nlambda;
861 for (nf = 0; nf < nb_frames; nf++) {
863 ima_tmp=cpl_imagelist_get(scaled,nf);
864 pscaled=cpl_image_get_data_float(ima_tmp);
865 ima_tmp2=cpl_imagelist_get(
data,nf);
866 pdata=cpl_image_get_data_float(ima_tmp2);
867 ima_tmp3=cpl_imagelist_get(qual,nf);
868 pqual=cpl_image_get_data_int(ima_tmp3);
871 pmsk=cpl_mask_get_data(cpl_image_get_bpm(ima_tmp));
872 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
876 from_idx = nl + (ns - slit_index[nf]) * nlambda;
881 pscaled[dest_idx] = from_data1[from_idx] / dest_data1[dest_idx];
892 pdata[dest_idx] = from_data1[from_idx] ;
893 pqual[dest_idx] = from_qual1[from_idx] ;
894 if( ( ( dest_qual1[dest_idx] & decode_bp ) > 0 ) ||
895 ( ( from_qual1[from_idx] & decode_bp ) > 0 ) ||
896 isnan(pscaled[dest_idx]) ||
897 isinf(pscaled[dest_idx]) ||
898 fabs(from_errs1[from_idx]/from_data1[from_idx]) > 5 ||
899 fabs(dest_errs1[from_idx]/dest_data1[from_idx]) > 5
901 pmsk[dest_idx]=CPL_BINARY_1;
958 sprintf(fname,
"data_rectified_order_%d.fits",no);
960 sprintf(fname,
"qual_rectified_order_%d.fits",no);
963 sprintf(fname,
"scale_rectified_order_%d.fits",no);
970 cpl_imagelist* scale_factors;
971 double slit_ext_min, slit_ext_max,
slit_step;
972 if(scale_method > 0) {
981 switch(scale_method) {
985 scale, nlambda, nslit, no));
990 scale, nlambda, nslit, no, slit_ext_min, slit_ext_max));
995 scale, nlambda, nslit, no));
999 cpl_imagelist_delete(scaled);
1000 cpl_imagelist_delete(
data);
1001 cpl_imagelist_delete(qual);
1003 return scale_factors;
1138 int *slit_index,
int nb_frames,
int no,
1139 int method,
const int decode_bp)
1142 int nslit, from_slit, nlambda;
1158 double gauss_c=sy/2;
1165 xsh_msg(
"gauss_c=%g from_slit=%d nb_frames=%d",gauss_c,from_slit,nb_frames);
1170 float *from_data1 = NULL;
1172 for (nf = 0; nf < nb_frames; nf++) {
1173 xsh_msg(
"slit_index[%d]=%d",nf,slit_index[nf]);
1174 sprintf(fname,
"data_%d.fits",nf);
1178 for (ns = 0; ns < nslit; ns++) {
1179 for (nl = 0; nl < nlambda; nl++) {
1181 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
1185 from_idx = nl + (ns - slit_index[nf]) * nlambda;
1186 from_data1[from_idx] = 0;
1221 for (nf = 0; nf < nb_frames; nf++) {
1222 sprintf(fname,
"data_%d.fits",nf);
1226 ima= cpl_image_wrap_float(nlambda,nslit,from_data1);
1228 cpl_image_save(ima, fname,CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT);
1230 cpl_image_save(ima, fname,CPL_TYPE_FLOAT, NULL, CPL_IO_EXTEND);
1328 static cpl_error_code
1330 int *slit_index,
int nb_frames,
int no,
1331 int method,
const int decode_bp,
const int nf)
1333 int nslit, from_slit, nlambda;
1334 float *dest_data1 = NULL, *dest_errs1 = NULL;
1335 int *dest_qual1 = NULL;
1336 float *from_data1 = NULL, *from_errs1 = NULL;
1337 int *from_qual1 = NULL;
1345 "xsh_rec_list_add: nb frames: %d, order: %d", nb_frames, no);
1355 cpl_frame* frm=NULL;
1360 for (ns = 0; ns < nslit; ns++) {
1361 for (nl = 0; nl < nlambda; nl++) {
1363 dest_idx = nl + ns * nlambda;
1364 dest_data1[dest_idx] = 0;
1365 dest_errs1[dest_idx] = 0;
1366 dest_qual1[dest_idx] = 0;
1375 for (ns = 0; ns < nslit; ns++) {
1376 for (nl = 0; nl < nlambda; nl++) {
1380 dest_idx = nl + ns * nlambda;
1383 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
1386 from_idx = nl + (ns - slit_index[nf]) * nlambda;
1391 dest_data1[dest_idx] = from_data1[from_idx];
1392 dest_errs1[dest_idx] = from_errs1[from_idx];
1393 dest_qual1[dest_idx] = from_qual1[from_idx];
1399 sprintf(name,
"input_resampled_shifted_%d.fits",nf);
1406 return cpl_error_get_code();
1414 int *slit_index,
int nb_frames,
int no,
1415 int method,
const int decode_bp)
1417 int nslit, from_slit, nlambda;
1418 float *dest_data1 = NULL, *dest_errs1 = NULL;
1419 int *dest_qual1 = NULL;
1420 float *from_data1 = NULL, *from_errs1 = NULL;
1421 int *from_qual1 = NULL;
1423 double *flux_tab = NULL;
1424 cpl_vector *flux_vect = NULL;
1425 double *err_tab = NULL;
1426 cpl_vector *err_vect = NULL;
1434 cpl_frame* frm=NULL;
1435 for (nf = 0; nf < nb_frames; nf++) {
1436 sprintf(fname,
"list_%d.fits",nf);
1442 "xsh_rec_list_add: nb frames: %d, order: %d", nb_frames, no);
1455 for (nf = 0; nf < nb_frames; nf++) {
1457 "slit index: max %d min=%d", slit_index[nf], slit_index[nf]+from_slit);
1462 for (ns = 0; ns < nslit; ns++) {
1463 for (nl = 0; nl < nlambda; nl++) {
1473 dest_idx = nl + ns * nlambda;
1475 for (nf = 0; nf < nb_frames; nf++) {
1478 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
1481 from_idx = nl + (ns - slit_index[nf]) * nlambda;
1491 if ((from_qual1[from_idx] & decode_bp) == 0) {
1492 qflag |= from_qual1[from_idx];
1493 flux_tab[good] = from_data1[from_idx];
1494 err_tab[good] = from_errs1[from_idx];
1497 }
else if ((from_qual1[from_idx] & decode_bp) > 0) {
1498 flux_tab[good + bad] = from_data1[from_idx];
1499 err_tab[good + bad] = from_errs1[from_idx];
1500 badflag |= from_qual1[from_idx];
1510 qflag |= from_qual1[from_idx];
1512 flux_tab[isum] = from_data1[from_idx];
1514 err_tab[isum] = from_errs1[from_idx];
1527 check( flux_vect = cpl_vector_wrap( bad, flux_tab));
1528 check( err_vect = cpl_vector_wrap( bad, err_tab));
1530 dest_qual1[dest_idx] |= badflag;
1532 dest_qual1[dest_idx] |= qflag;
1537 check( flux_vect = cpl_vector_wrap( good, flux_tab));
1538 check( err_vect = cpl_vector_wrap( good, err_tab));
1545 dest_qual1[dest_idx] |= qflag;
1549 check( flux_vect = cpl_vector_wrap( isum, flux_tab));
1550 check( err_vect = cpl_vector_wrap( isum, err_tab));
1554 check( dest_data1[dest_idx] = cpl_vector_get_mean( flux_vect));
1557 check( dest_data1[dest_idx] = cpl_vector_get_median( flux_vect));
1565 cpl_image* ima_bp=cpl_image_wrap_int(nl,ns,dest_qual1);
1566 sprintf(fname,
"ima_bp_%d.fits",no);
1570 sprintf(fname,
"tab_bp_%d.fits",no);
1572 cpl_image_unwrap(ima_bp);
1577 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1588 int *slit_index,
int nb_frames,
int no,
int method,
const int decode_bp,
1589 cpl_imagelist* scale_factors,
const int scale_method,
const cpl_table* bp)
1607 double sum_good_pix=0.;
1608 double sum_bad_pix=0.;
1617 int win_hsx=win_hsz;
1618 int win_sx=2*win_hsx+1;
1630 int *dest_qual1 = NULL;
1633 cpl_image* ima_bp=cpl_image_wrap_int(nlambda,nslit,dest_qual1);
1634 sprintf(fname,
"ima_bp_%d.fits",no);
1640 sprintf(fname,
"tab_bp_%d.fits",no);
1641 cpl_table_save(tab_bpm,NULL,NULL,fname,CPL_IO_DEFAULT);
1643 cpl_image_unwrap(ima_bp);
1645 int size=cpl_table_get_nrow(tab_bpm);
1646 int* px=cpl_table_get_data_int(tab_bpm,
"x");
1647 int* py=cpl_table_get_data_int(tab_bpm,
"y");
1651 double slit_ext_min=0;
1652 double slit_ext_max=0;
1657 for (
int nf = 0; nf < nb_frames; nf++) {
1659 if(slit_index[nf]>ns_min) {
1660 ns_min=slit_index[nf];
1662 if( (slit_index[nf]+from_slit) < ns_max) {
1663 ns_max=(slit_index[nf]+from_slit);
1677 ima=cpl_image_wrap_float(nlambda,nslit,dest_data1);
1679 cpl_image_unwrap(ima);
1689 int x_min=nl-win_hsx, x_max=nl+win_hsx;
1696 }
else if ( x_max > nlambda) {
1703 if( (ns > ns_min) && (ns < ns_max) ) {
1704 nlambda_ns=nlambda*ns;
1717 for(
int i=x_min;i<=x_max;i++) {
1718 for(
int nf=0; nf < nb_frames; nf++) {
1721 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
1728 from_idx = i + (ns - slit_index[nf]) * nlambda;
1730 sprintf(cname,
"f%d",nf);
1731 const int* pq=cpl_table_get_data_int_const(bp,cname);
1737 if( (from_qual1[from_idx] & decode_bp) == 0 ) {
1743 if((ns >= slit_ext_min && ns <= slit_ext_max) &&
1744 pq[
m]==0 && i != 0) {
1745 sum_good_pix += (from_data1[from_idx]);
1748 sum_bad_pix += (from_data1[from_idx]);
1756 sum_all_pix= sum_good_pix+sum_bad_pix;
1758 scale = sum_all_pix/sum_good_pix*num_good_pix/nb_frames;
1760 if(isinf(scale) || isnan(scale)) {
1761 xsh_msg(
"found infinite sum_good: %g sum_bad: %g num_good: %d",
1762 sum_good_pix, sum_bad_pix, num_good_pix);
1763 xsh_msg(
"x_min=%d x_max=%d",x_min,x_max);
1773 dest_data1[pix] = scale;
1781 ima=cpl_image_wrap_float(nlambda,nslit,dest_data1);
1782 sprintf(fname,
"ima_cor_%d.fits",no);
1783 cpl_image_save(ima, fname, CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT);
1784 cpl_table_save(bp,NULL,NULL,
"bp_tab.fits",CPL_IO_DEFAULT);
1785 cpl_image_unwrap(ima);
1786 cpl_table_delete(tab_bpm);
1790 return cpl_error_get_code();
1795 int *slit_index,
int nb_frames,
int no,
1796 int method,
const int decode_bp,
1797 cpl_imagelist* scale_factors,
const int scale_method)
1800 cpl_image* scale_ima;
1804 double norm_good_pix=0.;
1822 int *dest_qual1 = NULL;
1825 cpl_image* ima_bp=cpl_image_wrap_int(nlambda,nslit,dest_qual1);
1826 sprintf(fname,
"ima_bp_%d.fits",no);
1830 sprintf(fname,
"tab_bp_%d.fits",no);
1832 cpl_image_unwrap(ima_bp);
1834 int size=cpl_table_get_nrow(tab_bpm);
1835 int* px=cpl_table_get_data_int(tab_bpm,
"x");
1836 int* py=cpl_table_get_data_int(tab_bpm,
"y");
1840 double slit_ext_min=0;
1841 double slit_ext_max=0;
1846 for (
int nf = 0; nf < nb_frames; nf++) {
1848 if(slit_index[nf]>ns_min) {
1849 ns_min=slit_index[nf];
1851 if( (slit_index[nf]+from_slit) < ns_max) {
1852 ns_max=(slit_index[nf]+from_slit);
1866 ima=cpl_image_wrap_float(nlambda,nslit,dest_data1);
1868 cpl_image_unwrap(ima);
1877 if( (ns > ns_min) && (ns < ns_max) ) {
1878 nlambda_ns=nlambda*ns;
1888 for(
int nf=0; nf < nb_frames; nf++) {
1891 if ((ns < slit_index[nf]) || (ns >= (slit_index[nf] + from_slit))) {
1894 from_idx = nl + (ns - slit_index[nf]) * nlambda;
1895 if(scale_method < 2) {
1905 if( (from_qual1[from_idx] & decode_bp) == 0 ) {
1908 scale_ima=cpl_imagelist_get(scale_factors,nf);
1909 mask=cpl_image_get_bpm(scale_ima);
1910 pbpm=cpl_mask_get_data(mask);
1912 pscale=cpl_image_get_data_double(scale_ima);
1932 if((ns >= slit_ext_min && ns <= slit_ext_max) &&
1933 pbpm[pix_scale]==CPL_BINARY_0) {
1934 norm_good_pix += (from_data1[from_idx]) /
1935 (pscale[pix_scale]);
1964 norm_good_pix /= num_good_pix;
1972 if(isinf(norm_good_pix)) {
1979 dest_data1[pix] = norm_good_pix;
1987 ima=cpl_image_wrap_float(nlambda,nslit,dest_data1);
1989 cpl_image_unwrap(ima);
1990 cpl_table_delete(tab_bpm);
1993 return cpl_error_get_code();
2014 cpl_frame** res_frame_ext,
2015 const int scale_nod)
2018 cpl_frame *result = NULL ;
2020 int i, no, nb_orders;
2021 float slit_min=999, slit_max=-999;
2027 float *result_slit = NULL;
2029 char *fname = NULL ;
2030 char *tag_drl = NULL ;
2031 char *fname_drl = NULL ;
2032 int *slit_index = NULL;
2033 int slit_ext_min=-9999;
2034 int slit_ext_max=9999;
2035 cpl_propertylist *header = NULL;
2045 check( nb_frames = cpl_frameset_get_size( nod_frames));
2046 xsh_msg(
"---xsh_combine_nod (method %s) - Nb frames = %d",
2053 for ( i = 0 ; i < nb_frames ; i++ ) {
2054 cpl_frame * nod_frame = NULL ;
2057 check( nod_frame = cpl_frameset_get_frame( nod_frames, i));
2059 rec_input_list[i] = list;
2068 sprintf(name,
"input_resampled_%d.fits",i);
2075 for ( i = 0 ; i < nb_frames ; i++ ) {
2076 float nod_slit_min, nod_slit_max;
2079 float* nod_slit = NULL;
2081 list = rec_input_list[i];
2084 nod_slit_min = nod_slit[0];
2085 nod_slit_max = nod_slit[nslit-1];
2087 if ( nod_slit_min < slit_min){
2088 slit_min = nod_slit_min;
2090 if (nod_slit_max > slit_max){
2091 slit_max = nod_slit_max;
2094 rec_first = rec_input_list[0];
2098 nslit = (slit_max-slit_min)/
slit_step+1;
2102 for ( i = 0 ; i < nslit; i++ ) {
2106 xsh_msg(
"Combine nod slit : (%f,%f) step %f nslit %d", slit_min, slit_max,
2109 nb_orders = rec_first->
size;
2113 for ( no = 0 ; no < nb_orders ; no++ ) {
2114 int absorder, nlambda;
2115 double *dnew = NULL;
2116 double *dold = NULL;
2117 float *dslit = NULL;
2126 memcpy( dnew, dold, nlambda*
sizeof(
double));
2129 memcpy( dslit, result_slit, nslit*
sizeof(
float));
2135 slit_index, nb_frames));
2140 check( cpl_propertylist_append( result_list->
header,
2145 xsh_msg(
"Nod combination save extra files to evaluate pixel scaling");
2146 for (
int nf = 0; nf < nb_frames; nf++) {
2147 for ( no = 0; no < nb_orders; no++) {
2156 for ( no = 0; no < nb_orders; no++) {
2169 xsh_msg(
"combine-nod: scale flagged pixel");
2171 cpl_imagelist* sf = NULL;
2172 cpl_table* tab_bp=NULL;
2178 rec_input_list, no);
2184 slit_index, nb_frames, no, nod_par->
method,
2190 scale_method, tab_bp));
2260 for ( no = 0; no < nb_orders; no++) {
2263 for( nf = 0 ; nf < nb_frames ; nf++ ) {
2264 slit_ext_min=(slit_index[nf]>slit_ext_min) ? slit_index[nf]: slit_ext_min;
2265 slit_ext_max=(slit_index[nf]+from_slit<slit_ext_max) ? slit_index[nf]+from_slit: slit_ext_max;
2271 xsh_msg(
"slit index: min %f max=%f",
2303 if (cpl_error_get_code() != CPL_ERROR_NONE){
2308 if ( rec_input_list != NULL){
2309 for ( i = 0 ; i < nb_frames ; i++ ) {
static xsh_instrument * instrument
static cpl_imagelist * xsh_compute_scale_factors_by_object(cpl_imagelist *scaled, cpl_image *scale, const int nlambda, const int nslit, const int no, const double smin, const double smax)
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)
static cpl_table * xsh_qual2tab_frames(int nframes, const int code, int *slit_index, xsh_rec_list *dest, xsh_rec_list **from, const int no)
static cpl_imagelist * xsh_compute_scale_factors_pix_pix(cpl_imagelist *scaled, cpl_image *scale, const int nlambda, const int nslit, const int no)
static cpl_imagelist * xsh_compute_scale_factors_by_slice(cpl_imagelist *scaled, cpl_image *scale, const int nlambda, const int nslit, const int no)
void xsh_rec_list_add(xsh_rec_list *dest, xsh_rec_list **from, int *slit_index, int nb_frames, int no, int method, const int decode_bp)
cpl_error_code xsh_correct_scale_w(xsh_rec_list *dest, xsh_rec_list **from, int *slit_index, int nb_frames, int no, int method, const int decode_bp, cpl_imagelist *scale_factors, const int scale_method, const cpl_table *bp)
cpl_error_code xsh_correct_scale(xsh_rec_list *dest, xsh_rec_list **from, int *slit_index, int nb_frames, int no, int method, const int decode_bp, cpl_imagelist *scale_factors, const int scale_method)
static cpl_imagelist * xsh_find_image_scale_factors(xsh_rec_list *dest, xsh_rec_list **from, int *slit_index, int nb_frames, int no, int method, const int decode_bp, int scale_method)
void xsh_compute_slit_index(float slit_min, float slit_step, xsh_rec_list **from, int *slit_index_tab, int size)
static cpl_error_code xsh_rec_list_qc(xsh_rec_list *dest, xsh_rec_list **from, int *slit_index, int nb_frames, int no, int method, const int decode_bp, const int nf)
int xsh_rec_list_get_nslit(xsh_rec_list *list, int idx)
double * xsh_rec_list_get_lambda(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.
cpl_frame * xsh_rec_list_save2(xsh_rec_list *list, const char *filename, const char *tag)
save an rec list to a frame
cpl_error_code xsh_rec_get_nod_extract_slit_min_max(xsh_rec_list *rlist, const double slit_step, double *smin, double *smax)
xsh_rec_list * xsh_rec_list_create_with_size(int size, xsh_instrument *instr)
Create an empty order list.
float * xsh_rec_list_get_errs1(xsh_rec_list *list, int idx)
cpl_propertylist * xsh_rec_list_get_header(xsh_rec_list *list)
get header of the table
int xsh_rec_list_get_order(xsh_rec_list *list, int idx)
void xsh_rec_list_set_data_size(xsh_rec_list *list, int idx, int absorder, int nlambda, int ns)
Allocate memory for the order idx of the rectify list.
int * xsh_rec_list_get_qual1(xsh_rec_list *list, int idx)
float * xsh_rec_list_get_slit(xsh_rec_list *list, int idx)
int xsh_rec_list_get_nlambda(xsh_rec_list *list, int idx)
void xsh_rec_list_free(xsh_rec_list **list)
free memory associated to a rec_list
#define XSH_ASSURE_NOT_NULL(pointer)
#define xsh_msg_dbg_medium(...)
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_high(...)
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
void xsh_pfits_set_rectify_bin_lambda(cpl_propertylist *plist, double value)
WRITE the lambda binning.
void xsh_pfits_set_rectify_lambda_max(cpl_propertylist *plist, double value)
WRITE the lambda max value.
double xsh_pfits_get_rectify_lambda_min(cpl_propertylist *plist)
find out the rectify lambda min
double xsh_pfits_get_rectify_bin_lambda(cpl_propertylist *plist)
find out the rectify lambda binning
void xsh_pfits_set_rectify_space_max(cpl_propertylist *plist, double value)
WRITE the space (slit) max value.
double xsh_pfits_get_rectify_bin_space(cpl_propertylist *plist)
find out the rectify space (slit) binning
void xsh_pfits_set_rectify_space_min(cpl_propertylist *plist, double value)
WRITE the space (slit) min value.
void xsh_pfits_set_rectify_bin_space(cpl_propertylist *plist, double value)
WRITE the space (slit) binning.
void xsh_pfits_set_rectify_lambda_min(cpl_propertylist *plist, double value)
WRITE the lambda min value.
void xsh_pfits_set_extract_slit_min(cpl_propertylist *plist, double value)
WRITE the min slit for extraction.
void xsh_pfits_set_extract_slit_max(cpl_propertylist *plist, double value)
WRITE the min slit for extraction.
double xsh_pfits_get_rectify_lambda_max(cpl_propertylist *plist)
find out the rectify lambda max
int xsh_pfits_get_qc_ncrh(const cpl_propertylist *plist)
Find out the QC NCRH value.
void xsh_pfits_set_qc_ncrh_mean(cpl_propertylist *plist, const double value)
Write the QC.NCRH.AVG value.
void xsh_pfits_set_qc_ncrh_tot(cpl_propertylist *plist, const int value)
Write the QC.NCRH.TOT value.
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
double xsh_vector_get_err_median(cpl_vector *vect)
Computes median error on a data set.
double xsh_vector_get_err_mean(cpl_vector *vect)
Computes mean error on a data set.
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
long xsh_round_double(double x)
Computes round(x)
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
void xsh_free_imagelist(cpl_imagelist **i)
Deallocate an image list and set the pointer to NULL.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
enum combine_method method
cpl_propertylist * header
#define QFLAG_INCOMPLETE_NOD
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
#define COMBINE_METHOD_PRINT(method)
#define XSH_QC_CRH_NUMBER
#define XSH_FREE(POINTER)
#define XSH_MALLOC(POINTER, TYPE, SIZE)
#define XSH_CALLOC(POINTER, TYPE, SIZE)
cpl_table * xsh_qual2tab(cpl_image *qual, const int code)