karhunen_loeve_generator#
- class arte.utils.karhunen_loeve_generator.KarhunenLoeveGenerator(pupil, covariance_matrix)#
Bases:
objectGenerator of KL polynomials departing from a covariance matrix and a user defined base of polynomials.
The user can specify the diameter of the pupil
pupilor specify aCircularMaskIn the case a scalar real value is passed as
pupilargument, The shape of the returned array cannot be specified: it is a square array of size ceil(pupil_diameter). The center of the unit disk cannot be specified and it is the central pixel of the array (if the array size is odd) or the corner of the 4 central pixels (if the array size is even).In the case a
CircularMaskis passed aspupilargument, the mask is used as unit disk over which the polynomial are computed. Non-integer center coordinates and radius are properly managed.- Parameters:
pupil (real or
CircularMask) – If a scalar value, the argument is used as pupil diameter in pixels. If aCircularMask, the argument is used as mask representing the unit disk.covariance_matrix (
arrayof shape (nModes, nModes) representing) – the phenomenon covariance matrix
Examples
Create a KL polynomial using Zernike description of Kolmogorov turbulence >>> from arte.atmo.utils import getFullKolmogorovCovarianceMatrix >>> from arte.utils.zernike_generator import ZernikeGenerator >>> from arte.utils.kl_generator import KLGenerator >>> from arte.types.mask import CircularMask >>> import numpy as np >>> import matplotlib.pyplot as plt
>>> mask = CircularMask((128,128), 64, (64,64)) >>> zz = ZernikeGenerator(mask) >>> nmodes=100 >>> kolm_covar = getFullKolmogorovCovarianceMatrix(nmodes) >>> zbase = np.rollaxis(np.ma.masked_array([zz.getZernike(n) for n in range(2,nmodes+2)]),0,3) >>> generator = KLGenerator(mask, kolm_covar) >>> generator.generateFromBase(zbase) >>> kl =generator.getKL(2) >>> plt.imshow(kl)
Methods
Return X, Y maps of cartesian coordinates
center()Y, X coordinates of the unit disk center
First mode index
radius()Radius of the unit disk
degree
generateFromBase
getCube
getDerivativeX
getDerivativeXDict
getDerivativeY
getDerivativeYDict
getKL
getKLDict
getModesDict
- cartesian_coordinates()#
Return X, Y maps of cartesian coordinates
The KL polynomials and derivatives are evaluated over a grid of points, whose coordinates are accessible through
cartesian_coordinates- Returns:
X,Y – coordinates of points of the unit disk where the polynomials are evaluated
- Return type:
Examples
Create KL polynomials on a unit disk defined over 4 pixels. The returned arrays have (4,4) shape (corresponding to the coords [-0.75, -0.25, 0.25, 0.75])
>>> zg = KLGenerator(4) >>> x, y = zg.cartesian_coordinates() >>> x[0] array([-0.75, -0.25, 0.25, 0.75])
As above with 3 pixels
>>> zg = KLGenerator(3) >>> x, y = zg.cartesian_coordinates() >>> x[0] array([-0.666, 0, 0.666])
In case of non-integer diameter, the array size is rounded up to the next integer
>>> zg = KLGenerator(2.5) >>> x, y = zg.cartesian_coordinates() >>> x[0] array([-0.8, 0, 0.8])
- center()#
Y, X coordinates of the unit disk center
- Returns:
center – Y, X coordinate of the unit disk center in the array reference system
- Return type:
arrayof shape (2,)
- classmethod degree(index)#
- first_mode()#
First mode index
- generateFromBase(inBase)#
- getCube()#
- getDerivativeX(index)#
- getDerivativeXDict(indexVector)#
- getDerivativeY(index)#
- getDerivativeYDict(indexVector)#
- getKL(index)#
- getKLDict(indexVector)#
- getModesDict(indexVector)#
- radius()#
Radius of the unit disk
- Returns:
radius – unit disk radius in pixel
- Return type:
real