mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
The Zernike Basis

int mx::sigproc::noll_nm (int &n, int &m, int j)
 Get the Zernike coefficients n,m corrresponding the Noll index j. More...
 
int mx::sigproc::noll_j (unsigned n, int m)
 Get the Noll index j corresponding to Zernike coefficients n,m. More...
 
int mx::sigproc::nZernRadOrd (unsigned n)
 Get the number of Zernikes up to and including a radial order. More...
 
template<typename realT >
int mx::sigproc::zernikeRCoeffs (std::vector< realT > &c, int n, int m)
 Calculate the coefficients of a Zernike radial polynomial. More...
 
template<typename realT , typename calcRealT >
realT mx::sigproc::zernikeR (realT rho, int n, int m, std::vector< calcRealT > &c)
 Calculate the value of a Zernike radial polynomial at a given separation. More...
 
template<typename realT , typename calcRealT >
realT mx::sigproc::zernikeR (realT rho, int n, int m)
 Calculate the value of a Zernike radial polynomial at a given separation. More...
 
template<typename realT , typename calcRealT >
realT mx::sigproc::zernike (realT rho, realT phi, int n, int m, std::vector< calcRealT > &c)
 Calculate the value of a Zernike radial polynomial at a given radius and angle. More...
 
template<typename realT , typename calcRealT >
realT mx::sigproc::zernike (realT rho, realT phi, int n, int m)
 Calculate the value of a Zernike radial polynomial at a given radius and angle. More...
 
template<typename realT , typename calcRealT >
realT mx::sigproc::zernike (realT rho, realT phi, int j)
 Calculate the value of a Zernike radial polynomial at a given radius and angle. More...
 
template<typename arrayT , typename calcRealT , int overscan = 2>
int mx::sigproc::zernike (arrayT &arr, int n, int m, typename arrayT::Scalar xcen, typename arrayT::Scalar ycen, typename arrayT::Scalar rad=-1)
 Fill in an Eigen-like array with a Zernike polynomial. More...
 
template<typename arrayT , typename calcRealT >
int mx::sigproc::zernike (arrayT &arr, int j, typename arrayT::Scalar xcen, typename arrayT::Scalar ycen, typename arrayT::Scalar rad=-1)
 Fill in an Eigen-like array with a Zernike polynomial. More...
 
template<typename arrayT , typename calcRealT >
int mx::sigproc::zernike (arrayT &arr, int n, int m, typename arrayT::Scalar rad=-1)
 Fill in an Eigen-like array with a Zernike polynomial. More...
 
template<typename arrayT , typename calcRealT >
int mx::sigproc::zernike (arrayT &arr, int j, typename arrayT::Scalar rad=-1)
 Fill in an Eigen-like array with a Zernike polynomial. More...
 
template<typename cubeT , typename calcRealT >
int mx::sigproc::zernikeBasis (cubeT &cube, typename cubeT::Scalar rad=-1, int minj=2)
 Fill in an Eigencube-like array with Zernike polynomials in Noll order. More...
 
template<typename realT >
realT mx::sigproc::zernikeQNorm (realT k, realT phi, int n, int m)
 Calculate the square-normed Fourier transform of a Zernike polynomial at position (k,phi) More...
 
template<typename realT >
realT mx::sigproc::zernikeQNorm (realT k, realT phi, int j)
 Calculate the square-normed Fourier transform of a Zernike polynomial at position (k,phi) More...
 
template<typename arrayT >
int mx::sigproc::zernikeQNorm (arrayT &arr, arrayT &k, arrayT &phi, int j)
 Fill in an Eigen-like array with the square-normed Fourier transform of a Zernike polynomial. More...
 
template<typename realT >
realT mx::sigproc::zernikePPiston (const realT &kD)
 Calculate the spatial power spectrum of Piston. More...
 
template<typename realT >
realT mx::sigproc::zernikePTipTilt (const realT &kD)
 Calculate the spatial power spectrum of Tip & Tilt. More...
 
template<typename realT >
realT mx::sigproc::zernikePDefocus (const realT &kD)
 Calculate the spatial power spectrum of Defocus. More...
 
