orb.ext package

Submodules

orb.ext.zern module

@file zern.py @brief Zernike basis function utilities @package libtim.zern @brief Zernike basis function utilities @author Tim van Werkhoven (werkhoven@strw.leidenuniv.nl) @copyright Creative Commons Attribution-Share Alike license versions 3.0 or higher, see http://creativecommons.org/licenses/by-sa/3.0/ @date 20120403 Construct and analyze Zernike basis functions

orb.ext.zern.calc_zern_basis(nmodes, rad, modestart=1, calc_covmat=False)

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.

orb.ext.zern.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

orb.ext.zern.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

orb.ext.zern.fix_noll_map(max)

Translate old incorrect Noll coordinates to correct values. This function repairs data generated with noll_to_zern_broken().

orb.ext.zern.mk_rad_mask(r0, r1=None, norm=True, center=None, dtype=<class 'numpy.float64'>, getxy=False)

Make a rectangular matrix of size (r0, r1) where the value of each element is the Euclidean distance to center. If center is not given, it is the middle of the matrix. If norm is True (default), the distance is normalized to half the radius, i.e. values will range from [-1, 1] for both axes. If only r0 is given, the matrix will be (r0, r0). If r1 is also given, the matrix will be (r0, r1) To make a circular binary mask of (r0, r0), use

mk_rad_mask(r0) < 1

@param [in] r0 The width (and height if r1==None) of the mask. @param [in] r1 The height of the mask. @param [in] norm Normalize the distance such that 2/(r0, r1) equals a distance of 1. @param [in] getxy Return x, y-values instead of r @param [in] dtype Datatype to use for radial coordinates @param [in] center Set distance origin to center (defaults to the middle of the rectangle)

orb.ext.zern.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. @param [in] j Zernike mode Noll index @return (n, m) tuple of Zernike indices @see <https://oeis.org/A176988>.

orb.ext.zern.noll_to_zern_broken(j)

Previous and incorrect Noll-to-Zernike conversion. Stored for reference purposes. Fixed around 1321970330.98158 or Tue Nov 22 13:59:10 2011 UTC. All data generated before this has invalid mapping. @deprecated Incorrect mapping, use noll_to_zern instead

orb.ext.zern.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>.

orb.ext.zern.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. @param [in] m Radial Zernike index @param [in] n Azimuthal Zernike index @param [in] rho Radial coordinate grid @param [in] phi Azimuthal coordinate grid @param [in] norm Normalize modes to unit variance @return 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>.

orb.ext.zern.zernike_rad(m, n, rho)

Make radial Zernike polynomial on coordinate grid rho. @param [in] m Radial Zernike index @param [in] n Azimuthal Zernike index @param [in] rho Radial coordinate grid @return Radial polynomial with identical shape as rho

orb.ext.zern.zernikel(j, rho, phi, norm=True)

Module contents