mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
zernikeBasis.hpp
Go to the documentation of this file.
1 /** \file zernikeBasis.hpp
2  * \author Jared R. Males (jaredmales@gmail.com)
3  * \brief Generating a Zernike basis.
4  * \ingroup mxAO_files
5  *
6  */
7 
8 #ifndef __zernikeBasis_hpp__
9 #define __zernikeBasis_hpp__
10 
11 #include "../sigproc/zernike.hpp"
12 #include "../improc/fitsFile.hpp"
13 
14 
15 namespace mx
16 {
17 
18 namespace AO
19 {
20 
21 ///Make the Zernike basis
22 /**
23  * \param [in] basisName the name of the basis (not including the mx::AO path)
24  * \param [in] dim the linear size of the maps, that is they will be dimxdim in size.
25  * \param [in] N is the number of degrees of freedom. Number of modes will be (N+1)(N+1) - 1.
26  *
27  * \tparam realT the real numeric type for calculations
28  */
29 template<typename realT>
30 void makeZernikeBasis( const std::string & basisName,
31  const std::string & pupilName,
32  int dim,
33  int N )
34 {
35  improc::eigenCube<realT> rawModes;
36 
37  rawModes.resize(dim, dim, N);
38  zernikeBasis( rawModes);
39 
40  std::string pupilFName = mx::AO::path::pupil::pupilFile(pupilName);
41  Eigen::Array<realT, -1, -1> pupil;
42 
43  mx::improc::fitsFile<realT> ff;
44  ff.read(pupil, pupilFName);
45 
46  realT psum = pupil.sum();
47  realT norm;
48 
49  for(int i=0; i< rawModes.planes(); ++i)
50  {
51  rawModes.image(i) *= pupil;
52 
53  norm = rawModes.image(i).square().sum()/psum;
54 
55  rawModes.image(i)/= sqrt(norm);
56  }
57 
58 
59 
60 // realT p2v;
61 // for(int i=0; i<N; ++i)
62 // {
63 // p2v = rawModes.image(i).maxCoeff() - rawModes.image(i).minCoeff();
64 // rawModes.image(i) /= p2v;
65 // }
66 
67 
68 
69 
70 
71 
72 
73  std::string fName = mx::AO::path::basis::modes(basisName, true);
74 
75  ff.write(fName, rawModes);
76 }
77 
78 } //namespace AO
79 
80 
81 } //namespace mx
82 
83 
84 #endif //__fourierBasis_hpp__
Eigen::Map< Eigen::Array< dataT, Eigen::Dynamic, Eigen::Dynamic > > image(Index n)
Returns a 2D Eigen::Eigen::Map pointed at the specified image.
Definition: eigenCube.hpp:376
int zernikeBasis(cubeT &cube, typename cubeT::Scalar rad=-1, int minj=2)
Fill in an Eigencube-like array with Zernike polynomials in Noll order.
Definition: zernike.hpp:531
The mxlib c++ namespace.
Definition: mxError.hpp:107
void makeZernikeBasis(const std::string &basisName, const std::string &pupilName, int dim, int N)
Make the Zernike basis.