Ejemplo n.º 1
0
def add_pwn_parameters(table):
    """Add PWN parameters to the table.

    TODO: document
    """
    # Some of the computations (specifically `pwn.radius`) aren't vectorised
    # across all parameters; so here we loop over source parameters explicitly

    results = []

    for idx in range(len(table)):
        age = table["age"].quantity[idx]
        E_SN = table["E_SN"].quantity[idx]
        n_ISM = table["n_ISM"].quantity[idx]
        P0_birth = table["P0_birth"].quantity[idx]
        b_psr = table["B_PSR"].quantity[idx]

        # Compute properties
        pulsar = Pulsar(P0_birth, b_psr)
        snr = SNRTrueloveMcKee(e_sn=E_SN, n_ISM=n_ISM)
        pwn = PWN(pulsar, snr)
        r_out_pwn = pwn.radius(age).to_value("pc")
        results.append(dict(r_out_pwn=r_out_pwn))

    # Add columns to table
    table["r_out_PWN"] = Column(
        [_["r_out_pwn"] for _ in results], unit="pc", description="PWN outer radius"
    )
    return table
Ejemplo n.º 2
0
def add_pulsar_parameters(
    table,
    B_mean=12.05,
    B_stdv=0.55,
    P_mean=0.3,
    P_stdv=0.15,
    random_state="random-seed",
):
    """Add pulsar parameters to the table.

    For the initial normal distribution of period and logB can exist the following
    Parameters: B_mean=12.05[log Gauss], B_stdv=0.55, P_mean=0.3[s], P_stdv=0.15

    Parameters
    ----------
    random_state : {int, 'random-seed', 'global-rng', `~numpy.random.RandomState`}
        Defines random number generator initialisation.
        Passed to `~gammapy.utils.random.get_random_state`.
    """
    random_state = get_random_state(random_state)
    # Read relevant columns
    age = table["age"].quantity

    # Draw the initial values for the period and magnetic field
    def p_dist(x):
        return np.exp(-0.5 * ((x - P_mean) / P_stdv) ** 2)

    p0_birth = draw(0, 2, len(table), p_dist, random_state=random_state)
    p0_birth = Quantity(p0_birth, "s")

    log10_b_psr = random_state.normal(B_mean, B_stdv, len(table))
    b_psr = Quantity(10 ** log10_b_psr, "G")

    # Compute pulsar parameters
    psr = Pulsar(p0_birth, b_psr)
    p0 = psr.period(age)
    p1 = psr.period_dot(age)
    p1_birth = psr.P_dot_0
    tau = psr.tau(age)
    tau_0 = psr.tau_0
    l_psr = psr.luminosity_spindown(age)
    l0_psr = psr.L_0

    # Add columns to table
    table["P0"] = Column(p0, unit="s", description="Pulsar period")
    table["P1"] = Column(p1, unit="", description="Pulsar period derivative")
    table["P0_birth"] = Column(p0_birth, unit="s", description="Pulsar birth period")
    table["P1_birth"] = Column(
        p1_birth, unit="", description="Pulsar birth period derivative"
    )
    table["CharAge"] = Column(tau, unit="yr", description="Pulsar characteristic age")
    table["Tau0"] = Column(tau_0, unit="yr")
    table["L_PSR"] = Column(l_psr, unit="erg s-1")
    table["L0_PSR"] = Column(l0_psr, unit="erg s-1")
    table["B_PSR"] = Column(
        b_psr, unit="Gauss", description="Pulsar magnetic field at the poles"
    )
    return table
Ejemplo n.º 3
0
"""Plot spin frequency of the pulsar with time."""
import numpy as np
import matplotlib.pyplot as plt
from astropy.units import Quantity
from gammapy.astro.source import Pulsar

