Пример #1
0
def test_HSC_zernike():
    ZZernike = [0]
    with open(os.path.join(directory, "testdata", "HSC_Zernike.txt")) as f:
        for i, line in enumerate(f):
            if i > 38:
                ZZernike.append(float(line[9:20]))
    ZZernike = np.array(ZZernike)

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

    thx = np.deg2rad(0.0)
    thy = np.deg2rad(0.75)
    wavelength = 750e-9
    nx = 256

    bZernike = batoid.zernike(telescope,
                              thx,
                              thy,
                              wavelength,
                              jmax=37,
                              nx=nx,
                              projection='gnomonic')
    # revisit this with projection='zemax' once we're referencing the wavefront
    # to the chief ray...

    print()
    print("j      Zemax    batoid")
    print("----------------------")
    for j in range(1, 38):
        print("{:<4d} {:8.4f} {:8.4f}".format(j, ZZernike[j], bZernike[j]))

    # Don't care about piston, tip, or tilt.
    np.testing.assert_allclose(ZZernike[4:], bZernike[4:], rtol=0, atol=1e-3)
    np.testing.assert_allclose(ZZernike[11:], bZernike[11:], rtol=0, atol=2e-4)
Пример #2
0
def test_HSC_zernike():
    ZZernike = [0]
    with open(os.path.join(directory, "testdata", "HSC_Zernike.txt")) as f:
        for i, line in enumerate(f):
            if i > 38:
                ZZernike.append(float(line[9:20]))
    ZZernike = np.array(ZZernike)

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

    thx = np.deg2rad(0.0)
    thy = np.deg2rad(0.75)
    wavelength = 750e-9
    nx = 256

    bZernike = batoid.zernike(
        telescope, thx, thy, wavelength, jmax=37, nx=nx,
        projection='zemax', reference='chief'
    )

    print()
    print("j      Zemax    batoid    diff")
    print("------------------------------")
    for j in range(1, 38):
        print(
            f"{j:<4d} {ZZernike[j]:8.4f} {bZernike[j]:8.4f} "
            f"{ZZernike[j]-bZernike[j]:8.4f}"
        )

    # Don't care about piston, tip, or tilt.
    np.testing.assert_allclose(ZZernike[4:], bZernike[4:], rtol=0, atol=1e-2)
    np.testing.assert_allclose(ZZernike[11:], bZernike[11:], rtol=0, atol=3e-3)
Пример #3
0
def test_HSC_zernike():
    ZZernike = [0]
    with open(os.path.join(directory, "testdata", "HSC_Zernike.txt")) as f:
        for i, line in enumerate(f):
            if i > 38:
                ZZernike.append(float(line[9:20]))
    ZZernike = np.array(ZZernike)

    HSC_fn = os.path.join(batoid.datadir, "HSC", "HSC_no_obsc.yaml")
    config = yaml.load(open(HSC_fn))
    telescope = batoid.parse.parse_optic(config['opticalSystem'])

    thx = np.deg2rad(0.0)
    thy = np.deg2rad(0.75)
    wavelength = 750e-9
    nx = 256

    bZernike = batoid.zernike(telescope, thx, thy, wavelength, jmax=37, nx=nx)

    print()
    print("j      Zemax    batoid")
    print("----------------------")
    for j in range(1, 38):
        print("{:<4d} {:8.4f} {:8.4f}".format(j, ZZernike[j], bZernike[j]))

    # Don't care about piston, tip, or tilt.
    np.testing.assert_allclose(ZZernike[4:], bZernike[4:], rtol=0, atol=1e-3)
    np.testing.assert_allclose(ZZernike[11:], bZernike[11:], rtol=0, atol=2e-4)
