示例#1
0
def test_HSC_wf():
    fn = os.path.join(directory, "testdata", "HSC_wavefront.txt")
    with open(fn) as f:
        Zwf = np.loadtxt(f, skiprows=17)
    Zwf = Zwf[::-1]  # Need to invert, probably just a Zemax convention...

    telescope = batoid.Optic.fromYaml("HSC_no_obsc.yaml")

    thx = np.deg2rad(0.0)
    thy = np.deg2rad(0.75)
    wavelength = 750e-9
    nx = 512
    bwf = batoid.wavefront(telescope, thx, thy, wavelength, nx=nx)

    Zwf = np.ma.MaskedArray(data=Zwf,
                            mask=Zwf == 0)  # Turn Zwf into masked array

    # There are unimportant differences in piston, tip, and tilt terms.  So instead of comparing
    # the wavefront directly, we'll compare Zernike coefficients for j >= 4.
    x = np.linspace(-1, 1, nx, endpoint=False)
    x, y = np.meshgrid(x, x)
    w = ~Zwf.mask  # Use the same mask for both Zemax and batoid
    basis = galsim.zernike.zernikeBasis(37, x[w], y[w])
    Zcoefs, _, _, _ = np.linalg.lstsq(basis.T, Zwf[w], rcond=-1)
    Bcoefs, _, _, _ = np.linalg.lstsq(basis.T, bwf.array[w], rcond=-1)

    for j in range(1, 38):
        print("{:<4d} {:8.4f} {:8.4f}".format(j, Zcoefs[j], Bcoefs[j]))

    np.testing.assert_allclose(Zcoefs[4:], Bcoefs[4:], rtol=0, atol=0.01)
    # higher order Zernikes match even better
    np.testing.assert_allclose(Zcoefs[11:], Bcoefs[11:], rtol=0, atol=0.01)
示例#2
0
def test_LSST_wf(plot=False):
    thxs = [0.0, 0.0, 0.0, 1.176]
    thys = [0.0, 1.225, 1.75, 1.176]
    fns = [
        "LSST_wf_0.0_0.0.txt", "LSST_wf_0.0_1.225.txt", "LSST_wf_0.0_1.75.txt",
        "LSST_wf_1.176_1.176.txt"
    ]
    for thx, thy, fn in zip(thxs, thys, fns):
        fn = os.path.join(directory, "testdata", fn)
        with open(fn, encoding='utf-16-le') as f:
            Zwf = np.loadtxt(f, skiprows=16)
        Zwf = Zwf[::-1]  # Need to invert, probably just a Zemax convention...

        telescope = batoid.Optic.fromYaml("LSST_g_500.yaml")

        thx = np.deg2rad(thx)
        thy = np.deg2rad(thy)
        wavelength = 500e-9
        nx = 32

        bwf = batoid.wavefront(telescope,
                               thx,
                               thy,
                               wavelength,
                               nx=nx,
                               reference='chief',
                               projection='zemax')
        # Turn Zwf into masked array
        Zwf = np.ma.MaskedArray(data=Zwf, mask=Zwf == 0)

        if plot:
            import matplotlib.pyplot as plt
            fig, axes = plt.subplots(ncols=3, figsize=(10, 3))
            i0 = axes[0].imshow(bwf.array)
            i1 = axes[1].imshow(Zwf)
            i2 = axes[2].imshow(bwf.array - Zwf)
            axes[0].set_title("batoid")
            axes[1].set_title("Zemax")
            axes[2].set_title("difference")
            plt.colorbar(i0, ax=axes[0], label='waves')
            plt.colorbar(i1, ax=axes[1], label='waves')
            plt.colorbar(i2, ax=axes[2], label='waves')
            plt.tight_layout()
            plt.show()

        np.testing.assert_allclose(Zwf * wavelength,
                                   bwf.array * wavelength,
                                   atol=1e-11,
                                   rtol=0)  # 10 picometer tolerance!