64 const char* fname = NULL;
65 cpl_image* raw_ima = NULL;
66 cpl_image* tmp_ima = NULL;
68 cpl_propertylist* header = NULL;
76 cpl_vector* cor_val_vect=NULL;
77 cpl_imagelist* iml=NULL;
78 cpl_image* ima_ext=NULL;
86 fname = cpl_frame_get_filename(raw);
88 header = cpl_propertylist_load(fname, 0);
97 ptmp = cpl_image_get_data_float(tmp_ima);
109 ima_ext = cpl_image_extract(raw_ima, naxis1 - ovscx, 1, naxis1, naxis2);
110 iml = cpl_imagelist_new();
111 cpl_imagelist_set(iml, ima_ext,0);
115 *cor_val = cpl_vector_get(cor_val_vect, 0);
123 ima_ext = cpl_image_extract(raw_ima, 1, 1, prscx, naxis2);
124 iml = cpl_imagelist_new();
125 cpl_imagelist_set(iml, ima_ext,0);
129 *cor_val = cpl_vector_get(cor_val_vect, 0);
138 ima_ext = cpl_image_extract(raw_ima, 1, 1, prscx, naxis2);
139 iml = cpl_imagelist_new();
140 cpl_imagelist_set(iml, ima_ext,0);
144 *cor_val = cpl_vector_get(cor_val_vect, 0);
148 ima_ext = cpl_image_extract(raw_ima, naxis1 - ovscx, 1, naxis1, naxis2);
149 iml = cpl_imagelist_new();
150 cpl_imagelist_set(iml, ima_ext,0);
154 *cor_val += cpl_vector_get(cor_val_vect, 0);
170 for (j = 0; j < naxis2; j++) {
171 tmp_val = cpl_image_get_median_window(raw_ima, naxis1 - ovscx, j + 1,
173 for (i = 0; i < naxis1; i++) {
174 ptmp[j * naxis1 + i] = tmp_val;
181 for (j = 0; j < naxis2; j++) {
182 tmp_val = cpl_image_get_median_window(raw_ima, 1, j + 1,prscx, j + 1);
183 for (i = 0; i < naxis1; i++) {
184 ptmp[j * naxis1 + i] = tmp_val;
192 for (j = 0; j < naxis2; j++) {
194 tmp_val = cpl_image_get_median_window(raw_ima, 1, j + 1,prscx, j + 1);
196 tmp_val += cpl_image_get_median_window(raw_ima, naxis1 - ovscx, j + 1, naxis1, j + 1);
200 for (i = 0; i < naxis1; i++) {
201 ptmp[j * naxis1 + i] = tmp_val;
212 cpl_image_subtract_scalar(raw_ima, *cor_val);
214 *cor_val = cpl_image_get_median_window(tmp_ima, 1, 1, naxis1, naxis2);
215 cpl_image_subtract(raw_ima, tmp_ima);
218 xsh_msg(
"Apply pre-overscan correction %g", *cor_val);
220 if (corr_mode > 0 && corr_mode < 4) {
221 if (fabs(*cor_val) < 1.e-6) {
223 "The overscan correction is < 10^-6. Probably you have bad input");
224 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
230 check(cpl_image_save( raw_ima, cor_fname, CPL_BPP_IEEE_FLOAT, header,
232 cpl_frame_set_filename(raw, cor_fname);
243 return cpl_error_get_code();
250 const int nsamples=10;
260 static double dit_samples[10]={2,4,8,16,32,64,128,256,400,1024};
263 static double ron_samples[10]={21.3,18.4,14.8,11.7,9.0,7.3,6.3,6.2,7.0,9.0};
265 for(i=0;i<nsamples-1;i++){
266 if(dit_samples[i] < dit) i_min=i;
269 dit_min=dit_samples[i_min];
270 ron_min=ron_samples[i_min];
272 dit_max=dit_samples[i_min+1];
273 ron_max=ron_samples[i_min+1];
274 slope=(ron_max-ron_min)/(dit_max-dit_min);
276 ron=ron_min+slope*(dit-dit_min);
333 if ( cpl_error_get_code() != CPL_ERROR_NONE){
343 if(cpl_propertylist_has(pre->
data_header,
"EXPTIME")) {
393 if ( cpl_error_get_code() != CPL_ERROR_NONE){
394 xsh_msg(
"WARNING : No binning keywords found. Force binning to 1x1");
452 const bool flag_neg_and_thresh_pix) {
454 const char* framename = NULL;
455 const char* frame_tag = NULL;
465 cpl_image *image = NULL;
469 const char *bpfilename = NULL;
470 cpl_propertylist* bplist = NULL, *data_header = NULL;
471 int bpnaxis1 = 0, bpnaxis2 = 0;
494 check(framename = cpl_frame_get_filename(raw));
495 check(result->
group = cpl_frame_get_group(raw));
496 check(frame_tag = cpl_frame_get_tag(raw));
499 check(nextensions = cpl_frame_get_nextensions(raw));
505 check_msg(data_header = cpl_propertylist_load(framename, 0),
506 "Could not load header of file '%s'", framename);
509 if (pre_overscan_corr > 0) {
511 check(framename = cpl_frame_get_filename(raw));
516 if (strstr(frame_tag,
"AFC") != NULL) {
553 result->
data = cpl_image_extract(image, result->
cutx + 1,
558 result->
nx = cpl_image_get_size_x(result->
data);
559 result->
ny = cpl_image_get_size_y(result->
data);
563 check(errs = cpl_image_get_data_float(result->
errs));
567 double ron2 = result->
ron * result->
ron;
568 int nx_ny = result->
nx * result->
ny;
569 double ron_div_conad = result->
ron / result->
conad;
576 for (i = 0; i < nx_ny; i++) {
580 errs[i] = sqrt(cdata * result->
conad + ron2) / result->
conad;
582 errs[i] = ron_div_conad;
591 flag_neg_and_thresh_pix, is_flat, &nsat);
592 frac_sat = (double) nsat / (nx_ny);
651 result->
data = cpl_image_extract(image, result->
cutx + 1,
665 flag_neg_and_thresh_pix, is_flat, &nsat));
666 int nx_ny = result->
nx * result->
ny;
667 frac_sat = (double) nsat / (nx_ny);
695 check(errs = cpl_image_get_data_float(result->
errs));
705 float ron_div_conad = result->
ron / result->
conad;
707 for (i = 0; i < nx_ny; i++) {
708 errs[i] = ron_div_conad;
720 for (i = 0; i < nx_ny; i++) {
726 float* mbias_data = NULL;
727 double ron2 = result->
ron * result->
ron;
729 double ron_div_conad = result->
ron / result->
conad;
731 int flag_err_comp = 0;
732 if (bias_data != (cpl_image *)-1) {
735 xsh_msg(
"pre_overscan=%d",pre_overscan_corr);
736 if (pre_overscan_corr == 0) {
739 check(bias_x = cpl_image_get_size_x(bias_data));
740 check(bias_y = cpl_image_get_size_y(bias_data));
742 "bias_x=%d nx=%d bias_y=%d ny=%d", bias_x, result->
nx, bias_y, result->
ny);
744 bias_x == result->
nx,
745 "Master bias X size different from raw frame X size. Input image frames must match in arm and bin!");
747 bias_y == result->
ny,
748 "Master bias Y size different from raw frame Y size. Input image frames must match in arm and bin!");
751 check( mbias_data = cpl_image_get_data_float( bias_data));
752 for (i = 0; i < nx_ny; i++) {
754 cdata =
data[i] - mbias_data[i];
756 errs[i] = sqrt(cdata * result->
conad + ron2) / result->
conad;
758 errs[i] = ron_div_conad;
765 if (flag_err_comp == 0) {
767 for (i = 0; i < nx_ny; i++) {
771 errs[i] = sqrt(cdata * result->
conad + ron2) / result->
conad;
773 errs[i] = ron_div_conad;
785 check(bpfilename = cpl_frame_get_filename(bpmap));
786 xsh_msg(
"Use Bad pixel map file %s\n", bpfilename);
787 check(bplist = cpl_propertylist_load(bpfilename, 0));
791 assure(bpnaxis1 == result->
nx && bpnaxis2 == result->
ny,
792 CPL_ERROR_ILLEGAL_INPUT,
793 "qual image %d %d must have same size of data\
795 bpnaxis1, bpnaxis2, result->
nx, result->
ny);
806 cleanup:
if (cpl_error_get_code() != CPL_ERROR_NONE) {
854 const char *filename = NULL;
856 cpl_propertylist* data_header = NULL;
863 check (filename = cpl_frame_get_filename (frame));
868 check(result->
group = cpl_frame_get_group(frame));
875 check_msg (data_header = cpl_propertylist_load (filename,extension),
876 "Cannot read the FITS header from '%s' extension %d",
877 filename, extension);
886 "Error loading image from %s extension 0", filename);
890 "Cannot read the FITS header from '%s' extension 1",filename);
892 CPL_ERROR_ILLEGAL_INPUT,
"extension 1 must be a errs extension");
894 "Error loading image from %s extension 1", filename);
897 "Cannot read the FITS header from '%s' extension 2",filename);
899 CPL_ERROR_ILLEGAL_INPUT,
"extension 2 must be a qual extension");
901 "Error loading image from %s extension 2", filename);
939 if (cpl_error_get_code () != CPL_ERROR_NONE) {
940 xsh_error_msg(
"can't load frame %s",cpl_frame_get_filename(frame));
957 assure(pre != NULL, CPL_ERROR_NULL_INPUT,
"Null PRE");
961 assure (result != NULL, CPL_ERROR_ILLEGAL_OUTPUT,
962 "Memory allocation failed!");
985 "can't copy data image");
991 "can't copy errs image");
998 "can't copy qual image");
1002 if (cpl_error_get_code () != CPL_ERROR_NONE) {
1020 const char *filename,
1024 cpl_frame *product_frame = NULL;
1037 "Could not save data to %s extension 0", filename);
1040 "Could not save errs to %s extension 1", filename);
1043 "Could not save qual to %s extension 2", filename);
1045 product_frame = cpl_frame_new ();
1048 check ((cpl_frame_set_filename (product_frame, filename),
1049 cpl_frame_set_tag(product_frame,tag),
1050 cpl_frame_set_type (product_frame, CPL_FRAME_TYPE_IMAGE),
1055 check( cpl_frame_set_level(product_frame,
1056 CPL_FRAME_LEVEL_TEMPORARY));
1062 if (cpl_error_get_code () != CPL_ERROR_NONE) {
1064 product_frame = NULL;
1066 return product_frame;
1086 cpl_frameset* frameset,
1087 const cpl_parameterlist* parameters,
1088 const char* recipe_id,
1091 cpl_frame* result = NULL;
1095 const char* tag=NULL;
1104 check( cpl_frame_set_group (frame, CPL_FRAME_GROUP_PRODUCT));
1106 frame, frameset, parameters,
1111 if ( prefix == NULL ) {
1112 sprintf(filename,
"PRODUCT_%s",cpl_frame_get_filename (frame));
1117 sprintf( filename,
"%s_%dx%d_%s.fits", prefix, pre->
binx, pre->
biny,
1121 sprintf( filename,
"%s_%dx%d.fits", prefix, pre->
binx, pre->
biny );
1125 cpl_frame_set_type (result, CPL_FRAME_TYPE_IMAGE),
1126 cpl_frame_set_group (result, CPL_FRAME_GROUP_PRODUCT),
1127 cpl_frame_set_level (result, CPL_FRAME_LEVEL_FINAL);
1129 if (cpl_error_get_code () != CPL_ERROR_NONE) {
1156 assure (
nx > 0 &&
ny > 0, CPL_ERROR_ILLEGAL_INPUT,
1157 "Illegal image size: %dx%d",
nx,
ny);
1172 if (cpl_error_get_code () != CPL_ERROR_NONE) {
1262 assure (pre != NULL, CPL_ERROR_NULL_INPUT,
"Null PRE");
1281 double*
x,
double*
y)
1296 *
y = pre->
ny + pre->
cutx - raw_x;
1299 *
x = raw_x - pre->
cutx;
1300 *
y = raw_y - pre->
cuty;
1351 cpl_frame_group result = CPL_FRAME_GROUP_NONE;
1354 result = pre->
group;
1368 cpl_mask* mask = NULL;
1369 cpl_binary* binary = NULL;
1375 check(mask = cpl_image_get_bpm(pre->
qual));
1376 check(qual = cpl_image_get_data_int(pre->
qual));
1377 check(binary = cpl_mask_get_data(mask));
1378 nx_ny = pre->
nx * pre->
ny;
1379 for (i = 0; i < nx_ny; i++) {
1382 binary[i] = CPL_BINARY_1;
1386 cleanup:
return mask;
1413 float* errs1 = NULL;
1414 float* errs2 = NULL;
1426 CPL_ERROR_INCOMPATIBLE_INPUT,
1427 "Image sizes don't match: %dx%d and %dx%d",
1435 check(errs1 = cpl_image_get_data_float(self->
errs));
1436 check(errs2 = cpl_image_get_data_float(right->
errs));
1438 for(i=0;i< self->
nx*self->
ny; i++){
1439 errs1[i] = sqrt(pow(errs1[i],2)+pow(errs2[i],2));
1491 cpl_frame* frm=NULL;
1492 cpl_frame* cor=NULL;
1493 cpl_frameset* result=NULL;
1495 const char * name=NULL;
1496 size=cpl_frameset_get_size(set);
1497 result=cpl_frameset_new();
1498 for(i=0;i<
size;i++) {
1499 frm=cpl_frameset_get_frame(set,i);
1500 name=cpl_frame_get_filename(frm);
1501 sprintf(filename,
"SUB_%s_%d_%s",spec,i,name);
1503 cpl_frameset_insert(result,cor);
1530 const char *filename,
1532 const int clean_tmp)
1537 cpl_frame * result = NULL ;
1538 const char* tag=NULL;
1554 check(tag=cpl_frame_get_tag(one));
1559 check ((cpl_frame_set_filename (result, filename),
1560 cpl_frame_set_type (result, CPL_FRAME_TYPE_IMAGE),
1562 cpl_frame_set_level (result, CPL_FRAME_LEVEL_TEMPORARY),
1563 cpl_frame_set_tag( result,tag)));
1592 float* errs1 = NULL;
1593 float* errs2 = NULL;
1606 CPL_ERROR_INCOMPATIBLE_INPUT,
1607 "Image sizes don't match: %dx%d and %dx%d",
1615 check( errs1 = cpl_image_get_data_float( self->
errs));
1616 check( errs2 = cpl_image_get_data_float( right->
errs));
1618 for(i=0;i< self->
nx*self->
ny; i++){
1619 errs1[i] = sqrt(pow(errs1[i],2)+pow(errs2[i],2));
1668 float *errsi = NULL;
1669 float *errso = NULL;
1670 float *datai = NULL;
1671 float *datao = NULL;
1690 float inv_binx_biny=1;
1693 assure (self != NULL, CPL_ERROR_NULL_INPUT,
"Null image!");
1694 assure (
binx >0, CPL_ERROR_ILLEGAL_INPUT,
"binx <=0!");
1695 assure (
biny >0, CPL_ERROR_ILLEGAL_INPUT,
"biny <=0!");
1698 check(datai = cpl_image_get_data_float(self->
data));
1699 check(errsi = cpl_image_get_data_float(self->
errs));
1700 check(quali = cpl_image_get_data_int(self->
qual));
1709 check(datao = cpl_image_get_data_float(result->
data));
1710 check(errso = cpl_image_get_data_float(result->
errs));
1711 check(qualo = cpl_image_get_data_int(result->
qual));
1718 for (j = 0; j <
ny; j++) {
1721 for (i = 0; i <
nx; i++) {
1722 pixeli = j_biny*nx_binx + (i*
binx);
1727 cpix = pixeli +
m*nx_binx;
1728 for (k = 0; k <
binx;k++) {
1731 datao[pixelo] += datai[cpix_k];
1732 errso[pixelo] += errsi[cpix_k] * errsi[cpix_k];
1733 qualo[pixelo] |= quali[cpix_k];
1737 errso[pixelo] = sqrt(errso[pixelo]);
1745 for (i = 0; i < nx_ny; i++) {
1746 datao[i] *= inv_binx_biny;
1747 errso[i] *= inv_binx_biny;
1755 for (i = 0; i < nx_ny; i++) {
1756 datao[i] *= binx_biny;
1757 errso[i] *= binx_biny;
1788 float *errs1 = NULL;
1789 float *errs2 = NULL;
1790 float *data1 = NULL;
1791 float *data2 = NULL;
1796 assure (self != NULL, CPL_ERROR_NULL_INPUT,
"Null image!");
1797 assure (right != NULL, CPL_ERROR_NULL_INPUT,
"Null image!");
1802 CPL_ERROR_INCOMPATIBLE_INPUT,
1803 "Image sizes don't match: %dx%d and %dx%d",
1809 check(data1 = cpl_image_get_data_float(self->
data));
1810 check(data2 = cpl_image_get_data_float(right->
data));
1811 check(errs1 = cpl_image_get_data_float(self->
errs));
1812 check(errs2 = cpl_image_get_data_float(right->
errs));
1813 check(qual1 = cpl_image_get_data_int(self->
qual));
1814 check(qual2 = cpl_image_get_data_int(right->
qual));
1815 nx_ny=self->
nx*self->
ny;
1817 for(i=0;i< nx_ny; i++){
1819 if ( (qual2[i] & self->
decode_bp) > 0 ) {
1829 qual1[i] |= qual2[i];
1841 if (qual1[i] > 0 ) {
1855 double d1 = 0.0, d2 = 0.0;
1856 double e1 = 0.0, e2 =0.0;
1863 error = fabs( 1.0/d2) * sqrt( (e1*e1) + (e2*e2*d1*d1)/(d2*d2) );
1864 errs1[i] = (float) error;
1865 data1[i] = (float)(d1/d2);
1896 float *errs1 = NULL;
1897 float *errs2 = NULL;
1898 float *data1 = NULL;
1899 float *data2 = NULL;
1904 assure (self != NULL, CPL_ERROR_NULL_INPUT,
"Null image!");
1905 assure (right != NULL, CPL_ERROR_NULL_INPUT,
"Null image!");
1910 CPL_ERROR_INCOMPATIBLE_INPUT,
1911 "Image sizes don't match: %dx%d and %dx%d",
1917 check(data1 = cpl_image_get_data_float(self->
data));
1918 check(data2 = cpl_image_get_data_float(right->
data));
1919 check(errs1 = cpl_image_get_data_float(self->
errs));
1920 check(errs2 = cpl_image_get_data_float(right->
errs));
1921 check(qual1 = cpl_image_get_data_int(self->
qual));
1922 check(qual2 = cpl_image_get_data_int(right->
qual));
1923 nx_ny=self->
nx*self->
ny;
1924 for(i=0;i< nx_ny; i++){
1926 if ( (qual2[i] & self->
decode_bp) > 0 ) {
1936 qual1[i] |= qual2[i];
1944 double d1 = 0.0, d2 = 0.0;
1945 double e1 = 0.0, e2 =0.0;
1952 error = sqrt( d2*d2*e1*e1 + d1*d1*e2*e2 );
1953 errs1[i] = (float) error;
1954 data1[i] = (float)(d1*d2);
1980 check(val1 = cpl_image_get(self->
data, i, 1, &rej));
1982 while (val1 == 0 || rej == 1);
1986 check(cpl_image_normalise( self->
data, CPL_NORM_MEAN));
1989 check(ct1 = val1/ cpl_image_get(self->
data, i1, 1, &rej));
1991 xsh_msg(
"normalize estimate pixel (%d,1) : %f",i1,ct1);
1994 check( cpl_image_divide_scalar( self->
errs, ct1));
2010 double * median,
double * stdev )
2013 float * ppix = NULL;
2015 cpl_vector * ptemp = NULL;
2023 assure (
nx != 0, cpl_error_get_code (),
"Cant get X size");
2025 assure (
ny != 0, cpl_error_get_code (),
"Cant get Y size");
2027 check( ptemp = cpl_vector_new(
nx*
ny )) ;
2028 check( ppix = cpl_image_get_data_float( preFrame->
data ) ) ;
2029 check( pbad = cpl_image_get_data_int( preFrame->
qual ) ) ;
2031 for( ng = 0, i = 0 ; i < nx_ny ; i++ ) {
2032 if ( (pbad[i] & preFrame->
decode_bp) == 0 ){
2034 check( cpl_vector_set( ptemp, ng, (
double)(ppix[i]) )) ;
2040 check( cpl_vector_set_size( ptemp, ng ) );
2041 check( *mean = cpl_vector_get_mean( ptemp ) );
2042 check( *stdev = cpl_vector_get_stdev( ptemp ) );
2043 check( *median = cpl_vector_get_median( ptemp ) );
2046 if (cpl_error_get_code() != CPL_ERROR_NONE){
2069 double * median,
double * stdev,
2070 const int llx,
const int lly,
2071 const int urx,
const int ury )
2073 int i=0, ng=0,
nx=0,
ny=0 ;
2075 float * ppix = NULL;
2077 cpl_vector * ptemp = NULL;
2086 assure (
nx != 0, cpl_error_get_code (),
"Cant get X size");
2088 assure (
ny != 0, cpl_error_get_code (),
"Cant get Y size");
2093 check( ptemp = cpl_vector_new( vx*vy )) ;
2094 check( ppix = cpl_image_get_data_float( preFrame->
data ) ) ;
2095 check( pbad = cpl_image_get_data_int( preFrame->
qual ) ) ;
2099 for( j =
lly-1 ; j <
ury ; j++ ) {
2100 for( i =
llx-1 ; i <
urx ; i++ ) {
2102 if ( (pbad[i] & preFrame->
decode_bp) == 0) {
2104 check( cpl_vector_set( ptemp, ng, (
double)(ppix[j*
nx+i]) )) ;
2110 cpl_table* tab=NULL;
2111 cpl_table* ext=NULL;
2118 tab=cpl_table_new(ng);
2119 cpl_table_wrap_double(tab,cpl_vector_get_data(ptemp),
"VAL");
2122 *median=cpl_table_get_column_median(tab,
"VAL");
2123 *mean=cpl_table_get_column_mean(tab,
"VAL");
2124 *stdev=cpl_table_get_column_stdev(tab,
"VAL");
2125 for(i=0;i<niter1;i++) {
2127 cpl_table_and_selected_double(tab,
"VAL",CPL_LESS_THAN,
2128 *median+
kappa*(*stdev));
2129 cpl_table_and_selected_double(tab,
"VAL",CPL_GREATER_THAN,
2130 *median-
kappa*(*stdev));
2132 ext=cpl_table_extract_selected(tab);
2133 *median=cpl_table_get_column_median(ext,
"VAL");
2134 *mean=cpl_table_get_column_mean(ext,
"VAL");
2135 *stdev=cpl_table_get_column_stdev(ext,
"VAL");
2140 for(i=0;i<niter2;i++) {
2141 cpl_table_and_selected_double(tab,
"VAL",CPL_LESS_THAN,
2142 *mean+
kappa*(*stdev));
2143 cpl_table_and_selected_double(tab,
"VAL",CPL_GREATER_THAN,
2144 *mean-
kappa*(*stdev));
2146 ext=cpl_table_extract_selected(tab);
2147 *median=cpl_table_get_column_median(ext,
"VAL");
2148 *mean=cpl_table_get_column_mean(ext,
"VAL");
2149 *stdev=cpl_table_get_column_stdev(ext,
"VAL");
2153 ext=cpl_table_extract_selected(tab);
2155 cpl_table_unwrap(tab,
"VAL");
2156 *median=cpl_table_get_column_median(ext,
"VAL");
2157 *mean=cpl_table_get_column_mean(ext,
"VAL");
2158 *stdev=cpl_table_get_column_stdev(ext,
"VAL");
2167 if (cpl_error_get_code() != CPL_ERROR_NONE){
2201 int search_window_hsize,
int running_median_hsize,
int* xadj,
int* yadj)
2203 int search_win_xmin, search_win_xmax, search_win_ymin, search_win_ymax;
2206 double* median_tab = NULL;
2207 int median_box_size = 0;
2208 double max_flux = -99999;
2210 int xpos = -1, ypos = -1;
2216 XSH_CMP_INT( xcen, >=, 0,
"Check central x position",);
2217 XSH_CMP_INT( xcen, <, pre->
nx,
"Check central x position",);
2218 XSH_CMP_INT( ycen, >=, 0,
"Check central x position",);
2219 XSH_CMP_INT( ycen, <, pre->
ny,
"Check central x position",);
2221 median_box_size = 1+running_median_hsize*2;
2223 search_win_xmin = xcen-search_window_hsize;
2224 search_win_xmax = xcen+search_window_hsize;
2225 search_win_ymin = ycen-search_window_hsize;
2226 search_win_ymax = ycen+search_window_hsize;
2228 if ( search_win_xmin < 0){
2229 search_win_xmin = 0;
2231 if ( search_win_xmax >= pre->
nx){
2232 search_win_xmax = pre->
nx-1;
2234 if ( search_win_ymin < 0){
2235 search_win_ymin = 0;
2237 if ( search_win_ymax >= pre->
ny){
2238 search_win_ymax = pre->
ny-1;
2242 check( qual = cpl_image_get_data_int( pre->
qual));
2243 XSH_CALLOC(median_tab,
double, median_box_size* median_box_size);
2246 double med_flux = 0.0;
2248 for (jbox=search_win_ymin; jbox <= (search_win_ymax+1-median_box_size);
2250 yc = jbox+running_median_hsize;
2251 int array_shift=yc*pre->
nx;
2252 for (ibox=search_win_xmin; ibox <= (search_win_xmax+1-median_box_size);
2256 ibox, jbox, median_box_size, median_box_size, median_tab,&status);
2258 if ( cpl_error_get_code() == CPL_ERROR_NONE){
2260 if (max_flux < med_flux) {
2261 xc = ibox+running_median_hsize;
2262 if ( (qual[xc+array_shift] & pre->
decode_bp ) == 0) {
2265 max_flux = med_flux;
2279 if (xpos < 0 || ypos < 0){
2311 int size_x,
int size_y,
double* tab,
int* status)
2314 cpl_vector* v = NULL;
2332 if ( (
x+size_x) >= pre->
nx){
2335 if ( (
y+size_y) >= pre->
ny){
2342 check(qual = cpl_image_get_data_int(pre->
qual));
2346 int x_plus_size_x =
x + size_x;
2347 int y_plus_size_y =
y + size_y;
2348 int ix_plus_offset = 0;
2349 for( iy=
y; iy< y_plus_size_y; iy++){
2351 for( ix=
x; ix<x_plus_size_x;ix++){
2352 ix_plus_offset = ix + offset;
2353 if ( (qual[ix_plus_offset] & pre->
decode_bp) == 0 ) {
2365 }
else if (
size==1) {
2368 }
else if (
size>1) {
2371 check( flux = cpl_vector_get_median(v));
2387const cpl_propertylist *
2390 cpl_propertylist *header = NULL;
2425 cpl_image *
data = NULL;
2455 cpl_image *errs = NULL;
2485 cpl_image *qual = NULL;
2514 double *buffer = NULL;
2520 passure (cpl_image_get_type (pre->
data) == CPL_TYPE_DOUBLE,
" ");
2521 buffer = (
double *) cpl_image_get_data (pre->
data);
2548 double *buffer = NULL;
2551 passure (cpl_image_get_type (pre->
errs) == CPL_TYPE_DOUBLE,
" ");
2552 buffer = (
double *) cpl_image_get_data (pre->
errs);
2582 cpl_stats *stats = NULL;
2585 fprintf (stream,
"Null");
2589 stats = cpl_stats_new_from_image (pre->
data, CPL_STATS_ALL);
2591 cpl_stats_dump (stats, CPL_STATS_ALL, stream);
2615 check (cpl_image_multiply_scalar(pre->
data,
x));
2618 check (cpl_image_multiply_scalar(pre->
errs, fabs(
x)));
2636 check (cpl_image_divide_scalar(pre->
data,
x));
2639 check (cpl_image_divide_scalar(pre->
errs, fabs(
x)));
2677 check (cpl_image_subtract_scalar(pre->
data,
x));
2691 cpl_image *abs = NULL;
2697 check ( cpl_image_multiply(pre->
data, img));
2698 check( abs = cpl_image_abs_create( img));
2699 check ( cpl_image_multiply(pre->
errs, abs));
2716 cpl_image *result = NULL;
2717 int *result_data = NULL;
2725 check( result = cpl_image_new( pre->
nx, pre->
ny, CPL_TYPE_INT));
2726 check( result_data = cpl_image_get_data_int( result));
2730 for(i =0; i <
size; i++){
2732 result_data[i] = -1;
2760 cpl_frame* result=NULL;
2761 cpl_frame* frame=NULL;
2762 cpl_image*
data=NULL;
2763 cpl_image* errs=NULL;
2764 cpl_image* qual=NULL;
2767 cpl_imagelist* iml_data=NULL;
2768 cpl_imagelist* iml_errs=NULL;
2769 cpl_imagelist* iml_qual=NULL;
2771 cpl_propertylist* plist=NULL;
2773 const char* name=NULL;
2774 cpl_frame* frm_tmp=NULL;
2780 size=cpl_frameset_get_size(set);
2781 iml_data=cpl_imagelist_new();
2782 iml_errs=cpl_imagelist_new();
2783 iml_qual=cpl_imagelist_new();
2785 for(i=0;i<
size;i++) {
2786 frame=cpl_frameset_get_frame(set,i);
2790 cpl_imagelist_set(iml_data,cpl_image_duplicate(pre->
data),i);
2791 cpl_imagelist_set(iml_errs,cpl_image_duplicate(pre->
errs),i);
2792 cpl_imagelist_set(iml_qual,cpl_image_duplicate(pre->
qual),i);
2801 pre->
data=cpl_imagelist_collapse_create(iml_data);
2802 pre->
errs=cpl_imagelist_collapse_create(iml_errs);
2803 pre->
qual=cpl_imagelist_collapse_create(iml_qual);
2805 cpl_image_divide_scalar(pre->
data,
size);
2806 cpl_image_divide_scalar(pre->
errs,
size);
2807 cpl_image_divide_scalar(pre->
qual,
size);
2809 frame=cpl_frameset_get_frame(set,0);
2810 name=cpl_frame_get_filename(frame);
2811 plist=cpl_propertylist_load(name,0);
2813 sprintf(name_o,
"%s.fits",tag);
2817 CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL);
2844 cpl_image * img = NULL ;
2849 check( cpl_image_turn( img, rot ) ) ;
2852 check( cpl_image_turn( img, rot ) ) ;
2855 check( cpl_image_turn( img, rot ) ) ;
2877 cpl_image * img = NULL ;
2878 cpl_image * ext_img = NULL ;
2886 check( ext_img = cpl_image_extract( img, xmin, ymin, xmax, ymax));
2888 pre->
data = ext_img;
2891 check( ext_img = cpl_image_extract( img, xmin, ymin, xmax, ymax));
2893 pre->
errs = ext_img;
2896 check( ext_img = cpl_image_extract( img, xmin, ymin, xmax, ymax));
2898 pre->
qual = ext_img;
2913 cpl_image * img = NULL ;
2918 check( cpl_image_flip( img, angle ) ) ;
2921 check( cpl_image_flip( img, angle ) ) ;
2924 check( cpl_image_flip( img, angle ) ) ;
cpl_vector * xsh_irplib_imagelist_get_clean_mean_levels(const cpl_imagelist *iml, const double kappa, const int nclip, const double tolerance)
find out the character string associated to the DIT keyword in a propertylist
static xsh_instrument * instrument
void xsh_badpixelmap_or(xsh_pre *self, const xsh_pre *right)
cpl_error_code xsh_badpixelmap_flag_saturated_pixels(xsh_pre *pre, xsh_instrument *instr, const double cor_val, const int flag, const int is_flat, int *nsat)
void xsh_image_flag_bp(cpl_image *image, cpl_image *bpmap, xsh_instrument *inst)
cpl_error_code xsh_badpixelmap_image_coadd(cpl_image **self, const cpl_image *right, const int mode)
cpl_error_code xsh_badpixelmap_count_range_pixels(xsh_pre *pre, const double thresh_min, const double thresh_max, const double cor_val, int *nrange, double *frange)
void xsh_pre_add(xsh_pre *self, const xsh_pre *right)
Add two PRE images.
cpl_image * xsh_pre_get_data(xsh_pre *pre)
Get data.
xsh_pre * xsh_pre_duplicate(const xsh_pre *pre)
Copy a PRE structure.
void xsh_pre_flip(xsh_pre *pre, int angle)
Flip an image on a given miror line.
void xsh_pre_from_raw_get(xsh_pre *pre, double raw_x, double raw_y, double *x, double *y)
Get x, y coordinates in image from RAW coordinates.
double * xsh_pre_get_data_buffer(xsh_pre *pre)
Get data buffer.
double * xsh_pre_get_errs_buffer(xsh_pre *pre)
Get errs buffer.
cpl_frame * xsh_pre_save_product(xsh_pre *pre, cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, const char *prefix)
Save PRE frame like a product on disk.
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
void xsh_pre_extract(xsh_pre *pre, int xmin, int ymin, int xmax, int ymax)
Create a sub pre image.
cpl_mask * xsh_pre_get_bpmap(const xsh_pre *pre)
Get bpmap of pre structure.
cpl_frame_group xsh_pre_get_group(const xsh_pre *pre)
Get ny of pre structure.
const double * xsh_pre_get_errs_buffer_const(const xsh_pre *pre)
Get errs buffer.
void xsh_pre_divide(xsh_pre *self, const xsh_pre *right, const int is_flat, double threshold)
Divide a PRE image from another.
void xsh_pre_multiply_image(const xsh_pre *pre, cpl_image *img)
multiply a frame in PRE format by an image
cpl_image * xsh_pre_get_qual(xsh_pre *pre)
Get qual.
void xsh_pre_divide_scalar(const xsh_pre *pre, double x)
divides a frame in PRE format by a scalar
int xsh_pre_get_ny(const xsh_pre *pre)
Get ny of pre structure.
int xsh_pre_window_best_median_flux_pos(xsh_pre *pre, int xcen, int ycen, int search_window_hsize, int running_median_hsize, int *xadj, int *yadj)
Search pixel position of best running median flux in the search window.
void xsh_pre_multiply_scalar(const xsh_pre *pre, double x)
multiply a frame in PRE format by a scalar
cpl_image * xsh_pre_abs(const xsh_pre *pre)
computes absolute value of a frame in PRE format
static void xsh_pre_init(xsh_pre *pre, cpl_propertylist *header, xsh_instrument *instrument)
Fill the XSH_PRE structure from FITS header file.
float xsh_pre_get_pszx(const xsh_pre *pre)
Get pszx of pre structure.
void xsh_pre_add_scalar(const xsh_pre *pre, double x)
add a scalar to a frame in PRE format
int xsh_pre_get_binx(const xsh_pre *pre)
Get binx of pre structure.
void xsh_pre_turn(xsh_pre *pre, int rot)
cpl_frame * xsh_pre_frame_subtract(cpl_frame *one, cpl_frame *two, const char *filename, xsh_instrument *instr, const int clean_tmp)
Subtract 2 frames (in XSH_PRE format) Just loads the 2 frames, subtract (xsh_pre_subtract) and save r...
xsh_pre * xsh_pre_new(int nx, int ny)
Create new PRE image.
void xsh_pre_normalize(xsh_pre *self)
Normalize data flux.
void xsh_pre_multiply(xsh_pre *self, const xsh_pre *right, double threshold)
Multiply a PRE image from another.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
const cpl_image * xsh_pre_get_data_const(const xsh_pre *pre)
Get data.
int xsh_pre_get_biny(const xsh_pre *pre)
Get biny of pre structure.
static cpl_error_code xsh_preoverscan_corr(cpl_frame *raw, const int corr_mode, double *cor_val)
xsh_pre * xsh_pre_create(cpl_frame *raw, cpl_frame *bpmap, cpl_image *bias_data, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
Create a XSH_PRE from a raw frame.
int xsh_pre_get_nx(const xsh_pre *pre)
Get nx of pre structure.
float xsh_pre_get_pszy(const xsh_pre *pre)
Get pszy of pre structure.
double xsh_compute_ron_nir(const double dit)
cpl_frame * xsh_frameset_average_pre(cpl_frameset *set, xsh_instrument *instr, const char *tag)
Average set of frames in PRE format.
xsh_pre * xsh_pre_subsample(xsh_pre *self, const int binx, const int biny, const int rescale, xsh_instrument *inst)
Subsample a PRE image of a bin factor binx X biny.
cpl_frameset * xsh_pre_frameset_subtract_frame(cpl_frameset *set, cpl_frame *sub, const char *spec, xsh_instrument *instr)
Subtract 2 frames (in XSH_PRE format) Just loads the 2 frames, subtract (xsh_pre_subtract) and save r...
void xsh_pre_subtract_scalar(const xsh_pre *pre, double x)
subtract a scalar from a frame in PRE format
double xsh_pre_data_window_median_flux_pa(xsh_pre *pre, int x, int y, int size_x, int size_y, double *tab, int *status)
compute median sample value on the data window with preallocated memory tab. Only good pixels codes a...
cpl_propertylist * xsh_pre_get_header(xsh_pre *pre)
Get header.
const cpl_propertylist * xsh_pre_get_header_const(const xsh_pre *pre)
Get header.
const double * xsh_pre_get_data_buffer_const(const xsh_pre *pre)
Get data buffer.
void xsh_pre_subtract(xsh_pre *self, const xsh_pre *right)
Subtract one PRE image from another The data units are subtracted data = data1 - data2 The error imag...
float xsh_pre_get_gain(const xsh_pre *pre)
Get gain of pre structure.
const cpl_image * xsh_pre_get_qual_const(const xsh_pre *pre)
Get QUAL.
cpl_image * xsh_pre_get_errs(xsh_pre *pre)
Get errs.
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
void xsh_pre_median_mean_stdev_window(xsh_pre *preFrame, double *mean, double *median, double *stdev, const int llx, const int lly, const int urx, const int ury)
const cpl_image * xsh_pre_get_errs_const(const xsh_pre *pre)
Get errs.
void xsh_pre_dump(const xsh_pre *pre, FILE *stream)
Dump image to stream.
void xsh_pre_median_mean_stdev(xsh_pre *preFrame, double *mean, double *median, double *stdev)
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define assure(CONDITION, ERROR_CODE,...)
#define XSH_CMP_INT(A, OPERATOR, B, SUFFIX,...)
#define check_msg(COMMAND,...)
#define xsh_error_reset()
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
#define xsh_error_msg(...)
#define XSH_ASSURE_NOT_NULL(pointer)
#define passure(CONDITION,...)
int xsh_instrument_get_binx(xsh_instrument *instrument)
int xsh_instrument_get_biny(xsh_instrument *instrument)
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
#define xsh_msg_warning(...)
Print an warning message.
#define xsh_msg_dbg_medium(...)
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
#define xsh_msg_dbg_high(...)
void xsh_pfits_set_arm(cpl_propertylist *plist, xsh_instrument *instr)
int xsh_pfits_get_ovscx(const cpl_propertylist *plist)
find out the OVSCX value
double xsh_pfits_get_pszx(const cpl_propertylist *plist)
find out the PSZX (size of 1 pixel in Microns)
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
double xsh_pfits_get_conad(const cpl_propertylist *plist)
find out the CONAD value
void xsh_pfits_set_dpr_tech(cpl_propertylist *plist, const char *value)
Write the DPR TECH value.
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
const char * xsh_pfits_get_extname(const cpl_propertylist *plist)
find out the EXTNAME
double xsh_pfits_get_det_gain(const cpl_propertylist *plist)
find out the ESO DET OUT1 GAIN value
double xsh_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
void xsh_pfits_set_extname(cpl_propertylist *plist, const char *value)
Write the EXTNAME value.
void xsh_pfits_set_nsat(cpl_propertylist *plist, int value)
Write the number of saturated pixels value.
cpl_error_code xsh_pfits_set_wcs(cpl_propertylist *header, const double crpix1, const double crval1, const double cdelt1, const double crpix2, const double crval2, const double cdelt2)
const char * xsh_pfits_get_pcatg(const cpl_propertylist *plist)
find out the pcatg
void xsh_pfits_set_frac_sat(cpl_propertylist *plist, double value)
Write the fraction of saturated pixels value.
int xsh_pfits_get_ovscy(const cpl_propertylist *plist)
find out the OVSCY value
void xsh_pfits_set_frac_range_pix(cpl_propertylist *plist, double value)
Write the fraction of range pixels value.
void xsh_pfits_set_n_range_pix(cpl_propertylist *plist, int value)
Write the number of range pixels value.
double xsh_pfits_get_pszy(const cpl_propertylist *plist)
find out the PSZY (size of 1 pixel in Microns)
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
void xsh_pfits_set_bunit(cpl_propertylist *plist, const char *value)
Write the BUNIT value.
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
int xsh_pfits_is_flat(cpl_propertylist *plist)
int xsh_pfits_get_prscx(const cpl_propertylist *plist)
find out the PRSCX value
double xsh_pfits_get_ron(const cpl_propertylist *plist)
find out the RON value
int xsh_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
int xsh_pfits_get_prscy(const cpl_propertylist *plist)
find out the PRSCY value
double xsh_pfits_get_det_pxspace(const cpl_propertylist *plist)
find out the DET CHIP PXSPACE
int xsh_pfits_get_naxis2(const cpl_propertylist *plist)
find out the NAXIS2 value
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector 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.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_stats(cpl_stats **s)
Deallocate a stats object and set the pointer to NULL.
char * xsh_get_basename(const char *filename)
Return base filename.
int xsh_time_stamp_get(void)
get timestamp
char * xsh_sdate_utc(time_t *now)
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_propertylist * qual_header
cpl_propertylist * errs_header
xsh_instrument * instrument
cpl_propertylist * data_header
#define QFLAG_OUTSIDE_DATA_RANGE
#define QFLAG_CALIB_FILE_DEFECT
#define QFLAG_DIVISOR_ZERO
#define QFLAG_SATURATED_DATA
#define XSH_PRE_DATA_TYPE
#define XSH_PRE_QUAL_TYPE
#define XSH_NIR_DEFAULT_CUT_Y
#define XSH_PRE_ERRS_TYPE
#define XSH_NIR_DEFAULT_CUT_X
#define XSH_NIR_DEFAULT_CUT
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_BP_MAP_NL_UVB
#define XSH_RAW_BP_MAP_NL_UVB
#define XSH_RAW_IMA_SLIT_UVB
#define XSH_LINEARITY_UVB
#define XSH_RAW_IMA_SLIT_VIS
#define XSH_RAW_BP_MAP_NL_VIS
#define XSH_LINEARITY_VIS
#define XSH_BP_MAP_NL_VIS
#define XSH_DPR_TECH_SINGLE_PINHOLE
#define XSH_BUNIT_FLUX_REL_C
#define XSH_NEW_PROPERTYLIST(POINTER)
#define XSH_FREE(POINTER)
#define XSH_CALLOC(POINTER, TYPE, SIZE)