示例#1
0
def test_complist_from_table_and_table_from_complist():
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    tab['RA'] = [100.0] * len(tab) * u.deg
    tab['DEC'] = [-0.8] * len(tab) * u.deg
    tab['vmin'] = [-50.] * len(tab) * u.km / u.s
    tab['vmax'] = [100.] * len(tab) * u.km / u.s
    tab['reliability'] = ['a', 'b', 'b', 'none', 'a']
    complist = ltiu.complist_from_table(tab)
    assert np.sum(complist[0].vlim == [-50., 100.] * u.km / u.s) == 2
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['z_comp'], tab2['z_comp'])

    # test other columns
    tab['logN'] = 13.7
    tab['sig_logN'] = 0.1
    tab['flag_logN'] = 1
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['logN'], tab2['logN'])

    comp = complist[0]
    # comment now
    tab['comment'] = [
        'good', 'good', 'bad', 'bad',
        'This is a longer comment with symbols &*^%$'
    ]
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.comment == 'This is a longer comment with symbols &*^%$'
    assert tab2['comment'][-1] == comp.comment
    assert tab2['reliability'][-1] == comp.reliability

    # other naming
    tab['name'] = tab['ion_name']
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.name == 'OVI'
    # other attributes
    tab['b'] = [10, 10, 20, 10, 60] * u.km / u.s
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.attrib['b'] == 60 * u.km / u.s

    # test errors
    tab['sig_b'] = [1, 2, 3, 4, 5] * u.AA
    with pytest.raises(IOError):
        complist = ltiu.complist_from_table(tab)  # bad units for sig_b
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    with pytest.raises(IOError):
        complist = ltiu.complist_from_table(
            tab)  # not enough mandatory columns
示例#2
0
def test_get_components_at_z():
    tab = mk_comptable()
    complist = ltiu.complist_from_table(tab)
    z01_comps = ltiu.get_components_at_z(complist, 0.1, [-1000,1000]*u.km/u.s)
    assert len(z01_comps) == 3
    # check expected errors
    with pytest.raises(IOError):
        ltiu.get_components_at_z([1,2,3], 0.1, [-1000,1000]*u.km/u.s) # wrong complist
    with pytest.raises(IOError):
        ltiu.get_components_at_z(complist, 0.1, [-1000,1000, 1000]*u.km/u.s) # wrong vlims size
    with pytest.raises(IOError):
        ltiu.get_components_at_z(complist, 0.1, [-1000,1000]*u.km)  # wrong vlims units
示例#3
0
def test_complist_from_table_and_table_from_complist():
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    tab['RA'] = [100.0]*len(tab) * u.deg
    tab['DEC'] = [-0.8]*len(tab) * u.deg
    tab['vmin'] = [-50.] *len(tab) * u.km / u.s
    tab['vmax'] = [100.] *len(tab) * u.km / u.s
    complist = ltiu.complist_from_table(tab)
    assert np.sum(complist[0].vlim == [ -50., 100.] * u.km / u.s) == 2
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['z_comp'], tab2['z_comp'])

    # test other columns
    tab['logN'] = 13.7
    tab['sig_logN'] = 0.1
    tab['flag_logN'] = 1
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['logN'], tab2['logN'])

    comp = complist[0]
    # comment now
    tab['comment'] = ['good', 'good', 'bad', 'bad', 'This is a longer comment with symbols &*^%$']
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.comment == 'This is a longer comment with symbols &*^%$'
    assert tab2['comment'][-1] == comp.comment

    # other naming
    tab['name'] = tab['ion_name']
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.name == 'OVI'
    # other attributes
    tab['b'] = [10, 10, 20, 10, 60] * u.km / u.s
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.attrib['b'] == 60*u.km/u.s

    # test errors
    tab['sig_b'] = [1,2,3,4,5] * u.AA
    with pytest.raises(IOError):
        complist = ltiu.complist_from_table(tab) # bad units for sig_b
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    with pytest.raises(IOError):
        complist = ltiu.complist_from_table(tab) # not enough mandatory columns
