Esempio n. 1
0
def test_AsymmetricObscuredAperture(display=False):
    """  Test that we can run the code with asymmetric spiders
    """

    from ..misc import airy_2d

    pri_diam = 1
    sec_diam = 0.4
    # Analytic PSF for 1 meter diameter aperture
    analytic = airy_2d(diameter=pri_diam, obscuration=sec_diam/pri_diam)
    analytic /= analytic.sum() # for comparison with poppy outputs normalized to total=1


    # Numeric PSF for 1 meter diameter aperture
    osys = poppy_core.OpticalSystem()
    osys.add_pupil(
            optics.CompoundAnalyticOptic( [optics.CircularAperture(radius=pri_diam/2) ,
                                           optics.AsymmetricSecondaryObscuration(secondary_radius=sec_diam/2, support_angle=[0,150,210], support_width=0.1) ]) )
    osys.add_detector(pixelscale=0.030,fov_pixels=512, oversample=1)
    if display: osys.display()
    numeric = osys.calc_psf(wavelength=1.0e-6, display=False)

    # Comparison
    difference = numeric[0].data-analytic
    #assert np.all(np.abs(difference) < 3e-5)


    if display:
        from .. import utils
        #from matplotlib.colors import LogNorm
        #norm = LogNorm(vmin=1e-6, vmax=1e-2)

        #ax2=pl.imshow(numeric[0].data, norm=norm)
        utils.display_PSF(numeric, vmin=1e-8, vmax=1e-2, colorbar=False)
Esempio n. 2
0
def test_AsymmetricObscuredAperture(display=False):
    """  Test that we can run the code with asymmetric spiders
    """

    from ..misc import airy_2d

    pri_diam = 1
    sec_diam = 0.4
    # Analytic PSF for 1 meter diameter aperture
    analytic = airy_2d(diameter=pri_diam, obscuration=sec_diam/pri_diam)
    analytic /= analytic.sum() # for comparison with poppy outputs normalized to total=1


    # Numeric PSF for 1 meter diameter aperture
    osys = poppy_core.OpticalSystem()
    osys.addPupil(
            optics.CompoundAnalyticOptic( [optics.CircularAperture(radius=pri_diam/2) ,
                                           optics.AsymmetricSecondaryObscuration(secondary_radius=sec_diam/2, support_angle=[0,150,210], support_width=0.1) ]) )
    osys.addDetector(pixelscale=0.030,fov_pixels=512, oversample=1)
    if display: osys.display()
    numeric = osys.calcPSF(wavelength=1.0e-6, display=False)

    # Comparison
    difference = numeric[0].data-analytic
    #assert np.all(np.abs(difference) < 3e-5)


    if display:
        from .. import utils
        #from matplotlib.colors import LogNorm
        #norm = LogNorm(vmin=1e-6, vmax=1e-2)

        #ax2=pl.imshow(numeric[0].data, norm=norm)
        utils.display_PSF(numeric, vmin=1e-8, vmax=1e-2, colorbar=False)
Esempio n. 3
0
def test_CompoundAnalyticOptic(display=False):
    wavelen = 2e-6
    nwaves = 2
    r = 3

    osys_compound = poppy_core.OpticalSystem()
    osys_compound.addPupil(
        optics.CompoundAnalyticOptic([
            optics.CircularAperture(radius=r),
            optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen,
                            radius=r)
        ])
    )
    osys_compound.addDetector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_compound = osys_compound.calcPSF(wavelength=wavelen, display=False)

    osys_separate = poppy_core.OpticalSystem()
    osys_separate.addPupil(optics.CircularAperture(radius=r))    # pupil radius in meters
    osys_separate.addPupil(optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen,
                                           radius=r))
    osys_separate.addDetector(pixelscale=0.01, fov_pixels=512, oversample=1)
    psf_separate = osys_separate.calcPSF(wavelength=wavelen, display=False)

    if display:
        from matplotlib import pyplot as plt
        from poppy import utils
        plt.figure()
        plt.subplot(1, 2, 1)
        utils.display_PSF(psf_separate, title='From Separate Optics')
        plt.subplot(1, 2, 2)
        utils.display_PSF(psf_compound, title='From Compound Optics')

    difference = psf_compound[0].data - psf_separate[0].data

    assert np.all(np.abs(difference) < 1e-3)
