Beispiel #1
0
def test_calculate_electron_density_xyz():
    pc = Unit('pc')
    a = pygedm.calculate_electron_density_xyz(1, 2, 3)
    b = pygedm.calculate_electron_density_xyz(1 * pc, 2, 3)
    c = pygedm.calculate_electron_density_xyz(1, 2 * pc, 3)
    d = pygedm.calculate_electron_density_xyz(1, 2, 3 * pc)
    assert a == b == c == d
Beispiel #2
0
def test_calculate_electron_density_xyz():
    pc = Unit('pc')
    a = pygedm.calculate_electron_density_xyz(1, 2, 3, method='ne2001')
    b = pygedm.calculate_electron_density_xyz(1 * pc, 2, 3, method='ne2001')
    c = pygedm.calculate_electron_density_xyz(1, 2 * pc, 3, method='ne2001')
    d = pygedm.calculate_electron_density_xyz(1, 2, 3 * pc, method='ne2001')
    assert a == b == c == d
Beispiel #3
0
def test_calculate_electron_density_lbr():
    ed_gc = pygedm.calculate_electron_density_xyz(0, 0, 0, method='ne2001')
    ed_gc_lbr = pygedm.calculate_electron_density_lbr(0,
                                                      0,
                                                      8500,
                                                      method='ne2001')
    assert ed_gc == ed_gc_lbr
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')
Beispiel #5
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)
Beispiel #6
0
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'))
Beispiel #7
0
import pygedm
import pylab as plt
import numpy as np

# Create empty arrays for NE2001 and YMW16 model output
d_2016 = np.zeros((100, 100))
d_2001 = np.zeros((100, 100))

# Loop through pixels
for ii in range(100):
    for jj in range(100):
        # generate X, Y, Z in PC from indexes
        x, y, z = (ii - 50) * 400, (jj - 50) * 400, 0

        # Compute EDM
        d_2016[ii, jj] = pygedm.calculate_electron_density_xyz(
            x, y, z, method='ymw16').value
        d_2001[ii, jj] = pygedm.calculate_electron_density_xyz(
            x, y, z, method='ne2001').value

# Plot output images
plt.rcParams['font.size'] = 14

plt.figure(figsize=(4 * 3 * 2, 3 * 3))
plt.subplot(1, 2, 1)
plt.title("NE2001 electron density model, Z=0 plane")
plt.imshow(np.log10(d_2001),
           extent=(-50 * 400 / 1e3, 50 * 400 / 1e3, -50 * 400 / 1e3,
                   50 * 400 / 1e3),
           clim=(-5, 0))
plt.xlabel("X [kpc]")
plt.ylabel("Y [kpc]")