コード例 #1
0
def test_dm_to_dist():
    """ Test that astropy units / angles work with dm_to_dist """
    a = pygedm.dm_to_dist(204, -6.5, 200, method='ne2001')
    b = pygedm.dm_to_dist(Angle(204, unit='degree'), Angle(-6.5, unit='degree'), 200, method='ne2001')
    c = pygedm.dm_to_dist(204, -6.5, 200 * Unit('pc cm^-3'), method='ne2001')
    assert a[0] == b[0] == c[0]
    assert a[1] == b[1] == c[1]
コード例 #2
0
ファイル: test_tau_sc.py プロジェクト: FRBs/pygedm
def test_tau_sc_nu():
    """ Test that tau_sc changes with nu """
    dm, tau_sc = pygedm.dist_to_dm(0, 0, 100, method='ymw16', nu=1)
    dm_, tau_sc_ = pygedm.dist_to_dm(0, 0, 100, method='ymw16', nu=1000*u.MHz)
    assert dm == dm_
    assert tau_sc == tau_sc_

    dm, tau_sc = pygedm.dist_to_dm(0, 0, 100, method='ne2001', nu=1)
    dm_, tau_sc_ = pygedm.dist_to_dm(0, 0, 100, method='ne2001', nu=1000*u.MHz)
    assert dm == dm_
    assert tau_sc == tau_sc_    
    
    dist, tau_sc = pygedm.dist_to_dm(0, 0, 100, method='ymw16', nu=1)
    dist_, tau_sc_ = pygedm.dist_to_dm(0, 0, 100, method='ymw16', nu=1000*u.MHz)
    assert dist == dist_
    assert tau_sc == tau_sc_        

    dist, tau_sc = pygedm.dist_to_dm(0, 0, 100, method='ne2001', nu=1)
    dist_, tau_sc_ = pygedm.dist_to_dm(0, 0, 100, method='ne2001', nu=1000*u.MHz)
    assert dist == dist_
    assert tau_sc == tau_sc_     
    
    dm, tau_sc_1GHz = pygedm.dm_to_dist(0, 0, 1000, method='ymw16', nu=1.0)
    dm, tau_sc_100MHz = pygedm.dm_to_dist(0, 0, 1000, method='ymw16', nu=0.1)
    assert np.isclose(tau_sc_1GHz.value, 0.31681767)
    assert np.isclose(tau_sc_100MHz.value, 3168.17671061)
    
    assert np.isclose((0.1/1.0)**(-4) * tau_sc_1GHz.value, tau_sc_100MHz.value)
    
    dm, tau_sc_1GHz = pygedm.dm_to_dist(0, 0, 1000, method='ne2001', nu=1.0)
    dm, tau_sc_100MHz = pygedm.dm_to_dist(0, 0, 1000, method='ne2001', nu=0.1)
    assert np.isclose(tau_sc_1GHz.value, 198.57881596)
    assert np.isclose(tau_sc_100MHz.value, 4988074.33385041)    
コード例 #3
0
def test_raises():
    """ Test that IGM mode FAILS as expected """
    with pytest.raises(RuntimeError):
        pygedm.dm_to_dist(100, 10, 100, method='ymw1066')
    with pytest.raises(RuntimeError):
        pygedm.dist_to_dm(100, 10, 100, method='ne2020')
    with pytest.raises(RuntimeError):
        pygedm.calculate_electron_density_xyz(100, 10, 100, method='tc93')
    with pytest.raises(RuntimeError):
        pygedm.calculate_electron_density_lbr(100,
                                              10,
                                              100,
                                              method='ymwPaleolithic')
    with pytest.raises(RuntimeError):
        pygedm.dist_to_dm(100, 10, 100, mode='igm', method='ne2001')
    with pytest.raises(RuntimeError):
        pygedm.convert_lbr_to_xyz(0, 0, 0, method='chicken')