Esempio n. 4
0
def test_CompoundAnalyticOptic(display=False):
    wavelen = 2e-6
    nwaves = 2
    r = 3

    osys_compound = poppy_core.OpticalSystem()
    osys_compound.addPupil(
        optics.CompoundAnalyticOptic([
            optics.CircularAperture(radius=r),
            optics.ThinLens(nwaves=nwaves,
                            reference_wavelength=wavelen,
                            radius=r)
        ]))
    osys_compound.addDetector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_compound = osys_compound.calcPSF(wavelength=wavelen, display=False)

    osys_separate = poppy_core.OpticalSystem()
    osys_separate.addPupil(
        optics.CircularAperture(radius=r))  # pupil radius in meters
    osys_separate.addPupil(
        optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen, radius=r))
    osys_separate.addDetector(pixelscale=0.01, fov_pixels=512, oversample=1)
    psf_separate = osys_separate.calcPSF(wavelength=wavelen, display=False)

    if display:
        from matplotlib import pyplot as plt
        from poppy import utils
        plt.figure()
        plt.subplot(1, 2, 1)
        utils.display_PSF(psf_separate, title='From Separate Optics')
        plt.subplot(1, 2, 2)
        utils.display_PSF(psf_compound, title='From Compound Optics')

    difference = psf_compound[0].data - psf_separate[0].data

    assert np.all(np.abs(difference) < 1e-3)
Esempio n. 5
0
def test_CompoundAnalyticOptic(display=False):
    wavelen = 2e-6
    nwaves = 2
    r = 3

    # First test the "and" mergemode

    osys_compound = poppy_core.OpticalSystem()
    osys_compound.add_pupil(
        optics.CompoundAnalyticOptic([
            optics.CircularAperture(radius=r),
            optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen,
                            radius=r)
        ]
        , mergemode='and')
    )
    osys_compound.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_compound = osys_compound.calc_psf(wavelength=wavelen, display=False)

    osys_separate = poppy_core.OpticalSystem()
    osys_separate.add_pupil(optics.CircularAperture(radius=r))    # pupil radius in meters
    osys_separate.add_pupil(optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen,
                                           radius=r))
    osys_separate.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_separate = osys_separate.calc_psf(wavelength=wavelen, display=False)

    if display:
        from matplotlib import pyplot as plt
        from poppy import utils
        plt.figure()
        plt.subplot(1, 2, 1)
        utils.display_PSF(psf_separate, title='From Separate Optics (and)')
        plt.subplot(1, 2, 2)
        utils.display_PSF(psf_compound, title='From Compound Optics (and)')

    difference = psf_compound[0].data - psf_separate[0].data

    assert np.all(np.abs(difference) < 1e-3)

    # Next test the 'or' mergemode
    # This creates two overlapping RectangleAperture with different
    # heights and check that the result equals the larger

    #TODO this fails.  Looks like the resulting aperture is too small when doing calc_psf.

    w = 1.0
    h1=2.0 
    h2=0.5

    osys_compound = poppy_core.OpticalSystem()
    osys_c_pupil = optics.CompoundAnalyticOptic([
            optics.RectangleAperture(width=w, height=h1),
            optics.RectangleAperture(width=w, height=h2)
        ]
        , mergemode='or')
    osys_compound.add_pupil(
        osys_c_pupil
    )
    osys_compound.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_compound, ints_compound = osys_compound.calc_psf(wavelength=wavelen, display=False, return_intermediates=True)

    osys_separate = poppy_core.OpticalSystem()
    osys_s_pupil = optics.RectangleAperture(width=w, height=max(h1, h2))
    osys_separate.add_pupil(osys_s_pupil)
    osys_separate.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_separate, ints_separate = osys_separate.calc_psf(wavelength=wavelen, display=False, return_intermediates=True)
    if display: 
        #from matplotlib import pyplot as plt
        #from poppy import utils
        plt.figure()
        osys_s_pupil.display(title='Separate pupil (or)')
        plt.figure()
        osys_c_pupil.display(title='Compound pupil (or)')
        plt.figure()
        ints_separate[0].display(title='Separate wave[0] (or)')
        plt.figure()
        ints_compound[0].display(title='Compound wave[0] (or)')
        plt.figure()
        utils.display_PSF(psf_separate, title='From Separate Optics (or)')
        plt.figure()
        utils.display_PSF(psf_compound, title='From Compound Optics (or)')

    #check transmission of OpticalElement objects
    # PASSES commit 1e4709b
    testwave = poppy_core.Wavefront(wavelength=wavelen,npix=1024)
    diff_trans = osys_c_pupil.get_transmission(testwave) - osys_s_pupil.get_transmission(testwave)
    
    assert np.all(np.abs(diff_trans) < 1e-3)
    
    #check pupil amplitudes
    # FAILS commit 1e4709b
    diff_amp = ints_compound[0].amplitude - ints_separate[0].amplitude
    
    assert np.all(np.abs(diff_amp) < 1e-3)
    
    #check psf
    # FAILS commit 1e4709b
    difference = psf_compound[0].data - psf_separate[0].data

    assert np.all(np.abs(difference) < 1e-3)
