Пример #1
0
def test_interpolate_to_wv0(plot=False, lp='2'):
    err_msg = 'Something is wrong with LSF.interpolate_to_wv0()'
    wv0 = 1160 * u.AA
    cos_dict = dict(name='COS',
                    grating='G130M',
                    life_position=lp,
                    cen_wave='1309')
    stis_dict = dict(name='STIS', grating='G140L', slit='52x0.2')
    stis_echelle_dict = dict(name='STIS', grating='E140M', slit='0.2x0.06')
    lsf_cos = LSF(cos_dict)
    lsf_stis = LSF(stis_dict)
    lsf_stis_echelle = LSF(stis_echelle_dict)
    for lsf in [lsf_cos, lsf_stis, lsf_stis_echelle]:
        lsf_tab = lsf.interpolate_to_wv0(wv0)
        assert lsf_tab[len(lsf_tab) // 2]['wv'] == wv0.value, err_msg
        assert lsf_tab[len(lsf_tab) // 2]['kernel'] == np.max(
            lsf_tab['kernel']), err_msg
        if plot:
            import matplotlib.pyplot as plt
            if lp == '3':
                wv_array = np.linspace(1200, 1400, 10) * u.AA
            else:
                wv_array = np.arange(1200, 1400, 10) * u.AA

            for wv in wv_array:
                lsf_tab = lsf_cos.interpolate_to_wv0(wv)
                plt.plot(lsf_tab['wv'] - wv.value, lsf_tab['kernel'], '-')
                plt.suptitle(lsf.name)
            # import pdb; pdb.set_trace()
            plt.show()
    # test last column interpolation
    lsf = LSF(dict(name='COS', grating='G130M', life_position='1'))
    tab = lsf.interpolate_to_wv0(1450 * u.AA)
Пример #2
0
def test_interpolate_to_wv0(plot=False, lp='2'):
    err_msg = 'Something is wrong with LSF.interpolate_to_wv0()'
    wv0 = 1160 * u.AA
    cos_dict = dict(name='COS', grating='G130M', life_position=lp, cen_wave='1309')
    stis_dict = dict(name='STIS', grating='G140L', slit='52x0.2')
    lsf_cos = LSF(cos_dict)
    lsf_stis = LSF(stis_dict)
    for lsf in [lsf_cos, lsf_stis]:
        lsf_tab = lsf.interpolate_to_wv0(wv0)
        assert lsf_tab[len(lsf_tab) // 2]['wv'] == wv0.value, err_msg
        assert lsf_tab[len(lsf_tab) // 2]['kernel'] == np.max(lsf_tab['kernel']), err_msg
        if plot:
            import matplotlib.pyplot as plt
            if lp == '3':
                wv_array = np.linspace(1200, 1400, 10) * u.AA
            else:
                wv_array = np.arange(1200, 1400, 10) * u.AA

            for wv in wv_array:
                lsf_tab = lsf_cos.interpolate_to_wv0(wv)
                plt.plot(lsf_tab['wv'] - wv.value, lsf_tab['kernel'], '-')
                plt.suptitle(lsf.name)
            # import pdb; pdb.set_trace()
            plt.show()
    # test last column interpolation
    lsf = LSF(dict(name='COS', grating='G130M', life_position='1'))
    tab = lsf.interpolate_to_wv0(1450 * u.AA)
Пример #3
0
def test_interpolate_to_wv0(plot=False):
    err_msg = 'Something is wrong with LSF.interpolate_to_wv0()'
    wv0 = 1160*u.AA
    cos_dict = dict(name='COS',grating='G130M',life_position='2',cen_wave='1309')
    lsf_cos = LSF(cos_dict)
    lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    assert lsf_tab[len(lsf_tab)/2]['wv'] == wv0.value, err_msg
    assert lsf_tab[len(lsf_tab)/2]['kernel'] == np.max(lsf_tab['kernel']), err_msg
    if plot:
        import matplotlib.pyplot as plt
        wv_array = np.arange(1200,1400,10)*u.AA
        for wv in wv_array:
            lsf_tab = lsf_cos.interpolate_to_wv0(wv)
            plt.plot(lsf_tab['wv']-wv.value,lsf_tab['kernel'],'-')
        plt.show()
Пример #4
0
def test_shift_to_wv0(plot=False):
    instr_dict1 = {'name': 'Gaussian', 'pixel_scale': 0.225, 'FWHM': 0.7}
    glsf1 = LSF(instr_config=instr_dict1)
    thislsf1 = glsf1.shift_to_wv0(3600. * u.AA)

    # should not work for multiple tabulated kernels
    cos_dict = dict(name='COS', grating='G130M', life_position='1')
    lsf_cos = LSF(cos_dict)
    with pytest.raises(ValueError):
        thislsfX = lsf_cos.interpolate_to_wv0(3600. * u.AA)
Пример #5
0
def test_interpolate_to_wv0_wv0shortlong(plot=False):
    err_msg = 'Something is wrong with short wavelength handling in LSF.interpolate_to_wv0()'
    wv0 = 1105.0 * u.AA
    cos_dict = dict(name='COS', grating='G130M', life_position='1')
    lsf_cos = LSF(cos_dict)
    lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    assert lsf_tab[len(lsf_tab) // 2]['wv'] == wv0.value, err_msg
    assert lsf_tab[len(lsf_tab) // 2]['kernel'] == np.max(
        lsf_tab['kernel']), err_msg
    if plot:
        import matplotlib.pyplot as plt
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
        plt.plot(lsf_tab['wv'] - wv0.value, lsf_tab['kernel'], '-')
        plt.show()
    err_msg = 'Something is wrong with long wavelength handling in LSF.interpolate_to_wv0()'
    wv0 = 1796.0 * u.AA
    cos_dict = dict(name='COS', grating='G160M', life_position='1')
    lsf_cos = LSF(cos_dict)
    lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    assert lsf_tab[len(lsf_tab) // 2]['wv'] == wv0.value, err_msg
    assert lsf_tab[len(lsf_tab) // 2]['kernel'] == np.max(
        lsf_tab['kernel']), err_msg
    if plot:
        import matplotlib.pyplot as plt
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
        plt.plot(lsf_tab['wv'] - wv0.value, lsf_tab['kernel'], '-')
        plt.show()
    # test error outside range
    wv0 = 1300.0 * u.AA
    with pytest.raises(ValueError):
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    wv0 = 1900.0 * u.AA
    with pytest.raises(ValueError):
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
Пример #6
0
def test_interpolate_to_wv0_wv0shortlong(plot=False):
    err_msg = 'Something is wrong with short wavelength handling in LSF.interpolate_to_wv0()'
    wv0 = 1105.0 * u.AA
    cos_dict = dict(name='COS', grating='G130M', life_position='1')
    lsf_cos = LSF(cos_dict)
    lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    assert lsf_tab[len(lsf_tab) // 2]['wv'] == wv0.value, err_msg
    assert lsf_tab[len(lsf_tab) // 2]['kernel'] == np.max(lsf_tab['kernel']), err_msg
    if plot:
        import matplotlib.pyplot as plt
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
        plt.plot(lsf_tab['wv'] - wv0.value, lsf_tab['kernel'], '-')
        plt.show()
    err_msg = 'Something is wrong with long wavelength handling in LSF.interpolate_to_wv0()'
    wv0 = 1796.0 * u.AA
    cos_dict = dict(name='COS', grating='G160M', life_position='1')
    lsf_cos = LSF(cos_dict)
    lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    assert lsf_tab[len(lsf_tab) // 2]['wv'] == wv0.value, err_msg
    assert lsf_tab[len(lsf_tab) // 2]['kernel'] == np.max(lsf_tab['kernel']), err_msg
    if plot:
        import matplotlib.pyplot as plt
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
        plt.plot(lsf_tab['wv'] - wv0.value, lsf_tab['kernel'], '-')
        plt.show()
    # test error outside range
    wv0 = 1300.0 * u.AA
    with pytest.raises(ValueError):
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)
    wv0 = 1900.0 * u.AA
    with pytest.raises(ValueError):
        lsf_tab = lsf_cos.interpolate_to_wv0(wv0)