Example #1
0
 def test_bb_sed_luminosity(self, R_out, mu_s):
     """test that the luminosity of the disk BB SED is the same as L_disk,
     create disks with different outer radii"""
     disk = SSDisk(M_BH_test, L_disk_test, 1 / 12, 6, R_out, R_g_units=True)
     # compute the SEDs, assume a random redshift
     z = 0.23
     nu = np.logspace(10, 20, 100) * u.Hz
     sed = disk.sed_flux(nu, z, mu_s)
     # compute back the luminosity
     d_L = Distance(z=z).to("cm")
     F_nu = sed / nu
     # renormalise, the factor 2 includes the two sides of the Disk
     L = 2 * (4 * np.pi * np.power(d_L, 2) * np.trapz(F_nu, nu, axis=0))
     assert u.isclose(L, L_disk_test, atol=0 * u.Unit("erg s-1"), rtol=1e-2)
Example #2
0
 def test_absorption_disk_reference_tau(self, r):
     """test agnpy gamma-gamma optical depth for Disk against the one in 
     Figure 14 of Finke 2016"""
     # reference tau
     E_ref, tau_ref = extract_columns_sample_file(
         f"{data_dir}/reference_taus/finke_2016/figure_14_left/tau_SSdisk_r_{r}_R_Ly_alpha.txt",
         "GeV",
     )
     nu_ref = E_ref.to("Hz", equivalencies=u.spectral())
     # target
     M_BH = 1.2 * 1e9 * M_sun.cgs
     L_disk = 2e46 * u.Unit("erg s-1")
     eta = 1 / 12
     R_in = 6
     R_out = 200
     disk = SSDisk(M_BH, L_disk, eta, R_in, R_out, R_g_units=True)
     R_Ly_alpha = 1.1e17 * u.cm
     _r = float(r) * R_Ly_alpha
     # recompute the tau, use the full energy range of figure 14
     z = 0.859
     abs_disk = Absorption(disk, _r, z)
     tau_agnpy = abs_disk.tau(nu_ref)
     # comparison plot
     make_comparison_plot(
         nu_ref,
         tau_agnpy,
         tau_ref,
         "agnpy",
         "Figure 14, Finke (2016)",
         f"Absorption Shakura Sunyaev Disk, r = {r} R(Ly alpha)",
         f"{figures_dir}/disk/tau_disk_comparison_r_{r}_R_Ly_alpha_figure_14_finke_2016.png",
         "tau",
         y_range=[1e-10, 1e5],
     )
     assert True
Example #3
0
 def test_ec_disk_reference_sed(self):
     """test agnpy SED for EC on Disk against the one in Figure 8 of Finke 2016"""
     # reference SED
     sampled_ec_disk_table = np.loadtxt(
         f"{tests_dir}/sampled_seds/ec_disk_figure_8_finke_2016.txt",
         delimiter=",",
         comments="#",
     )
     sampled_ec_disk_nu = sampled_ec_disk_table[:, 0] * u.Hz
     sampled_ec_disk_sed = sampled_ec_disk_table[:, 1] * u.Unit("erg cm-2 s-1")
     # agnpy SED
     M_BH = 1.2 * 1e9 * M_sun.cgs
     L_disk = 2 * 1e46 * u.Unit("erg s-1")
     eta = 1 / 12
     R_in = 6
     R_out = 200
     disk = SSDisk(M_BH, L_disk, eta, R_in, R_out, R_g_units=True)
     # recompute the SED at the same ordinates where the figure was sampled
     ec_disk = ExternalCompton(BPL_BLOB, disk, r=1e17 * u.cm)
     agnpy_ec_disk_sed = ec_disk.sed_flux(sampled_ec_disk_nu)
     # sed comparison plot
     make_sed_comparison_plot(
         sampled_ec_disk_nu,
         sampled_ec_disk_sed,
         agnpy_ec_disk_sed,
         "External Compton on Shakura Sunyaev Disk",
         "ec_disk_comparison_figure_8_finke_2016",
     )
     # requires that the SED points deviate less than 40% from the figure
     assert u.allclose(
         agnpy_ec_disk_sed,
         sampled_ec_disk_sed,
         atol=0 * u.Unit("erg cm-2 s-1"),
         rtol=0.4,
     )
