-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement NaimaModel wrapper class #2124
Changes from 12 commits
0f93c5b
9593e45
0930c1e
c5baf5a
ec13e58
ea2f41b
af0aa50
f20f116
619753e
866e017
6fbe601
95f302f
300d034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
import pytest | ||
import numpy as np | ||
import naima | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to restructure the testing here, because My suggestion would be to implement a @requires_dependency("naima")
class TestNaimaModel:
def test_pion_decay_(self):
import naima
model = NaimaModel()
assert_quantity_allclose()
assert_quantity_allclose()
def test_ic(self):
import naima
model = NaimaModel()
assert_quantity_allclose()
assert_quantity_allclose()
def test_synchrotron(self):
import naima
model = NaimaModel()
assert_quantity_allclose()
assert_quantity_allclose() |
||
import astropy.units as u | ||
from ...utils.energy import EnergyBounds | ||
from ...utils.testing import assert_quantity_allclose | ||
|
@@ -15,6 +16,7 @@ | |
AbsorbedSpectralModel, | ||
Absorption, | ||
ConstantModel, | ||
NaimaModel, | ||
) | ||
|
||
|
||
|
@@ -192,8 +194,58 @@ def table_model(): | |
except ImportError: | ||
pass | ||
|
||
# Add Naima models | ||
particle_distributions = [ | ||
naima.models.PowerLaw(amplitude=2e33 / u.eV, e_0=10 * u.TeV, alpha=2.5), | ||
naima.models.ExponentialCutoffBrokenPowerLaw( | ||
amplitude=2e33 / u.eV, | ||
e_0=10 * u.TeV, | ||
alpha_1=2.5, | ||
alpha_2=2.7, | ||
e_break=900 * u.GeV, | ||
e_cutoff=10 * u.TeV, | ||
), | ||
naima.models.LogParabola(amplitude=2e33 / u.eV, e_0=10 * u.TeV, alpha=1.3, beta=0.5), | ||
] | ||
radiative_models = [ | ||
naima.radiative.PionDecay(particle_distributions[0], nh=1 * u.cm ** -3), | ||
naima.radiative.InverseCompton(particle_distributions[1], seed_photon_fields=["CMB"]), | ||
naima.radiative.Synchrotron(particle_distributions[2], B=2 * u.G), | ||
] | ||
|
||
TEST_MODELS.append( | ||
dict( | ||
name="naima1", | ||
model=NaimaModel(radiative_models[0]), | ||
val_at_2TeV=9.725347355450884e-14 * u.Unit("cm-2 s-1 TeV-1"), | ||
integral_1_10TeV=3.530537143620737e-13 * u.Unit("cm-2 s-1"), | ||
eflux_1_10TeV=7.643559573105779e-13 * u.Unit("TeV cm-2 s-1"), | ||
) | ||
) | ||
|
||
TEST_MODELS.append( | ||
dict( | ||
name="naima2", | ||
model=NaimaModel(radiative_models[1]), | ||
val_at_2TeV=4.347836316893546e-12 * u.Unit("cm-2 s-1 TeV-1"), | ||
integral_1_10TeV=1.5958109911918303e-11 * u.Unit("cm-2 s-1"), | ||
eflux_1_10TeV=2.851281562480875e-11 * u.Unit("TeV cm-2 s-1"), | ||
) | ||
) | ||
|
||
TEST_MODELS.append( | ||
dict( | ||
name="naima3", | ||
model=NaimaModel(radiative_models[2]), | ||
val_at_2TeV=1.0565840392550432e-24 * u.Unit("cm-2 s-1 TeV-1"), | ||
integral_1_10TeV=4.4491861907713736e-13 * u.Unit("cm-2 s-1"), | ||
eflux_1_10TeV=4.594120986691428e-13 * u.Unit("TeV cm-2 s-1"), | ||
) | ||
) | ||
|
||
|
||
@requires_dependency("uncertainties") | ||
@requires_dependency("naima") | ||
@pytest.mark.parametrize("spectrum", TEST_MODELS, ids=[_["name"] for _ in TEST_MODELS]) | ||
def test_models(spectrum): | ||
model = spectrum["model"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove TODO? Or is this really something we want / need to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All spectral models prevent the intialization of new attributes after
__init__
because they have parameters declared in__slots__
. For Naima models this turns out to be tricky (see previous answer: #2124 (comment)), but for consistency I think we will probably need to implement this TODO here