Skip to content

Commit

Permalink
Merge pull request #88 from cosimoNigro/prepare_0_0_10_release
Browse files Browse the repository at this point in the history
Prepare 0.0.10 release: change name of one of the spectra, fixes in docs
  • Loading branch information
cosimoNigro authored Apr 12, 2021
2 parents 25e270c + ab8dde2 commit f9252be
Show file tree
Hide file tree
Showing 17 changed files with 936 additions and 341 deletions.
164 changes: 84 additions & 80 deletions agnpy/spectra/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__all__ = [
"ElectronDistribution",
"PowerLaw",
"PowerLawExpCutOff",
"ExpCutoffPowerLaw",
"BrokenPowerLaw",
"LogParabola",
]
Expand Down Expand Up @@ -180,85 +180,6 @@ def __str__(self):
+ f" - gamma_max: {self.gamma_max:.2e}\n"
)

class PowerLawExpCutOff(ElectronDistribution):
r"""Class for power-law with an exponetial cutoff particle spectrum.
When called, the particle density :math:`n_e(\gamma)` in :math:`\mathrm{cm}^{-3}` is returned.
.. math::
n_e(\gamma') = k_e \, \gamma'^{-p} exp(-\gamma'/\gamma_c) \, H(\gamma'; \gamma'_{\rm min}, \gamma'_{\rm max})
Parameters
----------
k_e : :class:`~astropy.units.Quantity`
spectral normalisation
p : float
spectral index, note it is positive by definition, will change sign in the function
gamma_c : float
cutoff Lorentz factor of the electron distribution
gamma_min : float
minimum Lorentz factor of the electron distribution
gamma_max : float
maximum Lorentz factor of the electron distribution
integrator: func
function to be used for integration, default is :class:`~numpy.trapz`
"""

def __init__(
self,
k_e=1e-13 * u.Unit("cm-3"),
p=2.1,
gamma_c=1e3,
gamma_min=10,
gamma_max=1e5,
integrator=np.trapz,
):
super().__init__(integrator)
self.k_e = k_e
self.p = p
self.gamma_c = gamma_c
self.gamma_min = gamma_min
self.gamma_max = gamma_max

@property
def parameters(self):
return [self.k_e, self.p, self.gamma_c, self.gamma_min, self.gamma_max]

@staticmethod
def evaluate(gamma, k_e, p, gamma_c, gamma_min, gamma_max):
return np.where(
(gamma_min <= gamma) * (gamma <= gamma_max), k_e * gamma ** (-p) *np.exp( -gamma / gamma_c) , 0
)

def __call__(self, gamma):
return self.evaluate(gamma, self.k_e, self.p, self.gamma_c , self.gamma_min, self.gamma_max)

@staticmethod
def evaluate_SSA_integrand(gamma, k_e, p, gamma_c, gamma_min, gamma_max):
r"""(analytical) integrand for the synchrotron self-absorption:
:math:`\gamma'^2 \frac{d}{d \gamma'} \left(\frac{n_e(\gamma)}{\gamma'^2}\right)`"""
prefactor = -(p + 2) / gamma + (-1 / gamma_c)

return prefactor * PowerLawExpCutOff.evaluate(
gamma, k_e, p, gamma_c, gamma_min, gamma_max
)

def SSA_integrand(self, gamma):
return self.evaluate_SSA_integrand(
gamma, self.k_e, self.p, self.gamma_c, self.gamma_min, self.gamma_max
)

def __str__(self):
return (
f"* electron spectrum\n"
+ f" - power law\n"
+ f" - k_e: {self.k_e:.2e}\n"
+ f" - p: {self.p:.2f}\n"
+ f" - gamma_c: {self.gamma_c:.2f}\n"
+ f" - gamma_min: {self.gamma_min:.2e}\n"
+ f" - gamma_max: {self.gamma_max:.2e}\n"
)



class BrokenPowerLaw(ElectronDistribution):
r"""Class for broken power-law particle spectrum.
Expand Down Expand Up @@ -469,3 +390,86 @@ def __str__(self):
+ f" - gamma_min: {self.gamma_min:.2e}\n"
+ f" - gamma_max: {self.gamma_max:.2e}\n"
)


class ExpCutoffPowerLaw(ElectronDistribution):
r"""Class for power-law with an exponetial cutoff particle spectrum.
When called, the particle density :math:`n_e(\gamma)` in :math:`\mathrm{cm}^{-3}` is returned.
.. math::
n_e(\gamma') = k_e \, \gamma'^{-p} exp(-\gamma'/\gamma_c) \, H(\gamma'; \gamma'_{\rm min}, \gamma'_{\rm max})
Parameters
----------
k_e : :class:`~astropy.units.Quantity`
spectral normalisation
p : float
spectral index, note it is positive by definition, will change sign in the function
gamma_c : float
cutoff Lorentz factor of the electron distribution
gamma_min : float
minimum Lorentz factor of the electron distribution
gamma_max : float
maximum Lorentz factor of the electron distribution
integrator: func
function to be used for integration, default is :class:`~numpy.trapz`
"""

def __init__(
self,
k_e=1e-13 * u.Unit("cm-3"),
p=2.1,
gamma_c=1e3,
gamma_min=10,
gamma_max=1e5,
integrator=np.trapz,
):
super().__init__(integrator)
self.k_e = k_e
self.p = p
self.gamma_c = gamma_c
self.gamma_min = gamma_min
self.gamma_max = gamma_max

@property
def parameters(self):
return [self.k_e, self.p, self.gamma_c, self.gamma_min, self.gamma_max]

@staticmethod
def evaluate(gamma, k_e, p, gamma_c, gamma_min, gamma_max):
return np.where(
(gamma_min <= gamma) * (gamma <= gamma_max),
k_e * gamma ** (-p) * np.exp(-gamma / gamma_c),
0,
)

def __call__(self, gamma):
return self.evaluate(
gamma, self.k_e, self.p, self.gamma_c, self.gamma_min, self.gamma_max
)

@staticmethod
def evaluate_SSA_integrand(gamma, k_e, p, gamma_c, gamma_min, gamma_max):
r"""(analytical) integrand for the synchrotron self-absorption:
:math:`\gamma'^2 \frac{d}{d \gamma'} \left(\frac{n_e(\gamma)}{\gamma'^2}\right)`"""
prefactor = -(p + 2) / gamma + (-1 / gamma_c)

return prefactor * ExpCutoffPowerLaw.evaluate(
gamma, k_e, p, gamma_c, gamma_min, gamma_max
)

def SSA_integrand(self, gamma):
return self.evaluate_SSA_integrand(
gamma, self.k_e, self.p, self.gamma_c, self.gamma_min, self.gamma_max
)

def __str__(self):
return (
f"* electron spectrum\n"
+ f" - power law\n"
+ f" - k_e: {self.k_e:.2e}\n"
+ f" - p: {self.p:.2f}\n"
+ f" - gamma_c: {self.gamma_c:.2f}\n"
+ f" - gamma_min: {self.gamma_min:.2e}\n"
+ f" - gamma_max: {self.gamma_max:.2e}\n"
)
1 change: 0 additions & 1 deletion agnpy/synchrotron/synchrotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
import astropy.units as u
from astropy.constants import e, h, c, m_e, sigma_T
from ..spectra import PowerLaw
from ..utils.math import axes_reshaper, gamma_to_integrate
from ..utils.conversion import nu_to_epsilon_prime, B_to_cgs, lambda_c

Expand Down
160 changes: 0 additions & 160 deletions agnpy/tests/test_geometry.py

This file was deleted.

Loading

0 comments on commit f9252be

Please sign in to comment.