Ejemplo n.º 1
0
def microphysics(Gsh, Rb, tb, n_amb, epsb, epse, pe, fe, electron_y):
    warnings.filterwarnings('ignore', category=DeprecationWarning)

    specific_heat_ratio = 4 / 3 + 1 / Gsh
    compression_ratio = (specific_heat_ratio * Gsh +
                         1) / (specific_heat_ratio - 1)

    B = (np.sqrt(8 * np.pi * epsb * compression_ratio * n_amb * m_p * c**2 *
                 (Gsh - 1))).to((u.erg * pcm)**(1 / 2))
    Ne = fe * n_amb * 4 / 3 * np.pi * Rb**3

    gm = (epse / fe * (pe - 2) / (pe - 1) * m_p / m_e * (Gsh - 1)).cgs

    _gc = (6 * np.pi * mec * Gsh / (sigma_T * B**2 * tb)).cgs
    Y = (-1 + np.sqrt(1 + 4 * min(1, (gm / _gc)**(pe - 2)) * epse / epsb)) / 2
    Y *= float(electron_y)
    gc = _gc / (1 + Y)

    g_syn_max = np.sqrt(6 * np.pi * e / (sigma_T * B * (1 + Y))).cgs
    g_esc_max = (e * B * Rb) / (12 * Gsh * mec2).cgs

    g0 = max(2, min(gm, gc))
    g_break = max(2, gm, gc)
    p1 = pe if gm < gc else 2
    p2 = pe + 1
    g_cutoff = min(g_syn_max, g_esc_max)
    beta_cutoff = 2 if g_syn_max < g_esc_max else 1

    # amp = (Ne/mec2/( g0/(p1-1) + g_break*(g_break/g0)**(-p1)*(p2-p1)/(p1-1)/(p2-1) )).to(1/u.eV)
    amp = (Ne / mec2 / (g0 / (p1 - 1))).to(1 / u.eV)

    electrons = ExponentialCutoffBrokenPowerLaw(
        amplitude=amp,
        e_0=(g0 * mec2).to(u.eV),
        e_break=(g_break * mec2).to(u.eV),
        alpha_1=p1,
        alpha_2=p2,
        e_cutoff=(g_cutoff * mec2).to(u.eV),
        beta=beta_cutoff,
    )

    return electrons, B
Ejemplo n.º 2
0
import numpy as np
from astropy.io import ascii
from astropy.constants import c
import astropy.units as u
import naima
from naima.models import (
    ExponentialCutoffBrokenPowerLaw,
    Synchrotron,
    InverseCompton,
)

ECBPL = ExponentialCutoffBrokenPowerLaw(
    amplitude=3.699e36 / u.eV,
    e_0=1 * u.TeV,
    e_break=0.265 * u.TeV,
    alpha_1=1.5,
    alpha_2=3.233,
    e_cutoff=1863 * u.TeV,
    beta=2.0,
)

eopts = {"Eemax": 50 * u.PeV, "Eemin": 0.1 * u.GeV}

SYN = Synchrotron(ECBPL, B=125 * u.uG, Eemax=50 * u.PeV, Eemin=0.1 * u.GeV)

# Compute photon density spectrum from synchrotron emission assuming R=2.1 pc
Rpwn = 2.1 * u.pc
Esy = np.logspace(-7, 9, 100) * u.eV
Lsy = SYN.flux(Esy, distance=0 * u.cm)  # use distance 0 to get luminosity
phn_sy = Lsy / (4 * np.pi * Rpwn**2 * c) * 2.24
Ejemplo n.º 3
0
# parameters for comoving frame
amplitude = 1.e35 / u.eV
e_0 = 1 * u.TeV  # normalization energy
e_break = 10 * u.GeV
alpha_1 = 2.
alpha_2 = 3.
e_cutoff = 1 * u.TeV
beta = 1.  # exponential cutoff rapidity
Emin = 1 * u.GeV
Emax = 10 * u.TeV

comoving = ExponentialCutoffBrokenPowerLaw(
    amplitude=amplitude,
    e_0=e_0,
    e_break=e_break,
    alpha_1=alpha_1,
    alpha_2=alpha_2,
    e_cutoff=e_cutoff,
    beta=beta,
)

