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

BasisSet

Base class for all basis sets.

ChebyshevPolynomials

Chebyshev polynomials are a suitable basis set for fields defined on rectangular apertures.

FringeZernikes

Fringe Zernike polyonimals as described in Gross' Handbook of Optics (2nd vol) or http://www.jcmwave.com/JCMsuite/doc/html/ParameterReference/0c19949d2f03c5a96890075a6695b258.html

LegendrePolynomials

Legendre polynomials are a suitable basis set for fields defined on rectangular apertures.

NumericallyOrthogonalized

Represents a basis set that is numerically orthogonalized through a Gram-Schmidt procedure on the given grid.

Polynomials

Polynomials in x and y.

PresampledBasisSet

Sampled basis functions.

RescaledBasis

Rescale basis functions on a new aperture/mask.

TensorProductBasis

Abstract 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.

Functions

basis_from_generating_function

Generate a BasisSet object from a given field function.

fringe_to_n_m

Map Fringe Zernike index j to Zernike indices n, m.

fringe_zernike

Fringe Zernike Z_j at the points (x, y) of the unit disk (no mask is applied, peak value 1 on the unit circle).

fringe_zernike_R_nm

Radial polynomial for Zernikes.

fringe_zernike_Y_m

Angle dependence of Zernike polynomials.

fringe_zernike_norm

Norm of the j-th Fringe Zernike polynomial on a disk.

fringe_zernike_sum

Sum of Fringe Zernikes on the unit disk.

legendre_norm_1d

Return norm of L_n(x).

legendre_norm_2d

Return norm of tensor product basis state L_n(x)*L_m(y).

local_coordinates

Coordinates in a frame that is shifted to (x0, y0) and rotated by angle.

poly_basis_size

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: object

Base class for all basis sets. Should not be instantiated directly.

eval_single(index)[source]

Return a single basis function.

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: BasisSet

Sampled basis functions.

Substitutes run-time recomputation of data by lookups of precomputed data.

eval_single(index)[source]

Return a single basis function.

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_to_n_m(j)[source]

Map Fringe Zernike index j to Zernike indices n, m.

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: BasisSet

Fringe Zernike polyonimals as described in Gross’ Handbook of Optics (2nd vol) or http://www.jcmwave.com/JCMsuite/doc/html/ParameterReference/0c19949d2f03c5a96890075a6695b258.html

eval_single(j)[source]

Return a single basis function.

eval_single_scattered(x, y, j)[source]

Return the j-th Fringe Zernike at scattered points (no mask is applied).

Parameters:
x, yarrays

Coordinates of the points.

jint

Fringe index.

Returns:
valarray

Z_j in the shifted and rotated coordinates of the basis, normalized to R_norm.

normalization_factor(i)[source]

Norm <Z_i|Z_i> of i-th Fringe-Zernike polynomial.

Parameters:
iint
Returns:
normdouble

Notes

The Fringe Zernikes get their normalization from the choice of R(R_max) = 1. This means the norm over the entire (unit) disk may differ with the Fringe index.

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: BasisSet

Abstract 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(index)[source]

Return a single basis function.

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.

single_index_to_n_m(index)[source]

Convert single index to indices n, m for P_n(x) and P_m(y).

class pyoptics.bases.LegendrePolynomials(x, y, a=1.0, b=1.0, x0=0.0, y0=0.0, angle=0.0)[source]

Bases: TensorProductBasis

Legendre 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.

eval_1d(t, n)[source]

Evaluate the Legendre polynomial of degree n.

Parameters:
tarray

Scaled coordinates in [-1, 1].

nint

Degree.

Returns:
valarray

P_n(t).

normalization_factor(i)[source]

Norm <L_i|L_i> of i-th Legendre basis function.

Parameters:
iint
Returns:
normdouble
class pyoptics.bases.ChebyshevPolynomials(x, y, a=1.0, b=1.0, x0=0.0, y0=0.0, angle=0.0)[source]

Bases: TensorProductBasis

Chebyshev 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.

eval_1d(t, n)[source]

Evaluate the Chebyshev polynomial (first kind) of degree n.

Parameters:
tarray

Scaled coordinates in [-1, 1].

nint

Degree.

Returns:
valarray

T_n(t).

pyoptics.bases.poly_basis_size(order)[source]

Number of monomials up to given order.

class pyoptics.bases.Polynomials(x, y)[source]

Bases: BasisSet

Polynomials in x and y.

class pyoptics.bases.NumericallyOrthogonalized(x, y, basis_type=None, indices=None, new_mask=None, weight_func=None, norm_func=None, **kwargs)[source]

Bases: PresampledBasisSet

Represents a basis set that is numerically orthogonalized through a Gram-Schmidt procedure on the given grid.

eval_single_scattered(x, y, i, interpolation='linear')[source]

Evaluation at scattered points (not implemented yet).

Parameters:
x, yarrays

Coordinates of the points.

iint

Index of the basis function.

interpolationstr, optional

Interpolation method.

Raises:
NotImplementedError

Always.

class pyoptics.bases.RescaledBasis(x, y, basis_to_rescale_type=None, mask=None, scale_func=None, scale_val_func=None, **kwargs)[source]

Bases: BasisSet

Rescale 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.

get_rescaling_factor(index)[source]

Get factor to rescale with.

get_rescaling_factor_from_sampled_func(index, sampled_func)[source]

Rescaling factor for a sampled basis function.

Parameters:
indexint

Index of the basis function.

sampled_funcarray

The basis function sampled on the new aperture.

Returns:
factornumber

scale_val_func(index)/scale_func(sampled_func).

eval_single(index)[source]

Return a single basis function.

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