Exemplo n.º 1
0
def test_todict_withjson():
    radec = SkyCoord(ra=123.1143 * u.deg, dec=-12.4321 * u.deg)
    # HI Lya, Lyb
    lya = AbsLine(1215.670 * u.AA)
    lya.limits.set([-300., 300.] * u.km / u.s)
    lya.attrib['z'] = 2.92939
    lya.attrib['coord'] = radec
    lyb = AbsLine(1025.7222 * u.AA)
    lyb.limits.set([-300., 300.] * u.km / u.s)
    lyb.attrib['z'] = lya.attrib['z']
    lyb.attrib['coord'] = radec
    abscomp = AbsComponent.from_abslines([lya, lyb])
    # Instantiate
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Dict
    adict = HIsys.to_dict()
    assert isinstance(adict, dict)
    # Verify it is JSON compatible (failing in Python 3)
    import io, json
    with io.open('tmp.json', 'w', encoding='utf-8') as f:
        f.write(
            unicode(
                json.dumps(adict,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': '))))
Exemplo n.º 2
0
def test_from_json():
    # Tests from_dict too
    HIsys = LymanAbsSystem.from_json(data_path('HILya_abssys.json'))
    np.testing.assert_allclose(HIsys.zabs, 2.92939)
    # Tests ordering
    gensys = GenericAbsSystem.from_json(data_path('generic_abssys.json'))
    np.testing.assert_allclose(gensys._components[0].zcomp, 2.92939)
Exemplo n.º 3
0
def test_from_json():
    # Tests from_dict too
    HIsys = LymanAbsSystem.from_json(data_path('HILya_abssys.json'))
    np.testing.assert_allclose(HIsys.zabs, 2.92939)
    # Tests ordering
    gensys = GenericAbsSystem.from_json(data_path('generic_abssys.json'))
    np.testing.assert_allclose(gensys._components[0].zcomp, 2.92939)
Exemplo n.º 4
0
def test_one_component():
    # Instantiate
    abscomp = lyman_comp(radec)
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Test
    assert HIsys.abs_type == 'HILyman'
    assert len(HIsys._components) == 1
    assert HIsys._components[0].Zion[0] == 1
    assert HIsys._components[0].Zion[1] == 1
Exemplo n.º 5
0
def test_one_component():
    # Instantiate
    abscomp = lyman_comp(radec)
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Test
    assert HIsys.abs_type == 'HILyman'
    assert len(HIsys._components) == 1
    assert HIsys._components[0].Zion[0] == 1
    assert HIsys._components[0].Zion[1] == 1
Exemplo n.º 6
0
def test_one_component():
    radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
    # HI Lya, Lyb
    lya = AbsLine(1215.670*u.AA)
    lya.analy['vlim'] = [-300.,300.]*u.km/u.s
    lya.attrib['z'] = 2.92939
    lyb = AbsLine(1025.7222*u.AA)
    lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
    lyb.attrib['z'] = lya.attrib['z']
    abscomp = AbsComponent.from_abslines([lya,lyb])
    abscomp.coord = radec
    # Instantiate
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Test
    assert HIsys.abs_type == 'HILyman'
    assert len(HIsys._components) == 1
    assert HIsys._components[0].Zion[0] == 1
    assert HIsys._components[0].Zion[1] == 1
Exemplo n.º 7
0
def test_todict():
    radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
    # HI Lya, Lyb
    lya = AbsLine(1215.670*u.AA)
    lya.analy['vlim'] = [-300.,300.]*u.km/u.s
    lya.attrib['z'] = 2.92939
    lyb = AbsLine(1025.7222*u.AA)
    lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
    lyb.attrib['z'] = lya.attrib['z']
    abscomp = AbsComponent.from_abslines([lya,lyb])
    abscomp.coord = radec
    # Instantiate
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Dict
    adict = HIsys.to_dict()
    assert isinstance(adict, dict)
    # Instantiate
    newsys = AbsSystem.from_dict(adict)
    assert isinstance(newsys, AbsSystem)
Exemplo n.º 8
0
def test_one_component():
    radec = SkyCoord(ra=123.1143 * u.deg, dec=-12.4321 * u.deg)
    # HI Lya, Lyb
    lya = AbsLine(1215.670 * u.AA)
    lya.analy['vlim'] = [-300., 300.] * u.km / u.s
    lya.attrib['z'] = 2.92939
    lya.attrib['N'] = 1e17 / u.cm**2
    lyb = AbsLine(1025.7222 * u.AA)
    lyb.analy['vlim'] = [-300., 300.] * u.km / u.s
    lyb.attrib['z'] = lya.attrib['z']
    abscomp = AbsComponent.from_abslines([lya, lyb])
    abscomp.coord = radec
    # Instantiate
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Test
    assert HIsys.abs_type == 'HILyman'
    assert len(HIsys._components) == 1
    assert HIsys._components[0].Zion[0] == 1
    assert HIsys._components[0].Zion[1] == 1
Exemplo n.º 9
0
def test_todict():
    radec = SkyCoord(ra=123.1143 * u.deg, dec=-12.4321 * u.deg)
    # HI Lya, Lyb
    lya = AbsLine(1215.670 * u.AA)
    lya.analy['vlim'] = [-300., 300.] * u.km / u.s
    lya.attrib['z'] = 2.92939
    lya.attrib['coord'] = radec
    lyb = AbsLine(1025.7222 * u.AA)
    lyb.analy['vlim'] = [-300., 300.] * u.km / u.s
    lyb.attrib['z'] = lya.attrib['z']
    lyb.attrib['coord'] = radec
    abscomp = AbsComponent.from_abslines([lya, lyb])
    # Instantiate
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Dict
    adict = HIsys.to_dict()
    assert isinstance(adict, dict)
    # Instantiate
    #pdb.set_trace()
    newsys = AbsSystem.from_dict(adict)
    assert isinstance(newsys, AbsSystem)
Exemplo n.º 10
0
def test_todict_withjson():
    radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
    # HI Lya, Lyb
    lya = AbsLine(1215.670*u.AA)
    lya.analy['vlim'] = [-300.,300.]*u.km/u.s
    lya.attrib['z'] = 2.92939
    lyb = AbsLine(1025.7222*u.AA)
    lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
    lyb.attrib['z'] = lya.attrib['z']
    abscomp = AbsComponent.from_abslines([lya,lyb])
    abscomp.coord = radec
    # Instantiate
    HIsys = LymanAbsSystem.from_components([abscomp])
    # Dict
    adict = HIsys.to_dict()
    assert isinstance(adict, dict)
    # Verify it is JSON compatible (failing in Python 3)
    import io,json
    with io.open('tmp.json', 'w', encoding='utf-8') as f:
        f.write(unicode(json.dumps(adict, sort_keys=True, indent=4,
                                   separators=(',', ': '))))
Exemplo n.º 11
0
def test_write_json():
    HIsys = LymanAbsSystem.from_json(data_path('HILya_abssys.json'))
    HIsys.write_json()
Exemplo n.º 12
0
def test_write_json():
    HIsys = LymanAbsSystem.from_json(data_path('HILya_abssys.json'))
    HIsys.write_json()
Exemplo n.º 13
0
def test_from_json():
    # Tests from_dict too
    HIsys = LymanAbsSystem.from_json(data_path('HILya_abssys.json'))
    np.testing.assert_allclose(HIsys.zabs, 2.92939)