TwiceAsNice
2019-02-18
|
Functions | |
def | zernike_rad (m, n, rho) |
def | zernike (m, n, rho, phi, norm=True) |
def | noll_to_zern (j) |
def | zernikel (j, rho, phi, norm=True) |
def | zernike_screen (j, size, norm=True) |
def | zern_normalisation (nmodes=30) |
def | calc_zern_basis (nmodes, rad, modestart=1, calc_covmat=False) |
Higher level Zernike generating / fitting functions. More... | |
def | fit_zernike (wavefront, zern_data={}, nmodes=10, startmode=1, fitweight=None, center=(-0.5, -0.5), rad=-0.5, rec_zern=True, err=None) |
def | calc_zernike (zern_vec, rad, zern_data={}, mask=True) |
def laospy.zernike.calc_zern_basis | ( | nmodes, | |
rad, | |||
modestart = 1 , |
|||
calc_covmat = False |
|||
) |
Higher level Zernike generating / fitting functions.
Calculate a basis of **nmodes** Zernike modes with radius **rad**. ((If **mask** is true, set everything outside of radius **rad** to zero (default). If this is not done, the set of Zernikes will be **rad** by **rad** square and are not orthogonal anymore.)) --> Nothing is masked, do this manually using the 'mask' entry in the returned dict. This output of this function can be used as cache for other functions. @param [in] nmodes Number of modes to generate @param [in] rad Radius of Zernike modes @param [in] modestart First mode to calculate (Noll index, i.e. 1=piston) @param [in] calc_covmat Return covariance matrix for Zernike modes, and its inverse @return Dict with entries 'modes' a list of Zernike modes, 'modesmat' a matrix of (nmodes, npixels), 'covmat' a covariance matrix for all these modes with 'covmat_in' its inverse, 'mask' is a binary mask to crop only the orthogonal part of the modes.
def laospy.zernike.calc_zernike | ( | zern_vec, | |
rad, | |||
zern_data = {} , |
|||
mask = True |
|||
) |
Construct wavefront with Zernike amplitudes **zern_vec**. Given vector **zern_vec** with the amplitude of Zernike modes, return the reconstructed wavefront with radius **rad**. This function uses **zern_data** as cache. If this is not given, it will be generated. See calc_zern_basis() for details. If **mask** is True, set everything outside radius **rad** to zero, this is the default and will use orthogonal Zernikes. If this is False, the modes will not be cropped. @param [in] zern_vec 1D vector of Zernike amplitudes @param [in] rad Radius for Zernike modes to construct @param [in] zern_data Zernike basis cache @param [in] mask If True, set everything outside the Zernike aperture to zero, otherwise leave as is. @see See calc_zern_basis() for details on **zern_data** cache and **mask**
def laospy.zernike.fit_zernike | ( | wavefront, | |
zern_data = {} , |
|||
nmodes = 10 , |
|||
startmode = 1 , |
|||
fitweight = None , |
|||
center = (-0.5, -0.5) , |
|||
rad = -0.5 , |
|||
rec_zern = True , |
|||
err = None |
|||
) |
Fit **nmodes** Zernike modes to a **wavefront**. The **wavefront** will be fit to Zernike modes for a circle with radius **rad** with origin at **center**. **weigh** is a weighting mask used when fitting the modes. If **center** or **rad** are between 0 and -1, the values will be interpreted as fractions of the image shape. **startmode** indicates the Zernike mode (Noll index) to start fitting with, i.e. ***startmode**=4 will skip piston, tip and tilt modes. Modes below this one will be set to zero, which means that if **startmode** == **nmodes**, the returned vector will be all zeroes. This parameter is intended to ignore low order modes when fitting (piston, tip, tilt) as these can sometimes not be derived from data. If **err** is an empty list, it will be filled with measures for the fitting error: 1. Mean squared difference 2. Mean absolute difference 3. Mean absolute difference squared This function uses **zern_data** as cache. If this is not given, it will be generated. See calc_zern_basis() for details. @param [in] wavefront Input wavefront to fit @param [in] zern_data Zernike basis cache @param [in] nmodes Number of modes to fit @param [in] startmode Start fitting at this mode (Noll index) @param [in] fitweight Mask to use as weights when fitting @param [in] center Center of Zernike modes to fit @param [in] rad Radius of Zernike modes to fit @param [in] rec_zern Reconstruct Zernike modes and calculate errors. @param [out] err Fitting errors @return Tuple of (wf_zern_vec, wf_zern_rec, fitdiff) where the first element is a vector of Zernike mode amplitudes, the second element is a full 2D Zernike reconstruction and the last element is the 2D difference between the input wavefront and the full reconstruction. @see See calc_zern_basis() for details on **zern_data** cache
def laospy.zernike.noll_to_zern | ( | j | ) |
Convert linear Noll index to tuple of Zernike indices. j is the linear Noll coordinate, n is the radial Zernike index and m is the azimuthal Zernike index. Parameters ---------- j : integer Zernike mode Noll index Returns ------- (n, m) : tuple of integer Zernike indices see <https://oeis.org/A176988>.
def laospy.zernike.zern_normalisation | ( | nmodes = 30 | ) |
Calculate normalisation vector. This function calculates a **nmodes** element vector with normalisation constants for Zernike modes that have not already been normalised. @param [in] nmodes Size of normalisation vector. @see <http://research.opt.indiana.edu/Library/VSIA/VSIA-2000_taskforce/TOPS4_2.html> and <http://research.opt.indiana.edu/Library/HVO/Handbook.html>.
def laospy.zernike.zernike | ( | m, | |
n, | |||
rho, | |||
phi, | |||
norm = True |
|||
) |
Calculate Zernike mode (m,n) on grid rho and phi. rho and phi should be radial and azimuthal coordinate grids of identical shape, respectively. Parameters ---------- m : integer Radial Zernike index n : integer Azimuthal Zernike index rho Radial coordinate grid phi Azimuthal coordinate grid norm : boolean Normalize modes to unit variance Returns ------- Zernike mode (m,n) with identical shape as rho, phi see <http://research.opt.indiana.edu/Library/VSIA/VSIA-2000_taskforce/TOPS4_2.html> and <http://research.opt.indiana.edu/Library/HVO/Handbook.html>.
def laospy.zernike.zernike_rad | ( | m, | |
n, | |||
rho | |||
) |
Make radial Zernike polynomial on coordinate grid rho. Parameters: ----------- m : integer Radial Zernike index n : integer Azimuthal Zernike index rho : Radial coordinate grid Returns: -------- Radial polynomial with identical shape as rho
def laospy.zernike.zernike_screen | ( | j, | |
size, | |||
norm = True |
|||
) |
Returns a quadratic masked array with the jth Zernike polynomial Use an odd value for the size to have the center of the resulting Zernike polynomial on a full pixel Parameters ---------- j : integer Zernike mode Noll index (starts at 1 = Piston) size : integer diameter of the unit circle = size of the returned array. norm : boolean Normalize modes to unit variance (default) Returns ------- masked array with Zernike polynomial in a circular author: Thomas Bertram date: 20130731
def laospy.zernike.zernikel | ( | j, | |
rho, | |||
phi, | |||
norm = True |
|||
) |
Calculate Zernike mode with Noll index j on grid rho and phi. Parameters ---------- j : integer Zernike mode Noll index rho : Radial coordinate grid phi : Azimuthal coordinate grid norm : boolean Normalize modes to unit variance Returns ------- Zernike mode j with identical shape as rho, phi