def test_power_law_integral(self, p, integrator): """test the integration of the power law for different spectral indexes different integrating functions""" pwl = PowerLaw(k_e_test, p, gamma_min_test, gamma_max_test, integrator=integrator) numerical_integral = pwl.integral(gamma_min_test, gamma_max_test) analytical_integral = power_law_integral(k_e_test, p, gamma_min_test, gamma_max_test) assert u.isclose(numerical_integral, analytical_integral, atol=0 * u.Unit("cm-3"), rtol=1e-2)
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") pwl = PowerLaw.from_norm_at_gamma_1(norm=norm, p=p_test, gamma_min=1, gamma_max=gamma_max_test) assert u.isclose(norm, pwl(1), atol=0 * u.Unit("cm-3"), rtol=1e-2)
def test_from_normalised_energy_density(self): """test the intialisation of the power law from the total particle energy density""" u_e = 3e-4 * u.Unit("erg cm-3") pwl = PowerLaw.from_normalised_energy_density(u_e=u_e, p=p_test, gamma_min=gamma_min_test, gamma_max=gamma_max_test) # calculate u_e u_e_calc = mec2 * pwl.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)
def test_from_normalised_density(self): """test the intialisation of the power law from the total particle density""" n_e_tot = 1e-5 * u.Unit("cm-3") pwl = PowerLaw.from_normalised_density( n_e_tot=n_e_tot, p=p_test, gamma_min=gamma_min_test, gamma_max=gamma_max_test, ) # calculate n_e_tot n_e_tot_calc = pwl.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)
# tests on spectra module import numpy as np import astropy.units as u from astropy.constants import m_e from agnpy.spectra import PowerLaw, BrokenPowerLaw, LogParabola, ExpCutoffPowerLaw 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)