示例#4
0
def test_get_components_at_z():
    tab = mk_comptable()
    complist = ltiu.complist_from_table(tab)
    z01_comps = ltiu.get_components_at_z(complist, 0.1,
                                         [-1000, 1000] * u.km / u.s)
    assert len(z01_comps) == 3
    # check expected errors
    with pytest.raises(IOError):
        ltiu.get_components_at_z([1, 2, 3], 0.1,
                                 [-1000, 1000] * u.km / u.s)  # wrong complist
    with pytest.raises(IOError):
        ltiu.get_components_at_z(complist, 0.1, [-1000, 1000, 1000] * u.km /
                                 u.s)  # wrong vlims size
    with pytest.raises(IOError):
        ltiu.get_components_at_z(complist, 0.1,
                                 [-1000, 1000] * u.km)  # wrong vlims units
示例#5
0
def test_complist_from_table_and_table_from_complist():
    # Setup
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['Z'] = [1, 1, 4, 14, 8]
    tab['ion'] = [1, 1, 4, 2, 6]
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    tab['RA'] = [100.0] * len(tab) * u.deg
    tab['DEC'] = [-0.8] * len(tab) * u.deg
    tab['vmin'] = [-50.] * len(tab) * u.km / u.s
    tab['vmax'] = [100.] * len(tab) * u.km / u.s
    tab['Ej'] = [0.] * len(tab) / u.cm
    tab['reliability'] = ['a', 'b', 'b', 'none', 'a']
    complist = ltiu.complist_from_table(tab)
    tmp = [-50., 100.] * u.km / u.s
    assert np.all(np.isclose(complist[0].vlim.value, tmp.value))
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['z_comp'], tab2['z_comp'])

    # Without units
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['Z'] = [1, 1, 4, 14, 8]
    tab['ion'] = [1, 1, 4, 2, 6]
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    tab['RA'] = [100.0] * len(tab) * u.deg
    tab['DEC'] = [-0.8] * len(tab) * u.deg
    tab['vmin'] = [-50.] * len(tab)
    tab['vmax'] = [100.] * len(tab)
    tab['Ej'] = [0.] * len(tab)
    tab['reliability'] = ['a', 'b', 'b', 'none', 'a']
    complist = ltiu.complist_from_table(tab)
    assert np.all(np.isclose(complist[0].vlim.value, tmp.value))
    assert complist[0].Ej.unit == 1 / u.cm

    # test other columns
    tab['logN'] = 13.7
    tab['sig_logN'] = 0.1 * np.ones((len(tab), 2))
    tab['flag_logN'] = 1
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['logN'], tab2['logN'])

    # NHI obj
    SiIIcomp1, _ = mk_comp('SiII',
                           vlim=[-300., 50.] * u.km / u.s,
                           add_spec=True)
    SiIIIcomp1, _ = mk_comp('SiIII',
                            vlim=[-300., 50.] * u.km / u.s,
                            add_spec=True)
    NHI_obj = DummyObj()
    NHI_obj.NHI = 21.0
    NHI_obj.sig_NHI = np.array([0.1, 0.1])
    NHI_obj.flag_NHI = 1
    tab2b = ltiu.table_from_complist([SiIIcomp1, SiIIIcomp1], NHI_obj=NHI_obj)
    assert tab2b['Z'][-1] == 1
    assert tab2b['ion_name'][-1] == 'HI'

    # comment now
    tab['comment'] = [
        'good', 'good', 'bad', 'bad',
        'This is a longer comment with symbols &*^%$'
    ]
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.comment == 'This is a longer comment with symbols &*^%$'
    assert tab2['comment'][-1] == comp.comment
    assert tab2['reliability'][-1] == comp.reliability

    # other naming
    tab['name'] = tab['ion_name']
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.name == 'OVI'
    # other attributes
    tab['b'] = [10, 10, 20, 10, 60] * u.km / u.s
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.attrib['b'] == 60 * u.km / u.s

    # test errors
    #tab['sig_b'] = [1,2,3,4,5] * u.AA
    #with pytest.raises(IOError):
    #    complist = ltiu.complist_from_table(tab) # bad units for sig_b
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    with pytest.raises(IOError):
        complist = ltiu.complist_from_table(
            tab)  # not enough mandatory columns