Esempio n. 6
0
def test_CompoundAnalyticOptic(display=False):
    wavelen = 2e-6
    nwaves = 2
    r = 3

    # First test the "and" mergemode

    osys_compound = poppy_core.OpticalSystem()
    osys_compound.add_pupil(
        optics.CompoundAnalyticOptic([
            optics.CircularAperture(radius=r),
            optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen,
                            radius=r)
        ]
        , mergemode='and')
    )
    osys_compound.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_compound = osys_compound.calc_psf(wavelength=wavelen, display=False)

    osys_separate = poppy_core.OpticalSystem()
    osys_separate.add_pupil(optics.CircularAperture(radius=r))    # pupil radius in meters
    osys_separate.add_pupil(optics.ThinLens(nwaves=nwaves, reference_wavelength=wavelen,
                                           radius=r))
    osys_separate.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_separate = osys_separate.calc_psf(wavelength=wavelen, display=False)

    if display:
        from matplotlib import pyplot as plt
        from poppy import utils
        plt.figure()
        plt.subplot(1, 2, 1)
        utils.display_PSF(psf_separate, title='From Separate Optics (and)')
        plt.subplot(1, 2, 2)
        utils.display_PSF(psf_compound, title='From Compound Optics (and)')

    difference = psf_compound[0].data - psf_separate[0].data

    assert np.all(np.abs(difference) < 1e-3)

    # Next test the 'or' mergemode
    # This creates two overlapping RectangleAperture with different
    # heights and check that the result equals the larger

    #TODO this fails.  Looks like the resulting aperture is too small when doing calc_psf.

    w = 1.0
    h1=2.0 
    h2=0.5

    osys_compound = poppy_core.OpticalSystem()
    osys_c_pupil = optics.CompoundAnalyticOptic([
            optics.RectangleAperture(width=w, height=h1),
            optics.RectangleAperture(width=w, height=h2)
        ]
        , mergemode='or')
    osys_compound.add_pupil(
        osys_c_pupil
    )
    osys_compound.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_compound, ints_compound = osys_compound.calc_psf(wavelength=wavelen, display=False, return_intermediates=True)

    osys_separate = poppy_core.OpticalSystem()
    osys_s_pupil = optics.RectangleAperture(width=w, height=max(h1, h2))
    osys_separate.add_pupil(osys_s_pupil)
    osys_separate.add_detector(pixelscale=0.010, fov_pixels=512, oversample=1)
    psf_separate, ints_separate = osys_separate.calc_psf(wavelength=wavelen, display=False, return_intermediates=True)
    if display: 
        #from matplotlib import pyplot as plt
        #from poppy import utils
        plt.figure()
        osys_s_pupil.display(title='Separate pupil (or)')
        plt.figure()
        osys_c_pupil.display(title='Compound pupil (or)')
        plt.figure()
        ints_separate[0].display(title='Separate wave[0] (or)')
        plt.figure()
        ints_compound[0].display(title='Compound wave[0] (or)')
        plt.figure()
        utils.display_PSF(psf_separate, title='From Separate Optics (or)')
        plt.figure()
        utils.display_PSF(psf_compound, title='From Compound Optics (or)')

    #check transmission of OpticalElement objects
    # PASSES commit 1e4709b
    testwave = poppy_core.Wavefront(wavelength=wavelen,npix=1024)
    diff_trans = osys_c_pupil.get_transmission(testwave) - osys_s_pupil.get_transmission(testwave)
    
    assert np.all(np.abs(diff_trans) < 1e-3)
    
    #check pupil amplitudes
    # FAILS commit 1e4709b
    diff_amp = ints_compound[0].amplitude - ints_separate[0].amplitude
    
    assert np.all(np.abs(diff_amp) < 1e-3)
    
    #check psf
    # FAILS commit 1e4709b
    difference = psf_compound[0].data - psf_separate[0].data

    assert np.all(np.abs(difference) < 1e-3)