Пример #1
0
 def test_broken_power_law_integral(self, p1, p2, gamma_b, integrator):
     """test the integration of the log parabola for different spectral 
     indexes and breaks and different integrating functions"""
     bpwl = BrokenPowerLaw(
         k_e_test,
         p1,
         p2,
         gamma_b,
         gamma_min_test,
         gamma_max_test,
         integrator=integrator,
     )
     numerical_integral = bpwl.integral(gamma_low=gamma_min_test,
                                        gamma_up=gamma_max_test,
                                        gamma_power=0)
     analytical_integral = broken_power_law_integral(
         k_e_test, p1, p2, gamma_b, gamma_min_test, gamma_max_test)
     assert u.isclose(numerical_integral,
                      analytical_integral,
                      atol=0 * u.Unit("cm-3"),
                      rtol=1e-2)
Пример #2
0
 def test_from_norm_at_gamma_1(self):
     """test the intialisation of the powerlaw from the normalisation at 
     gamma = 1"""
     norm = 1e-13 * u.Unit("cm-3")
     bpwl = BrokenPowerLaw.from_norm_at_gamma_1(
         norm=norm,
         p1=p1_test,
         p2=p2_test,
         gamma_b=gamma_b_test,
         gamma_min=1,
         gamma_max=gamma_max_test,
     )
     assert u.isclose(norm, bpwl(1), atol=0 * u.Unit("cm-3"), rtol=1e-2)
Пример #3
0
 def test_from_normalised_energy_density(self):
     """test the intialisation of the powerlaw from the total particle 
     energy density"""
     u_e = 3e-4 * u.Unit("erg cm-3")
     bpwl = BrokenPowerLaw.from_normalised_energy_density(
         u_e=u_e,
         p1=p1_test,
         p2=p2_test,
         gamma_b=gamma_b_test,
         gamma_min=gamma_min_test,
         gamma_max=gamma_max_test,
     )
     # calculate u_e
     u_e_calc = mec2 * bpwl.integral(
         gamma_low=gamma_min_test, gamma_up=gamma_max_test, gamma_power=1)
     assert u.isclose(u_e, u_e_calc, atol=0 * u.Unit("erg cm-3"), rtol=1e-2)
Пример #4
0
 def test_from_normalised_density(self):
     """test the intialisation of the broken power law from the total particle 
     density"""
     n_e_tot = 1e-5 * u.Unit("cm-3")
     bpwl = BrokenPowerLaw.from_normalised_density(
         n_e_tot=n_e_tot,
         p1=p1_test,
         p2=p2_test,
         gamma_b=gamma_b_test,
         gamma_min=gamma_min_test,
         gamma_max=gamma_max_test,
     )
     # calculate n_e_tot
     n_e_tot_calc = bpwl.integral(gamma_low=gamma_min_test,
                                  gamma_up=gamma_max_test,
                                  gamma_power=0)
     assert u.isclose(n_e_tot,
                      n_e_tot_calc,
                      atol=0 * u.Unit("cm-3"),
                      rtol=1e-2)
Пример #5
0
from agnpy.utils.math import trapz_loglog
from agnpy.utils.conversion import mec2
import pytest

# variables with _test are global and meant to be used in all tests
# global PowerLaw
k_e_test = 1e-13 * u.Unit("cm-3")
p_test = 2.1
gamma_min_test = 10
gamma_max_test = 1e7
pwl_test = PowerLaw(k_e_test, p_test, gamma_min_test, gamma_max_test)
# global BrokenPowerLaw
p1_test = 2.1
p2_test = 3.1
gamma_b_test = 1e3
bpwl_test = BrokenPowerLaw(k_e_test, p1_test, p2_test, gamma_b_test,
                           gamma_min_test, gamma_max_test)
# global LogParabola
q_test = 0.2
gamma_0_test = 1e4
lp_test = LogParabola(k_e_test, p_test, q_test, gamma_0_test, gamma_min_test,
                      gamma_max_test)
# global PowerLaw exp Cutoff
gamma_c_test = 1e3
epwl_test = ExpCutoffPowerLaw(k_e_test, p_test, gamma_c_test, gamma_min_test,
                              gamma_max_test)


def power_law_integral(k_e, p, gamma_min, gamma_max):
    """analytical integral of the power law"""
    if np.isclose(p, 1.0):
        integral = np.log(gamma_max / gamma_min)