template<typename realT >
realT mx::sigproc::zernikePAstig (const realT &kD)
 Calculate the spatial power spectrum of Astigmatism. More...
 
template<typename realT >
realT mx::sigproc::zernikePComa (const realT &kD)
 Calculate the spatial power spectrum of Coma. More...
 
template<typename realT >
realT mx::sigproc::zernikePTrefoil (const realT &kD)
 Calculate the spatial power spectrum of Trefoil. More...
 

Function Documentation

◆ noll_j()

int mx::sigproc::noll_j ( unsigned  n,
int  m 
)

Get the Noll index j corresponding to Zernike coefficients n,m.

Calculates the value j for(n,m) following Noll (1976) [17] See also: http://en.wikipedia.org/wiki/Zernike_polynomials

Return values
>=0 on success
-1on error (n-m odd)
Parameters
[in]nn the radial index of the Zernike polynomial
[in]mm the azimuthal index of the Zernnike polynomial.

◆ noll_nm()

int mx::sigproc::noll_nm ( int &  n,
int &  m,
int  j 
)

Get the Zernike coefficients n,m corrresponding the Noll index j.

Calculates the values of (n,m) for an index j following Noll (1976) [17] See also: http://en.wikipedia.org/wiki/Zernike_polynomials

If j is odd, this returns m <= 0.

Return values
0on success
-1on error (j < 1)
Test:
Scenario: testing noll_nm [test doc]
Parameters
[out]nn the radial index of the Zernike polynomial
[out]mm the azimuthal index of the Zernnike polynomial. m < 0 if j odd.
[in]jj the Noll index, j > 0.

Definition at line 38 of file zernike.cpp.

References mx::math::func::sign().

Referenced by SCENARIO(), mx::AO::analysis::zernikeTemporalPSD< _realT, aosysT >::singleLayerPSD(), mx::sigproc::zernike(), and mx::sigproc::zernikeQNorm().

◆ nZernRadOrd()

int mx::sigproc::nZernRadOrd ( unsigned  n)

Get the number of Zernikes up to and including a radial order.

Calculates the total number of Zernike polynomials through radial order n. See Noll (1976) [17] See also: http://en.wikipedia.org/wiki/Zernike_polynomials

Return values
thenumber of
-1on error (n-m odd)
Parameters
n[n] the radial order

◆ zernike() [1/7]

template<typename arrayT , typename calcRealT >
int mx::sigproc::zernike ( arrayT &  arr,
int  j,
typename arrayT::Scalar  rad = -1 
)

Fill in an Eigen-like array with a Zernike polynomial.

The geometric center of the array, 0.5*(arr.rows()-1), 0.5*(arr.cols()-1), is used as the center. Sets any pixel which is at rad <= r < rad+0.5 pixels to rho = 1, to be consistent with mx::circularPupil

Parameters
[out]arris the allocated array with an Eigen-like interface. The rows() and cols() members are used to size the polynomial.
[in]jis the Noll index of the polynomial
[in]rad[optional] is the desired radius. If rad <= 0, then the maximum radius based on dimensions of m is used.
Template Parameters
arrayTis an Eigen-like array of real floating type
calcRealTis a real floating type used for internal calculations, should be at least double

Definition at line 511 of file zernike.hpp.

◆ zernike() [2/7]

template<typename arrayT , typename calcRealT >
int mx::sigproc::zernike ( arrayT &  arr,
int  j,
typename arrayT::Scalar  xcen,
typename arrayT::Scalar  ycen,
typename arrayT::Scalar  rad = -1 
)

Fill in an Eigen-like array with a Zernike polynomial.

Sets any pixel which is at rad <= r <= rad+0.5 pixels to rho = 1, to be consistent with mx::circularPupil

Parameters
[out]arris the allocated array with an Eigen-like interface. The rows() and cols() members are used to size the polynomial.
[in]jis the Noll index of the polynomial
[in]xcenis the x coordinate of the desired center of the polynomial, in pixels
[in]ycenis the y coordinate of the desired center of the polynomial, in pixels
[in]rad[optional] is the desired radius. If rad <= 0, then the maximum radius based on dimensions of m is used.
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double

