示例#1
0
def test_gaussian_temporal_model_integral():
    temporal_model = GaussianTemporalModel(t_ref=50003 * u.d, sigma="2.0 day")
    start = [1, 3, 5] * u.day
    stop = [2, 3.5, 6] * u.day
    t_ref = Time(50000, format="mjd")
    gti = GTI.create(start, stop, reference_time=t_ref)
    val = temporal_model.integral(gti.time_start, gti.time_stop)
    assert len(val) == 3
    assert_allclose(np.sum(val), 0.682679, rtol=1e-5)
示例#2
0
def test_gaussian_temporal_model_evaluate():
    t = Time(46301, format="mjd")
    t_ref = 46300 * u.d
    sigma = 2.0 * u.d
    temporal_model = GaussianTemporalModel(t_ref=t_ref, sigma=sigma)
    val = temporal_model(t)
    assert_allclose(val, 0.882497, rtol=1e-5)
    F(t) = exp(-0.5* \frac{ (t - t_{ref})^2 } { \sigma^2 })
"""

# %%
# Example plot
# ------------
# Here is an example plot of the model:

from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
from gammapy.modeling.models import Models, GaussianTemporalModel, SkyModel
sigma = "3 h"
t_ref = Time("2020-10-01")
time_range = [t_ref - 0.5 * u.d , t_ref + 0.5 * u.d]
gaussian_model = GaussianTemporalModel(t_ref = t_ref.mjd * u.d, sigma=sigma)
gaussian_model.plot(time_range)
plt.grid(which="both")

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import PowerLawSpectralModel
model = SkyModel(spectral_model=PowerLawSpectralModel(), temporal_model= gaussian_model, name="gaissian_model")
models = Models([model])

print(models.to_yaml())