示例#6
0
def test_complist_from_table_and_table_from_complist():
    # Setup
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['Z'] = [1,1,4,14,8]
    tab['ion'] = [1,1,4,2,6]
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    tab['RA'] = [100.0]*len(tab) * u.deg
    tab['DEC'] = [-0.8]*len(tab) * u.deg
    tab['vmin'] = [-50.] *len(tab) * u.km / u.s
    tab['vmax'] = [100.] *len(tab) * u.km / u.s
    tab['Ej'] = [0.] *len(tab) / u.cm
    tab['reliability'] = ['a', 'b', 'b', 'none', 'a']
    complist = ltiu.complist_from_table(tab)
    tmp = [-50.,100.]*u.km/u.s
    assert np.all(np.isclose(complist[0].vlim.value, tmp.value))
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['z_comp'], tab2['z_comp'])

    # Without units
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['Z'] = [1,1,4,14,8]
    tab['ion'] = [1,1,4,2,6]
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    tab['RA'] = [100.0]*len(tab) * u.deg
    tab['DEC'] = [-0.8]*len(tab) * u.deg
    tab['vmin'] = [-50.] *len(tab)
    tab['vmax'] = [100.] *len(tab)
    tab['Ej'] = [0.] *len(tab)
    tab['reliability'] = ['a', 'b', 'b', 'none', 'a']
    complist = ltiu.complist_from_table(tab)
    assert np.all(np.isclose(complist[0].vlim.value, tmp.value))
    assert complist[0].Ej.unit == 1/u.cm

    # test other columns
    tab['logN'] = 13.7
    tab['sig_logN'] = 0.1*np.ones((len(tab),2))
    tab['flag_logN'] = 1
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    np.testing.assert_allclose(tab['logN'], tab2['logN'])

    # NHI obj
    SiIIcomp1,_ = mk_comp('SiII',vlim=[-300.,50.]*u.km/u.s, add_spec=True)
    SiIIIcomp1,_ = mk_comp('SiIII',vlim=[-300.,50.]*u.km/u.s, add_spec=True)
    NHI_obj = DummyObj()
    NHI_obj.NHI = 21.0
    NHI_obj.sig_NHI = np.array([0.1,0.1])
    NHI_obj.flag_NHI = 1
    tab2b = ltiu.table_from_complist([SiIIcomp1, SiIIIcomp1], NHI_obj=NHI_obj)
    assert tab2b['Z'][-1] == 1
    assert tab2b['ion_name'][-1] == 'HI'

    # comment now
    tab['comment'] = ['good', 'good', 'bad', 'bad', 'This is a longer comment with symbols &*^%$']
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.comment == 'This is a longer comment with symbols &*^%$'
    assert tab2['comment'][-1] == comp.comment
    assert tab2['reliability'][-1] == comp.reliability

    # other naming
    tab['name'] = tab['ion_name']
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.name == 'OVI'
    # other attributes
    tab['b'] = [10, 10, 20, 10, 60] * u.km / u.s
    complist = ltiu.complist_from_table(tab)
    tab2 = ltiu.table_from_complist(complist)
    comp = complist[-1]
    assert comp.attrib['b'] == 60*u.km/u.s

    # test errors
    #tab['sig_b'] = [1,2,3,4,5] * u.AA
    #with pytest.raises(IOError):
    #    complist = ltiu.complist_from_table(tab) # bad units for sig_b
    tab = Table()
    tab['ion_name'] = ['HI', 'HI', 'CIV', 'SiII', 'OVI']
    tab['z_comp'] = [0.05, 0.0999, 0.1, 0.1001, 0.6]
    with pytest.raises(IOError):
        complist = ltiu.complist_from_table(tab) # not enough mandatory columns