-
Notifications
You must be signed in to change notification settings - Fork 50
Description
import numpy as np
from prysm.polynomials.qpoly import compute_z_zprime_Q2d, Q2d_nm_c_to_a_b, Q2d
from prysm.polynomials import fringe_to_nm, nm_to_name
from prysm import geometry, coordinates
import matplotlib.pyplot as plt
from matplotlib import colors
def plot_q2d(fringes, coeffs):
x, y = coordinates.make_xy_grid(2048, diameter=2)
r, t = coordinates.cart_to_polar(x, y)
z = np.zeros((2048, 2048))
dr = np.zeros((2048, 2048))
dt = np.zeros((2048, 2048))
nms = []
for J, C in zip(fringes, coeffs):
(n, m) = fringe_to_nm(J)
print(f"(n: {n}, m: {m}) - {C}")
nms.append((n, m))
(cms, ams, bms )= Q2d_nm_c_to_a_b(nms, coeffs)
(_z, _dr, _dt) = compute_z_zprime_Q2d(cms, ams, bms, r, t)
z = (_z)
dr = (_dr)
dt = (_dt)
# Mask out a circle for plotting
mask = geometry.circle(1, r)
z[mask!=1]=np.nan
dr[mask!=1]=np.nan
dt[mask!=1]=np.nan
# Plotting
width = 20
fig = plt.figure(figsize=(width,width/3))
color_norm=colors.TwoSlopeNorm(vcenter=0.0)
z_ax = fig.add_subplot(1, 3, 1)
z_ax.imshow(z, norm=color_norm, cmap="RdBu", extent=[-1, 1, -1, 1])
z_ax.set_title("Phase")
fig.colorbar(z_ax.get_images()[0])
color_norm=colors.TwoSlopeNorm(vcenter=0.0)
dr_ax = fig.add_subplot(1, 3, 2)
dr_ax.imshow(dr, norm=color_norm, cmap="RdBu", extent=[-1, 1, -1, 1])
dr_ax.set_title("Radial derivative of phase")
fig.colorbar(dr_ax.get_images()[0])
color_norm=colors.TwoSlopeNorm(vcenter=0.0)
dt_ax = fig.add_subplot(1, 3, 3)
dt_ax.imshow(dt, norm=color_norm, cmap="RdBu", extent=[-1, 1, -1, 1])
dt_ax.set_title("Tangential derivative of phase")
fig.colorbar(dt_ax.get_images()[0])
fig.suptitle("Q2D stuff")
plt.show()
plt.close(fig)
zernikes = np.arange(1, 6)
coeffs = np.zeros(zernikes.shape)
#coeffs[5] = 1
#coeffs[4] = 0.5
coeffs[1] = 10
plot_q2d(zernikes, coeffs)
So I've been trying to wrap my head around all things Q2d, and so far compute_z_z_prime seems to the be function I need. Right now the Q2d function will take any n and m values in terms of zernike-esque indices. However trying to do that with a combination of Q2d_nm_c_to_a_b
and compute_z_zprime_Q2d
you run into errors if negative and positive m terms don't match.
(Ignore the variable name and fact this is based off of zernike code for a sec)
In this example if I dozernikes = np.arange(1, 3)
, which corresponds to the following nms in zernike indexing:
(n: 0, m: 0) (n: 1, m: 1)
It will error in Q2d_nm_c_to_a_b
with:
Traceback (most recent call last):
File "c:\Users\alist\Documents\GitHub\SympleyWavey\simulations\q2d_polynomials_sanity.py", line 84, in <module>
plot_q2d(zernikes, coeffs)
File "c:\Users\alist\Documents\GitHub\SympleyWavey\simulations\q2d_polynomials_sanity.py", line 24, in plot_q2d
(cms, ams, bms )= Q2d_nm_c_to_a_b(nms, coeffs)
File "C:\Users\alist\miniconda3\envs\prysm\lib\site-packages\prysm\polynomials\qpoly.py", line 1257, in Q2d_nm_c_to_a_b
max_m_b = max(list(bc.keys()))
ValueError: max() arg is an empty sequence
Now this obviously isn't a very imposing issue to work around, but it is one I had to peak at the source of qpoly.py to figure out, and the docstrings don't list the restriction.
So it looks like either a case the function should handle or have listed as a restriction?