34 recmat::recmat(std::string fname)
47 load_recmat_LBT(fname);
52 if(R) gsl_matrix_float_free(R);
62 int recmat::load_recmat_LBT(std::string fname)
67 long naxes[2], fpix[2]={1,1}, lpix[2];
68 int f_nmodes, f_nslopes;
70 std::cout << fname << std::endl;
73 fits_open_file(&fptr, fname.c_str(), READONLY, &fstatus);
77 fprintf(stderr,
"Error in get_open_file.\n");
78 fits_report_error(stderr, fstatus);
85 fits_get_img_dim(fptr, &naxis, &fstatus);
89 fprintf(stderr,
"Error in get_img_dim.\n");
90 fits_report_error(stderr, fstatus);
94 fits_get_img_size(fptr, naxis, naxes, &fstatus);
97 fprintf(stderr,
"Error in get_img_size.\n");
98 fits_report_error(stderr, fstatus);
104 f_nslopes = naxes[0];
106 std::cerr <<
"Fits image size: " << f_nmodes <<
" X " << f_nslopes << std::endl;
108 float *fR =
new float[f_nmodes*f_nslopes*2];
111 fits_read_key(fptr, TDOUBLE,
"IM_MODES", &nm, 0, &fstatus);
113 std::cerr <<
"Actual number of modes: " << nm <<
"\n";
126 get_fits_im(fR, 1, fpix, lpix, &fptr, 0);
129 for(
int k = f_nslopes - 1; k > -1; k--)
131 if(fR[k] !=0 || fR[1*f_nslopes + k] !=0 || fR[2*f_nslopes + k] !=0)
138 std::cerr <<
"Actual # slopes " <<
n_slopes << std::endl;
142 gsl_matrix_float_free(R);
151 gsl_matrix_float_set(R, i, j, fR[i*f_nslopes + j]);
161 init_gpurecon(n_modes,
n_slopes, R->data);
166 fitting_error_sq = fitting_A * pow(n_modes, fitting_B)*pow(tel_diam, 5./3.)/(4.*3.14159*3.14159)*pow(median_r0_lam*1e3/median_r0, 2.);
168 std::cerr <<
"fitting error squared = " << fitting_error_sq << std::endl;
172 fits_close_file(fptr, &fstatus);
182 cblas_sgemv(CblasRowMajor, CblasNoTrans, n_modes,
n_slopes, 1., R->data,
n_slopes, slopes, 1, 0.,
amp, 1);
187 gpurecon(slopes,
amp);
189 std::cerr <<
"No GPU available.\n";
203 for(
int j=m0;j<m1; ++j)
205 *sumvar += fact*
amp[j]*
amp[j];
208 if(fiterr) *sumvar += fitting_error_sq;
int gpu_inited
Flag for whether the gpu globals are initialized.
int n_slopes
The number of slopes, and the columns in the reconstructor matrix.
int rec_tech
Which reconstructor technique to use, either REC_ATLAS or REC_CPU.
std::string filePath
The full path to the reconstructor matrix.
Declarations for a class to manage a reconstructor matrix.
float unit_conversion
Factor to convert variances to nanometers.
float * amp
The reconstructed amplitudes, a vector of length n_modes.
int calc_sumvar(float *sumvar, int m0=2, int m1=-1, bool fiterr=true)
Calculate the sum of the variances, e.g. the dot product of the amplitude vector. ...
int n_modes
The number of modes, and the rows in the reconstructor matrix.
int reconstruct(float *slopes)
Given a new slopes vector, reconstruct the amplitudes.
float reflection_gain
Factor to apply to reconstructed amplitudes to account for mirror reflection.