2024-06-19 23:56:02 +08:00
|
|
|
from ctypes import c_int, c_double
|
2018-04-29 06:35:56 -04:00
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
from numpy.ctypeslib import ndpointer
|
|
|
|
|
|
|
|
|
|
from . import _dll
|
|
|
|
|
|
2018-05-16 21:25:29 -04:00
|
|
|
|
2018-10-21 18:59:03 -04:00
|
|
|
_dll.calc_zn.restype = None
|
|
|
|
|
_dll.calc_zn.argtypes = [c_int, c_double, c_double, ndpointer(c_double)]
|
2018-05-13 19:21:36 -04:00
|
|
|
|
2018-10-21 18:59:03 -04:00
|
|
|
_dll.calc_zn_rad.restype = None
|
|
|
|
|
_dll.calc_zn_rad.argtypes = [c_int, c_double, ndpointer(c_double)]
|
2018-08-03 16:44:21 -05:00
|
|
|
|
2018-04-29 06:35:56 -04:00
|
|
|
|
|
|
|
|
def calc_zn(n, rho, phi):
|
|
|
|
|
""" Calculate the n-th order modified Zernike polynomial moment for a
|
|
|
|
|
given angle (rho, theta) location in the unit disk. The normalization of
|
|
|
|
|
the polynomials is such that the integral of Z_pq*Z_pq over the unit disk
|
|
|
|
|
is exactly pi
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
n : int
|
|
|
|
|
Maximum order
|
|
|
|
|
rho : float
|
|
|
|
|
Radial location in the unit disk
|
|
|
|
|
phi : float
|
2019-11-22 22:56:16 +00:00
|
|
|
Theta (radians) location in the unit disk
|
2018-04-29 06:35:56 -04:00
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
numpy.ndarray
|
|
|
|
|
Corresponding resulting list of coefficients
|
|
|
|
|
"""
|
|
|
|
|
|
2018-05-06 20:14:54 -04:00
|
|
|
num_bins = ((n + 1) * (n + 2)) // 2
|
2018-04-29 06:35:56 -04:00
|
|
|
zn = np.zeros(num_bins, dtype=np.float64)
|
2018-10-21 18:59:03 -04:00
|
|
|
_dll.calc_zn(n, rho, phi, zn)
|
2018-04-29 06:35:56 -04:00
|
|
|
return zn
|
|
|
|
|
|
2018-08-07 10:19:29 -05:00
|
|
|
|
2018-08-03 16:44:21 -05:00
|
|
|
def calc_zn_rad(n, rho):
|
2018-08-07 10:19:29 -05:00
|
|
|
""" Calculate the even orders in n-th order modified Zernike polynomial
|
|
|
|
|
moment with no azimuthal dependency (m=0) for a given radial location in
|
|
|
|
|
the unit disk. The normalization of the polynomials is such that the
|
|
|
|
|
integral of Z_pq*Z_pq over the unit disk is exactly pi.
|
2018-08-03 16:44:21 -05:00
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
n : int
|
|
|
|
|
Maximum order
|
|
|
|
|
rho : float
|
|
|
|
|
Radial location in the unit disk
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
numpy.ndarray
|
|
|
|
|
Corresponding resulting list of coefficients
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
num_bins = n // 2 + 1
|
|
|
|
|
zn_rad = np.zeros(num_bins, dtype=np.float64)
|
2018-10-21 18:59:03 -04:00
|
|
|
_dll.calc_zn_rad(n, rho, zn_rad)
|
2018-08-03 16:44:21 -05:00
|
|
|
return zn_rad
|