Definition at line 461 of file zernike.hpp.

◆ zernike() [3/7]

template<typename arrayT , typename calcRealT >
int mx::sigproc::zernike ( arrayT &  arr,
int  n,
int  m,
typename arrayT::Scalar  rad = -1 
)

Fill in an Eigen-like array with a Zernike polynomial.

The geometric center of the array, 0.5*(arr.rows()-1), 0.5*(arr.cols()-1), is used as the center. Sets any pixel which is at rad <= r < rad+0.5 pixels to rho = 1, to be consistent with mx::circularPupil

Parameters
[out]arris the allocated array with an Eigen-like interface. The rows() and cols() members are used to size the polynomial.
[in]jis the Noll index of the polynomial
[in]rad[optional] is the desired radius. If rad <= 0, then the maximum radius based on dimensions of m is used.
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double

Definition at line 488 of file zernike.hpp.

◆ zernike() [4/7]

template<typename arrayT , typename calcRealT , int overscan = 2>
int mx::sigproc::zernike ( arrayT &  arr,
int  n,
int  m,
typename arrayT::Scalar  xcen,
typename arrayT::Scalar  ycen,
typename arrayT::Scalar  rad = -1 
)

Fill in an Eigen-like array with a Zernike polynomial.

Sets any pixel which is at rad <= r < rad+0.5 pixels to rho = 1, to be consistent with mx::circularPupil

Parameters
[out]arris the allocated array with an Eigen-like interface. The rows() and cols() members are used to size the polynomial.
[in]nis the radial index of the polynomial
[in]mis the azimuthal index of the polynomial
[in]xcenis the x coordinate of the desired center of the polynomial, in pixels
[in]ycenis the y coordinate of the desired center of the polynomial, in pixels
[in]rad[optional] is the desired radius. If rad <= 0, then the maximum radius based on dimensions of m is used.
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double

Definition at line 397 of file zernike.hpp.

◆ zernike() [5/7]

template<typename realT , typename calcRealT >
realT mx::sigproc::zernike ( realT  rho,
realT  phi,
int  j 
)

Calculate the value of a Zernike radial polynomial at a given radius and angle.

Return values
-9999indicates a possible error
Rthe value of the Zernike radial polynomial otherwise
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double
Parameters
[in]rhothe radial coordinate, \( 0 \le \rho \le 1 \).
[in]phithe azimuthal angle (in radians)
[in]jthe Noll index of the Zernike polynomial.

Definition at line 356 of file zernike.hpp.

References mx::sigproc::noll_nm().

◆ zernike() [6/7]

template<typename realT , typename calcRealT >
realT mx::sigproc::zernike ( realT  rho,
realT  phi,
int  n,
int  m 
)

Calculate the value of a Zernike radial polynomial at a given radius and angle.

Return values
-9999indicates a possible error
Rthe value of the Zernike radial polynomial otherwise
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double
Parameters
[in]rhothe radial coordinate, \( 0 \le \rho \le 1 \).
[in]phithe azimuthal angle (in radians)
[in]nthe radial index of the Zernike polynomial.
[in]mthe azimuthal index of the Zernike polynomial.

Definition at line 319 of file zernike.hpp.

References mx::astro::constants::c().

◆ zernike() [7/7]

template<typename realT , typename calcRealT >
realT mx::sigproc::zernike ( realT  rho,
realT  phi,
int  n,
int  m,
std::vector< calcRealT > &  c 
)

Calculate the value of a Zernike radial polynomial at a given radius and angle.

Parameters
[in]rhois the radial coordinate, \( 0 \le \rho \le 1 \).
[in]phiis the azimuthal angle (in radians)
[in]nis the radial index of the Zernike polynomial.
[in]mis the azimuthal index of the Zernike polynomial.
[in]cis contains the radial polynomial coeeficients, and must be of length \( 0.5(n-m)+1\).
Return values
-9999indicates a possible error
Rthe value of the Zernike radial polynomial otherwise
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double

Definition at line 264 of file zernike.hpp.

References mx::astro::constants::c().

