-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4734 from meeseeksmachine/auto-backport-of-pr-472…
…1-on-v1.1.x Backport PR #4721 on branch v1.1.x (Exposing NormSpectralModels)
- Loading branch information
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
examples/models/spectral/plot_exp_cutoff_powerlaw_norm_spectral.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
r""" | ||
.. _exp-cutoff-powerlaw-norm-spectral-model: | ||
Exponential cutoff power law norm spectral model | ||
======================== | ||
This model parametrises a cutoff power law spectral correction with a norm parameter. | ||
""" | ||
|
||
# %% | ||
# Example plot | ||
# ------------ | ||
# Here is an example plot of the model: | ||
|
||
from astropy import units as u | ||
import matplotlib.pyplot as plt | ||
from gammapy.modeling.models import ( | ||
ExpCutoffPowerLawNormSpectralModel, | ||
ExpCutoffPowerLawSpectralModel, | ||
Models, | ||
SkyModel, | ||
TemplateSpectralModel, | ||
) | ||
|
||
energy_bounds = [0.1, 100] * u.TeV | ||
|
||
energy = [0.3, 1, 3, 10, 30] * u.TeV | ||
values = [40, 30, 20, 10, 1] * u.Unit("TeV-1 s-1 cm-2") | ||
template = TemplateSpectralModel(energy, values) | ||
norm = ExpCutoffPowerLawNormSpectralModel( | ||
norm=2, | ||
reference=1 * u.TeV, | ||
) | ||
|
||
template.plot(energy_bounds=energy_bounds, label="Template model") | ||
ecpl_norm = template * norm | ||
ecpl_norm.plot( | ||
energy_bounds, label="Template model with ExpCutoffPowerLaw norm correction" | ||
) | ||
plt.legend(loc="best") | ||
plt.grid(which="both") | ||
|
||
# %% | ||
# YAML representation | ||
# ------------------- | ||
# Here is an example YAML file using the model: | ||
|
||
model = SkyModel(spectral_model=ecpl_norm, name="exp-cutoff-power-law-norm-model") | ||
models = Models([model]) | ||
|
||
print(models.to_yaml()) |
51 changes: 51 additions & 0 deletions
51
examples/models/spectral/plot_logparabola_norm_spectral.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
r""" | ||
.. _logparabola-spectral-norm-model: | ||
Log parabola spectral norm model | ||
=========================== | ||
This model parametrises a log parabola spectral correction with a norm parameter. | ||
""" | ||
|
||
# %% | ||
# Example plot | ||
# ------------ | ||
# Here is an example plot of the model: | ||
|
||
from astropy import units as u | ||
import matplotlib.pyplot as plt | ||
from gammapy.modeling.models import ( | ||
LogParabolaNormSpectralModel, | ||
LogParabolaSpectralModel, | ||
Models, | ||
SkyModel, | ||
TemplateSpectralModel, | ||
) | ||
|
||
energy_bounds = [0.1, 100] * u.TeV | ||
|
||
energy = [0.3, 1, 3, 10, 30] * u.TeV | ||
values = [40, 30, 20, 10, 1] * u.Unit("TeV-1 s-1 cm-2") | ||
template = TemplateSpectralModel(energy, values) | ||
norm = LogParabolaNormSpectralModel( | ||
norm=1.5, | ||
reference=1 * u.TeV, | ||
) | ||
|
||
template.plot(energy_bounds=energy_bounds, label="Template model") | ||
lp_norm = template * norm | ||
lp_norm.plot(energy_bounds, label="Template model with LogParabola norm correction") | ||
plt.legend(loc="best") | ||
plt.grid(which="both") | ||
|
||
|
||
# %% | ||
# YAML representation | ||
# ------------------- | ||
# Here is an example YAML file using the model: | ||
|
||
model = SkyModel(spectral_model=lp_norm, name="log-parabola-norm-model") | ||
models = Models([model]) | ||
|
||
print(models.to_yaml()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
r""" | ||
.. _powerlaw-spectral-norm-model: | ||
Power law norm spectral model | ||
======================== | ||
This model parametrises a power law spectral correction with a norm and tilt parameter. | ||
""" | ||
|
||
# %% | ||
# Example plot | ||
# ------------ | ||
# Here is an example plot of the model: | ||
|
||
from astropy import units as u | ||
import matplotlib.pyplot as plt | ||
from gammapy.modeling.models import ( | ||
Models, | ||
PowerLawNormSpectralModel, | ||
PowerLawSpectralModel, | ||
SkyModel, | ||
TemplateSpectralModel, | ||
) | ||
|
||
energy_bounds = [0.1, 100] * u.TeV | ||
|
||
energy = [0.3, 1, 3, 10, 30] * u.TeV | ||
values = [40, 30, 20, 10, 1] * u.Unit("TeV-1 s-1 cm-2") | ||
template = TemplateSpectralModel(energy, values) | ||
norm = PowerLawNormSpectralModel( | ||
norm=5, | ||
reference=1 * u.TeV, | ||
) | ||
|
||
template.plot(energy_bounds=energy_bounds, label="Template model") | ||
pwl_norm = template * norm | ||
pwl_norm.plot(energy_bounds, label="Template model with PowerLaw norm correction") | ||
plt.legend(loc="best") | ||
plt.grid(which="both") | ||
|
||
# %% | ||
# YAML representation | ||
# ------------------- | ||
# Here is an example YAML file using the model: | ||
|
||
model = SkyModel(spectral_model=pwl_norm, name="power-law-norm-model") | ||
models = Models([model]) | ||
|
||
print(models.to_yaml()) |