pyoptics.bases¶
Module for basis sets.
In optics, different basis sets are used to describe fields in the plane, e.g. Zernike polynomials in the description of aberrations in systems with circular aperture stops. This module offers an object oriented approach to such basis sets.
References¶
F. Zernike, “Beugungstheorie des Schneidenverfahrens und seiner verbesserten Form, der Phasenkontrastmethode”, Physica 1, 689-704 (1934).
R. J. Noll, “Zernike polynomials and atmospheric turbulence”, J. Opt. Soc. Am. 66, 207-211 (1976).
J. C. Wyant and K. Creath, “Basic wavefront aberration theory for optical metrology”, in R. R. Shannon and J. C. Wyant (eds.), Applied Optics and Optical Engineering, Vol. XI, Academic Press (1992).
V. N. Mahajan and G.-m. Dai, “Orthonormal polynomials in wavefront analysis: analytical solution”, J. Opt. Soc. Am. A 24, 2994-3016 (2007).
Classes
Base class for all basis sets. |
|
Chebyshev polynomials are a suitable basis set for fields defined on rectangular apertures. |
|
Fringe Zernike polyonimals as described in Gross' Handbook of Optics (2nd vol) or http://www.jcmwave.com/JCMsuite/doc/html/ParameterReference/0c19949d2f03c5a96890075a6695b258.html |
|
Legendre polynomials are a suitable basis set for fields defined on rectangular apertures. |
|
Represents a basis set that is numerically orthogonalized through a Gram-Schmidt procedure on the given grid. |
|
Polynomials in x and y. |
|
Sampled basis functions. |
|
Rescale basis functions on a new aperture/mask. |
|
Abstract base class for tensor product bases P_n(u/a)*P_m(v/b) on the rectangle |
Functions
Generate a BasisSet object from a given field function. |
|
Map Fringe Zernike index j to Zernike indices n, m. |
|
Fringe Zernike Z_j at the points (x, y) of the unit disk (no mask is applied, peak value 1 on the unit circle). |
|
Radial polynomial for Zernikes. |
|
Angle dependence of Zernike polynomials. |
|
Norm of the j-th Fringe Zernike polynomial on a disk. |
|
Sum of Fringe Zernikes on the unit disk. |
|
Return norm of L_n(x). |
|
Return norm of tensor product basis state L_n(x)*L_m(y). |
|
Coordinates in a frame that is shifted to (x0, y0) and rotated by angle. |
|
Number of monomials up to given order. |
- pyoptics.bases.local_coordinates(x, y, x0=0.0, y0=0.0, angle=0.0)[source]¶
Coordinates in a frame that is shifted to (x0, y0) and rotated by angle.
A basis function f(u, v) evaluated at the local coordinates (u, v) of the points (x, y) is the function f moved to (x0, y0) and rotated counterclockwise (from x towards y) by angle about that point.
- Parameters:
- x, yarrays or numbers
Coordinates of the same shape.
- x0, y0numbers, optional
Origin of the local frame.
- anglenumber, optional
Rotation angle in radians, counterclockwise.
- Returns:
- u, varrays
u = cos(angle)*(x - x0) + sin(angle)*(y - y0), v = -sin(angle)*(x - x0) + cos(angle)*(y - y0).
- class pyoptics.bases.BasisSet(x, y)[source]¶
Bases:
objectBase class for all basis sets. Should not be instantiated directly.
- eval_single_scattered(x, y, i)[source]¶
Return the i-th basis function at scattered points.
Implemented by the subclasses; used for fits to scattered data.
- Parameters:
- x, yarrays
Coordinates of the points.
- iint
Index of the basis function.
- Returns:
- valarray
Basis function at (x, y), same shape as x.
- eval_scattered(inds, coeffs, x, y)[source]¶
Evaluate basis for scattered x, y data.
- Parameters:
- indsiterable
Indices to evaluate.
- coeffsiterable
- x, yarrays
- Returns:
- valarray
- normalization_factor(i)[source]¶
Return norm of i-th basis function. This is used in basis expansions.
- coeffs_from_field(field, indices, method='LSTSQ')[source]¶
Expand a sampled field in the basis set.
- Parameters:
- field2d array
Field on the grid x, y of the basis.
- indicesiterable of int
Indices of the basis functions to use.
- method{“LSTSQ”, “DI”}, optional
“LSTSQ” (default): least squares fit; “DI”: overlap integrals (direct integration) with the masked field, divided by the norms.
- Returns:
- coeffsarray
Expansion coefficients in the order of indices.
- coeffs_from_scattered(x, y, data, indices, do_scale=False)[source]¶
Fit basis to given scattered data.
- Parameters:
- x, yarrays
- dataarrays
Data sampled at x, y. Of identical shape as each x and y.
- indicesarray or list
Indices to be used in fit.
- do_scaleboolean, optional
If True, apply preconditioning to least squares problem. Defaults to False.
- Returns:
- coeffsarray
- class pyoptics.bases.PresampledBasisSet(x, y, basis_type=None, indices=None, **kwargs)[source]¶
Bases:
BasisSetSampled basis functions.
Substitutes run-time recomputation of data by lookups of precomputed data.
- pyoptics.bases.fringe_zernike_norm(j, R_norm=1.0)[source]¶
Norm of the j-th Fringe Zernike polynomial on a disk.
- Parameters:
- jint
Fringe index.
- R_normnumber, optional
Radius of the disk.
- Returns:
- normnumber
Integral of Z_j**2 over the disk, R_norm**2*pi*(1 + delta_m0)/(2*(n + 1)).
- pyoptics.bases.fringe_zernike_R_nm(n, m, rho)[source]¶
Radial polynomial for Zernikes.
- Parameters:
- nint
- mint
- rhoarray or number
- Returns:
- R_mmnumber or array
- pyoptics.bases.fringe_zernike_Y_m(m, phi)[source]¶
Angle dependence of Zernike polynomials.
- Parameters:
- mint
- phiarray or number
- Returns:
- Y_mnumber or array
- pyoptics.bases.fringe_zernike(j, x, y)[source]¶
Fringe Zernike Z_j at the points (x, y) of the unit disk (no mask is applied, peak value 1 on the unit circle).
- Parameters:
- jint
Fringe index.
- x, yarrays or numbers
Coordinates normalized to the radius of the disk.
- Returns:
- Z_jarray
- pyoptics.bases.fringe_zernike_sum(coeffs, x, y)[source]¶
Sum of Fringe Zernikes on the unit disk.
- Parameters:
- coeffsdict
{j: c_j}, real or complex coefficients. None or {} gives zeros.
- x, yarrays
Coordinates in units of the disk radius.
- Returns:
- valarray
sum_j c_j Z_j(x, y), shape of the broadcast x and y.
- class pyoptics.bases.FringeZernikes(x, y, R_norm=1.0, x0=0.0, y0=0.0, angle=0.0)[source]¶
Bases:
BasisSetFringe Zernike polyonimals as described in Gross’ Handbook of Optics (2nd vol) or http://www.jcmwave.com/JCMsuite/doc/html/ParameterReference/0c19949d2f03c5a96890075a6695b258.html
- pyoptics.bases.legendre_norm_1d(n, a=1.0)[source]¶
Return norm of L_n(x).
- Parameters:
- nint
Index to L_n(x).
- anumber
Scaling parameter.
- Returns:
- normnumber
- pyoptics.bases.legendre_norm_2d(j, a=1.0, b=1.0)[source]¶
Return norm of tensor product basis state L_n(x)*L_m(y).
- Parameters:
- jint
Single index to tensor product state. Maps to n, m as in LegendrePolynomials class.
- a, bnumbers
x and y scaling parameters.
- Returns:
- normnumber
- class pyoptics.bases.TensorProductBasis(x, y, a=1.0, b=1.0, x0=0.0, y0=0.0, angle=0.0)[source]¶
Bases:
BasisSetAbstract base class for tensor product bases P_n(u/a)*P_m(v/b) on the rectangle
|u|<= a,|v|<= b, built from a family P_n of 1D polynomials.(u, v) are the local coordinates of the rectangle that is centered at (x0, y0) and rotated counterclockwise by angle (see local_coordinates()). Subclasses implement eval_1d(); a subclass that knows its norms sets _has_norm = True and implements normalization_factor().
The single index j enumerates the pairs (n, m) by total order n + m: (0, 0), (1, 0), (0, 1), (2, 0), (1, 1), (0, 2), …
- abstractmethod eval_1d(t, n)[source]¶
Evaluate the n-th 1D polynomial (implemented by the subclasses).
- Parameters:
- tarray
Scaled coordinates in [-1, 1].
- nint
Degree.
- Returns:
- valarray
P_n(t).
- eval_single_scattered(x, y, i)[source]¶
Return the i-th basis function at scattered points (no mask is applied).
- Parameters:
- x, yarrays
Coordinates of the points.
- iint
Single index of the basis function (see
single_index_to_n_m()).
- Returns:
- valarray
P_n(u/a)*P_m(v/b) in the shifted and rotated coordinates u, v.
- class pyoptics.bases.LegendrePolynomials(x, y, a=1.0, b=1.0, x0=0.0, y0=0.0, angle=0.0)[source]¶
Bases:
TensorProductBasisLegendre polynomials are a suitable basis set for fields defined on rectangular apertures.
The basis set is the product of two Legendre polynomials L_n(u/a)*L_m(v/b); see TensorProductBasis for the parameters.
- class pyoptics.bases.ChebyshevPolynomials(x, y, a=1.0, b=1.0, x0=0.0, y0=0.0, angle=0.0)[source]¶
Bases:
TensorProductBasisChebyshev polynomials are a suitable basis set for fields defined on rectangular apertures.
The basis set is the product of two Chebyshev polynomials T_n(u/a)*T_m(v/b); see TensorProductBasis for the parameters. The basis is orthogonal with respect to a specific scalar product with weight function 1/sqrt(1-x**2) for each dimension.
- class pyoptics.bases.NumericallyOrthogonalized(x, y, basis_type=None, indices=None, new_mask=None, weight_func=None, norm_func=None, **kwargs)[source]¶
Bases:
PresampledBasisSetRepresents a basis set that is numerically orthogonalized through a Gram-Schmidt procedure on the given grid.
- class pyoptics.bases.RescaledBasis(x, y, basis_to_rescale_type=None, mask=None, scale_func=None, scale_val_func=None, **kwargs)[source]¶
Bases:
BasisSetRescale basis functions on a new aperture/mask.
Use this for e.g. normalizing FringeZernikes an non-circular aperture such that coefficients can again be read as maximum values on the aperture.
- pyoptics.bases.basis_from_generating_function(index_func, field_func, **kwargs)[source]¶
Generate a BasisSet object from a given field function.
- Parameters:
- index_funccallable
Maps a single integer n to one or several indices i, j, k…
- field_funccallable
Field or basis function generating function with signature
field_func(i, j, k, ..., x, y, **kwargs).
- Returns:
- generated_basisBasisSet object