class StepModel(StressModelBase): """Stressmodel that simulates a step trend. Parameters ---------- tstart: str or Timestamp String with the start date of the step, e.g. '2018-01-01'. This value is fixed by default. Use ml.set_vary("step_tstart", 1) to vary the start time of the step trend. name: str String with the name of the stressmodel. rfunc: pastas.rfunc.RfuncBase, optional Pastas response function used to simulate the effect of the step. Default is rfunc.One, an instant effect. up: bool, optional Force a direction of the step. Default is None. Notes ----- This step trend is calculated as follows. First, a binary series is created, with zero values before tstart, and ones after the start. This series is convoluted with the block response to simulate a step trend. """ _name = "StepModel" def __init__(self, tstart, name, rfunc=One, up=True, cutoff=0.999): rfunc = rfunc(up=up, cutoff=cutoff, meanstress=1.0) StressModelBase.__init__(self, name=name, tmin=Timestamp.min, tmax=Timestamp.max, rfunc=rfunc) self.tstart = Timestamp(tstart) self.set_init_parameters() def set_init_parameters(self): self.parameters = self.rfunc.get_init_parameters(self.name) tmin = Timestamp.min.toordinal() tmax = Timestamp.max.toordinal() tinit = self.tstart.toordinal() self.parameters.loc[self.name + "_tstart"] = (tinit, tmin, tmax, False, self.name) def simulate(self, p, tmin=None, tmax=None, freq=None, dt=1): tstart = Timestamp.fromordinal(int(p[-1]), freq="D") tindex = date_range(tmin, tmax, freq=freq) h = Series(0, tindex, name=self.name) h.loc[h.index > tstart] = 1 b = self.get_block(p[:-1], dt, tmin, tmax) npoints = h.index.size h = Series(data=fftconvolve(h, b, 'full')[:npoints], index=h.index, name=self.name, fastpath=True) return h def to_dict(self, series=True): data = { "stressmodel": self._name, 'tstart': self.tstart, 'name': self.name, "up": self.rfunc.up, 'rfunc': self.rfunc._name } return data