Python code to handle complex- and real-valued Zernike polynomials. This module was part of enzpy but will be further developed here instead.
You can install zernike
using pip
pip install --user zernike
python -m zernike.pyramid
import numpy as np
import matplotlib.pyplot as plt
from zernike import RZern
cart = RZern(6)
L, K = 200, 250
ddx = np.linspace(-1.0, 1.0, K)
ddy = np.linspace(-1.0, 1.0, L)
xv, yv = np.meshgrid(ddx, ddy)
cart.make_cart_grid(xv, yv)
c = np.zeros(cart.nk)
plt.figure(1)
for i in range(1, 10):
plt.subplot(3, 3, i)
c *= 0.0
c[i] = 1.0
Phi = cart.eval_grid(c, matrix=True)
plt.imshow(Phi, origin='lower', extent=(-1, 1, -1, 1))
plt.axis('off')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from zernike import RZern
cart = RZern(6)
L, K = 200, 250
ddx = np.linspace(-1.0, 1.0, K)
ddy = np.linspace(-1.0, 1.0, L)
xv, yv = np.meshgrid(ddx, ddy)
cart.make_cart_grid(xv, yv)
c0 = np.random.normal(size=cart.nk)
Phi = cart.eval_grid(c0, matrix=True)
c1 = cart.fit_cart_grid(Phi)[0]
plt.figure(1)
plt.subplot(1, 2, 1)
plt.imshow(Phi, origin='lower', extent=(-1, 1, -1, 1))
plt.axis('off')
plt.subplot(1, 2, 2)
plt.plot(range(1, cart.nk + 1), c0, marker='.')
plt.plot(range(1, cart.nk + 1), c1, marker='.')
plt.show()
import numpy as np
from zernike import RZern, FitZern
pol = RZern(6)
L, K = 200, 250
ip = FitZern(pol, L, K)
pol.make_pol_grid(ip.rho_j, ip.theta_i)
c_true = np.random.normal(size=pol.nk)
Phi = pol.eval_grid(c_true)
c_hat = ip.fit(Phi)
R = np.zeros((pol.nk, 3))
R[:, 0] = c_true
R[:, 1] = c_hat
R[:, 2] = np.abs(c_true - c_hat)
print(R)
np.linalg.norm(c_true - c_hat)/np.linalg.norm(c_true)
git clone https://github.com/jacopoantonello/zernike
and hit enter. Do not use
GitHub's Download ZIP button above, as the installation script will not
work in that case.install.bat
.python -m zernike.test