Example #1
0
    def test_normalisations_real(self):
        log = logging.getLogger('TestZern.test_normalisations_real')
        n_alpha = 6
        L, K = 400, 357

        # polar grid
        pol = RZern(n_alpha)
        fitAlpha = FitZern(pol, L, K)
        t1 = time()
        pol.make_pol_grid(fitAlpha.rho_j, fitAlpha.theta_i)
        t2 = time()
        log.debug('make pol grid {:.6f}'.format(t2 - t1))

        # cartesian grid
        cart = RZern(n_alpha)
        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_alpha, 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])
                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)
Example #2
0
    def test_normalisations_real(self):
        log = logging.getLogger('TestZern.test_normalisations_real')
        n_alpha = 6
        L, K = 400, 357

        # polar grid
        pol = RZern(n_alpha)
        fitAlpha = FitZern(pol, L, K)
        t1 = time()
        pol.make_pol_grid(fitAlpha.rho_j, fitAlpha.theta_i)
        t2 = time()
        log.debug('make pol grid {:.6f}'.format(t2 - t1))

        # cartesian grid
        cart = RZern(n_alpha)
        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_alpha, 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])
                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)
Example #3
0
        try:
            alpha[args.noll - 1] = args.rms
        except:
            print('Cannot set the required Noll index k.')
            print('Index k must be between 1 and ' + str(alpha.size))
            sys.exit(1)

    # set the alpha coefficients randomly
    if args.random:
        alpha1 = normal(size=alpha.size-1)
        alpha1 = (args.rms/norm(alpha1))*alpha1
        alpha[1:] = alpha1
        del alpha1

    # evaluate the phase corresponding to alpha
    Phi = phase_pol.eval_grid(alpha)

    # evaluate the generalised pupil function P corresponding to alpha
    P = np.exp(1j*Phi)

    # estimate the beta coefficients from P
    beta_hat = ip.fit(P)

    # plot the results
    phaseplot = PhasePlot(n=args.n_alpha)  # to plot beta and the PSF
    betaplot = BetaPlot(args)  # to plot the phase

    # plot alpha
    p.figure(10)
    p.subplot2grid((1, 3), (0, 0), colspan=2)
    h1 = p.plot(range(1, phase_pol.nk + 1), alpha, marker='o')
Example #4
0
        try:
            alpha[args.noll - 1] = args.rms
        except BaseException:
            print('Cannot set the required Noll index k.')
            print('Index k must be between 1 and ' + str(alpha.size))
            sys.exit(1)

    # set the alpha coefficients randomly
    if args.random:
        alpha1 = normal(size=alpha.size-1)
        alpha1 = (args.rms/norm(alpha1))*alpha1
        alpha[1:] = alpha1
        del alpha1

    # evaluate the phase corresponding to alpha
    Phi = phase_pol.eval_grid(alpha)

    # evaluate the generalised pupil function P corresponding to alpha
    P = np.exp(1j*Phi)

    # estimate the beta coefficients from P
    beta_hat = ip.fit(P)

    # plot the results
    phaseplot = PhasePlot(n=args.n_alpha)  # to plot beta and the PSF
    betaplot = BetaPlot(args)  # to plot the phase

    # plot alpha
    p.figure(10)
    p.subplot2grid((1, 3), (0, 0), colspan=2)
    h1 = p.plot(range(1, phase_pol.nk + 1), alpha, marker='o')
Example #5
0
    # grid sizes
    L, K = 95, 105

    # real-valued Zernike polynomials up to the 6-th radial order
    phase_pol = RZern(6)

    # FitZern computes the approximate inner products, see Eq. (B2) in [A2015]
    ip = FitZern(phase_pol, L, K)
    phase_pol.make_pol_grid(ip.rho_j, ip.theta_i)  # make a polar grid

    # random vector of Zernike coefficients to be estimated
    alpha_true = normal(size=phase_pol.nk)

    # phase grid
    Phi = phase_pol.eval_grid(alpha_true)

    # estimate the random vector from the phase grid
    alpha_hat = ip.fit(Phi)

    # plot the results
    p.figure(2)

    # Zernike coefficients of alpha_true and alpha_hat
    ax = p.subplot2grid((3, 3), (0, 0), colspan=3)
    h1 = ax.plot(range(1, phase_pol.nk + 1), alpha_true, marker='o')
    h2 = ax.plot(range(1, phase_pol.nk + 1), alpha_hat, marker='x')
    p.legend(h1 + h2, [r'$\alpha$', r'$\hat{\alpha}$'])
    p.ylabel('[rad]')
    p.xlabel('$k$')
Example #6
0
    # grid sizes
    L, K = 95, 105

    # real-valued Zernike polynomials up to the 6-th radial order
    phase_pol = RZern(6)

    # FitZern computes the approximate inner products, see Eq. (B2) in [A2015]
    ip = FitZern(phase_pol, L, K)
    phase_pol.make_pol_grid(ip.rho_j, ip.theta_i)  # make a polar grid

    # random vector of Zernike coefficients to be estimated
    alpha_true = normal(size=phase_pol.nk)

    # phase grid
    Phi = phase_pol.eval_grid(alpha_true)

    # estimate the random vector from the phase grid
    alpha_hat = ip.fit(Phi)

    # plot the results
    p.figure(2)

    # Zernike coefficients of alpha_true and alpha_hat
    ax = p.subplot2grid((3, 3), (0, 0), colspan=3)
    h1 = ax.plot(range(1, phase_pol.nk + 1), alpha_true, marker='o')
    h2 = ax.plot(range(1, phase_pol.nk + 1), alpha_hat, marker='x')
    p.legend(h1 + h2, [r'$\alpha$', r'$\hat{\alpha}$'])
    p.ylabel('[rad]')
    p.xlabel('$k$')