Example #4
0
 def test_mu_from_r_tilde(self):
     mu = SSDisk.evaluate_mu_from_r_tilde(R_in_tilde_test,
                                          R_out_tilde_test,
                                          r_tilde=10)
     mu_min_expected = 0.050
     mu_max_expected = 0.858
     assert np.isclose(mu[0], mu_min_expected, atol=0, rtol=1e-2)
     assert np.isclose(mu[-1], mu_max_expected, atol=0, rtol=1e-2)
Example #5
0
 def test_epsilon_mu(self):
     r_tilde = 10
     # assume R_tilde = 10 as before
     mu = 1 / np.sqrt(2)
     epsilon_disk_expected = 2.7e-5
     epsilon_disk = SSDisk.evaluate_epsilon_mu(
         L_disk_test, M_BH_test, eta_test, mu, r_tilde
     )
     assert np.allclose(epsilon_disk, epsilon_disk_expected, atol=0, rtol=1e-2)
z = 1
delta_D = 40
Gamma = 40
blob = Blob(R_b, z, delta_D, Gamma, B, spectrum_norm, spectrum_dict)
print("\nblob definition:")
print(blob)

# disk parameters
M_sun = const.M_sun.cgs
M_BH = 1.2 * 1e9 * M_sun
R_g = ((const.G * M_BH) / (const.c * const.c)).cgs
L_disk = 2 * 1e46 * u.Unit("erg s-1")
eta = 1 / 12
R_in = 6 * R_g
R_out = 200 * R_g
disk = SSDisk(M_BH, L_disk, eta, R_in, R_out)
print("\ndisk definition:")
print(disk)

# blr definition
epsilon_line = 2e-5
csi_line = 0.024
R_line = 1e17 * u.cm
blr = SphericalShellBLR(disk, csi_line, epsilon_line, R_line)
print("\nblr definition:")
print(blr)

# dust torus definition
T_dt = 1e3 * u.K
epsilon_dt = 2.7 * ((const.k_B * T_dt) / (const.m_e * const.c * const.c)).decompose()
csi_dt = 0.1
Example #7
0
 def test_R_in_R_out_units(self, R_in, R_out, R_g_units):
     """check if a TypeError is raised when passing R_in and R_out with 
     (without) units but specifiying R_g_units True (False)"""
     with pytest.raises(TypeError):
         disk = SSDisk(M_BH, L_DISK, ETA, R_in, R_out, R_g_units)
Example #8
0
import astropy.units as u
from astropy.constants import e, c, m_e, M_sun, G, sigma_sb
from agnpy.targets import SSDisk
import pytest

# global quantities defining the test disk
M_BH = 1.2 * 1e9 * M_sun
L_DISK = 1.512 * 1e46 * u.Unit("erg s-1")
ETA = 1 / 12
R_G = 1.77 * 1e14 * u.cm
R_IN_G_UNITS = 6
R_OUT_G_UNITS = 200
R_IN = R_IN_G_UNITS * R_G
R_OUT = R_OUT_G_UNITS * R_G

DISK = SSDisk(M_BH, L_DISK, ETA, R_IN, R_OUT)

# useful for checks
L_EDD = 15.12 * 1e46 * u.Unit("erg s-1")
M_DOT = 2.019 * 1e26 * u.Unit("g s-1")

RTOL = 1e-2


class TestDisk:
    """class grouping all the tests related to the SSDisk target"""
    def test_L_Edd(self):
        assert u.allclose(DISK.L_Edd, L_EDD, rtol=RTOL)

    def test_l_Edd(self):
        assert u.allclose(DISK.l_Edd, 0.1, rtol=RTOL)
