1 #ifndef directPhaseReconstructor_hpp
2 #define directPhaseReconstructor_hpp
4 #pragma GCC system_header
7 #include <mx/signalWindows.hpp>
10 #define BREAD_CRUMB std::cout << "DEBUG: " << __FILE__ << " " << __LINE__ << "\n";
26 struct slopeReconstructorSpec
29 std::string basisName;
37 template<
typename realT>
38 class directPhaseReconstructor
46 typedef Eigen::Array<realT, -1, -1>
imageT;
49 typedef Eigen::Array<realT, -1, -1>
rmatT;
51 typedef slopeReconstructorSpec
specT;
57 eigenCube<realT> _rImages;
68 mx::eigenCube<realT> *_modes {
nullptr};
80 mx::eigenImaged _spectrum;
88 template<
typename AOSysT>
89 void initialize(AOSysT & AOSys,
specT & spec)
92 _modes = &AOSys.dm._infF;
100 _pupil = &AOSys._pupil;
103 _mask.resize(_pupil->rows(), _pupil->cols());
109 mx::fitsFile<realT> ff;
110 ff.write(
"dprMask.fits", _mask);
112 std::string recMatrix = mx::AO::path::sys::cal::iMat( AOSys._sysName,
122 template<
typename AOSysT>
123 void linkSystem(AOSysT & AOSys);
165 template<
typename measurementT,
typename wfsImageT>
169 template<
typename measurementT,
typename wfsImageT>
170 void reconstruct(measurementT & commandVect, wfsImageT & wfsImage);
186 template<
typename measurementT>
189 template<
typename measurementT,
typename wfsImageT>
190 void accumulateRMat(
int i, measurementT &measureVec, wfsImageT & wfsImage);
198 void saveRImages(std::string fname);
203 template<
typename realT>
209 template<
typename realT>
210 template<
typename AOSysT>
211 void directPhaseReconstructor<realT>::linkSystem(AOSysT & AOSys)
213 _modes = &AOSys.dm._modes;
215 _nModes = _modes->planes();
216 _detRows = _modes->rows();
217 _detCols = _modes->cols();
219 _measurementSize = _detRows*_detCols;
221 _pupil = &AOSys._pupil;
222 _measurementSize = _pupil->sum();
224 _mask.resize(_pupil->rows(), _pupil->cols());
225 mx::tukey2d(_mask.data(), _mask.rows(), (realT) _mask.rows(), 0.0, 0.5*(_mask.rows()-1), 0.5*(_mask.cols()-1));
227 mx::fitsFile<realT> ff;
228 ff.write(
"dprMask.fits", _mask);
232 template<
typename realT>
235 return 0.5*780.0e-9/two_pi<realT>();
238 template<
typename realT>
244 template<
typename realT>
250 template<
typename realT>
256 template<
typename realT>
262 template<
typename realT>
265 mx::fitsFile<realT> ff;
268 ff.read(fname, _recon, head);
273 template<
typename realT>
276 return _measurementSize;
279 template<
typename realT>
280 template<
typename measurementT,
typename wfsImageT>
284 slopes.measurement.resize(1, _measurementSize );
288 for(
int i=0; i< wfsImage.image.rows(); ++i)
290 for(
int j=0; j < wfsImage.image.cols(); ++j)
292 if( (*_pupil)(i,j) == 0)
continue;
294 slopes.measurement(0,
k) = wfsImage.image(i,j);
301 template<
typename realT>
302 template<
typename measurementT,
typename wfsImageT>
310 calcMeasurement(slopes, wfsImage);
313 commandVect.measurement = slopes.measurement.matrix()*_recon.matrix();
316 commandVect.iterNo = wfsImage.iterNo;
319 template<
typename realT>
327 _rMat.resize(measurementSize(), nModes);
330 _rImages.resize(_detRows, _detCols, _nModes);
333 template<
typename realT>
334 template<
typename measurementT>
337 _rMat.col(i) = measureVec.measurement.row(0);
340 template<
typename realT>
341 template<
typename measurementT,
typename wfsImageT>
345 accumulateRMat(i, measureVec);
349 _rImages.image(i) = wfsImage.image;
352 template<
typename realT>
355 mx::fitsFile<realT> ff;
358 ff.write(fname, _rMat);
362 template<
typename realT>
363 void directPhaseReconstructor<realT>::saveRImages(std::string fname)
365 mx::fitsFile<realT> ff;
367 ff.write(fname, _rImages);
void saveRMat(std::string fname)
Write the accumulated response matrix to disk.
int detRows()
Get the number of detector rows (_detRows)
void loadRecon(const std::string &fname)
Load the reconstrutor from the specified FITS file.
int _nModes
The number of modes to be reconstructed.
void detCols(int dc)
Set the number of detector columns (_detCols)
Eigen::Array< realT, -1, -1 > imageT
The type of the WFS image.
int measurementSize()
Return the size of the unbinned measurement.
void calcMeasurement(measurementT &slopes, wfsImageT &wfsImage)
Calculate the slope measurement.
int _detRows
The size of the WFS image, in rows.
void initializeRMat(int nmodes, realT calamp, int detrows, int detcols)
Initialize the response matrix for acquisition.
realT calAmp()
Get the calibration amplitude used in response matrix acquisition (_calAmp)
directPhaseReconstructorSpec specT
The specificaion type.
void accumulateRMat(int i, measurementT &measureVec)
Accumalte the next measurement in the response matrix.
imageT _rMat
The response matrix.
void reconstruct(measurementT &commandVect, wfsImageT &wfsImage)
Reconstruct the wavefront from the input image, producing the modal amplitude vector.
int _measurementSize
The number of values in the measurement.
int _detCols
The size of the WFS image, in columns.
directPhaseReconstructor()
Default c'tor.
Eigen::Array< realT,-1,-1 > _recon
The reconstructor matrix.
Eigen::Array< realT, -1, -1 > rmatT
The type of the response matrix.
int detCols()
Get the number of detector columns (_detCols)
void calAmp(realT ca)
Set the calibration amplitude used in response matrix acquisition (_calAmp)
int nModes()
Get the number of modes (_nModes)
void detRows(int dr)
Set the number of detector rows (_detRows)
constexpr units::realT k()
Boltzmann Constant.
void tukey2d(realT *filt, int rows, int cols, realT D, realT alpha, realT xc, realT yc)
Create a 2-D Tukey window.