Passed
Pull Request — master (#1918)
by Christoph
05:37
created

gammapy/astro/population/velocity.py (8 issues)

1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
"""Pulsar velocity distribution models."""
3
from __future__ import absolute_import, division, print_function, unicode_literals
4
import numpy as np
5
from astropy.modeling import Fittable1DModel, Parameter
6
from astropy.units import Quantity
7
8
__all__ = [
9
    "FaucherKaspi2006VelocityMaxwellian",
10
    "FaucherKaspi2006VelocityBimodal",
11
    "Paczynski1990Velocity",
12
    "velocity_distributions",
13
]
14
15
# Simulation range used for random number drawing
16
VMIN, VMAX = Quantity([0, 4000], "km/s")
17
18
19
class FaucherKaspi2006VelocityMaxwellian(Fittable1DModel):
0 ignored issues
show
The variable __class__ seems to be unused.
Loading history...
20
    """Maxwellian pulsar velocity distribution.
21
22
    .. math ::
23
        f(v) = A \\sqrt{ \\frac{2}{\\pi}} \\frac{v ^ 2}{\\sigma ^ 3 }
24
               \\exp \\left(-\\frac{v ^ 2}{2 \\sigma ^ 2} \\right)
25
26
    Reference: http://adsabs.harvard.edu/abs/2006ApJ...643..332F
27
28
    Parameters
29
    ----------
30
    amplitude : float
31
        Value of the integral
32
    sigma : float
33
        Velocity parameter (km s^-1)
34
    """
35
36
    amplitude = Parameter()
37
    sigma = Parameter()
38
39
    def __init__(self, amplitude=1, sigma=265, **kwargs):
40
        super(FaucherKaspi2006VelocityMaxwellian, self).__init__(
41
            amplitude=amplitude, sigma=sigma, **kwargs
42
        )
43
44
    @staticmethod
45
    def evaluate(v, amplitude, sigma):
0 ignored issues
show
Parameters differ from overridden 'evaluate' method
Loading history...
The argument amplitude seems to be unused.
Loading history...
46
        """One dimensional velocity model function."""
47
        term1 = np.sqrt(2 / np.pi) * v ** 2 / sigma ** 3
48
        term2 = np.exp(-v ** 2 / (2 * sigma ** 2))
49
        return term1 * term2
50
51
52
class FaucherKaspi2006VelocityBimodal(Fittable1DModel):
0 ignored issues
show
The variable __class__ seems to be unused.
Loading history...
53
    """Bimodal pulsar velocity distribution - Faucher & Kaspi (2006).
54
55
    .. math ::
56
        f(v) = A\\sqrt{\\frac{2}{\\pi}} v^2 \\left[\\frac{w}{\\sigma_1^3}
57
        \\exp \\left(-\\frac{v^2}{2\\sigma_1^2} \\right) + \\frac{1-w}{\\sigma_2^3}
58
        \\exp \\left(-\\frac{v^2}{2\\sigma_2^2} \\right) \\right]
59
60
    Reference: http://adsabs.harvard.edu/abs/2006ApJ...643..332F (Formula (7))
61
62
    Parameters
63
    ----------
64
    amplitude : float
65
        Value of the integral
66
    sigma1 : float
67
        See model formula
68
    sigma2 : float
69
        See model formula
70
    w : float
71
        See model formula
72
    """
73
74
    amplitude = Parameter()
75
    sigma_1 = Parameter()
76
    sigma_2 = Parameter()
77
    w = Parameter()
78
79
    def __init__(self, amplitude=1, sigma_1=160, sigma_2=780, w=0.9, **kwargs):
0 ignored issues
show
The argument sigma_2 seems to be unused.
Loading history...
80
        super(FaucherKaspi2006VelocityBimodal, self).__init__(
81
            amplitude=amplitude, sigma_1=sigma_1, sigma_2=sigma_1, w=w, **kwargs
82
        )
83
84
    @staticmethod
85
    def evaluate(v, amplitude, sigma_1, sigma_2, w):
0 ignored issues
show
Parameters differ from overridden 'evaluate' method
Loading history...
86
        """One dimensional Faucher-Guigere & Kaspi 2006 velocity model function."""
87
        A = amplitude * np.sqrt(2 / np.pi) * v ** 2
88
        term1 = (w / sigma_1 ** 3) * np.exp(-v ** 2 / (2 * sigma_1 ** 2))
89
        term2 = (1 - w) / sigma_2 ** 3 * np.exp(-v ** 2 / (2 * sigma_2 ** 2))
90
        return A * (term1 + term2)
91
92
93
class Paczynski1990Velocity(Fittable1DModel):
0 ignored issues
show
The variable __class__ seems to be unused.
Loading history...
94
    """Distribution by Lyne 1982 and adopted by Paczynski and Faucher.
95
96
    .. math ::
97
        f(v) = A\\frac{4}{\\pi} \\frac{1}{v_0 \\left[1 + (v / v_0) ^ 2 \\right] ^ 2}
98
99
    Reference: http://adsabs.harvard.edu/abs/1990ApJ...348..485P (Formula (3))
100
101
    Parameters
102
    ----------
103
    amplitude : float
104
        Value of the integral
105
    v_0 : float
106
        Velocity parameter (km s^-1)
107
    """
108
109
    amplitude = Parameter()
110
    v_0 = Parameter()
111
112
    def __init__(self, amplitude=1, v_0=560, **kwargs):
113
        super(Paczynski1990Velocity, self).__init__(
114
            amplitude=amplitude, v_0=v_0, **kwargs
115
        )
116
117
    @staticmethod
118
    def evaluate(v, amplitude, v_0):
0 ignored issues
show
Parameters differ from overridden 'evaluate' method
Loading history...
119
        """One dimensional Paczynski 1990 velocity model function."""
120
        return amplitude * 4.0 / (np.pi * v_0 * (1 + (v / v_0) ** 2) ** 2)
121
122
123
"""Velocity distributions (dict mapping names to classes)."""
124
velocity_distributions = {
125
    "H05": FaucherKaspi2006VelocityMaxwellian,
126
    "F06B": FaucherKaspi2006VelocityBimodal,
127
    "F06P": Paczynski1990Velocity,
128
}
129