◆ zernikeBasis()

template<typename cubeT , typename calcRealT >
int mx::sigproc::zernikeBasis ( cubeT &  cube,
typename cubeT::Scalar  rad = -1,
int  minj = 2 
)

Fill in an Eigencube-like array with Zernike polynomials in Noll order.

The cube is pre-allocated to set the image size and the number of modes.

Returns
0 on success
-1 on error
Template Parameters
cubeTis an Eigencube-like array with real floating point type
calcRealTis a real floating type used for internal calculations, should be at least double
Parameters
cube[in.out] the pre-allocated cube which will be filled with the Zernike basis
[in]rad[optional] the radius of the aperture. If -1 then the full image size is used.
[in]minj[optional] the minimum j value to include. The default is j=2, which skips piston (j=1).

Definition at line 531 of file zernike.hpp.

Referenced by mx::AO::makeZernikeBasis().

◆ zernikePAstig()

template<typename realT >
realT mx::sigproc::zernikePAstig ( const realT &  kD)

Calculate the spatial power spectrum of Astigmatism.

Parameters
[in]kDSpatial frequency in diameter units, i.e. cycles per aperture.

Definition at line 704 of file zernike.hpp.

References mx::math::func::jincN().

◆ zernikePComa()

template<typename realT >
realT mx::sigproc::zernikePComa ( const realT &  kD)

Calculate the spatial power spectrum of Coma.

Parameters
[in]kDSpatial frequency in diameter units, i.e. cycles per aperture.

Definition at line 711 of file zernike.hpp.

References mx::math::func::jincN().

◆ zernikePDefocus()

template<typename realT >
realT mx::sigproc::zernikePDefocus ( const realT &  kD)

Calculate the spatial power spectrum of Defocus.

Parameters
[in]kDSpatial frequency in diameter units, i.e. cycles per aperture.

Definition at line 697 of file zernike.hpp.

References mx::math::func::jincN().

◆ zernikePPiston()

template<typename realT >
realT mx::sigproc::zernikePPiston ( const realT &  kD)

Calculate the spatial power spectrum of Piston.

Parameters
[in]kDSpatial frequency in diameter units, i.e. cycles per aperture.

Definition at line 683 of file zernike.hpp.

References mx::math::func::jinc().

◆ zernikePTipTilt()

template<typename realT >
realT mx::sigproc::zernikePTipTilt ( const realT &  kD)

Calculate the spatial power spectrum of Tip & Tilt.

Parameters
[in]kDSpatial frequency in diameter units, i.e. cycles per aperture.

Definition at line 690 of file zernike.hpp.

References mx::math::func::jincN().

◆ zernikePTrefoil()

template<typename realT >
realT mx::sigproc::zernikePTrefoil ( const realT &  kD)

Calculate the spatial power spectrum of Trefoil.

Parameters
[in]kDSpatial frequency in diameter units, i.e. cycles per aperture.

Definition at line 718 of file zernike.hpp.

References mx::math::func::jincN().

◆ zernikeQNorm() [1/3]

template<typename arrayT >
int mx::sigproc::zernikeQNorm ( arrayT &  arr,
arrayT &  k,
arrayT &  phi,
int  j 
)

Fill in an Eigen-like array with the square-normed Fourier transform of a Zernike polynomial.

The array is filled in with the values of |Q(k,phi)|^2 according to Equation (8) of Noll (1976) [17].

Test:
Scenario: testing zernikeQNorm [test doc]
Returns
0 on success
-1 on error
Template Parameters
arrayTis the Eigen-like array type. Arithmetic will be done in arrayT::Scalar.
Parameters
[out]arrthe allocated array. The rows() and cols() members are used to size the transform.
[in]kthe normalized spatial frequency magnitude at each pixel. This is in the [17] convention of cycles-per-radius.
[in]phithe spatial frequency angle at each pixel
[in]jthe polynomial index in the Noll convention [17]

Definition at line 650 of file zernike.hpp.

References mx::astro::constants::k(), and mx::sigproc::noll_nm().

Referenced by mx::sigproc::zernikeQNorm().