t = Quantity(np.logspace(0, 6, 100), "yr")
pulsar = Pulsar(P_0=Quantity(0.01, "s"), logB=12)
plt.plot(t.value, 1 / pulsar.period(t).cgs.value)
plt.xlabel("time [years]")
plt.ylabel("frequency [1/s]")
plt.ylim(1e0, 1e2)
plt.loglog()
plt.show()
"""Plot spin frequency of the pulsar with time."""
import numpy as np
import matplotlib.pyplot as plt
from astropy.units import Quantity
from gammapy.astro.source import Pulsar

t = Quantity(np.logspace(0, 6, 100), "yr")

pulsar = Pulsar(P_0=Quantity(0.01, "s"), B="1e12 G")

plt.plot(t.value, 1 / pulsar.period(t).cgs.value)
plt.xlabel("time [years]")
plt.ylabel("frequency [1/s]")
plt.ylim(1e0, 1e2)
plt.loglog()
plt.show()
Ejemplo n.º 5
0
"""Plot spin frequency of the pulsar with time."""
import numpy as np
import matplotlib.pyplot as plt
from astropy.units import Quantity
from gammapy.astro.source import Pulsar

t = Quantity(np.logspace(0, 6, 100), "yr")

pulsar = Pulsar(P_0=Quantity(0.01, "s"), logB=12)

plt.plot(t.value, 1 / pulsar.period(t).cgs.value)
plt.xlabel("time [years]")
plt.ylabel("frequency [1/s]")
plt.ylim(1e0, 1e2)
plt.loglog()
plt.show()
Ejemplo n.º 6
0
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import scipy.integrate
from numpy.testing import assert_allclose
from astropy.table import Table
from astropy.units import Quantity
from gammapy.astro.source import Pulsar, SimplePulsar
from gammapy.utils.testing import assert_quantity_allclose

pulsar = Pulsar()
time = Quantity([1e2, 1e4, 1e6, 1e8], "yr")


def get_atnf_catalog_sample():
    data = """
    NUM   NAME            Gl          Gb       P0        P1        AGE        BSURF     EDOT
    1     J0006+1834      108.172    -42.985   0.693748  2.10e-15  5.24e+06   1.22e+12  2.48e+32
    2     J0007+7303      119.660     10.463   0.315873  3.60e-13  1.39e+04   1.08e+13  4.51e+35
    3     B0011+47        116.497    -14.631   1.240699  5.64e-16  3.48e+07   8.47e+11  1.17e+31
    7     B0021-72E       305.883    -44.883   0.003536  9.85e-20  5.69e+08   5.97e+08  8.79e+34
    8     B0021-72F       305.899    -44.892   0.002624  6.45e-20  6.44e+08   4.16e+08  1.41e+35
    16    J0024-7204O     305.897    -44.889   0.002643  3.04e-20  1.38e+09   2.87e+08  6.49e+34
    18    J0024-7204Q     305.877    -44.899   0.004033  3.40e-20  1.88e+09   3.75e+08  2.05e+34
    21    J0024-7204T     305.890    -44.894   0.007588  2.94e-19  4.09e+08   1.51e+09  2.65e+34
    22    J0024-7204U     305.890    -44.905   0.004343  9.52e-20  7.23e+08   6.51e+08  4.59e+34
    28    J0026+6320      120.176      0.593   0.318358  1.50e-16  3.36e+07   2.21e+11  1.84e+32
    """
    return Table.read(data, format="ascii")


def test_SimplePulsar_atnf():
    """Test functions against ATNF pulsar catalog values"""
Ejemplo n.º 7
0
"""Plot spin frequency of the pulsar with time."""
import numpy as np
import matplotlib.pyplot as plt
from astropy.units import Quantity
from gammapy.astro.source import Pulsar

t = Quantity(np.logspace(0, 6, 100), 'yr')
pulsar = Pulsar(P_0=Quantity(0.01, 's'), logB=12)
plt.plot(t.value, 1 / pulsar.period(t).cgs.value, color='b')
plt.xlabel('time [years]')
plt.ylabel('frequency [1/s]')
plt.ylim(1E0, 1E2)
plt.loglog()
plt.show()