Skip to content

Commit

Permalink
Merge pull request #151 from cosimoNigro/fix_z_d_L_issue
Browse files Browse the repository at this point in the history
added cosmology as an optional argument instead of d_L
  • Loading branch information
cosimoNigro authored Sep 4, 2023
2 parents 717bece + cd6958f commit e6f5783
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions agnpy/emission_regions/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ class Blob:
size of the array of electrons Lorentz factors
gamma_p_size : int
size of the array of protons Lorentz factors
cosmology : :class:`~astropy.cosmology.Cosmology`
(optional) cosmology used to convert the redshift in a distance,
see https://docs.astropy.org/en/stable/cosmology/index.html
"""

def __init__(
self,
R_b=1e16 * u.cm,
z=0.069,
d_L=None,
delta_D=10,
Gamma=10,
B=1 * u.G,
Expand All @@ -63,11 +65,12 @@ def __init__(
xi=1.0,
gamma_e_size=200,
gamma_p_size=200,
cosmology=None
):
self.R_b = R_b.to("cm")
self.z = z
# if the luminosity distance is not specified, it will be computed from z
self.d_L = Distance(z=self.z).cgs if d_L is None else d_L
self.d_L = Distance(z=self.z, cosmology=cosmology).cgs
self.delta_D = delta_D
self.Gamma = Gamma
self.B = B
Expand Down
7 changes: 4 additions & 3 deletions agnpy/tests/test_emission_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import astropy.units as u
from astropy.constants import m_e, m_p
from astropy.cosmology import Planck18
import pytest
from agnpy.spectra import PowerLaw, BrokenPowerLaw
from agnpy.emission_regions import Blob
Expand Down Expand Up @@ -39,9 +40,9 @@ def test_blob_properties(self):
# - automatically set d_L
blob = Blob(z=2.1)
assert u.isclose(blob.d_L, 5.21497473e28 * u.cm, atol=0 * u.cm, rtol=1e-3)
# - set a different d_L, not computed from z
d_L = 1.5e27 * u.cm
blob = Blob(z=0.1, d_L=d_L)
# - change cosmology
blob = Blob(z=0.1, cosmology=Planck18)
d_L = 1.4682341e+27 * u.cm
assert u.isclose(blob.d_L, d_L, atol=0 * u.cm, rtol=1e-5)

def test_particles_spectra(self):
Expand Down

0 comments on commit e6f5783

Please sign in to comment.