6#ifndef __pywfsSlopeReconstructor_hpp__
7#define __pywfsSlopeReconstructor_hpp__
23struct pywfsSlopeReconstructorSpec
26 std::string basisName;
34template <
typename _
floatT>
38 typedef _floatT floatT;
44 typedef Eigen::Array<floatT, -1, -1>
imageT;
47 typedef Eigen::Array<floatT, -1, -1>
rmatT;
49 typedef pywfsSlopeReconstructorSpec specT;
83 template <
typename AOSysT>
84 void initialize( AOSysT &AOSys, specT &spec )
87 AOSys._sysName, spec.dmName, AOSys._wfsName, AOSys._pupilName, spec.basisName, spec.rMatId );
119 void maskFile(
const std::string &mf );
159 template <
typename measurementT,
typename wfsImageT>
163 template <
typename measurementT,
typename wfsImageT>
164 void reconstruct( measurementT &commandVect, wfsImageT &wfsImage );
173 void initializeRMat(
int nmodes, floatT calamp,
int detrows,
int detcols );
180 template <
typename measurementT>
183 template <
typename measurementT,
typename wfsImageT>
184 void accumulateRMat(
int i, measurementT &measureVec, wfsImageT &wfsImage );
192 void saveRImages( std::string fname );
195template <
typename floatT>
206template <
typename floatT>
212template <
typename floatT>
220template <
typename floatT>
226template <
typename floatT>
234template <
typename floatT>
240template <
typename floatT>
248template <
typename floatT>
254template <
typename floatT>
260template <
typename floatT>
266template <
typename floatT>
272template <
typename floatT>
279template <
typename floatT>
285template <
typename floatT>
292template <
typename floatT>
302 _maskFile = head[
"MASKFILE"].value<std::string>();
307 _calAmp = head[
"CALAMP"].value<floatT>();
309 _nModes = head[
"NMODES"].value<
int>();
311 _detRows = head[
"DETROWS"].value<
int>();
312 _detCols = head[
"DETCOLS"].value<
int>();
317template <
typename floatT>
324 std::cerr <<
"Loading Mask: " <<
_maskFile <<
"\n";
341template <
typename floatT>
349template <
typename floatT>
350template <
typename measurementT,
typename wfsImageT>
360 std::cout <<
"rebinning" <<
"\n";
361 _wfsImage.resize( wfsImage.image.rows() /
_binFact, wfsImage.image.cols() /
_binFact );
362 imageDownSample( _wfsImage, wfsImage.image );
366 _wfsImage = wfsImage.image;
369 int nsz = _wfsImage.rows();
373 std::vector<int> x( nPix ), y( nPix );
376 for(
int i = 0; i <
_quadMask.rows(); ++i )
378 for(
int j = 0; j <
_quadMask.rows(); ++j )
389 slopes.measurement.resize( 1, 2. * nPix );
391 floatT I0, I1, I2, I3;
393 floatT norm = _wfsImage.sum();
395 for(
int i = 0; i < nPix; ++i )
397 I0 = _wfsImage( x[i], y[i] );
398 I1 = _wfsImage( x[i] + 0.5 * nsz, y[i] );
399 I2 = _wfsImage( x[i], y[i] + 0.5 * nsz );
400 I3 = _wfsImage( x[i] + 0.5 * nsz, y[i] + 0.5 * nsz );
404 slopes.measurement( 0, i ) = 0;
406 slopes.measurement( 0, i + nPix ) = 0;
410 slopes.measurement( 0, i ) = ( I0 + I1 - I2 - I3 ) / norm;
411 slopes.measurement( 0, i + nPix ) = ( I0 + I2 - I1 - I3 ) / norm;
425template <
typename floatT>
426template <
typename measurementT,
typename wfsImageT>
433 commandVect.measurement = slopes.measurement.matrix() *
_recon.matrix();
435 commandVect.iterNo = wfsImage.iterNo;
438template <
typename floatT>
455template <
typename floatT>
456template <
typename measurementT>
459 _rMat.col( i ) = measureVec.measurement.row( 0 );
462template <
typename floatT>
463template <
typename measurementT,
typename wfsImageT>
466 accumulateRMat( i, measureVec );
468 _rImages.image( i ) = wfsImage.image;
471template <
typename floatT>
489 head.
append(
"CALAMP",
_calAmp,
"DM Calibration amplitude" );
490 head.
append(
"NMODES",
_nModes,
"Number of modes included in the response matrix." );
496template <
typename floatT>
497void pywfsSlopeReconstructor<floatT>::saveRImages( std::string fname )
504 head.
append(
"MASKFILE", maskFile(),
"Name of mask file" );
508 head.
append(
"MASKRAD", maskRadius(),
"Mask radius, in pixels" );
509 head.
append(
"MASKOBS", maskObscuration(),
"Mask fractional central obscuration" );
512 head.
append(
"DETROWS", _detRows,
"WFS detector rows" );
513 head.
append(
"DETCOLS", _detCols,
"WFS detector cols" );
514 head.
append(
"CALAMP", _calAmp,
"DM Calibration amplitude" );
515 head.
append(
"NMODES", _nModes,
"Number of modes included in the response matrix." );
518 ff.
write( fname, _rImages, head );
Standardized paths for the mx::AO system.
std::string iMat(const std::string &sysName, const std::string &dmName, const std::string &wfsName, const std::string &pupilName, const std::string &basisName, const std::string &id, bool create=false)
Path for the system response interaction matrix.
floatT calAmp()
Get the calibration amplitude used in response matrix acquisition (_calAmp).
int _detCols
The size of the WFS image, in columns.
void reconstruct(measurementT &commandVect, wfsImageT &wfsImage)
Reconstruct the wavefront from the input image, producing the modal amplitude vector.
int _detRows
The size of the WFS image, in rows.
int nModes()
Get the number of modes (_nModes).
floatT _maskRadius
0 is centrally obscured circle, 1 is supplied by fits files
std::string _maskFile
The name of the quadrant mask file.
void saveRMat(std::string fname)
Write the accumulated response matrix to disk.
floatT maskObscuration()
Get the quadrant mask central obscuration ratio (_maskObscuration).
Eigen::Array< floatT, -1, -1 > _recon
The reconstructor matrix.
Eigen::Array< floatT, -1, -1 > _quadMask
The quadrant mask.
int _nModes
The number of modes to be reconstructed.
int detCols()
Get the number of detector columns (_detCols).
int _measurementSize
The number of slopes in the measurement.
Eigen::Array< floatT, -1, -1 > imageT
The type of the measurement (i.e. the slope vector).
int measurementSize()
Return the size of the unbinned measurement.
bool _maskMade
Whether or not the mask has been made.
int _binFact
The binning to apply before reconstructing.
floatT _calAmp
The calibration amplitude used for response matrix acquisition.
void calcMeasurement(measurementT &slopes, wfsImageT &wfsImage)
Calculate the slope measurement.
void accumulateRMat(int i, measurementT &measureVec)
Accumalte the next measurement in the response matrix.
Eigen::Array< floatT, -1, -1 > rmatT
The type of the response matrix.
floatT _maskObscuration
The central obscuration of the quadrant mask.
int detRows()
Get the number of detector rows (_detRows).
void loadRecon(std::string fname)
Load the reconstrutor from the specified FITS file.
imageT _rMat
The response matrix.
floatT maskRadius()
Get the quadrant mask radius (_maskRadius).
std::string maskFile()
Get the quadrant mask file name (_maskFile).
void initializeRMat(int nmodes, floatT calamp, int detrows, int detcols)
Initialize the response matrix for acquisition.
pywfsSlopeReconstructor()
Default c'tor.
void calcMask()
Calculates the quadrant mask.
Class to manage interactions with a FITS file.
error_t read(dataT *data)
Read the contents of the FITS file into an array.
error_t write(const dataT *im, int d1, int d2, int d3, fitsHeader< verboseT > *head)
Write the contents of a raw array to the FITS file.
An image cube with an Eigen-like API.
An image cube with an Eigen API.
Declares and defines a class to work with a FITS file.
int circularPupil(arrayT &m, typename arrayT::Scalar eps=0, typename arrayT::Scalar rad=0, typename arrayT::Scalar overscan=0)
Fill in an Eigen-like array with a circular pupil mask.
Utilities for modeling image formation.