def test_normalisations_complex(self): log = logging.getLogger('TestZern.test_normalisations_complex') n_beta = 6 L, K = 400, 393 # polar grid pol = CZern(n_beta) fitBeta = FitZern(pol, L, K) t1 = time() pol.make_pol_grid(fitBeta.rho_j, fitBeta.theta_i) t2 = time() log.debug('make pol grid {:.6f}'.format(t2 - t1)) # cartesian grid cart = CZern(n_beta) dd = np.linspace(-1.0, 1.0, max(L, K)) xx, yy = np.meshgrid(dd, dd) t1 = time() cart.make_cart_grid(xx, yy) t2 = time() log.debug('make cart grid {:.6f}'.format(t2 - t1)) smap = np.isfinite(cart.eval_grid(np.zeros(cart.nk))) scale = (1.0 / np.sum(smap)) log.debug('') log.debug('{} modes, {} x {} grid'.format(n_beta, L, K)) for i in range(pol.nk): a = np.zeros(pol.nk) a[i] = 1.0 Phi_a = cart.eval_grid(a) for j in range(pol.nk): b = np.zeros(pol.nk) b[j] = 1.0 Phi_b = cart.eval_grid(b) ip = scale * np.sum(Phi_a[smap] * (Phi_b[smap].conj())) if i == j: eip = 1.0 else: eip = 0.0 iperr = abs(ip - eip) log.debug('<{:02},{:02}> = {:+e} {:+e}'.format( i + 1, j + 1, ip, iperr)) self.assertTrue(iperr < self.max_ip_err)
def test_normalisations_complex(self): log = logging.getLogger('TestZern.test_normalisations_complex') n_beta = 6 L, K = 400, 393 # polar grid pol = CZern(n_beta) fitBeta = FitZern(pol, L, K) t1 = time() pol.make_pol_grid(fitBeta.rho_j, fitBeta.theta_i) t2 = time() log.debug('make pol grid {:.6f}'.format(t2 - t1)) # cartesian grid cart = CZern(n_beta) dd = np.linspace(-1.0, 1.0, max(L, K)) xx, yy = np.meshgrid(dd, dd) t1 = time() cart.make_cart_grid(xx, yy) t2 = time() log.debug('make cart grid {:.6f}'.format(t2 - t1)) smap = np.isfinite(cart.eval_grid(np.zeros(cart.nk))) scale = (1.0/np.sum(smap)) log.debug('') log.debug('{} modes, {} x {} grid'.format(n_beta, L, K)) for i in range(pol.nk): a = np.zeros(pol.nk) a[i] = 1.0 Phi_a = cart.eval_grid(a) for j in range(pol.nk): b = np.zeros(pol.nk) b[j] = 1.0 Phi_b = cart.eval_grid(b) ip = scale*np.sum(Phi_a[smap]*(Phi_b[smap].conj())) if i == j: eip = 1.0 else: eip = 0.0 iperr = abs(ip - eip) log.debug('<{:02},{:02}> = {:+e} {:+e}'.format( i + 1, j + 1, ip, iperr)) self.assertTrue(iperr < self.max_ip_err)
# grid sizes L, K = 95, 105 # complex-valued Zernike polynomials up to the 4-th radial order gpf_pol = CZern(4) # to approximate the GPF # FitZern computes the approximate inner products, see Eq. (B4) in [A2015] ip = FitZern(gpf_pol, L, K) gpf_pol.make_pol_grid(ip.rho_j, ip.theta_i) # make a polar grid # random vector of Zernike coefficients to be estimated beta_true = normal(size=gpf_pol.nk) + 1j * normal(size=gpf_pol.nk) # random generalised pupil function P P = gpf_pol.eval_grid(beta_true) # estimate the random vector from the GPF grid beta_hat = ip.fit(P) # plot the results p.figure(2) # real part of the Zernike coefficients of beta_true and beta_hat ax = p.subplot(3, 1, 1) h1 = ax.plot(range(1, gpf_pol.nk + 1), beta_true.real, marker='o') h2 = ax.plot(range(1, gpf_pol.nk + 1), beta_hat.real, marker='x') p.legend(h1 + h2, [r'$\mathcal{R}[\beta]$', r'$\mathcal{R}[\hat{\beta}]$']) p.ylabel('[rad]') p.xlabel('$k$')
# grid sizes L, K = 95, 105 # complex-valued Zernike polynomials up to the 4-th radial order gpf_pol = CZern(4) # to approximate the GPF # FitZern computes the approximate inner products, see Eq. (B4) in [A2015] ip = FitZern(gpf_pol, L, K) gpf_pol.make_pol_grid(ip.rho_j, ip.theta_i) # make a polar grid # random vector of Zernike coefficients to be estimated beta_true = normal(size=gpf_pol.nk) + 1j*normal(size=gpf_pol.nk) # random generalised pupil function P P = gpf_pol.eval_grid(beta_true) # estimate the random vector from the GPF grid beta_hat = ip.fit(P) # plot the results p.figure(2) # real part of the Zernike coefficients of beta_true and beta_hat ax = p.subplot(3, 1, 1) h1 = ax.plot(range(1, gpf_pol.nk + 1), beta_true.real, marker='o') h2 = ax.plot(range(1, gpf_pol.nk + 1), beta_hat.real, marker='x') p.legend( h1 + h2, [r'$\mathcal{R}[\beta]$', r'$\mathcal{R}[\hat{\beta}]$']) p.ylabel('[rad]') p.xlabel('$k$')