◆ zernikeQNorm() [2/3]

template<typename realT >
realT mx::sigproc::zernikeQNorm ( realT  k,
realT  phi,
int  j 
)

Calculate the square-normed Fourier transform of a Zernike polynomial at position (k,phi)

Implements Equation (8) of Noll (1976) [17].

Returns
the value of |Q(k,phi)|^2
Template Parameters
realTis the floating point type used for arithmetic
Parameters
[in]kthe radial coordinate of normalized spatial frequency. This is in the [17] convention of cycles-per-radius.
[in]phithe azimuthal coordinate of normalized spatial frequency
[in]jthe Zernike polynomial index j (Noll convention)

Definition at line 627 of file zernike.hpp.

References mx::astro::constants::k(), mx::sigproc::noll_nm(), and mx::sigproc::zernikeQNorm().

◆ zernikeQNorm() [3/3]

template<typename realT >
realT mx::sigproc::zernikeQNorm ( realT  k,
realT  phi,
int  n,
int  m 
)

Calculate the square-normed Fourier transform of a Zernike polynomial at position (k,phi)

Implements Equation (8) of Noll (1976) [17].

Todo:
need a more robust jinc_n function for n > 1
Test:
Scenario: testing zernikeQNorm [test doc]
Returns
the value of |Q(k,phi)|^2
Template Parameters
realTis the floating point type used for arithmetic
Parameters
[in]kthe radial coordinate of normalized spatial frequency. This is in the [17] convention of cycles-per-radius.
[in]phithe azimuthal coordinate of normalized spatial frequency
[in]nthe Zernike polynomial n
[in]mthe Zernike polynomial m

Definition at line 569 of file zernike.hpp.

References mx::math::func::bessel_j(), and mx::astro::constants::k().

Referenced by mx::AO::analysis::F_zernike(), and SCENARIO().

◆ zernikeR() [1/2]

template<typename realT , typename calcRealT >
realT mx::sigproc::zernikeR ( realT  rho,
int  n,
int  m 
)

Calculate the value of a Zernike radial polynomial at a given separation.

Return values
-9999indicates a possible error
Rthe value of the Zernike radial polynomial otherwise
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calculations, should be at least double
Parameters
[in]rhothe radial coordinate, \( 0 \le \rho \le 1 \).
[in]nthe radial index of the Zernike polynomial.
[in]mthe azimuthal index of the Zernike polynomial.

Definition at line 214 of file zernike.hpp.

References mx::astro::constants::c(), and mx::sigproc::zernikeRCoeffs().

◆ zernikeR() [2/2]

template<typename realT , typename calcRealT >
realT mx::sigproc::zernikeR ( realT  rho,
int  n,
int  m,
std::vector< calcRealT > &  c 
)

Calculate the value of a Zernike radial polynomial at a given separation.

Return values
-9999indicates a possible error
Rthe value of the Zernike radial polynomial otherwise
Template Parameters
realTis a real floating type
calcRealTis a real floating type used for internal calcs, should be at least double.
Parameters
[in]rhothe radial coordinate, \( 0 \le \rho \le 1 \).
[in]nthe radial index of the Zernike polynomial.
[in]mthe azimuthal index of the Zernike polynomial.
[in]ccontains the radial polynomial coeeficients, and must be of length \( 0.5(n-m)+1\).

Definition at line 160 of file zernike.hpp.

References mx::astro::constants::c(), and mx::astro::constants::k().

◆ zernikeRCoeffs()

template<typename realT >
int mx::sigproc::zernikeRCoeffs ( std::vector< realT > &  c,
int  n,
int  m 
)

Calculate the coefficients of a Zernike radial polynomial.

Return values
0on success
-1on error
Template Parameters
realTis a real floating type
Parameters
[out]callocated to length \( 0.5(n-m)+1\) and filled with the coefficients.
[in]nthe radial index of the Zernike polynomial.
[in]mthe azimuthal index of the Zernike polynomial.

Definition at line 103 of file zernike.hpp.

References mx::astro::constants::c(), and mx::astro::constants::k().

Referenced by mx::sigproc::zernikeR().