Пример #4
0
def test_zernikePyramid():
    telescope = batoid.Optic.fromYaml("LSST_r.yaml")

    thxs = np.linspace(-1.7, 1.7, 9)
    thys = np.linspace(-1.7, 1.7, 9)

    vmin = -0.3
    vmax = 0.3
    zs = []
    thxplot = []
    thyplot = []
    for ix, thx in enumerate(thxs):
        for iy, thy in enumerate(thys):
            if np.hypot(thx, thy) > 1.75:
                continue
            zs.append(batoid.zernike(
                telescope, np.deg2rad(thx), np.deg2rad(thy), 500e-9,
                jmax=15, eps=0.61, nx=16
            ))
            thxplot.append(thx)
            thyplot.append(thy)
    zs = np.array(zs).T
    thxplot = np.array(thxplot)
    thyplot = np.array(thyplot)

    zranges = [slice(4, 16), slice(4, 11)]

    for zrange, vdim in zip(zranges, [True, False]):
        fig = Figure(figsize=(13, 8))
        batoid.plotUtils.zernikePyramid(
            thxplot, thyplot, zs[zrange],
            vmin=vmin, vmax=vmax, s=100,
            fig=fig
        )
        fig.savefig("pyramid.png")

        # cleanup
        try:
            os.remove("pyramid.png")
        except OSError:
            pass
Пример #5
0
def test_zernikeGQ():
    if __name__ == '__main__':
        nx = 1024
        rings = 10
        tol = 1e-4
    else:
        nx = 128
        rings = 5
        tol = 1e-3
    telescope = batoid.Optic.fromYaml("LSST_r.yaml")
    telescope.clearObscuration()
    telescope['LSST.M1'].obscuration = batoid.ObscNegation(
        batoid.ObscCircle(4.18))
    zSquare = batoid.zernike(telescope,
                             0.0,
                             0.0,
                             625e-9,
                             nx=nx,
                             jmax=28,
                             reference='chief')
    zGQ = batoid.zernikeGQ(telescope,
                           0.0,
                           0.0,
                           625e-9,
                           rings=rings,
                           jmax=28,
                           reference='chief')

    np.testing.assert_allclose(zSquare, zGQ, rtol=0, atol=tol)

    # Repeat with annular Zernikes
    telescope['LSST.M1'].obscuration = batoid.ObscNegation(
        batoid.ObscAnnulus(0.61 * 4.18, 4.18))
    zSquare = batoid.zernike(telescope,
                             0.0,
                             0.0,
                             625e-9,
                             nx=nx,
                             jmax=28,
                             reference='chief',
                             eps=0.61)
    zGQ = batoid.zernikeGQ(telescope,
                           0.0,
                           0.0,
                           625e-9,
                           rings=rings,
                           jmax=28,
                           reference='chief',
                           eps=0.61)

    np.testing.assert_allclose(zSquare, zGQ, rtol=0, atol=tol)

    # Try off-axis
    zSquare = batoid.zernike(telescope,
                             np.deg2rad(0.2),
                             np.deg2rad(0.1),
                             625e-9,
                             nx=nx,
                             jmax=28,
                             reference='chief',
                             eps=0.61)
    zGQ = batoid.zernikeGQ(telescope,
                           np.deg2rad(0.2),
                           np.deg2rad(0.1),
                           625e-9,
                           rings=rings,
                           jmax=28,
                           reference='chief',
                           eps=0.61)

    np.testing.assert_allclose(zSquare, zGQ, rtol=0, atol=tol)

    # Try reference == mean
    # Try off-axis
    zSquare = batoid.zernike(telescope,
                             np.deg2rad(0.2),
                             np.deg2rad(0.1),
                             625e-9,
                             nx=nx,
                             jmax=28,
                             reference='mean',
                             eps=0.61)
    zGQ = batoid.zernikeGQ(telescope,
                           np.deg2rad(0.2),
                           np.deg2rad(0.1),
                           625e-9,
                           rings=rings,
                           jmax=28,
                           reference='mean',
                           eps=0.61)
    # Z1-3 less reliable, but mostly uninteresting anyway...
    np.testing.assert_allclose(zSquare[4:], zGQ[4:], rtol=0, atol=tol)