Implement general TemporalModel.integrate method
@@ -166,6 +166,28 @@ class TemporalModel(ModelBase):
return t_min + time
+ def integral(self, t_min, t_max, oversampling_factor=100, **kwargs):
+ """Evaluate the integrated flux within the given time intervals
+
+ Parameters
+ ----------
+ t_min: `~astropy.time.Time`
+ Start times of observation
+ t_max: `~astropy.time.Time`
+ Stop times of observation
+ oversampling_factor : int
+ Oversampling factor to be used for numerical integration.
+
+ Returns
+ -------
+ norm : float
+ Integrated flux norm on the given time intervals
+ """
+ times = Time(np.linspace(t_min.mjd, t_max.mjd, oversampling_factor, axis=-1), format="mjd")
+ values = self(times)
+ integral = np.sum(values / oversampling_factor, axis=-1)
+ return integral / self.time_sum(t_min, t_max).to_value("d")
+
class ConstantTemporalModel(TemporalModel):
"""Constant temporal model."""
@@ -389,33 +411,6 @@ class GeneralizedGaussianTemporalModel(TemporalModel):
val = np.where(time < t_ref, val_rise, val_decay)
return val
- def integral(self, t_min, t_max, **kwargs):
- """Evaluate the integrated flux within the given time intervals
-
- Parameters
- ----------
- t_min: `~astropy.time.Time`
- Start times of observation
- t_max: `~astropy.time.Time`
- Stop times of observation
-
- Returns
- -------
- norm : float
- Integrated flux norm on the given time intervals
- """
-
- pars = self.parameters
- t_rise = pars["t_rise"].quantity
- t_decay = pars["t_decay"].quantity
- eta = pars["eta"].quantity
- t_ref = Time(pars["t_ref"].quantity, format="mjd")
-
- integral = scipy.integrate.quad(
- self.evaluate, t_min.mjd, t_max.mjd, args=(t_ref.mjd, t_rise, t_decay, eta)
- )[0]
- return integral / self.time_sum(t_min, t_max).to_value("d")
-
class LightCurveTemplateTemporalModel(TemporalModel):
"""Temporal light curve model.