lab = ExponentialCutoffBrokenPowerLaw(
    amplitude=amplitude * delta**3,
    e_0=e_0 * delta,
    e_break=e_break * delta,
    alpha_1=alpha_1,
    alpha_2=alpha_2,
    e_cutoff=e_cutoff * delta,
    beta=beta,
)
Ejemplo n.º 4
0
def tophat(E0, g0, energy, time, theta_obs, D_L):
    mu_obs = np.cos(theta_obs)
    z = z_at_value(Planck15.luminosity_distance, D_L)
    if isinstance(energy.to_value(u.eV), float):
        energy = np.array([energy.to_value(u.eV)]) * u.eV

    # calc: R_b, t_b, Gamma_sh
    u0, b0 = np.sqrt(g0**2 - 1), np.sqrt(1 - 1 / g0**2)
    if g0 == 1.0:
        return 0 * u.erg / u.cm**2 / u.s

    R_dec = ((3. * E0 / (4. * np.pi * n_amb * m_p * c**2 *
                         (g0**2 - 1)))**(1 / 3)).to(u.pc)
    xi_z = (c * time / (1 + z) / R_dec).cgs

    if np.isposinf(alpha_stf):
        u_xi = lambda xi: u0 if xi < 1e-1 else (u0 * xi**(
            -3 / 2) if xi > 1e1 else np.sqrt(
                ((g0 + 1) / 2 * xi**(-3) *
                 (np.sqrt(1 + 4 * g0 / (g0 + 1) * xi**3 + 4 /
                          (g0 + 1)**2 * xi**6) - 1))**2 - 1))
    else:
        ui = np.inf
        eiso_u = lambda u: (max(u0, min(ui, u))**(-alpha_stf) - ui**(
            -alpha_stf)) / (u0**(-alpha_stf) - ui**(-alpha_stf))
        I = lambda u: alpha_stf / (alpha_stf + 2) * u**(-alpha_stf - 2) * (
            1 + hyp2f1(-1 / 2, -1 - alpha_stf / 2, -alpha_stf / 2, -u**2))
        miso_u = lambda u: (I(max(u0, min(ui, u))) - I(ui)) / (u0**(
            -alpha_stf) - ui**(-alpha_stf))
        u_xi = lambda xi: fsolve(
            lambda _u: xi**3 *
            (_u[0] / u0)**2 - eiso_u(_u[0]) + miso_u(_u[0]) *
            (np.sqrt(_u[0]**2 + 1) - 1), u0)[0]

    eats = lambda xi: -mu_obs * xi + quad(
        lambda _xi: np.sqrt(u_xi(_xi)**2 + 1) / u_xi(_xi), 0, xi)[0]
    xi = fsolve(lambda _xi: eats(_xi[0]) - xi_z,
                b0 * xi_z / (1 - b0 * mu_obs))[0]

    R_b = xi * R_dec
    t_b = (R_dec / c).cgs * quad(
        lambda _xi: np.sqrt(u_xi(_xi)**2 + 1) / u_xi(_xi), 0, xi)[0]
    Gamma_sh = np.sqrt(u_xi(xi)**2 + 1)

    if Gamma_sh == 1.0:
        return 0 * u.erg / u.cm**2 / u.s

    # calc: electron distribution
    specific_heat_ratio = 4 / 3 + 1 / Gamma_sh
    compression_ratio = (specific_heat_ratio * Gamma_sh +
                         1) / (specific_heat_ratio - 1)

    B = (np.sqrt(8 * np.pi * eps_B * compression_ratio * n_amb * m_p * c**2 *
                 (Gamma_sh - 1))).to((u.erg * pcm)**(1 / 2))
    Ne = zeta_e * 4 / 3 * np.pi * R_b**3 * n_amb

    gm = (eps_e / zeta_e * (p_e - 2) / (p_e - 1) * m_p / m_e *
          (Gamma_sh - 1)).cgs

    _gc = 6 * np.pi * mec * Gamma_sh / (sigma_T * B**2 * t_b)
    Y = (-1 +
         np.sqrt(1 + 4 * min(1, (gm / _gc)**(p_e - 2)) * eps_e / eps_B)) / 2
    gc = _gc.cgs / (1 + Y)  # rough estimate from Sari & Esin (2001)

    e_syn_max = (min(np.sqrt(3 * e / (sigma_T * B * (1 + Y))), (e * B * R_b) /
                     (12 * 2 * np.pi * Gamma_sh * mec2)) * mec2).to(u.TeV)

    electrons = ExponentialCutoffBrokenPowerLaw(
        amplitude=(Ne * (p_e - 1) / (max(2., gm) * mec2) *
                   min(1., (gm / 2.)**(p_e - 1)) if gm < gc else Ne /
                   (max(2., gc) * mec2) * min(1., gc / 2.)).to(1 / u.eV),
        e_0=(max(2., min(gm, gc)) * mec2).to(u.TeV),
        e_break=(max(2., max(gm, gc)) * mec2).to(u.TeV),
        alpha_1=p_e if gm < gc else 2.,
        alpha_2=p_e + 1,
        e_cutoff=max(((max(2., min(gm, gc)) + 1) * mec2).to(u.TeV), e_syn_max),
        beta=2.0,
    )

    # calc: syn+ic flux
    SYN = Synchrotron(
        electrons,
        B=B.to_value((u.erg * pcm)**(1 / 2)) * u.G,
        Eemax=electrons.e_cutoff,
        Eemin=electrons.e_0,
        nEed=50,
    )
    '''E_ph = np.logspace(-7, 14, 22) * u.eV
    L_syn = self.SYN.flux(E_ph, distance=0 * u.cm)
    phn_syn = L_syn / (4 * np.pi * self.R ** 2 * c) * 2.24

    IC = InverseCompton(
        self.electrons,
        seed_photon_fields=[
            #"CMB",
            #["FIR", 70 * u.K, 0.5 * u.eV / u.cm ** 3],
            #["NIR", 5000 * u.K, 1 * u.eV / u.cm ** 3],
            ["SSC", E_ph, phn_syn],
        ],
        Eemax=self.electrons.e_cutoff, 
        Eemin=self.electrons.e_0,
        nEed=50,
    )'''

    Doppler = 1 / (Gamma_sh * (1 - np.sqrt(1 - 1 / Gamma_sh**2) * mu_obs))
    flx = Doppler**4 * SYN.sed((1 + z) * energy / Doppler, D_L)[0]
    tran = EblAbsorptionModel(redshift=z).transmission(e=energy)[0]
    return (flx * tran).to(u.erg / u.cm**2 / u.s)