Skip to content

Commit

Permalink
Fix temporal model gallery format
Browse files Browse the repository at this point in the history
  • Loading branch information
adonath committed Nov 21, 2021
1 parent 05a1485 commit 52db5df
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
8 changes: 4 additions & 4 deletions examples/models/temporal/plot_constant_temporal.py
Expand Up @@ -19,10 +19,6 @@
from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
ConstantTemporalModel,
Models,
Expand All @@ -35,6 +31,10 @@
constant_model.plot(time_range)
plt.grid(which="both")

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
Expand Down
8 changes: 4 additions & 4 deletions examples/models/temporal/plot_expdecay_temporal.py
Expand Up @@ -20,10 +20,6 @@
from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
ExpDecayTemporalModel,
Models,
Expand All @@ -38,6 +34,10 @@
expdecay_model.plot(time_range)
plt.grid(which="both")

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
Expand Down
8 changes: 4 additions & 4 deletions examples/models/temporal/plot_gaussian_temporal.py
Expand Up @@ -19,10 +19,6 @@
from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
GaussianTemporalModel,
Models,
Expand All @@ -37,6 +33,10 @@
gaussian_model.plot(time_range)
plt.grid(which="both")

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
Expand Down
10 changes: 5 additions & 5 deletions examples/models/temporal/plot_linear_temporal.py
Expand Up @@ -19,10 +19,6 @@
from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
LinearTemporalModel,
Models,
Expand All @@ -31,10 +27,14 @@
)

time_range = [Time.now(), Time.now() + 2 * u.d]
linear_model = LinearTemporalModel(alpha=1, beta=0.5/u.d, t_ref=(time_range[0].mjd-0.1)*u.d)
linear_model = LinearTemporalModel(alpha=1, beta=0.5/u.d, t_ref=(time_range[0].mjd - 0.1) * u.d)
linear_model.plot(time_range)
plt.grid(which="both")

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
Expand Down
11 changes: 6 additions & 5 deletions examples/models/temporal/plot_powerlaw_temporal.py
Expand Up @@ -19,10 +19,6 @@
from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
Models,
PowerLawSpectralModel,
Expand All @@ -31,11 +27,16 @@
)

time_range = [Time.now(), Time.now() + 2 * u.d]
pl_model = PowerLawTemporalModel(alpha=-2., t_ref=(time_range[0].mjd-0.1)*u.d)
pl_model = PowerLawTemporalModel(alpha=-2., t_ref=(time_range[0].mjd - 0.1) * u.d)
pl_model.plot(time_range)
plt.grid(which="both")
plt.yscale('log')

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
temporal_model=pl_model,
Expand Down
12 changes: 6 additions & 6 deletions examples/models/temporal/plot_sine_temporal.py
Expand Up @@ -20,10 +20,6 @@
from astropy import units as u
from astropy.time import Time
import matplotlib.pyplot as plt
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
Models,
PowerLawSpectralModel,
Expand All @@ -32,11 +28,15 @@
)

time_range = [Time.now(), Time.now() + 16 * u.d]
omega = np.pi/4. * u.rad/u.day
sine_model = SineTemporalModel(amp=0.5, omega=omega, t_ref=(time_range[0].mjd-0.1)*u.d)
omega = np.pi / 4. * u.rad / u.day
sine_model = SineTemporalModel(amp=0.5, omega=omega, t_ref=(time_range[0].mjd-0.1) * u.d)
sine_model.plot(time_range)
plt.grid(which="both")

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
Expand Down
Expand Up @@ -11,10 +11,6 @@


from astropy.time import Time
# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:
from gammapy.modeling.models import (
LightCurveTemplateTemporalModel,
Models,
Expand All @@ -27,6 +23,10 @@
light_curve_model = LightCurveTemplateTemporalModel.read(path)
light_curve_model.plot(time_range)

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(
spectral_model=PowerLawSpectralModel(),
Expand Down
1 change: 1 addition & 0 deletions gammapy/modeling/models/temporal.py
Expand Up @@ -79,6 +79,7 @@ def plot(self, time_range, ax=None, **kwargs):
time_axis = TimeMapAxis.from_time_bounds(
time_min=time_min, time_max=time_max, nbin=100
)
time_axis.time_format = "mjd"

m = RegionNDMap.create(
region=None, axes=[time_axis]
Expand Down

0 comments on commit 52db5df

Please sign in to comment.