naclib.stpol

Main ST-polynomial decomposition functionality.

By Edo van Veen @ Nynke Dekker Lab, TU Delft (2021)

naclib.stpol.Nnmu(n, mu)

Calculate N_{n, mu}.

class naclib.stpol.STPolynomials(j_max_S, j_max_T)

ST-polynomials class for calculating the ST-polynomial decomposition coefficients of a distortion map, and for calculating a correction field from decomposition coefficents.

Parameters:
  • j_max_S (int) – Maximum term for S-polynomials.

  • j_max_T (int) – Maximum term for T-polynomials.

get_decomposition(locs, field_D, mean_error_convergence=1e-06, mean_error_divergence=0.01, max_iter=10000, return_error=False, verbose=True)

Get the optimal decomposition coefficients for a distortion map with N points by using the iterative method.

Parameters:
  • locs (np.array of floats) – x and y coordinates of the distortion map coordinates, shape (N, 2).

  • field_D (np.array of floats) – x and y components of the distortion vectors at the coordinates given by locs, shape (N, 2).

  • mean_error_convergence (float (optional)) – The iteration is considered converged when the mean error reaches this value. Default: 1e-6.

  • mean_error_divergence (float (optional)) – The iteration is considered diverged when the mean error reaches this value. Default: 1e-2.

  • max_iter (int (optional)) – Maximum number of iterations. Default: 10000.

  • return_error (bool (optional)) – If True, the error is given as a third return value. Default: False.

  • verbose (bool (optional)) – If True, print message on convergence or divergence. Default: True.

Returns:

  • a_Stot (dict) – Dictionary with S-polynomial indices/coefficients as key/value pairs.

  • a_Ttot (dict) – Dictionary with T-polynomial indices/coefficients as key/value pairs.

get_decomposition_gramschmidt(locs, field_D)

Get the decomposition coefficients for a distortion map with N points, by using Gram-Schmidt orthonormalization to orthonormalize the ST polynomials on the finite grid.

Parameters:
  • locs (np.array of floats) – x and y coordinates of the distortion map coordinates, shape (N, 2).

  • field_D (np.array of floats) – x and y components of the distortion vectors at the coordinates given by locs, shape (N, 2).

Returns:

  • coefs_S (dict) – Dictionary with S-polynomial indices/coefficients as key/value pairs.

  • coefs_T (dict) – Dictionary with T-polynomial indices/coefficients as key/value pairs.

get_decomposition_noniterative(locs, field_D)

Get the decomposition coefficients for a distortion map with N points without using the iterative method and without Gram-Schmidt orthonormalization.

Parameters:
  • locs (np.array of floats) – x and y coordinates of the distortion map coordinates, shape (N, 2).

  • field_D (np.array of floats) – x and y components of the distortion vectors at the coordinates given by locs, shape (N, 2).

Returns:

  • coefs_S (dict) – Dictionary with S-polynomial indices/coefficients as key/value pairs.

  • coefs_T (dict) – Dictionary with T-polynomial indices/coefficients as key/value pairs.

get_field(locs, coefs_S, coefs_T)

Get the correction field from ST-polynomial decomposition coefficients.

Parameters:
  • locs (np.array of floats) – x and y coordinates of input coordinates, shape (N, 2).

  • coefs_S (dict) – Dictionary with S-polynomial indices/coefficients as key/value pairs.

  • coefs_T (dict) – Dictionary with T-polynomial indices/coefficients as key/value pairs.

Returns:

field_ST – x and y components of the correction vectors at the coordinates given by locs, shape (N, 2).

Return type:

np.array of floats

naclib.stpol.get_Rzern(j_max)

Get an Rzern object from the zernike library.

naclib.stpol.get_ST_terms(j_max)

Get all S/T terms for a value of j_max.

naclib.stpol.get_Z_derivatives(j_max)

Calculate Zernike polynomial derivatives, from https://doi.org/10.1364/OE.26.018878 eqs 44-51.

naclib.stpol.get_highest_converging_j_max(locs, D, mean_error_convergence=1e-06, mean_error_divergence=0.01, max_iter=10000)

Get the highest value of j_max (up to 45) for which the ST polynomial decomposition converges.

Parameters:
  • locs (np.array of floats) – x and y coordinates of the distortion map coordinates, shape (N, 2).

  • D (np.array of floats) – x and y components of the distortion vectors at the coordinates given by locs, shape (N, 2).

  • mean_error_convergence (float (optional)) – The iteration is considered converged when the mean error reaches this value. Default: 1e-6.

  • mean_error_divergence (float (optional)) – The iteration is considered diverged when the mean error reaches this value. Default: 1e-2.

  • max_iter (int (optional)) – Maximum number of iterations. Default: 10000.

Returns:

j_max_best – Highest converging maximum term for S- and T-polynomials.

Return type:

int

naclib.stpol.get_phi_derivatives(j_max)

Calculate phi vector field derivatives.

naclib.stpol.gramschmidt(V)

Transform field basis V (shape (n_basis, n_locs, 2)) into orthonormal basis U; also return transformation matrix M (shape (n_basis, n_basis)).

naclib.stpol.inprod(A, B)

Inner product between fields A (shape (n_locs, 2)) and B (shape (n_locs, 2)).

naclib.stpol.nm2nmu(n, m)

Convert an (n, m) pair to an (n, mu) pair.

naclib.stpol.nmu2nm(n, mu)

Convert an (n, mu) pair to an (n, m) pair.