Example #9
0
import astropy.constants as const
from agnpy.targets import SSDisk, SphericalShellBLR, RingDustTorus
from agnpy.absorption import Absorption
import matplotlib.pyplot as plt
from agnpy.utils.plot import load_mpl_rc

# matplotlib adjustments
load_mpl_rc()

# disk parameters
M_BH = 1.2 * 1e9 * const.M_sun.cgs
L_disk = 2 * 1e46 * u.Unit("erg s-1")
eta = 1 / 12
R_in = 6
R_out = 200
disk = SSDisk(M_BH, L_disk, eta, R_in, R_out, R_g_units=True)

# blr definition
csi_line = 0.024
R_line = 1e17 * u.cm
blr = SphericalShellBLR(L_disk, csi_line, "Lyalpha", R_line)

# dust torus definition
T_dt = 1e3 * u.K
csi_dt = 0.1
dt = RingDustTorus(L_disk, csi_dt, T_dt)

# consider a fixed distance of the blob from the target fields
r = 1.1e16 * u.cm
# let us consider 3C 454.3 as source
z = 0.859
Example #10
0
z = 0
delta_D = 40
Gamma = 40
blob = Blob(R_b, z, delta_D, Gamma, B, spectrum_norm, spectrum_dict)
print("blob definition:")
print(blob)

# disk parameters
M_sun = const.M_sun.cgs
M_BH = 1.2 * 1e9 * M_sun
R_g = ((const.G * M_BH) / (const.c * const.c)).cgs
L_disk = 2 * 1e46 * u.Unit("erg s-1")
eta = 1 / 12
R_in = 6 * R_g
R_out = 200 * R_g
disk = SSDisk(M_BH, L_disk, eta, R_in, R_out)
print("disk definition:")
print(disk)

# blr definition
epsilon_line = 2e-5
csi_line = 0.024
R_line = 1e17 * u.cm
blr = SphericalShellBLR(disk, csi_line, epsilon_line, R_line)
print("blr definition:")
print(blr)

# dust torus definition
T_dt = 1e3 * u.K
epsilon_dt = 2.7 * ((const.k_B * T_dt) /
                    (const.m_e * const.c * const.c)).decompose()
Example #11
0
 def test_phi_disk_mu(self):
     r_tilde = 10
     mu = 1 / np.sqrt(2)
     phi_disk_expected = 0.225
     phi_disk = SSDisk.evaluate_phi_disk_mu(mu, R_in_tilde_test, r_tilde)
     assert np.allclose(phi_disk, phi_disk_expected, atol=0, rtol=1e-2)
Example #12
0
# CMB at z = 1
cmb_test = CMB(z=1)

# PointSourceBehindJet
ps_test = PointSourceBehindJet(1e46 * u.Unit("erg s-1"), 1e-5)

# disk
M_BH_test = 1.2 * 1e9 * M_sun
L_disk_test = 1.512 * 1e46 * u.Unit("erg s-1")
eta_test = 1 / 12
R_g_test = 1.77 * 1e14 * u.cm
R_in_tilde_test = 6
R_out_tilde_test = 200
R_in_test = R_in_tilde_test * R_g_test
R_out_test = R_out_tilde_test * R_g_test
disk_test = SSDisk(M_BH_test, L_disk_test, eta_test, R_in_test, R_out_test)
# useful for checks
L_Edd_test = 15.12 * 1e46 * u.Unit("erg s-1")
m_dot_test = 2.019 * 1e26 * u.Unit("g s-1")

# SphericalShellBLR
blr_test = SphericalShellBLR(L_disk_test, 0.1, "Lyalpha", 1e17 * u.cm)

# dust torus definition
dt_test = RingDustTorus(L_disk_test, 0.1, 1000 * u.K)


class TestCMB:
    """class grouping all the tests related to the CMB"""
    def test_u(self):
        """test u in the stationary reference frame"""