コード例 #4
0
def test_igm():
    """ Test that IGM mode works as expected

    Note: tested against YMW16 code with:
    # CMD:    ./ ymw16 -d data -v IGM 204 -6.5 2000 100 1
    # OUTPUT: DM_Gal:  252.05 DM_MC:    0.00 DM_IGM: 1647.95 DM_Host:  100.00
    #         z:  2.311   Dist:  5336.4   log(tau_sc): -2.218
    """

    dist, tau = pygedm.dm_to_dist(204, -6.5, 2000, dm_host=100, mode='igm')
    assert np.isclose(dist.value, 5336.4, rtol=0.1)
    assert np.isclose(np.log10(tau.value), -2.218, rtol=0.1)

    dm, tau = pygedm.dist_to_dm(204, -6.5, 5336.4, mode='igm')
    dm_total = dm.value + 252.05 + 100  # Add galactic and host contribution
    assert np.isclose(dm_total, 2000, rtol=0.1)

    dm, tau = pygedm.dist_to_dm(204, -6.5, 5336.4 * u.Mpc, mode='igm')
    dm_total = dm.value + 252.05 + 100  # Add galactic and host contribution
    assert np.isclose(dm_total, 2000, rtol=0.1)
コード例 #5
0
def test_basic():
    """ Basic tests of YMW16 model

    Note: tested against online NE2001 interface
    https://www.nrl.navy.mil/rsd/RORF/ne2001/
    """

    # No access to actual model via web interface
    #a = pygedm.calculate_electron_density_xyz(1, 2, 3)
    #assert np.isclose(a.value, 5.220655, atol=0.0001)

    # FRB180301 value
    dm, tau = pygedm.dist_to_dm(204, -6.5, 25*u.kpc, method='ne2001')
    assert np.isclose(dm.value, 150.80, atol=0.01)

    # Loop through distances and check round trip
    for dist in (10.*u.pc, 100.*u.pc, 1000.*u.pc):
        dm, tau = pygedm.dist_to_dm(0, 0, dist, method='ne2001')
        dist_out, tau = pygedm.dm_to_dist(0, 0, dm, method='ne2001')
        print(dist, dm, dist_out)
        assert np.isclose(dist_out.to('pc').value, dist.to('pc').value, rtol=0.1)
コード例 #6
0
def test_basic():
    """ Basic tests of YMW16 model

    Note: tested against online YMW16 interface
    http://www.atnf.csiro.au/research/pulsar/ymw16/index.php
    """

    a = pygedm.calculate_electron_density_xyz(1, 2, 3)
    assert np.isclose(a.value, 5.220655, atol=0.0001)

    a = pygedm.calculate_electron_density_lbr(0, 0, 4000)
    assert np.isclose(a.value, 0.388407, atol=0.0001)

    # FRB180301 value
    dm, tau = pygedm.dist_to_dm(204, -6.5, 25000)
    assert np.isclose(dm.value, 252.0501, atol=0.01)

    # Loop through distances and check round trip
    for dist in (10., 100., 1000.):
        dm, tau = pygedm.dist_to_dm(0, 0, dist)
        dist_out, tau = pygedm.dm_to_dist(0, 0, dm.value)
        assert np.isclose(dist_out.value, dist, rtol=0.1)
コード例 #7
0
ファイル: test_compare.py プロジェクト: abhimahour72/pygedm2
import pygedm

print("\n--- DM to dist ---")
print("YMW16:", pygedm.dm_to_dist(100, 0, 250, dm_host=0, method='ymw16'))
print("NE2001:", pygedm.dm_to_dist(100, 0, 250, dm_host=0, method='ne2001'))

print("\n--- dist to DM ---")
print("YMW16:", pygedm.dist_to_dm(100, 0, 250, method='ymw16'))
print("NE2001:", pygedm.dist_to_dm(100, 0, 250, method='ne2001'))

print("\n--- Electron density ---")
print("YMW16:", pygedm.calculate_electron_density_xyz(0, 0, 0, method='ymw16'))
print("NE2001:", pygedm.calculate_electron_density_xyz(0, 0, 0, method='ne2001'))
コード例 #8
0
def test_igm():
    """ Test that IGM mode FAILS as expected """
    with pytest.raises(RuntimeError):
        pygedm.dm_to_dist(100, 10, 100, mode='igm', method='ne2001')