69 float throwaway_high ) ;
90 const double sigma_y);
120 *dA=fabs(dxdu*dydv-dxdv*dydu)*du*dv;
121 return cpl_error_get_code();
151 assure (in != NULL, CPL_ERROR_NULL_INPUT,
"NULL input frame");
152 check(sx=cpl_image_get_size_x(in));
153 check(sy=cpl_image_get_size_y(in));
167 if(cpl_error_get_code() != CPL_ERROR_NONE) {
214 if (kernel_type==NULL) {
216 }
else if (!strcmp(kernel_type,
"default")) {
218 }
else if (!strcmp(kernel_type,
"sinc")) {
219 tab = cpl_malloc(samples *
sizeof(
double)) ;
221 tab[samples-1] = 0.0 ;
222 for (i=1 ; i<samples ; i++) {
226 }
else if (!strcmp(kernel_type,
"sinc2")) {
227 tab = cpl_malloc(samples *
sizeof(
double)) ;
229 tab[samples-1] = 0.0 ;
230 for (i=1 ; i<samples ; i++) {
231 x = 2.0 * (double)i/(
double)(samples-1) ;
235 }
else if (!strcmp(kernel_type,
"lanczos")) {
236 tab = cpl_malloc(samples *
sizeof(
double)) ;
237 for (i=0 ; i<samples ; i++) {
245 }
else if (!strcmp(kernel_type,
"hamming")) {
246 tab = cpl_malloc(samples *
sizeof(
double)) ;
248 inv_norm = 1.00 / (double)(samples - 1) ;
249 for (i=0 ; i<samples ; i++) {
251 if (i<(samples-1)/2) {
252 tab[i] = alpha + (1-alpha) * cos(2.0*
M_PI*
x*inv_norm) ;
257 }
else if (!strcmp(kernel_type,
"hann")) {
258 tab = cpl_malloc(samples *
sizeof(
double)) ;
260 inv_norm = 1.00 / (double)(samples - 1) ;
261 for (i=0 ; i<samples ; i++) {
263 if (i<(samples-1)/2) {
264 tab[i] = alpha + (1-alpha) * cos(2.0*
M_PI*
x*inv_norm) ;
269 }
else if (!strcmp(kernel_type,
"tanh")) {
272 xsh_msg_error(
"unrecognized kernel type [%s]: aborting generation",
298 return (
double)1.00 ;
300 return ((sin(
x * (
double)
M_PI)) / (
x * (
double)
M_PI)) ;
345 cpl_image * image_in,
347 cpl_polynomial * poly_u,
348 cpl_polynomial * poly_v
351 cpl_image * image_out ;
355 double neighbors[16] ;
369 if (image_in == NULL)
return NULL ;
374 if (kernel == NULL) {
375 xsh_msg_error(
"cannot generate kernel: aborting resampling") ;
378 ilx=cpl_image_get_size_x(image_in);
379 ily=cpl_image_get_size_y(image_in);
380 pidata=cpl_image_get_data_float(image_in);
386 image_out = cpl_image_new(lx_out, ly_out,CPL_TYPE_FLOAT) ;
387 podata=cpl_image_get_data_float(image_out);
391 leaps[0] = -1 - ilx ;
401 leaps[8] = -1 + ilx ;
406 leaps[12]= -1 + 2*ilx ;
408 leaps[14]= 1 + 2*ilx ;
409 leaps[15]= 2 + 2*ilx ;
411 vx=cpl_vector_new(2);
413 for (j=0 ; j < ly_out ; j++) {
414 for (i=0 ; i< lx_out ; i++) {
416 cpl_vector_set(vx,0,(
double)i);
417 cpl_vector_set(vx,1,(
double)j);
418 x = cpl_polynomial_eval(poly_u, vx);
419 y = cpl_polynomial_eval(poly_v, vx);
432 pos = px + py * ilx ;
433 for (k=0 ; k<16 ; k++)
434 neighbors[k] = (
double)(pidata[(int)(pos+leaps[k])]) ;
444 rsc[1] = kernel[tabx] ;
448 rsc[5] = kernel[taby] ;
452 sumrs = (rsc[0]+rsc[1]+rsc[2]+rsc[3]) *
453 (rsc[4]+rsc[5]+rsc[6]+rsc[7]) ;
456 cur = rsc[4] * ( rsc[0]*neighbors[0] +
457 rsc[1]*neighbors[1] +
458 rsc[2]*neighbors[2] +
459 rsc[3]*neighbors[3] ) +
460 rsc[5] * ( rsc[0]*neighbors[4] +
461 rsc[1]*neighbors[5] +
462 rsc[2]*neighbors[6] +
463 rsc[3]*neighbors[7] ) +
464 rsc[6] * ( rsc[0]*neighbors[8] +
465 rsc[1]*neighbors[9] +
466 rsc[2]*neighbors[10] +
467 rsc[3]*neighbors[11] ) +
468 rsc[7] * ( rsc[0]*neighbors[12] +
469 rsc[1]*neighbors[13] +
470 rsc[2]*neighbors[14] +
471 rsc[3]*neighbors[15] ) ;
474 podata[i+j*lx_out] = (
pixelvalue)(cur/sumrs) ;
479 cpl_vector_delete(vx);
485#define hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))
524 inv_np = 1.00 / (double)np ;
530 x = cpl_malloc((2*np+1)*
sizeof(
double)) ;
531 for (i=0 ; i<np/2 ; i++) {
532 ind = (double)i * 2.0 *
width * inv_np ;
536 for (i=np/2 ; i<np ; i++) {
537 ind = (double)(i-np) * 2.0 *
width * inv_np ;
550 kernel = cpl_malloc(samples *
sizeof(
double)) ;
551 for (i=0 ; i<samples ; i++) {
552 kernel[i] = 2.0 *
width *
x[2*i] * inv_np ;
559#define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr
591 n = (
unsigned long)nn << 1;
593 for (i=1 ; i<
n ; i+=2) {
599 while (
m>=2 && j>
m) {
608 theta = 2 *
M_PI / mmax;
609 wtemp = sin(0.5 * theta);
610 wpr = -2.0 * wtemp * wtemp;
614 for (
m=1 ;
m<mmax ;
m+=2) {
615 for (i=
m ; i<=
n ; i+=istep) {
617 tempr = wr *
data[j-1] - wi *
data[j];
618 tempi = wr *
data[j] + wi *
data[j-1];
624 wr = (wtemp = wr) * wpr - wi * wpi + wr;
625 wi = wi * wpr + wtemp * wpi + wi;
660 (void)fprintf(stdout,
"# Kernel is %s\n", kernel_name) ;
663 (void)fprintf(stdout,
"%g %g\n",
x, ker[i]) ;
682 cpl_mask *rejected = NULL;
683 cpl_image *im = NULL;
685 double robust_stdev = 0;
687 assure (image != NULL, CPL_ERROR_NULL_INPUT,
"NULL input frame");
688 assure( cut > 0, CPL_ERROR_ILLEGAL_INPUT,
"Illegal cut: %f", cut );
689 assure( dstdev == NULL, CPL_ERROR_ILLEGAL_INPUT,
"Unsupported");
691 median = cpl_image_get_median(image);
693 im = cpl_image_duplicate(image);
694 cpl_image_subtract_scalar(im, median);
695 cpl_image_power(im, 2);
698 rejected = cpl_mask_threshold_image_create(image,median - cut,
700 cpl_mask_not(rejected);
701 cpl_image_reject_from_mask(im, rejected);
703 robust_stdev = sqrt(cpl_image_get_mean(im));
721 cpl_mask *rejected = NULL;
722 cpl_image *im = NULL;
725 double robust_stdev = 0;
729 assure (image != NULL, CPL_ERROR_NULL_INPUT,
"NULL input frame");
730 assure( dstdev == NULL, CPL_ERROR_ILLEGAL_INPUT,
"Unsupported");
732 median = cpl_image_get_median(image);
733 stdev=cpl_image_get_stdev(image);
736 im = cpl_image_duplicate(image);
737 cpl_image_subtract_scalar(im, median);
738 cpl_image_power(im, 2);
741 rejected = cpl_mask_threshold_image_create(image,median - cut,
743 cpl_mask_not(rejected);
744 cpl_image_reject_from_mask(im, rejected);
746 robust_stdev = sqrt(cpl_image_get_mean(im));
769 double master_fixed_pattern_noise=0;
770 cpl_image *image1 = NULL;
771 cpl_image *image2 = NULL;
773 assure (master != NULL, CPL_ERROR_NULL_INPUT,
"NULL input frame");
778 if (cpl_image_get_size_x(master) >= 121 &&
779 cpl_image_get_size_y(master) >= 121) {
781 int mid_x = (cpl_image_get_size_x(master) + 1) / 2;
782 int mid_y = (cpl_image_get_size_y(master) + 1) / 2;
786 mid_x - 50, mid_y - 50,
787 mid_x + 50, mid_y + 50);
791 mid_x + 10 - 50, mid_y + 10 - 50,
792 mid_x + 10 + 50, mid_y + 10 + 50);
794 cpl_image_subtract(image1, image2);
796 master_fixed_pattern_noise = cpl_image_get_stdev(image1) / sqrt(2);
799 master_fixed_pattern_noise *= convert_ADU;
802 if (master_fixed_pattern_noise >= master_noise) {
804 master_fixed_pattern_noise = sqrt(master_fixed_pattern_noise*
805 master_fixed_pattern_noise
811 cpl_msg_warning(cpl_func,
812 "Zero-shift noise (%f ADU) is greater than "
813 "accumulated zero-shift and fixed pattern noise (%f ADU), "
814 "setting fixed pattern noise to zero",
816 master_fixed_pattern_noise);
817 master_fixed_pattern_noise = 0;
821 cpl_msg_warning(cpl_func,
822 "Master flat too small (%" CPL_SIZE_FORMAT
"x%" CPL_SIZE_FORMAT
"), "
823 "need size 121x121 to compute master flat "
824 "fixed pattern noise",
825 cpl_image_get_size_x(master),
826 cpl_image_get_size_y(master));
827 master_fixed_pattern_noise = -1;
834 return master_fixed_pattern_noise;
846 const cpl_image *second_raw,
849 double bias_fixed_pattern_noise=0;
850 cpl_image *image1 = NULL;
851 cpl_image *image2 = NULL;
854 assure (first_raw != NULL, CPL_ERROR_NULL_INPUT,
"NULL input image");
855 assure (second_raw != NULL, CPL_ERROR_NULL_INPUT,
"NULL input image");
861 nx = cpl_image_get_size_x(first_raw);
862 ny = cpl_image_get_size_y(first_raw);
870 cpl_image_subtract(image1, image2);
879 if (bias_fixed_pattern_noise > ron) {
881 bias_fixed_pattern_noise = sqrt(bias_fixed_pattern_noise *
882 bias_fixed_pattern_noise
887 cpl_msg_warning(cpl_func,
888 "Zero-shift noise (%f ADU) is greater than "
889 "accumulated zero-shift and fixed pattern "
891 "setting fixed pattern noise to zero",
893 bias_fixed_pattern_noise);
894 bias_fixed_pattern_noise = 0;
901 return bias_fixed_pattern_noise;
926 cpl_image *image_crop = NULL;
927 assure( image != NULL, CPL_ERROR_ILLEGAL_INPUT,
"Null input image" );
928 assure( 1 <= xlo && xlo <= xhi && xhi <= cpl_image_get_size_x(image) &&
929 1 <= ylo && ylo <= yhi && yhi <= cpl_image_get_size_y(image),
930 CPL_ERROR_ILLEGAL_INPUT,
931 "Cannot extraction region (%d, %d) - (%d, %d) of %" CPL_SIZE_FORMAT
"x%" CPL_SIZE_FORMAT
" image",
933 cpl_image_get_size_x(image),
934 cpl_image_get_size_y(image));
938 check(image_crop = cpl_image_extract(image,xlo, ylo,xhi, yhi));
953 if(cpl_error_get_code() != CPL_ERROR_NONE) {
1013 const cpl_polynomial *poly_x,
1014 const cpl_polynomial *poly_y)
1016 cpl_polynomial *dxdu=NULL;
1017 cpl_polynomial *dxdv=NULL;
1018 cpl_polynomial *dydu=NULL;
1019 cpl_polynomial *dydv=NULL;
1021 cpl_vector *val=NULL;
1031 if (out == NULL || poly_x == NULL || poly_y == NULL)
1032 return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
1034 if (cpl_polynomial_get_dimension(poly_x) != 2 ||
1035 cpl_polynomial_get_dimension(poly_y) != 2)
1036 return cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
1038 if (cpl_image_get_type(out) != CPL_TYPE_FLOAT &&
1039 cpl_image_get_type(out) != CPL_TYPE_DOUBLE)
1040 return cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE);
1047 dxdu = cpl_polynomial_duplicate(poly_x);
1048 dxdv = cpl_polynomial_duplicate(poly_x);
1049 dydu = cpl_polynomial_duplicate(poly_y);
1050 dydv = cpl_polynomial_duplicate(poly_y);
1052 cpl_polynomial_derivative(dxdu, 0);
1053 cpl_polynomial_derivative(dxdv, 1);
1054 cpl_polynomial_derivative(dydu, 0);
1055 cpl_polynomial_derivative(dydv, 1);
1063 nx = cpl_image_get_size_x(out);
1064 ny = cpl_image_get_size_y(out);
1066 val = cpl_vector_new(2);
1067 pval = cpl_vector_get_data(val);
1069 switch (cpl_image_get_type(out)) {
1070 case CPL_TYPE_FLOAT:
1071 fdata = cpl_image_get_data_float(out);
1072 for (j=0; j <
ny; j++) {
1074 for (i=0; i <
nx; i++) {
1076 *fdata++ = cpl_polynomial_eval(dxdu, val)
1077 * cpl_polynomial_eval(dydv, val)
1078 - cpl_polynomial_eval(dxdv, val)
1079 * cpl_polynomial_eval(dydu, val);
1083 case CPL_TYPE_DOUBLE:
1084 ddata = cpl_image_get_data_double(out);
1085 for (j=0; j <
ny; j++) {
1087 for (i=0; i <
nx; i++) {
1089 *ddata++ = cpl_polynomial_eval(dxdu, val)
1090 * cpl_polynomial_eval(dydv, val)
1091 - cpl_polynomial_eval(dxdv, val)
1092 * cpl_polynomial_eval(dydu, val);
1106 cpl_vector_delete(val);
1107 cpl_polynomial_delete(dxdu);
1108 cpl_polynomial_delete(dxdv);
1109 cpl_polynomial_delete(dydu);
1110 cpl_polynomial_delete(dydv);
1119 return CPL_ERROR_NONE;
1133 cpl_image* scharr_x=NULL;
1134 float* pscharr_x=NULL;
1142 check(scharr_x=cpl_image_duplicate(in));
1143 check(pscharr_x=cpl_image_get_data_float(scharr_x));
1144 check(pin=cpl_image_get_data_float(in));
1145 check(sx=cpl_image_get_size_x(in));
1146 check(sy=cpl_image_get_size_y(in));
1148 for(i=1;i<sx-1;i++) {
1149 for(j=1;j<sy-1;j++) {
1150 pscharr_x[i+j*sx]=3*pin[i-1+(j+1)*sx]-3*pin[i+1+(j+1)*sx]+
1151 10*pin[i-1+j*sx]-10*pin[i+1+j*sx]+
1152 3*pin[i-1+(j-1)*sx]-3*pin[i+1+(j-1)*sx];
1172 cpl_image* scharr_y=NULL;
1173 float* pscharr_y=NULL;
1181 check(scharr_y=cpl_image_duplicate(in));
1182 check(pscharr_y=cpl_image_get_data_float(scharr_y));
1183 check(pin=cpl_image_get_data_float(in));
1184 check(sx=cpl_image_get_size_x(in));
1185 check(sy=cpl_image_get_size_y(in));
1187 for(i=1;i<sx-1;i++) {
1188 for(j=1;j<sy-1;j++) {
1189 pscharr_y[i+j*sx]=3*pin[i-1+(j+1)*sx]+10*pin[i+(j+1)*sx]+3*pin[i+1+(j+1)*sx]+
1190 -3*pin[i-1+(j-1)*sx]-10*pin[i+(j-1)*sx]-3*pin[i+1+(j-1)*sx];
1219 check(lx=cpl_image_duplicate(in));
1220 check(plx=cpl_image_get_data_float(lx));
1221 check(pin=cpl_image_get_data_float(in));
1222 check(sx=cpl_image_get_size_x(in));
1223 check(sy=cpl_image_get_size_y(in));
1225 for(i=1;i<sx-1;i++) {
1226 for(j=1;j<sy-1;j++) {
1227 plx[i+j*sx]=pin[i-1+(j+1)*sx]-pin[i+1+(j+1)*sx]+
1228 2*pin[i-1+j*sx]-2*pin[i+1+j*sx]+
1229 pin[i-1+(j-1)*sx]-pin[i+1+(j-1)*sx];
1261 check(ly=cpl_image_duplicate(in));
1262 check(ply=cpl_image_get_data_float(ly));
1263 check(pin=cpl_image_get_data_float(in));
1264 check(sx=cpl_image_get_size_x(in));
1265 check(sy=cpl_image_get_size_y(in));
1267 for(i=1;i<sx-1;i++) {
1268 for(j=1;j<sy-1;j++) {
1269 ply[i+j*sx]=pin[i-1+(j+1)*sx]+2*pin[i+(j+1)*sx]+pin[i+1+(j+1)*sx]+
1270 -pin[i-1+(j-1)*sx]-2*pin[i+(j-1)*sx]-pin[i+1+(j-1)*sx];
1306 cpl_frame* bias1=NULL;
1307 cpl_frame* bias2=NULL;
1309 cpl_image* ima1=NULL;
1310 cpl_image* ima2=NULL;
1311 cpl_image* imad=NULL;
1313 const char* name1=NULL;
1314 const char* name2=NULL;
1321 cpl_propertylist* plist=NULL;
1325 check(nfrm=cpl_frameset_get_size(frames));
1327 if ( nfrm < 2 )
goto cleanup;
1329 check(bias1=cpl_frameset_get_frame(frames,0));
1330 check(bias2=cpl_frameset_get_frame(frames,1));
1331 check(name1=cpl_frame_get_filename(bias1));
1332 check(name2=cpl_frame_get_filename(bias2));
1333 check(ima1=cpl_image_load(name1,CPL_TYPE_FLOAT,0,0));
1334 check(ima2=cpl_image_load(name2,CPL_TYPE_FLOAT,0,0));
1336 check(nx1=cpl_image_get_size_x(ima1));
1337 check(nx2=cpl_image_get_size_x(ima2));
1339 check(ny1=cpl_image_get_size_y(ima1));
1340 check(ny2=cpl_image_get_size_y(ima2));
1342 if((nx1 != nx2) || (ny1 != ny2)) {
1343 xsh_error_msg(
"image1's size: [%d,%d] != from image2's size [%d,%d]",
1348 check(plist=cpl_propertylist_load(name1,0));
1361 check(imad=cpl_image_duplicate(ima1));
1362 check(cpl_image_subtract(imad,ima2));
1364 check(cpl_flux_get_noise_window(imad, zone,hsize,nsampl,ron,ron_err));
1379 check(cpl_propertylist_append_string(plist,
XSH_PCATG,
"BIAS_PAIR_DIFF"));
1390 if (cpl_error_get_code()) {
1430 float thresh_sigma_factor,
1431 float low_threshold,
1432 float high_threshold,
1438 cpl_image * bp_map =NULL;
1443 float * spectrum =NULL;
1446 Stats * stats =NULL;
1447 cpl_image* img_src=NULL;
1449 float* psrcdata=NULL;
1450 float* pbpdata=NULL;
1454 if ( NULL == darks )
1460 if ( thresh_sigma_factor <= 0. )
1465 if ( low_threshold < 0. || high_threshold < 0. || (low_threshold + high_threshold) >= 100. )
1471 lz=cpl_imagelist_get_size(darks);
1474 xsh_msg_error(
"not enough dark frames given for good statistics!") ;
1477 img_src=cpl_imagelist_get(darks,0);
1479 lx = cpl_image_get_size_x(img_src) ;
1480 ly = cpl_image_get_size_y(img_src) ;
1496 low_n = (int)(low_threshold/100. *(
float)lz) ;
1497 high_n = (int)(high_threshold/100. *(
float)lz) ;
1499 if (NULL == (bp_map = cpl_image_new (lx, ly,CPL_TYPE_FLOAT) ) )
1504 pbpdata=cpl_image_get_data(bp_map);
1505 if (NULL == (spectrum = (
float*) cpl_calloc(lz,
sizeof(
float)) ) )
1512 for ( row = 0 ; row < ly ; row++ ) {
1514 for ( col = 0 ; col < lx ; col++ ) {
1516 for ( z = 0 ; z < lz ; z++ ) {
1517 img_src=cpl_imagelist_get(darks,z);
1518 psrcdata=cpl_image_get_data(img_src);
1519 spectrum[z] = psrcdata[col+lx*row] ;
1525 for ( i = low_n ; i < lz - high_n ; i++ ) {
1526 pix_sum += (double)spectrum[i] ;
1527 sqr_sum += ((double)spectrum[i]*(
double)spectrum[i]) ;
1531 pix_sum /= (double)
n ;
1532 sqr_sum /= (double)
n ;
1534 pbpdata[col+lx*row] = (float)sqrt(sqr_sum - pix_sum*pix_sum) ;
1538 cpl_free(spectrum) ;
1545 cpl_image_delete (bp_map) ;
1551 for ( row = 0 ; row < ly ; row++ ) {
1552 for ( col = 0 ; col < lx ; col++ ) {
1553 if (pbpdata[col+lx*row] >
1555 pbpdata[col+lx*row] <
1562 pbpdata[col+lx*row] = 0. ;
1596 Stats * retstats=NULL;
1606 float * pix_array=NULL;
1616 if ( loReject+hiReject >= 100. )
1621 if ( loReject < 0. || loReject >= 100. ||
1622 hiReject < 0. || hiReject >= 100. )
1628 im_lx=cpl_image_get_size_x(im);
1629 im_ly=cpl_image_get_size_y(im);
1630 if (
llx < 0 ||
lly < 0 ||
1632 llx > im_lx ||
lly > im_ly ||
1633 urx > im_lx ||
ury > im_ly ||
1636 xsh_msg_error(
"sorry, wrong pixel coordinates of rectangle!") ;
1637 xsh_msg_error(
"llx < 0 || lly < 0 ||urx < 0 || ury < 0 ||llx > im_lx || lly > im_ly ||urx > im_lx || ury > im_ly || ury <= lly || urx <= llx");
1638 xsh_msg_error(
"llx=%d lly=%d urx=%d ury=%d im_lx=%d im_ly=%d",
1644 retstats = (
Stats*) cpl_calloc(1,
sizeof(
Stats)) ;
1646 pix_array = (
float*) cpl_calloc ( npix,
sizeof(
float) ) ;
1652 pim = cpl_image_get_data_float(im);
1658 col_min = (
llx>0) ?
llx : 0;
1659 row_min = (
lly>0) ?
lly : 0;
1660 col_max = (
urx<im_lx) ?
urx : im_lx-1;
1661 row_max = (
ury<im_ly) ?
ury : im_ly-1;
1663 for ( row = row_min ; row <= row_max ; row++ )
1665 for ( col = col_min ; col <= col_max ; col++ )
1667 if ( !isnan(pim[col + row*im_lx]) )
1669 pix_array[
n] = pim[col + row*im_lx] ;
1687 npix, loReject, hiReject)) )
1690 cpl_free(retstats) ;
1691 cpl_free(pix_array) ;
1697 lo_n = (int) (loReject / 100. * (
float)npix) ;
1698 hi_n = (int) (hiReject / 100. * (
float)npix) ;
1702 for ( i = lo_n ; i <= npix - hi_n ; i++ )
1704 pix_sum += (double)pix_array[i] ;
1705 sqr_sum += ((double)pix_array[i] * (
double)pix_array[i]) ;
1712 cpl_free(retstats) ;
1713 cpl_free(pix_array) ;
1716 retstats -> npix =
n ;
1717 pix_sum /= (double)
n ;
1718 sqr_sum /= (double)
n ;
1719 retstats -> cleanstdev = (float)sqrt(sqr_sum - pix_sum * pix_sum) ;
1720 cpl_free (pix_array) ;
1724#define PIX_SWAP(a,b) { pixelvalue temp=(a);(a)=(b);(b)=temp; }
1725#define PIX_STACK_SIZE 50
1755 for (j=l+1 ; j<=ir ; j++) {
1757 for (i=j-1 ; i>=1 ; i--) {
1758 if (pix_arr[i-1] <= a)
break;
1759 pix_arr[i] = pix_arr[i-1];
1763 if (j_stack == 0)
break;
1764 ir = i_stack[j_stack-- -1];
1765 l = i_stack[j_stack-- -1];
1769 if (pix_arr[l] > pix_arr[ir-1]) {
1770 PIX_SWAP(pix_arr[l], pix_arr[ir-1])
1772 if (pix_arr[l-1] > pix_arr[ir-1]) {
1773 PIX_SWAP(pix_arr[l-1], pix_arr[ir-1])
1775 if (pix_arr[l] > pix_arr[l-1]) {
1782 do i++;
while (pix_arr[i-1] < a);
1783 do j--;
while (pix_arr[j-1] > a);
1785 PIX_SWAP(pix_arr[i-1], pix_arr[j-1]);
1787 pix_arr[l-1] = pix_arr[j-1];
1794 if (ir-i+1 >= j-l) {
1795 i_stack[j_stack-1] = ir;
1796 i_stack[j_stack-2] = i;
1799 i_stack[j_stack-1] = j-1;
1800 i_stack[j_stack-2] = l;
1806#undef PIX_STACK_SIZE
1827 float throwaway_low,
1828 float throwaway_high )
1834 if ( array == NULL )
1840 if ( n_elements <= 0 )
1846 if ( throwaway_low < 0. || throwaway_high < 0. ||
1847 throwaway_low + throwaway_high >= 100. )
1853 lo_n = (int) (throwaway_low * (
float)n_elements / 100.) ;
1854 hi_n = (int) (throwaway_high * (
float)n_elements / 100.) ;
1861 for ( i = lo_n ; i < n_elements - hi_n ; i++ )
1863 if ( !isnan(array[i]) )
1875 return sum/(float)
n ;
1902 cpl_image* out=NULL;
1903 cpl_image* im_re=NULL;
1904 cpl_image* im_im=NULL;
1905 cpl_image* ifft_re=NULL;
1906 cpl_image* ifft_im=NULL;
1911 check(im_re = cpl_image_cast(inp, CPL_TYPE_DOUBLE));
1912 check(im_im = cpl_image_cast(inp, CPL_TYPE_DOUBLE));
1915 check(cpl_image_fft(im_re,im_im,CPL_FFT_DEFAULT));
1916 check(sx=cpl_image_get_size_x(inp));
1917 check(sy=cpl_image_get_size_y(inp));
1924 cpl_image_multiply(im_re,
filter);
1925 cpl_image_multiply(im_im,
filter);
1929 check(ifft_re = cpl_image_duplicate(im_re));
1930 check(ifft_im = cpl_image_duplicate(im_im));
1936 check(cpl_image_fft(ifft_re,ifft_im,CPL_FFT_INVERSE));
1937 check(out = cpl_image_cast(ifft_re, CPL_TYPE_FLOAT));
1947 if(cpl_error_get_code() != CPL_ERROR_NONE) {
1975 const double sigma_x,
1976 const double sigma_y)
1985 double gaussval= 0.0;
1986 double inv_sigma_x=1./sigma_x;
1987 double inv_sigma_y=1./sigma_y;
1991 cpl_image *lowpass_image=NULL;
1995 lowpass_image = cpl_image_new (xs, ys, CPL_TYPE_FLOAT);
1996 if (lowpass_image == NULL) {
1998 cpl_error_get_message());
2005 data = cpl_image_get_data_float(lowpass_image);
2020 for (i=1 ; i<=hlx ; i++) {
2021 x = i * inv_sigma_x;
2022 gaussval = exp(-0.5*
x*
x);
2024 data[xs-i] = gaussval;
2027 for (j=1; j<=hly ; j++) {
2028 y = j * inv_sigma_y;
2030 data[j*xs] = exp(-0.5*
y*
y);
2031 data[(ys-j)*xs] = exp(-0.5*
y*
y);
2033 for (i=1 ; i<=hlx ; i++) {
2035 x = i * inv_sigma_x;
2036 gaussval = exp (-0.5*(
x*
x+
y*
y));
2037 data[j*xs+i] = gaussval;
2038 data[(j+1)*xs-i] = gaussval;
2039 data[(ys-j)*xs+i] = gaussval;
2040 data[(ys+1-j)*xs-i] = gaussval;
2052 return lowpass_image;
2077 double* pinp = NULL;
2078 double* pout = NULL;
2085 cpl_image* out=NULL;
2088 check( out = cpl_image_cast( inp, CPL_TYPE_DOUBLE));
2089 check(sx = cpl_image_get_size_x(inp));
2090 check(sy = cpl_image_get_size_y(inp));
2091 check(pinp = cpl_image_get_data_double(inp));
2092 check(pout = cpl_image_get_data_double(out));
2093 for( j=r; j<sy-r; j++) {
2095 for( i=0; i<sx; i++) {
2096 for( k=-r; k<r; k++) {
2097 pout[pix] += pinp[pix+k*sx];
2104 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2138 cpl_image* out=NULL;
2143 check(out=cpl_image_cast(inp,CPL_TYPE_DOUBLE));
2144 check(sx=cpl_image_get_size_x(inp));
2145 check(sy=cpl_image_get_size_y(inp));
2146 check(pout=cpl_image_get_data_double(out));
2148 for(j=r+1;j<sy-r;j++) {
2150 pout[j*sx+i]=cpl_image_get_median_window(inp,i,j,i,j+r);
2156 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2194 cpl_image* out=NULL;
2198 check( out = cpl_image_cast( inp, CPL_TYPE_DOUBLE));
2199 check( sx=cpl_image_get_size_x(inp));
2200 check( sy=cpl_image_get_size_y(inp));
2201 check( pinp=cpl_image_get_data_double(inp));
2202 check( pout=cpl_image_get_data_double(out));
2204 for(i=r;i<sx-r;i++) {
2206 pout[j*sx+i]+=pinp[j*sx+i+k];
2214 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2258 cpl_image* out=NULL;
2263 check(out=cpl_image_cast(inp,CPL_TYPE_FLOAT));
2264 check(sx=cpl_image_get_size_x(inp));
2265 check(sy=cpl_image_get_size_y(inp));
2266 check(pout=cpl_image_get_data_float(out));
2269 for(i=r+1;i<sx-r;i++) {
2270 pout[j*sx+i]=cpl_image_get_median_window(inp,i,j,i+r,j);
2276 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2321 cpl_image* out=NULL;
2326 check(out=cpl_image_cast(inp,CPL_TYPE_DOUBLE));
2327 check(sx=cpl_image_get_size_x(inp));
2328 check(sy=cpl_image_get_size_y(inp));
2329 check(pout=cpl_image_get_data_double(out));
2331 for(j=r+1;j<sy-r;j++) {
2332 for(i=r+1;i<sx-r;i++) {
2333 pout[j*sx+i]=cpl_image_get_median_window(inp,i,j,i+r,j+r);
2339 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2365 cpl_image* ima=NULL;
2366 cpl_image* err=NULL;
2367 cpl_image* qua=NULL;
2368 cpl_propertylist* hima=NULL;
2369 cpl_propertylist* herr=NULL;
2370 cpl_propertylist* hqua=NULL;
2373 const char* name=NULL;
2383 name=cpl_frame_get_filename(in);
2384 hima=cpl_propertylist_load(name,0);
2385 herr=cpl_propertylist_load(name,1);
2386 hqua=cpl_propertylist_load(name,2);
2387 ima=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
2388 err=cpl_image_load(name,CPL_TYPE_DOUBLE,0,1);
2389 qua=cpl_image_load(name,CPL_TYPE_INT,0,2);
2391 nx=cpl_image_get_size_x(ima);
2392 ny=cpl_image_get_size_y(ima);
2394 pima=cpl_image_get_data_double(ima);
2395 pqua=cpl_image_get_data_int(qua);
2397 for(j=ry;j<
ny-ry;j++) {
2398 for(i=rx;i<
nx-rx;i++) {
2399 if(pqua[i+j*
nx]!=0) {
2400 pima[i+j*
nx]=cpl_image_get_median_window(ima,i-rx,j-ry,i+rx,j+ry);
2416 return cpl_error_get_code();
2452 cpl_vector* pix_pos=NULL;
2453 cpl_vector* pix_val=NULL;
2454 double x_centroid=0;
2458 check( pix_pos = cpl_vector_new( nelem ) ) ;
2459 check( pix_val = cpl_vector_new( nelem ) ) ;
2462 for( i = 0, ix =
llx ; ix <=
urx ; ix++, i++, dy += 1. ) {
2467 value = cpl_image_get(ima , ix, iy, &rej ) ;
2468 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
2473 cpl_vector_set( pix_val, i, value ) ;
2474 cpl_vector_set( pix_pos, i, dy ) ;
2478 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
2481 x_centroid=cpl_image_get_centroid_x_window(ima,
llx,ypos,
urx,ypos);
2527 cpl_vector* pix_pos=NULL;
2528 cpl_vector* pix_val=NULL;
2529 double y_centroid=0;
2533 check( pix_pos = cpl_vector_new( nelem ) ) ;
2534 check( pix_val = cpl_vector_new( nelem ) ) ;
2537 for( j = 0, jy =
lly ; jy <=
ury ; jy++, j++, dy += 1. ) {
2542 value = cpl_image_get(ima , jx, jy, &rej ) ;
2543 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
2548 cpl_vector_set( pix_val, j, value ) ;
2549 cpl_vector_set( pix_pos, j, dy ) ;
2553 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
2556 y_centroid=cpl_image_get_centroid_y_window(ima,xpos,
lly,xpos,
ury);
2593const int hsize,
const int method)
2596 cpl_table* table=NULL;
2616 naxis1=cpl_image_get_size_x(data_ima);
2617 naxis2=cpl_image_get_size_y(data_ima);
2619 table=cpl_table_new(naxis1);
2620 cpl_table_new_column(table,
"X",CPL_TYPE_INT);
2621 cpl_table_new_column(table,
"WAVELENGTH",CPL_TYPE_DOUBLE);
2622 cpl_table_new_column(table,
"POS",CPL_TYPE_DOUBLE);
2624 cpl_table_fill_column_window_int(table,
"X",0,naxis1,0);
2625 cpl_table_fill_column_window_double(table,
"WAVELENGTH",0,naxis1,0.);
2626 cpl_table_fill_column_window_double(table,
"POS",0,naxis1,0.);
2628 px=cpl_table_get_data_int(table,
"X");
2629 pwav=cpl_table_get_data_double(table,
"WAVELENGTH");
2630 pcy=cpl_table_get_data_double(table,
"POS");
2632 for(i=0;i<naxis1;i++) {
2634 pwav[i]=crval1+cdelt1*i;
2636 check(cpl_image_get_maxpos_window(data_ima,
llx,1,
llx,naxis2,&mx,&my));
2637 lly=(my-hsize>0) ? my-hsize:1;
2638 ury=(my+hsize<=naxis2) ? my+hsize:naxis2;
2673 const char* suffix,
const int hsize,
const int method)
2676 cpl_frame* result=NULL;
2677 cpl_table* table=NULL;
2678 cpl_image* data_ima=NULL;
2679 const char* name=NULL;
2681 cpl_propertylist* plist=NULL;
2685 check(name=cpl_frame_get_filename(frm_ima));
2687 check(data_ima=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0));
2688 plist=cpl_propertylist_load(name,0);
2693 sprintf(tag,
"MERGE3D_TRACE_OBJ_%s_%s",
2695 sprintf(fname,
"%s.fits",tag);
2697 check(cpl_table_save(table,plist,NULL,fname,CPL_IO_DEFAULT));
2700 CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL);
2739 cpl_frame* result=NULL;
2740 cpl_table* table=NULL;
2741 cpl_table* table_tot=NULL;
2743 cpl_image* data_ima=NULL;
2744 const char* name=NULL;
2746 cpl_propertylist* phead=NULL;
2747 cpl_propertylist* xhead=NULL;
2754 xsh_msg(
"Trace object position");
2755 check(name=cpl_frame_get_filename(frm_ima));
2756 nbext=cpl_frame_get_nextensions( frm_ima);
2758 table_tot=cpl_table_new(0);
2759 phead=cpl_propertylist_load(name,0);
2760 for(k=0;k<nbext;k+=3){
2761 nrow=cpl_table_get_nrow(table_tot);
2763 check(data_ima=cpl_image_load(name,CPL_TYPE_DOUBLE,0,k));
2764 xhead=cpl_propertylist_load(name,k);
2767 if(k==0)
check(cpl_table_copy_structure(table_tot,table));
2768 cpl_table_insert(table_tot,table,nrow);
2773 sprintf(tag,
"OBJ_POS_ORD_%s_%s",
2775 sprintf(fname,
"%s.fits",tag);
2777 check(cpl_table_save(table_tot,phead,NULL,fname,CPL_IO_DEFAULT));
2780 CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL);
2809static cpl_error_code
2812 cpl_propertylist* plist)
2834 check(cpl_table_and_selected_double(table,
"WAVELENGTH",CPL_GREATER_THAN,wmin));
2835 check(cpl_table_and_selected_double(table,
"WAVELENGTH",CPL_LESS_THAN,wmax));
2837 check(cpl_table_select_all(table));
2843 check(res_med=cpl_table_get_column_median(
qc_table,
"RES12"));
2844 check(res_rms=cpl_table_get_column_stdev(
qc_table,
"RES12"));
2858 res_min=cpl_table_get_column_min(
qc_table,
"RES32");
2859 res_max=cpl_table_get_column_max(
qc_table,
"RES32");
2860 res_avg=cpl_table_get_column_mean(
qc_table,
"RES32");
2861 res_med=cpl_table_get_column_median(
qc_table,
"RES32");
2862 res_rms=cpl_table_get_column_stdev(
qc_table,
"RES32");
2876 res_min=cpl_table_get_column_min(
qc_table,
"RES13");
2877 res_max=cpl_table_get_column_max(
qc_table,
"RES13");
2878 res_avg=cpl_table_get_column_mean(
qc_table,
"RES13");
2879 res_med=cpl_table_get_column_median(
qc_table,
"RES13");
2880 res_rms=cpl_table_get_column_stdev(
qc_table,
"RES13");
2896 return cpl_error_get_code();
2922static cpl_error_code
2924 const char* col_wav,
2925 const char* col_ref,
2926 const char* col_fit,
2927 const char* qualifier,
2928 cpl_propertylist* plist)
2932 cpl_polynomial* pol=NULL;
2933 cpl_vector* vx=NULL;
2934 cpl_vector* vy=NULL;
2945 nrow=cpl_table_get_nrow(*table);
2946 cpl_table_new_column(*table,col_fit,CPL_TYPE_DOUBLE);
2947 cpl_table_fill_column_window_double(*table,col_fit,0,nrow,0.);
2949 px=cpl_table_get_data_double(*table,col_wav);
2950 py=cpl_table_get_data_double(*table,col_ref);
2951 pf=cpl_table_get_data_double(*table,col_fit);
2953 vx = cpl_vector_wrap( nrow, px );
2954 vy = cpl_vector_wrap( nrow, py );
2958 for(k=0; k< nrow; k++){
2959 check( pf[k] = cpl_polynomial_eval_1d(pol,px[k],NULL));
2965 coeff = cpl_polynomial_get_coeff(pol, &power);
2966 cpl_propertylist_append_double(plist,key_name,coeff);
2967 cpl_propertylist_set_comment(plist,key_name,
"order 0 fit coeff");
2971 coeff = cpl_polynomial_get_coeff(pol, &power);
2972 cpl_propertylist_append_double(plist,key_name,coeff);
2973 cpl_propertylist_set_comment(plist,key_name,
"order 1 fit coeff");
2977 coeff = cpl_polynomial_get_coeff(pol, &power);
2978 cpl_propertylist_append_double(plist,key_name,coeff);
2979 cpl_propertylist_set_comment(plist,key_name,
"order 2 fit coeff");
2983 cpl_vector_unwrap(vx);
2984 cpl_vector_unwrap(vy);
2986 return cpl_error_get_code();
3007static cpl_error_code
3009 const char* col_comp,
3010 const char* col_ref,
3011 cpl_propertylist* plist)
3027 const double* pw=NULL;
3034 check(cmp_c0=cpl_propertylist_get_double(plist,key_name));
3036 cmp_c1=cpl_propertylist_get_double(plist,key_name);
3038 cmp_c2=cpl_propertylist_get_double(plist,key_name);
3041 ref_c0=cpl_propertylist_get_double(plist,key_name);
3043 ref_c1=cpl_propertylist_get_double(plist,key_name);
3045 ref_c2=cpl_propertylist_get_double(plist,key_name);
3048 dif_c0=cmp_c0-ref_c0;
3049 dif_c1=cmp_c1-ref_c1;
3050 dif_c2=cmp_c2-ref_c2;
3053 pw=cpl_table_get_data_double_const(table,
"WAVELENGTH");
3056 cmp_pos=cmp_c0+cmp_c1*wav+cmp_c2*wav*wav;
3057 ref_pos=ref_c0+ref_c1*wav+ref_c2*wav*wav;
3059 dif_pos=cmp_pos-ref_pos;
3069 cpl_propertylist_set_comment(plist,key_name,
"order 2 fit coeff diff");
3072 cpl_propertylist_set_comment(plist,key_name,
"fit trace diff pos");
3075 return cpl_error_get_code();
3110 const char* suffix,
const char* rec_prefix,
3111 const int win_min,
const int win_max,
3113 const int method,
const int compute_qc)
3115 cpl_frame* result=NULL;
3116 cpl_table* table=NULL;
3117 cpl_image* data_ima=NULL;
3119 cpl_imagelist* data_iml=NULL;
3120 cpl_imagelist* errs_iml=NULL;
3121 cpl_imagelist* swap1=NULL;
3122 cpl_imagelist* swap2=NULL;
3123 cpl_imagelist* data_swap=NULL;
3124 cpl_imagelist* errs_swap=NULL;
3126 const char* name=NULL;
3151 cpl_propertylist* plist=NULL;
3155 check(name=cpl_frame_get_filename(frm_cube));
3158 check(data_iml=cpl_imagelist_load(name,CPL_TYPE_DOUBLE,0));
3159 plist=cpl_propertylist_load(name,0);
3163 swap1=cpl_imagelist_swap_axis_create(data_iml,CPL_SWAP_AXIS_XZ);
3165 swap2=cpl_imagelist_swap_axis_create(swap1,CPL_SWAP_AXIS_YZ);
3167 data_swap=cpl_imagelist_swap_axis_create(swap2,CPL_SWAP_AXIS_XZ);
3171 check(errs_iml=cpl_imagelist_load(name,CPL_TYPE_DOUBLE,0));
3173 swap1=cpl_imagelist_swap_axis_create(errs_iml,CPL_SWAP_AXIS_XZ);
3175 swap2=cpl_imagelist_swap_axis_create(swap1,CPL_SWAP_AXIS_YZ);
3177 errs_swap=cpl_imagelist_swap_axis_create(swap2,CPL_SWAP_AXIS_XZ);
3181 check(naxis3=cpl_imagelist_get_size(data_swap));
3182 data_ima=cpl_imagelist_get(data_swap,0);
3184 naxis2=cpl_image_get_size_y(data_ima);
3186 table=cpl_table_new(naxis3);
3187 cpl_table_new_column(table,
"WAVELENGTH",CPL_TYPE_DOUBLE);
3189 cpl_table_new_column(table,
"POS_1",CPL_TYPE_DOUBLE);
3190 cpl_table_new_column(table,
"POS_2",CPL_TYPE_DOUBLE);
3191 cpl_table_new_column(table,
"POS_3",CPL_TYPE_DOUBLE);
3193 pwav=cpl_table_get_data_double(table,
"WAVELENGTH");
3194 pcx1=cpl_table_get_data_double(table,
"POS_1");
3195 pcx2=cpl_table_get_data_double(table,
"POS_2");
3196 pcx3=cpl_table_get_data_double(table,
"POS_3");
3198 cpl_table_fill_column_window_double(table,
"WAVELENGTH",0,naxis3,0.);
3199 cpl_table_fill_column_window_double(table,
"POS_1",0,naxis3,0.);
3200 cpl_table_fill_column_window_double(table,
"POS_2",0,naxis3,0.);
3201 cpl_table_fill_column_window_double(table,
"POS_3",0,naxis3,0.);
3204 for(k=0;k<naxis3;k++) {
3206 check(data_ima=cpl_imagelist_get(data_swap,k));
3208 pwav[k]=crval3+cdelt3*k;
3210 for(j=1;j<=naxis2;j++) {
3211 check(cpl_image_get_maxpos_window(data_ima,
3212 win_min,j,win_max,j,&mx,&my));
3213 llx=(mx-hsize>win_min) ? mx-hsize:win_min;
3214 urx=(mx+hsize<win_max) ? mx+hsize:win_max;
3218 check(cx=cpl_image_get_centroid_x_window(data_ima,
llx,j,
urx,j));
3223 case 1: pcx1[k]=cx;
break;
3224 case 2: pcx2[k]=cx;
break;
3225 case 3: pcx3[k]=cx;
break;
3232 cpl_table_duplicate_column(table,
"RES12",table,
"POS_1");
3233 cpl_table_subtract_columns(table,
"RES12",
"POS_2");
3235 cpl_table_duplicate_column(table,
"RES32",table,
"POS_3");
3236 cpl_table_subtract_columns(table,
"RES32",
"POS_2");
3238 cpl_table_duplicate_column(table,
"RES13",table,
"POS_1");
3239 cpl_table_subtract_columns(table,
"RES13",
"POS_3");
3254 sprintf(tag,
"%s_%s_TRACE_OBJ_%s",
3256 sprintf(fname,
"%s.fits",tag);
3257 check(cpl_table_save(table,plist,NULL,fname,CPL_IO_DEFAULT));
3259 CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL);
3286 cpl_imagelist** mask,
3287 const cpl_image* data_ima,
3288 const cpl_image* mask_ima,
3291 cpl_image* data_tmp=NULL;
3292 cpl_image* mask_tmp=NULL;
3297 check(
size=cpl_imagelist_get_size(*mask));
3299 check(data_tmp=cpl_imagelist_get(*
data,mk));
3300 check(mask_tmp=cpl_imagelist_get(*mask,mk));
3301 check(pmsk=cpl_image_get_data_int(mask_tmp));
3303 check(norm=pmsk[1]+1);
3304 check(cpl_image_add(data_tmp,data_ima));
3305 check(cpl_image_divide_scalar(data_tmp,norm));
3306 check(cpl_image_add_scalar(mask_tmp,1));
3307 check(cpl_imagelist_set(*mask,cpl_image_duplicate(mask_ima),mk));
3308 check(cpl_imagelist_set(*
data,cpl_image_duplicate(data_tmp),mk));
3311 check(cpl_imagelist_set(*mask,cpl_image_duplicate(mask_ima),mk));
3312 check(cpl_imagelist_set(*
data,cpl_image_duplicate(data_ima),mk));
3320 return cpl_error_get_code();
3334 cpl_imagelist** errs,
3335 cpl_imagelist** qual,
3336 const cpl_image* flux_b,
3337 const cpl_image* errs_b,
3338 const cpl_image* qual_b,
3339 const int mk,
const int decode_bp)
3342 cpl_image* flux_a=NULL;
3343 cpl_image* errs_a=NULL;
3344 cpl_image* qual_a=NULL;
3347 cpl_image* flux_r=NULL;
3348 cpl_image* errs_r=NULL;
3349 cpl_image* qual_r=NULL;
3350 cpl_image* weight_a=NULL;
3351 cpl_image* weight_b=NULL;
3359 check(flux_a=cpl_imagelist_get(*
data,mk));
3360 check(errs_a=cpl_imagelist_get(*errs,mk));
3361 check(qual_a=cpl_imagelist_get(*qual,mk));
3371 weight_a = cpl_image_duplicate(errs_a);
3372 weight_b = cpl_image_duplicate(errs_b);
3374 cpl_image_power(weight_a,-2);
3375 cpl_image_power(weight_b,-2);
3377 cpl_image* tmp_ima=cpl_image_duplicate(weight_a);
3378 cpl_image_add(tmp_ima,weight_b);
3379 cpl_image_power(tmp_ima,-1);
3380 errs_r = cpl_image_duplicate(tmp_ima);
3381 cpl_image_power(errs_r,0.5);
3383 cpl_image_multiply(weight_a,flux_a);
3384 cpl_image_multiply(weight_b,flux_b);
3386 cpl_image_add(weight_a,weight_b);
3388 flux_r=cpl_image_duplicate(weight_a);
3390 cpl_image_multiply(flux_r,tmp_ima);
3392 qual_r = cpl_image_duplicate(qual_a);
3400 check(cpl_imagelist_set(*
data,cpl_image_duplicate(flux_r),mk));
3401 check(cpl_imagelist_set(*errs,cpl_image_duplicate(errs_r),mk));
3402 check(cpl_imagelist_set(*qual,cpl_image_duplicate(qual_r),mk));
3409 check(cpl_imagelist_set(*
data,cpl_image_duplicate(flux_b),mk));
3410 check(cpl_imagelist_set(*errs,cpl_image_duplicate(errs_b),mk));
3411 check(cpl_imagelist_set(*qual,cpl_image_duplicate(qual_b),mk));
3416 return cpl_error_get_code();
3433 cpl_image* diff=NULL;
3434 cpl_image* flat_smooth=NULL;
3435 cpl_array* val=NULL;
3436 cpl_matrix* mx=NULL;
3445 int filter_width_x=7;
3446 int filter_width_y=7;
3454 const char* filename;
3459 filename=cpl_frame_get_filename(flat_frame);
3460 tag=cpl_frame_get_tag(flat_frame);
3471 if (
binx>1) filter_width_x=5;
3472 if (
biny>1) filter_width_y=5;
3476 check(mx=cpl_matrix_new(filter_width_x,filter_width_y));
3478 for(j=0; j< filter_width_y; j++){
3479 for(i=0; i< filter_width_x; i++){
3480 cpl_matrix_set( mx, i,j,1.0);
3485 check(diff=cpl_image_duplicate(mflat->
data));
3493 check(cpl_image_subtract(diff,flat_smooth));
3500 check(cpl_image_divide(diff,mflat->
errs));
3505 check(pqual=cpl_image_get_data_int(mflat->
qual));
3506 check(pima=cpl_image_get_data_float(diff));
3508 for(i=0;i<npixs;i++) {
3509 if(fabs(pima[i])>
kappa) {
3515 cpl_frame* frm=NULL;
3527 return cpl_error_get_code();
3542 int nx = 0,
ny = 0, nimg = 0, i = 0;
3543 float **pdata = NULL;
3544 cpl_binary ** pbinary = NULL;
3545 float* errsdata = NULL;
3546 double mpi_2=0.5*
M_PI;
3547 check(nimg = cpl_imagelist_get_size (list));
3548 assure(nimg > 0,CPL_ERROR_ILLEGAL_INPUT,
"you must have image to collapse");
3551 pdata = cpl_malloc (nimg *
sizeof (
float *));
3552 assure (pdata != NULL, cpl_error_get_code (),
3553 "Cant allocate memory for data pointers");
3555 pbinary = cpl_malloc (nimg *
sizeof (cpl_binary *));
3556 assure (pbinary != NULL, cpl_error_get_code (),
3557 "Cant allocate memory for binary pointers");
3560 for (i = 0; i < nimg; i++) {
3561 check( pdata[i] = cpl_image_get_data_float(cpl_imagelist_get (list, i)));
3562 check( pbinary[i] = cpl_mask_get_data(cpl_image_get_bpm(
3563 cpl_imagelist_get(list, i))));
3567 check(
nx = cpl_image_get_size_x (cpl_imagelist_get (list, 0)));
3568 check(
ny = cpl_image_get_size_y (cpl_imagelist_get (list, 0)));
3569 check(errsdata = cpl_image_get_data_float(errs));
3572 for (i = 0; i <
nx *
ny; i++){
3575 double errval = 0.0;
3577 for (count = 0, k = 0; k < nimg; k++) {
3579 if ( ((pbinary[k])[i] == CPL_BINARY_0) ) {
3580 errval += (pdata[k])[i] * (pdata[k])[i];
3589 errsdata[i] = sqrt (errval)/((double)count);
3590 }
else if (
mode==0){
3593 errsdata[i] = sqrt (errval)/((double)count);
3595 errsdata[i] = sqrt ( mpi_2*errval / ((
double)(count*(count- 1.))) );
3598 }
else if ( count == 1 ) {
3599 errsdata[i] = sqrt (errval);
3605 return cpl_error_get_code();
3632 cpl_image* ima_comb=NULL;
3633 cpl_image* ima_mask=NULL;
3640 double* point_mask=NULL;
3659 cpl_image* ima1=NULL;
3660 cpl_image* ima2=NULL;
3662 cpl_table *ordertable = NULL;
3663 cpl_propertylist *otab_header = NULL;
3664 cpl_polynomial *otab_traces = NULL;
3666 ima1=cpl_image_cast(ima1_in,CPL_TYPE_DOUBLE);
3667 ima2=cpl_image_cast(ima2_in,CPL_TYPE_DOUBLE);
3668 xsh_msg(
"list size=%d ord_min=%d ord_max=%d",
3698 sx=cpl_image_get_size_x(ima1);
3699 sy=cpl_image_get_size_y(ima1);
3700 assure(sx==cpl_image_get_size_x(ima2),CPL_ERROR_ILLEGAL_INPUT,
3702 assure(sy==cpl_image_get_size_y(ima2),CPL_ERROR_ILLEGAL_INPUT,
3724 xsh_msg(
"xpos min=%d max=%d",xpos_min,xpos_max);
3725 ima_mask = cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
3726 point_mask=cpl_image_get_data_double(ima_mask);
3729 for(i=xpos_max;i<sx;i++) {
3730 point_mask[j*sx+i]=1.;
3740 for(i=xpos_min;i<xpos_max;i++) {
3755 point_mask[j*sx+i] = 1.;
3776 fflux=cpl_image_get_median_window(ima1,
llx,
lly,
urx,
ury);
3787 dflux=cpl_image_get_median_window(ima2,
llx,
lly,
urx,
ury);
3791 xsh_msg(
"flux: n=%g d=%g s=%g",fflux,dflux,scale);
3794 ima_comb=cpl_image_duplicate(ima1);
3795 cpl_image_multiply(ima_comb,ima_mask);
3796 cpl_image_multiply_scalar(ima_mask,-1.);
3797 cpl_image_add_scalar(ima_mask,1.);
3798 cpl_image_multiply(ima2,ima_mask);
3799 cpl_image_multiply_scalar(ima2,scale);
3800 cpl_image_add(ima_comb,ima2);
3819 const char* name_o,
const int ext_i,
3821 const char* name = NULL;
3822 cpl_image* ima = NULL;
3823 cpl_propertylist* plist = NULL;
3825 name = cpl_frame_get_filename(frm);
3836 return cpl_error_get_code();
3841 const char* name = NULL;
3842 name = cpl_frame_get_filename(frm);
3843 cpl_image* ima = NULL;
3844 cpl_propertylist* plist = NULL;
3846 name=cpl_frame_get_filename(frm);
3848 plist=cpl_propertylist_load(name,0);
3850 cpl_image_add_scalar(ima,value);
3855 return cpl_error_get_code();
3859static cpl_error_code
3864 if(cpl_propertylist_has(*plist,kname) > 0) {
3867 check(cpl_propertylist_set_int(*plist,kname,value*fct));
3871 cpl_propertylist_append_int(*plist,kname,1);
3876 return cpl_error_get_code();
3879static cpl_error_code
3884 if(cpl_propertylist_has(*plist,kname) > 0) {
3887 check(cpl_propertylist_set_int(*plist,kname,value/fct));
3891 cpl_propertylist_append_int(*plist,kname,1);
3896 return cpl_error_get_code();
3900static cpl_error_code
3911 return cpl_error_get_code();
3928 cpl_image* ima_datr=NULL;
3930 const float* pdat=NULL;
3938 check(sx=cpl_image_get_size_x(ima_dat));
3939 check(sy=cpl_image_get_size_y(ima_dat));
3941 xsh_msg(
"org image size dat: %d %d",sx,sy);
3945 check(ima_datr=cpl_image_new(
nx,
ny,CPL_TYPE_FLOAT));
3947 check(pdat=cpl_image_get_data_float_const(ima_dat));
3948 check(pdatr=cpl_image_get_data_float(ima_datr));
3951 for (j = 0; j <
ny; j++) {
3952 for (
m = 0;
m < fcty;
m++) {
3953 for (i = 0; i <
nx; i++) {
3954 for (k = 0; k < fctx; k++) {
3959 pdatr[i + j *
nx] += pdat[i * fctx + k + (j * fcty +
m) * fctx *
nx];
3964 pdatr[i + j *
nx] /= (fctx * fcty);
3983 cpl_image* ima_datr=NULL;
3985 const float* pdat=NULL;
3993 check(
nx=cpl_image_get_size_x(ima_dat));
3994 check(
ny=cpl_image_get_size_y(ima_dat));
3997 check(ima_datr=cpl_image_new(fctx*
nx,fcty*
ny,CPL_TYPE_FLOAT));
3998 xsh_msg(
"new image size dat: %d %d",fctx*
nx,fcty*
ny);
4000 check(pdat=cpl_image_get_data_float_const(ima_dat));
4001 check(pdatr=cpl_image_get_data_float(ima_datr));
4004 for(
m=0;
m<fcty;
m++) {
4006 for(k=0;k<fctx;k++) {
4009 pdatr[i*fctx+k+(j*fcty+
m)*fctx*
nx]=pdat[i+j*
nx];
4024 const char* name=NULL;
4025 cpl_propertylist* plist=NULL;
4026 cpl_propertylist* hext=NULL;
4027 cpl_image* ima_dat=NULL;
4028 cpl_image* ima_datr=NULL;
4037 cpl_frame* frm_cor=NULL;
4038 const char* tag=NULL;
4040 const char* basename=NULL;
4043 check(name=cpl_frame_get_filename(frm));
4044 check(tag=cpl_frame_get_tag(frm));
4045 next=cpl_frame_get_nextensions(frm);
4046 check(plist=cpl_propertylist_load(name,0));
4052 xsh_msg(
"Prescan: %d,%d Overscan: %d,%d",prscx,prscy,ovscx,ovscy);
4057 sprintf(new_name,
"fctx%d_fcty%d_%s",fctx,fcty,basename);
4058 xsh_msg(
"new_name=%s",new_name);
4060 for(kk=0;kk<=next;kk++) {
4062 check(ima_dat=cpl_image_load(name,CPL_TYPE_FLOAT,0,kk));
4063 check(hext=cpl_propertylist_load(name,kk));
4082 frm_cor=cpl_frame_new();
4083 cpl_frame_set_filename(frm_cor,new_name);
4084 check(cpl_frame_set_tag(frm_cor,tag));
4085 cpl_frame_set_type(frm_cor,CPL_FRAME_TYPE_IMAGE);
4086 cpl_frame_set_group(frm_cor,CPL_FRAME_GROUP_CALIB);
4103 const char* name=NULL;
4104 cpl_propertylist* plist=NULL;
4105 cpl_propertylist* hext=NULL;
4106 cpl_image* ima_dat=NULL;
4107 cpl_image* ima_datr=NULL;
4116 cpl_frame* frm_cor=NULL;
4117 const char* tag=NULL;
4118 const char* basename=NULL;
4121 check(name=cpl_frame_get_filename(frm));
4122 check(tag=cpl_frame_get_tag(frm));
4123 next=cpl_frame_get_nextensions(frm);
4124 check(plist=cpl_propertylist_load(name,0));
4131 xsh_msg(
"Prescan: %d,%d Overscan: %d,%d",prscx,prscy,ovscx,ovscy);
4133 sprintf(new_name,
"fctx%d_fcty%d_%s",fctx,fcty,basename);
4134 xsh_msg(
"new_name=%s",new_name);
4137 for(kk=0;kk<=next;kk++) {
4139 check(ima_dat=cpl_image_load(name,CPL_TYPE_FLOAT,0,kk));
4140 check(hext=cpl_propertylist_load(name,kk));
4160 frm_cor=cpl_frame_new();
4161 cpl_frame_set_filename(frm_cor,new_name);
4162 cpl_frame_set_tag(frm_cor,tag);
4163 cpl_frame_set_type(frm_cor,CPL_FRAME_TYPE_IMAGE);
4164 cpl_frame_set_group(frm_cor,CPL_FRAME_GROUP_CALIB);
4173 cpl_propertylist* phead=NULL;
4174 cpl_propertylist* dhead=NULL;
4175 cpl_propertylist* ehead=NULL;
4176 cpl_propertylist* qhead=NULL;
4177 cpl_image* org_data_ima=NULL;
4178 cpl_image* cut_data_ima=NULL;
4179 cpl_image* org_errs_ima=NULL;
4180 cpl_image* cut_errs_ima=NULL;
4181 cpl_image* org_qual_ima=NULL;
4182 cpl_image* cut_qual_ima=NULL;
4184 const char* fname=NULL;
4199 fname=cpl_frame_get_filename(frame1d);
4200 next=cpl_frame_get_nextensions(frame1d);
4201 phead = cpl_propertylist_load(fname, 0);
4205 check(naxis1=cpl_image_get_size_x(org_data_ima));
4206 check(naxis2=cpl_image_get_size_y(org_data_ima));
4213 wave_max = wave_min + cdelt1*naxis1;
4214 cpl_ensure_code(wave_max > wave_cut, CPL_ERROR_ILLEGAL_INPUT);
4215 xcut = (int) ( (wave_cut-wave_min) / cdelt1 + 0.5 );
4216 cpl_ensure_code(xcut <= naxis1, CPL_ERROR_ILLEGAL_INPUT);
4218 if (xcut == naxis1) {
4219 return CPL_ERROR_NONE;
4221 sprintf(oname,
"tmp_%s",fname);
4223 for(i=0;i<next;i+=3) {
4228 dhead = cpl_propertylist_load(fname, i);
4229 ehead = cpl_propertylist_load(fname, i+1);
4230 qhead = cpl_propertylist_load(fname, i+2);
4232 cut_data_ima=cpl_image_extract(org_data_ima,1,1,xcut,naxis2);
4233 cut_errs_ima=cpl_image_extract(org_errs_ima,1,1,xcut,naxis2);
4234 cut_qual_ima=cpl_image_extract(org_qual_ima,1,1,xcut,naxis2);
4236 cpl_image_save( cut_data_ima, oname, CPL_BPP_IEEE_FLOAT, phead,
4238 cpl_image_save( cut_errs_ima, oname, CPL_BPP_IEEE_FLOAT, ehead,
4240 cpl_image_save( cut_qual_ima, oname, CPL_BPP_IEEE_FLOAT, qhead,
4249 cpl_image_save( org_data_ima, oname, CPL_BPP_IEEE_FLOAT, dhead,
4251 cpl_image_save( org_errs_ima, oname, CPL_BPP_IEEE_FLOAT, ehead,
4253 cpl_image_save( org_qual_ima, oname, CPL_BPP_IEEE_FLOAT, qhead,
4265 sprintf(cmd,
"mv %s %s",oname,fname);
4266 assure(system(cmd)==0,CPL_ERROR_UNSPECIFIED,
"unable to mv file");
4270 if(cpl_error_get_code() != CPL_ERROR_NONE) {
4273 return cpl_error_get_code();
4279 const int mode,
const int win_hsz)
4293 int win_sx=2*win_hsx+1;
4294 int win_sy=2*win_hsy+1;
4295 int sz=cpl_imagelist_get_size(iml_data);
4298 double sum_good_pix;
4306 cpl_imagelist* iml_good;
4307 cpl_imagelist* iml_all;
4309 cpl_binary* pbpm_tmp;
4311 cpl_mask* not=cpl_mask_duplicate(bpm);
4313 cpl_binary* pnot=cpl_mask_get_data(not);
4315 ima_tmp=cpl_imagelist_get(iml_data,0);
4316 cpl_imagelist* iml_copy=cpl_imagelist_duplicate(iml_data);
4318 int sx=cpl_image_get_size_x(ima_tmp);
4319 int sy=cpl_image_get_size_y(ima_tmp);
4321 res=cpl_image_new(sx,sy,CPL_TYPE_FLOAT);
4322 cpl_image_add_scalar(res,1.);
4323 pres=cpl_image_get_data(res);
4324 pbpm=cpl_mask_get_data(bpm);
4332 for(
int j=0;j<sy;j++) {
4336 for(
int i=0;i<sx;i++) {
4342 if ( pbpm[pix] == CPL_BINARY_0 ) {
4346 }
else if ( pbpm[pix] == CPL_BINARY_1 ) {
4353 int y_min=j-win_hsy, y_max=j+win_hsy;
4360 }
else if ( y_max > sy) {
4366 int x_min=i-win_hsx, x_max=i+win_hsx;
4372 }
else if ( x_max > sx) {
4386 iml_all = cpl_imagelist_new();
4387 iml_good = cpl_imagelist_new();
4391 for(
int k=0;k<sz;k++) {
4392 ima_tmp=cpl_imagelist_get(iml_copy,k);
4394 cpl_imagelist_set(iml_good,cpl_image_duplicate(ima_tmp),k);
4395 cpl_imagelist_set(iml_all,cpl_image_duplicate(ima_tmp),k);
4404 for(
int k=0;k<sz-frame_bad;k++) {
4406 ima_tmp=cpl_imagelist_get(iml_good,k);
4407 pdata=cpl_image_get_data_float(ima_tmp);
4408 bpm_tmp=cpl_image_get_bpm(ima_tmp);
4409 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
4411 if(pbpm_tmp[pix] == CPL_BINARY_1) {
4413 ima_tmp=cpl_imagelist_unset(iml_good,k);
4414 bpm_tmp=cpl_image_unset_bpm(ima_tmp);
4415 cpl_mask_delete(bpm_tmp);
4416 cpl_image_delete(ima_tmp);
4426 for(
int k=0;k<sz-frame_bad;k++) {
4427 ima_tmp=cpl_imagelist_get(iml_good,k);
4428 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
4429 cpl_mask_delete(bpm_tmp);
4433 for(
int k=0;k<sz;k++) {
4434 ima_tmp=cpl_imagelist_get(iml_all,k);
4435 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
4436 cpl_mask_delete(bpm_tmp);
4446 for(
y=y_min;
y <= y_max;
y++) {
4448 for(
x=x_min;
x <= x_max;
x++) {
4453 for(
int k=0;k<sz;k++) {
4454 ima_tmp=cpl_imagelist_get(iml_all,k);
4455 pdata=cpl_image_get_data_float(ima_tmp);
4456 bpm_tmp=cpl_image_get_bpm(ima_tmp);
4457 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
4459 if(pbpm_tmp[point] == CPL_BINARY_0) {
4460 sum_all += pdata[point];
4467 for(
int k=0;k<sz-frame_bad;k++) {
4468 ima_tmp=cpl_imagelist_get(iml_good,k);
4469 pdata=cpl_image_get_data_float(ima_tmp);
4470 bpm_tmp=cpl_image_get_bpm(ima_tmp);
4471 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
4473 if( pbpm[point] == CPL_BINARY_0 ) {
4474 sum_good += pdata[point];
4479 for(
int k=0;k<sz-frame_bad;k++) {
4480 ima_tmp=cpl_imagelist_get(iml_good,k);
4481 pdata=cpl_image_get_data_float(ima_tmp);
4483 if( pnot[pix] == CPL_BINARY_0 && pix != point) {
4484 sum_good_pix += pdata[pix];
4488 if( pnot[pix] == CPL_BINARY_0 && pix == point) {
4489 sum_tot_pix += pdata[pix];
4497 scale = sum_all / sum_good;
4500 pres[pix]=scale*num_tot_pix/sz;
4501 if( isnan( pres[pix] ) ) {
4510 int n=cpl_imagelist_get_size(iml_good);
4512 for(
int k=0;k<
n;k++) {
4513 ima_tmp=cpl_imagelist_get(iml_good,k);
4514 cpl_image_delete(ima_tmp);
4516 for(
int k=0;k<sz;k++) {
4517 ima_tmp=cpl_imagelist_get(iml_all,k);
4518 cpl_image_delete(ima_tmp);
4521 cpl_imagelist_unwrap(iml_good);
4522 cpl_imagelist_unwrap(iml_all);
4526 cpl_imagelist_delete(iml_copy);
4527 cpl_mask_delete(not);
4533 const int mode,
const int win_hsz)
4547 int win_sx=2*win_hsx+1;
4548 int win_sy=2*win_hsy+1;
4549 int sz=cpl_imagelist_get_size(iml_data);
4552 double sum_good_pix;
4561 cpl_imagelist* iml_good;
4562 cpl_imagelist* iml_all;
4564 cpl_binary* pbpm_tmp;
4566 cpl_mask* not=cpl_mask_duplicate(bpm);
4568 cpl_binary* pnot=cpl_mask_get_data(not);
4570 ima_tmp=cpl_imagelist_get(iml_data,0);
4571 cpl_imagelist* iml_copy=cpl_imagelist_duplicate(iml_data);
4573 int sx=cpl_image_get_size_x(ima_tmp);
4574 int sy=cpl_image_get_size_y(ima_tmp);
4576 res=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
4577 cpl_image_add_scalar(res,1.);
4578 pres=cpl_image_get_data(res);
4580 int* px=cpl_table_get_data_int(tab_bpm,
"x");
4581 int* py=cpl_table_get_data_int(tab_bpm,
"y");
4582 int size=cpl_table_get_nrow(tab_bpm);
4583 pbpm=cpl_mask_get_data(bpm);
4610 int y_min=j-win_hsy, y_max=j+win_hsy;
4617 }
else if ( y_max > sy) {
4623 int x_min=i-win_hsx, x_max=i+win_hsx;
4629 }
else if ( x_max > sx) {
4643 iml_all = cpl_imagelist_new();
4644 iml_good = cpl_imagelist_new();
4648 for(
int k=0;k<sz;k++) {
4649 ima_tmp=cpl_imagelist_get(iml_copy,k);
4651 cpl_imagelist_set(iml_good,cpl_image_duplicate(ima_tmp),k);
4652 cpl_imagelist_set(iml_all,cpl_image_duplicate(ima_tmp),k);
4661 for(
int k=0;k<sz-frame_bad;k++) {
4663 ima_tmp=cpl_imagelist_get(iml_good,k);
4664 pdata=cpl_image_get_data_float(ima_tmp);
4665 bpm_tmp=cpl_image_get_bpm(ima_tmp);
4666 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
4668 if(pbpm_tmp[pix] == CPL_BINARY_1) {
4670 ima_tmp=cpl_imagelist_unset(iml_good,k);
4671 bpm_tmp=cpl_image_unset_bpm(ima_tmp);
4672 cpl_mask_delete(bpm_tmp);
4673 cpl_image_delete(ima_tmp);
4683 for(
int k=0;k<sz-frame_bad;k++) {
4684 ima_tmp=cpl_imagelist_get(iml_good,k);
4685 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
4686 cpl_mask_delete(bpm_tmp);
4690 for(
int k=0;k<sz;k++) {
4691 ima_tmp=cpl_imagelist_get(iml_all,k);
4692 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
4693 cpl_mask_delete(bpm_tmp);
4702 for(
y=y_min;
y <= y_max;
y++) {
4704 for(
x=x_min;
x <= x_max;
x++) {
4709 for(
int k=0;k<sz;k++) {
4710 ima_tmp=cpl_imagelist_get(iml_all,k);
4711 pdata=cpl_image_get_data_float(ima_tmp);
4712 bpm_tmp=cpl_image_get_bpm(ima_tmp);
4713 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
4714 if(pbpm_tmp[point] == CPL_BINARY_0) {
4715 sum_all += pdata[point];
4722 for(
int k=0;k<sz-frame_bad;k++) {
4723 ima_tmp=cpl_imagelist_get(iml_good,k);
4724 pdata=cpl_image_get_data_float(ima_tmp);
4725 bpm_tmp=cpl_image_get_bpm(ima_tmp);
4726 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
4728 if( pbpm[point] == CPL_BINARY_0 ) {
4729 sum_good += pdata[point];
4734 for(
int k=0;k<sz-frame_bad;k++) {
4735 ima_tmp=cpl_imagelist_get(iml_good,k);
4736 pdata=cpl_image_get_data_float(ima_tmp);
4738 if( pnot[pix] == CPL_BINARY_0 && pix != point) {
4739 sum_good_pix += pdata[pix];
4743 if( pnot[pix] == CPL_BINARY_0 && pix == point) {
4744 sum_tot_pix += pdata[pix];
4752 scale = sum_all / sum_good;
4756 pres[pix]=scale*num_tot_pix/sz;
4759 xsh_msg(
"sum all %g good %g good_pix %g num_good %d sum_tot_pix %g num_tot_pix %d scale %g res: %g",
4760 sum_all,sum_good,sum_good_pix, num_good_pix, sum_tot_pix, num_tot_pix, scale, pres[pix]);
4763 int n=cpl_imagelist_get_size(iml_good);
4765 for(
int k=0;k<
n;k++) {
4766 ima_tmp=cpl_imagelist_get(iml_good,k);
4767 cpl_image_delete(ima_tmp);
4769 for(
int k=0;k<sz;k++) {
4770 ima_tmp=cpl_imagelist_get(iml_all,k);
4771 cpl_image_delete(ima_tmp);
4778 cpl_imagelist_unwrap(iml_good);
4779 cpl_imagelist_unwrap(iml_all);
4783 cpl_imagelist_delete(iml_copy);
4784 cpl_mask_delete(not);
4791 cpl_mask* bpm, cpl_table* tab_bpm,
const int mode,
4792 const int win_hsz,
const int decode_bp)
4806 int win_sx=2*win_hsx+1;
4807 int win_sy=2*win_hsy+1;
4808 int sz=cpl_imagelist_get_size(iml_data);
4811 double sum_good_pix;
4819 cpl_image* ima_data_tmp;
4820 cpl_image* ima_qual_tmp;
4823 cpl_imagelist* iml_data_good;
4824 cpl_imagelist* iml_data_all;
4825 cpl_imagelist* iml_qual_good;
4826 cpl_imagelist* iml_qual_all;
4828 ima_data_tmp=cpl_imagelist_get(iml_data,0);
4829 cpl_imagelist* iml_data_copy=cpl_imagelist_duplicate(iml_data);
4830 cpl_imagelist* iml_qual_copy=cpl_imagelist_duplicate(iml_qual);
4831 int sx=cpl_image_get_size_x(ima_data_tmp);
4832 int sy=cpl_image_get_size_y(ima_data_tmp);
4834 res=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
4835 cpl_image_add_scalar(res,1.);
4836 pres=cpl_image_get_data(res);
4838 int* px=cpl_table_get_data_int(tab_bpm,
"x");
4839 int* py=cpl_table_get_data_int(tab_bpm,
"y");
4840 int size=cpl_table_get_nrow(tab_bpm);
4870 int y_min=j-win_hsy, y_max=j+win_hsy;
4877 }
else if ( y_max >= sy) {
4883 int x_min=i-win_hsx, x_max=i+win_hsx;
4889 }
else if ( x_max >= sx) {
4903 iml_data_all = cpl_imagelist_new();
4904 iml_data_good = cpl_imagelist_new();
4905 iml_qual_all = cpl_imagelist_new();
4906 iml_qual_good = cpl_imagelist_new();
4910 for(
int k=0;k<sz;k++) {
4911 ima_data_tmp=cpl_imagelist_get(iml_data_copy,k);
4913 cpl_imagelist_set(iml_data_good,cpl_image_duplicate(ima_data_tmp),k);
4914 cpl_imagelist_set(iml_data_all,cpl_image_duplicate(ima_data_tmp),k);
4918 ima_qual_tmp=cpl_imagelist_get(iml_qual_copy,k);
4920 cpl_imagelist_set(iml_qual_good,cpl_image_duplicate(ima_qual_tmp),k);
4921 cpl_imagelist_set(iml_qual_all,cpl_image_duplicate(ima_qual_tmp),k);
4930 for(
int k=0;k<sz-frame_bad;k++) {
4932 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
4933 pdata=cpl_image_get_data_float(ima_data_tmp);
4936 ima_qual_tmp=cpl_imagelist_get(iml_qual_good,k);
4937 pqual=cpl_image_get_data_int(ima_qual_tmp);
4940 if( (pqual[pix] & decode_bp) > 0) {
4942 ima_data_tmp=cpl_imagelist_unset(iml_data_good,k);
4943 cpl_image_delete(ima_data_tmp);
4945 ima_qual_tmp=cpl_imagelist_unset(iml_qual_good,k);
4946 cpl_image_delete(ima_qual_tmp);
4956 for(
int k=0;k<sz-frame_bad;k++) {
4957 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
4958 bpm_tmp=cpl_image_set_bpm(ima_data_tmp,cpl_mask_duplicate(bpm));
4959 cpl_mask_delete(bpm_tmp);
4963 for(
int k=0;k<sz;k++) {
4964 ima_data_tmp=cpl_imagelist_get(iml_data_all,k);
4965 bpm_tmp=cpl_image_set_bpm(ima_data_tmp,cpl_mask_duplicate(bpm));
4966 cpl_mask_delete(bpm_tmp);
4975 for(
y=y_min;
y <= y_max;
y++) {
4977 for(
x=x_min;
x <= x_max;
x++) {
4982 for(
int k=0;k<sz;k++) {
4983 ima_data_tmp=cpl_imagelist_get(iml_data_all,k);
4984 pdata=cpl_image_get_data_float(ima_data_tmp);
4986 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
4987 pqual=cpl_image_get_data_int(ima_qual_tmp);
4989 if((pqual[point] & decode_bp) == 0) {
4990 sum_all += pdata[point];
4997 for(
int k=0;k<sz-frame_bad;k++) {
4998 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
4999 pdata=cpl_image_get_data_float(ima_data_tmp);
5001 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
5002 pqual=cpl_image_get_data_int(ima_qual_tmp);
5005 if( (pqual[point] & decode_bp) == 0 ) {
5006 sum_good += pdata[point];
5011 for(
int k=0;k<sz-frame_bad;k++) {
5012 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
5013 pdata=cpl_image_get_data_float(ima_data_tmp);
5015 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
5016 pqual=cpl_image_get_data_int(ima_qual_tmp);
5018 if( ( (pqual[point] & decode_bp) == 0) && pix != point) {
5019 sum_good_pix += pdata[pix];
5023 if( ( (pqual[point] & decode_bp) == 0) && pix == point) {
5024 sum_tot_pix += pdata[pix];
5032 scale = sum_all / sum_good;
5036 pres[pix]=scale*num_tot_pix/sz;
5039 xsh_msg(
"sum all %g good %g good_pix %g num_good %d sum_tot_pix %g num_tot_pix %d scale %g res: %g",
5040 sum_all,sum_good,sum_good_pix, num_good_pix, sum_tot_pix, num_tot_pix, scale, pres[pix]);
5043 int n=cpl_imagelist_get_size(iml_data_good);
5045 for(
int k=0;k<
n;k++) {
5046 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
5047 cpl_image_delete(ima_data_tmp);
5049 for(
int k=0;k<sz;k++) {
5050 ima_data_tmp=cpl_imagelist_get(iml_data_all,k);
5051 cpl_image_delete(ima_data_tmp);
5054 for(
int k=0;k<
n;k++) {
5055 ima_qual_tmp=cpl_imagelist_get(iml_qual_good,k);
5056 cpl_image_delete(ima_qual_tmp);
5058 for(
int k=0;k<sz;k++) {
5059 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
5060 cpl_image_delete(ima_qual_tmp);
5067 cpl_imagelist_unwrap(iml_data_good);
5068 cpl_imagelist_unwrap(iml_data_all);
5072 cpl_imagelist_delete(iml_data_copy);
5073 cpl_imagelist_delete(iml_qual_copy);
5080 cpl_mask* bpm, cpl_table* tab_bpm,
const int mode,
5081 const int win_hsz,
const int decode_bp)
5095 int win_sx=2*win_hsx+1;
5096 int win_sy=2*win_hsy+1;
5097 int sz=cpl_imagelist_get_size(iml_data);
5100 double sum_good_pix;
5108 cpl_image* ima_data_tmp;
5109 cpl_image* ima_qual_tmp;
5112 cpl_imagelist* iml_data_good;
5113 cpl_imagelist* iml_data_all;
5114 cpl_imagelist* iml_qual_good;
5115 cpl_imagelist* iml_qual_all;
5117 ima_data_tmp=cpl_imagelist_get(iml_data,0);
5118 cpl_imagelist* iml_data_copy=cpl_imagelist_duplicate(iml_data);
5119 cpl_imagelist* iml_qual_copy=cpl_imagelist_duplicate(iml_qual);
5120 int sx=cpl_image_get_size_x(ima_data_tmp);
5121 int sy=cpl_image_get_size_y(ima_data_tmp);
5123 res=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
5124 cpl_image_add_scalar(res,1.);
5125 pres=cpl_image_get_data(res);
5127 int* px=cpl_table_get_data_int(tab_bpm,
"x");
5128 int* py=cpl_table_get_data_int(tab_bpm,
"y");
5129 int size=cpl_table_get_nrow(tab_bpm);
5159 int y_min=j-win_hsy, y_max=j+win_hsy;
5166 }
else if ( y_max >= sy) {
5172 int x_min=i-win_hsx, x_max=i+win_hsx;
5178 }
else if ( x_max >= sx) {
5192 iml_data_all = cpl_imagelist_new();
5193 iml_data_good = cpl_imagelist_new();
5194 iml_qual_all = cpl_imagelist_new();
5195 iml_qual_good = cpl_imagelist_new();
5199 for(
int k=0;k<sz;k++) {
5200 ima_data_tmp=cpl_imagelist_get(iml_data_copy,k);
5202 cpl_imagelist_set(iml_data_good,ima_data_tmp,k);
5203 cpl_imagelist_set(iml_data_all,ima_data_tmp,k);
5207 ima_qual_tmp=cpl_imagelist_get(iml_qual_copy,k);
5209 cpl_imagelist_set(iml_qual_good,ima_qual_tmp,k);
5210 cpl_imagelist_set(iml_qual_all,ima_qual_tmp,k);
5219 for(
int k=0;k<sz-frame_bad;k++) {
5221 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
5222 pdata=cpl_image_get_data_float(ima_data_tmp);
5225 ima_qual_tmp=cpl_imagelist_get(iml_qual_good,k);
5226 pqual=cpl_image_get_data_int(ima_qual_tmp);
5229 if( (pqual[pix] & decode_bp) > 0) {
5231 ima_data_tmp=cpl_imagelist_unset(iml_data_good,k);
5234 ima_qual_tmp=cpl_imagelist_unset(iml_qual_good,k);
5245 for(
int k=0;k<sz-frame_bad;k++) {
5246 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
5247 bpm_tmp=cpl_image_set_bpm(ima_data_tmp,bpm);
5249 if(bpm_tmp != NULL) { cpl_mask_delete(bpm_tmp); }
5253 for(
int k=0;k<sz;k++) {
5254 ima_data_tmp=cpl_imagelist_get(iml_data_all,k);
5255 bpm_tmp=cpl_image_set_bpm(ima_data_tmp,bpm);
5257 if(bpm_tmp != NULL) { cpl_mask_delete(bpm_tmp); }
5266 for(
y=y_min;
y <= y_max;
y++) {
5268 for(
x=x_min;
x <= x_max;
x++) {
5273 for(
int k=0;k<sz;k++) {
5274 ima_data_tmp=cpl_imagelist_get(iml_data_all,k);
5275 pdata=cpl_image_get_data_float(ima_data_tmp);
5277 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
5278 pqual=cpl_image_get_data_int(ima_qual_tmp);
5280 if((pqual[point] & decode_bp) == 0) {
5281 sum_all += pdata[point];
5288 for(
int k=0;k<sz-frame_bad;k++) {
5289 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
5290 pdata=cpl_image_get_data_float(ima_data_tmp);
5292 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
5293 pqual=cpl_image_get_data_int(ima_qual_tmp);
5296 if( (pqual[point] & decode_bp) == 0 ) {
5297 sum_good += pdata[point];
5302 for(
int k=0;k<sz-frame_bad;k++) {
5303 ima_data_tmp=cpl_imagelist_get(iml_data_good,k);
5304 pdata=cpl_image_get_data_float(ima_data_tmp);
5306 ima_qual_tmp=cpl_imagelist_get(iml_qual_all,k);
5307 pqual=cpl_image_get_data_int(ima_qual_tmp);
5309 if( ( (pqual[point] & decode_bp) == 0) && pix != point) {
5310 sum_good_pix += pdata[pix];
5314 if( ( (pqual[point] & decode_bp) == 0) && pix == point) {
5315 sum_tot_pix += pdata[pix];
5323 scale = sum_all / sum_good;
5327 pres[pix]=scale*num_tot_pix/sz;
5330 xsh_msg(
"sum all %g good %g good_pix %g num_good %d sum_tot_pix %g num_tot_pix %d scale %g res: %g",
5331 sum_all,sum_good,sum_good_pix, num_good_pix, sum_tot_pix, num_tot_pix, scale, pres[pix]);
5334 int n=cpl_imagelist_get_size(iml_data_good);
5336 for(
int k=0;k<
n;k++) {
5337 ima_data_tmp=cpl_imagelist_unset(iml_data_good,k);
5340 for(
int k=0;k<sz;k++) {
5341 ima_data_tmp=cpl_imagelist_unset(iml_data_all,k);
5345 for(
int k=0;k<
n;k++) {
5346 ima_qual_tmp=cpl_imagelist_unset(iml_qual_good,k);
5349 for(
int k=0;k<sz;k++) {
5350 ima_qual_tmp=cpl_imagelist_unset(iml_qual_all,k);
5358 cpl_imagelist_unwrap(iml_data_good);
5359 cpl_imagelist_unwrap(iml_data_all);
5363 cpl_imagelist_delete(iml_data_copy);
5364 cpl_imagelist_delete(iml_qual_copy);
5372 int sx=cpl_image_get_size_x(qual);
5373 int sy=cpl_image_get_size_y(qual);
5374 const int size=sx*sy;
5375 cpl_table* xy_pos=cpl_table_new(
size);
5376 cpl_table_new_column(xy_pos,
"x",CPL_TYPE_INT);
5377 cpl_table_new_column(xy_pos,
"y",CPL_TYPE_INT);
5378 int* px=cpl_table_get_data_int(xy_pos,
"x");
5379 int* py=cpl_table_get_data_int(xy_pos,
"y");
5381 int* pqual=cpl_image_get_data_int(qual);
5386 for(
int j=0;j<sy;j++){
5388 for(
int i=0;i<sx;i++){
5390 if ( (pqual[pix] & code) > 0) {
5398 cpl_table_set_size(xy_pos,k);
static xsh_instrument * instrument
cpl_error_code xsh_badpixelmap_image_coadd(cpl_image **self, const cpl_image *right, const int mode)
int xsh_order_list_eval_int(xsh_order_list *list, cpl_polynomial *poly, double y)
Evaluate an order list poly but return the central pixel position rounding the polynomial.
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_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
#define XSH_ASSURE_NOT_NULL_MSG(pointer, msg)
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_msg(...)
#define XSH_ASSURE_NOT_NULL(pointer)
#define cknull_msg(NULLEXP,...)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_high(...)
int xsh_pfits_get_ovscx(const cpl_propertylist *plist)
find out the OVSCX value
double xsh_pfits_get_cdelt3(const cpl_propertylist *plist)
find out the cdelt3
int xsh_pfits_get_ovscy(const cpl_propertylist *plist)
find out the OVSCY value
cpl_error_code xsh_plist_div_by_fct(cpl_propertylist **plist, const int fctx, const int fcty)
double xsh_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the cdelt1
int xsh_pfits_get_prscx(const cpl_propertylist *plist)
find out the PRSCX value
double xsh_pfits_get_crval1(const cpl_propertylist *plist)
find out the crval1
int xsh_pfits_get_prscy(const cpl_propertylist *plist)
find out the PRSCY value
double xsh_pfits_get_crval3(const cpl_propertylist *plist)
find out the crval3
void xsh_pfits_set_qc_ron1(cpl_propertylist *plist, double value)
void xsh_pfits_set_qc_ron1_err(cpl_propertylist *plist, double value)
void xsh_pfits_set_qc_ron2_err(cpl_propertylist *plist, double value)
void xsh_pfits_set_qc_ron2(cpl_propertylist *plist, double value)
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.
cpl_error_code xsh_get_property_value(const cpl_propertylist *plist, const char *keyword, cpl_type keywordtype, void *result)
Read a property value from a property list.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_array(cpl_array **m)
Deallocate an array and set the pointer to NULL.
void xsh_free_mask(cpl_mask **m)
Deallocate an image mask and set the pointer to NULL.
char * xsh_get_basename(const char *filename)
Return base filename.
void xsh_free_matrix(cpl_matrix **m)
Deallocate a matrix 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_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.
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
#define QFLAG_OTHER_BAD_PIXEL
#define XSH_PRE_DATA_TYPE
#define XSH_PRE_QUAL_TYPE
#define XSH_PRE_ERRS_TYPE
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
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_UVB_DICHROIC_WAVE_CUT
#define XSH_QC_TRACE12_AVG
#define XSH_QC_TRACE_FIT_DIFF_C0
#define XSH_QC_TRACE32_MAX
#define XSH_QC_TRACE13_MED
#define XSH_QC_TRACE32_MIN
#define XSH_QC_TRACE13_MIN
#define XSH_QC_TRACE12_MAX
#define XSH_QC_TRACE32_RMS
#define XSH_QC_TRACE12_MED
#define XSH_QC_TRACE13_AVG
#define XSH_QC_TRACE12_RMS
#define XSH_QC_TRACE_FIT_DIFF_POS
#define XSH_QC_TRACE32_MED
#define XSH_QC_TRACE_FIT_C0
#define XSH_QC_TRACE_FIT_C2
#define XSH_QC_TRACE_FIT_DIFF_C1
#define XSH_QC_TRACE32_AVG
#define XSH_QC_TRACE13_RMS
#define XSH_QC_TRACE_FIT_C1
#define XSH_QC_TRACE13_MAX
#define XSH_QC_TRACE12_MIN
static const qc_description qc_table[]
cpl_image * xsh_image_smooth_median_y(cpl_image *inp, const int r)
double * xsh_generate_interpolation_kernel(const char *kernel_type)
void xsh_show_interpolation_kernel(char *kernel_name)
double xsh_image_get_stdev_robust(const cpl_image *image, double cut, double *dstdev)
Get robust empirical stdev of data.
cpl_error_code xsh_image_mflat_detect_blemishes(cpl_frame *flat_frame, xsh_instrument *instrument)
Flag blemishes in a flat image.
cpl_image * xsh_compute_scale_tab3(cpl_imagelist *iml_data, cpl_imagelist *iml_qual, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz, const int decode_bp)
cpl_table * xsh_qual2tab(cpl_image *qual, const int code)
cpl_error_code xsh_image_warp_polynomial_scale(cpl_image *out, const cpl_polynomial *poly_x, const cpl_polynomial *poly_y)
Compute area change ratio for a 2D polynomial transformation.
double xsh_fixed_pattern_noise_bias(const cpl_image *first_raw, const cpl_image *second_raw, double ron)
Compute fixed pattern noise in bias.
static cpl_image * xsh_image_mult_by_fct(const cpl_image *ima_dat, const int fctx, const int fcty)
cpl_image * xsh_warp_image_generic(cpl_image *image_in, char *kernel_type, cpl_polynomial *poly_u, cpl_polynomial *poly_v)
static double xsh_sinc(double x)
cpl_error_code xsh_image_cut_dichroic_uvb(cpl_frame *frame1d)
static cpl_error_code xsh_cube_trace_fit(cpl_table **table, const char *col_wav, const char *col_ref, const char *col_fit, const char *qualifier, cpl_propertylist *plist)
Fit cube traces and compute fit coeffs differences.
cpl_image * xsh_compute_scale_tab(cpl_imagelist *iml_data, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz)
cpl_image * xsh_sobel_lx(cpl_image *in)
Compute X Sobel filter transformation.
static void reverse_tanh_kernel(double *data, int nn)
void xsh_pixel_qsort(pixelvalue *pix_arr, int npix)
cpl_image * xsh_scharr_y(cpl_image *in)
Compute Y Scharr filter transformation.
static cpl_error_code xsh_key_scan_mult_by_fct(cpl_propertylist **plist, const char *kname, const int fct)
cpl_frame * xsh_frame_image_mult_by_fct(cpl_frame *frm, const int fctx, const int fcty)
double xsh_image_fit_gaussian_max_pos_x_window(const cpl_image *ima, const int llx, const int urx, const int ypos)
static cpl_image * xsh_image_crop(const cpl_image *image, int xlo, int ylo, int xhi, int yhi)
Crop image.
double xsh_fixed_pattern_noise(const cpl_image *master, double convert_ADU, double master_noise)
Compute fixed pattern noise in flat field.
cpl_image * xsh_image_smooth_fft(cpl_image *inp, const int fx, const int fy)
static cpl_error_code xsh_key_bin_div_by_fct(cpl_propertylist **plist, const char *kname, const int fct)
cpl_image * xsh_image_smooth_mean_y(cpl_image *inp, const int r)
cpl_error_code xsh_iml_merge_avg(cpl_imagelist **data, cpl_imagelist **mask, const cpl_image *data_ima, const cpl_image *mask_ima, const int mk)
merge imagelist via average
cpl_frame * xsh_frame_image_qc_trace_window(cpl_frame *frm_ima, xsh_instrument *instrument, const char *suffix, const int hsize, const int method)
Trace object position in an image.
static cpl_table * xsh_image_qc_trace_window(cpl_image *data_ima, cpl_propertylist *head, const int hsize, const int method)
Trace object position in an image.
cpl_image * xsh_image_smooth_mean_x(cpl_image *inp, const int r)
static cpl_error_code xsh_compute_geom_corr(const double dxdu, const double dydv, const double dxdv, const double dydu, const double du, const double dv, double *dA)
Pixel area geometric trasformation computation.
static cpl_error_code xsh_util_compute_qc_residuals(cpl_table *table, xsh_instrument *instrument, cpl_propertylist *plist)
Computes residuals statistics on given wave ranges.
cpl_image * xsh_image_search_bad_pixels_via_noise(cpl_imagelist *darks, float thresh_sigma_factor, float low_threshold, float high_threshold, int llx, int lly, int urx, int ury)
search bad pixels
cpl_error_code xsh_frame_image_save2ext(cpl_frame *frm, const char *name_o, const int ext_i, const int ext_o)
cpl_image * xsh_sobel_ly(cpl_image *in)
Compute Y Sobel filter transformation.
cpl_frame * xsh_frame_image_ext_qc_trace_window(cpl_frame *frm_ima, xsh_instrument *instrument, const char *suffix, const int hsize, const int method)
Trace object position in an image.
cpl_image * xsh_compute_scale_tab2(cpl_imagelist *iml_data, cpl_imagelist *iml_qual, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz, const int decode_bp)
cpl_error_code xsh_collapse_errs(cpl_image *errs, cpl_imagelist *list, const int mode)
static cpl_image * xsh_gen_lowpass(const int xs, const int ys, const double sigma_x, const double sigma_y)
Generate a low pass filter for FFT convolution .
cpl_image * xsh_image_smooth_median_x(cpl_image *inp, const int r)
cpl_image * xsh_combine_flats(cpl_image *ima1_in, cpl_image *ima2_in, xsh_order_list *qth_list, xsh_order_list *d2_list, const int xrad, const int yrad)
Combine flat frames line adjusting illumination level to merge them smoothly.
static Stats * xsh_image_stats_on_rectangle(cpl_image *im, float loReject, float hiReject, int llx, int lly, int urx, int ury)
cpl_image * xsh_compute_scale(cpl_imagelist *iml_data, cpl_mask *bpm, const int mode, const int win_hsz)
static cpl_error_code xsh_cube_trace_diff(const cpl_table *table, const char *col_comp, const char *col_ref, cpl_propertylist *plist)
Computes differences between cube fit trace coefficients.
cpl_error_code xsh_compute_ron(cpl_frameset *frames, int llx, int lly, int urx, int ury, int nsampl, int hsize, const int reg_id, double *ron, double *ron_err)
compute ron taking random windows of given size in a given region on 2 frames difference
double * xsh_generate_tanh_kernel(double steep)
cpl_frame * xsh_frame_image_div_by_fct(cpl_frame *frm, const int fctx, const int fcty)
cpl_image * xsh_image_compute_geom_corr(cpl_image *in)
Pixel area geometric trasformation computation.
cpl_error_code xsh_frame_image_add_double(cpl_frame *frm, const double value)
static float xsh_clean_mean(float *array, int n_elements, float throwaway_low, float throwaway_high)
cpl_image * xsh_scharr_x(cpl_image *in)
Compute X Scharr filter transformation.
cpl_image * xsh_image_smooth_median_xy(cpl_image *inp, const int r)
cpl_frame * xsh_cube_qc_trace_window(cpl_frame *frm_cube, xsh_instrument *instrument, const char *suffix, const char *rec_prefix, const int win_min, const int win_max, const int hsize, const int method, const int compute_qc)
Trace object position in a cube.
static cpl_image * xsh_image_div_by_fct(const cpl_image *ima_dat, const int fctx, const int fcty)
cpl_error_code xsh_iml_merge_wgt(cpl_imagelist **data, cpl_imagelist **errs, cpl_imagelist **qual, const cpl_image *flux_b, const cpl_image *errs_b, const cpl_image *qual_b, const int mk, const int decode_bp)
merge imagelist via average
cpl_error_code xsh_image_clean_badpixel(cpl_frame *in)
double xsh_image_get_stdev_clean(const cpl_image *image, double *dstdev)
Get clean (3*sigma clip) empirical stdev of data.
static cpl_error_code xsh_plist_mult_by_fct(cpl_propertylist **plist, const int fctx, const int fcty)
static double xsh_image_fit_gaussian_max_pos_y_window(const cpl_image *ima, const int lly, const int ury, const int xpos)
cpl_image * xsh_image_filter_median(const cpl_image *img, const cpl_matrix *mx)
cpl_polynomial * xsh_polynomial_fit_1d_create(const cpl_vector *x_pos, const cpl_vector *values, int degree, double *mse)