How to use the pastas.stressmodels.StressModelBase function in pastas

To help you get started, we’ve selected a few pastas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pastas / pastas / pastas / stressmodels.py View on Github external
for i, ind_obs in enumerate(tindex):
                t = ind_obs - stress.index
                mask = (ind_obs > stress.index) & (t <= tmax)
                if np.any(mask):
                    # calculate the step response
                    td = np.array(t[mask].total_seconds() / 86400)
                    values[i] += np.sum(stress[mask] * self.rfunc.step(p, td))
                mask = t > tmax
                if np.any(mask):
                    values[i] += np.sum(stress[mask] * gain)
            pass
        h = pd.Series(values, tindex, name=self.name)
        return h


class Constant(StressModelBase):
    _name = "Constant"
    __doc__ = """A constant value that is added to the time series model.

    Parameters
    ----------
    value : float, optional
        Initial estimate of the parameter value. E.g. The minimum of the
        observed series.

    """

    def __init__(self, name, value=0.0, pmin=np.nan, pmax=np.nan):
        self.nparam = 1
        self.value = value
        self.pmin = pmin
        self.pmax = pmax
github pastas / pastas / pastas / stressmodels.py View on Github external
dictionary with all necessary information to reconstruct the
            StressModel object.

        """
        data = dict()
        data["stressmodel"] = self._name
        data["rfunc"] = self.rfunc._name
        data["name"] = self.name
        data["up"] = True if self.rfunc.up == 1 else False
        data["cutoff"] = self.rfunc.cutoff
        data["stress"] = self.dump_stress(series)

        return data


class StressModel2(StressModelBase):
    _name = "StressModel2"
    __doc__ = """Time series model consisting of the convolution of two stresses with one
    response function. The first stress causes the head to go up and the second
    stress causes the head to go down.

    Parameters
    ----------
    stress: list of pandas.Series
        list of pandas.Series or pastas.TimeSeries objects containing the 
        stresses.
    rfunc: pastas.rfunc instance
        Response function used in the convolution with the stress.
    name: str
        Name of the stress
    up: Boolean
        True if response function is positive (default), False if negative.
github pastas / pastas / pastas / stressmodels.py View on Github external
dictionary with all necessary information to reconstruct the
            StressModel object.

        """
        data = {
            "stressmodel": self._name,
            "rfunc": self.rfunc._name,
            "name": self.name,
            "up": self.rfunc.up,
            "cutoff": self.rfunc.cutoff,
            "stress": self.dump_stress(series)
        }
        return data


class StepModel(StressModelBase):
    """Stressmodel that simulates a step trend.

    Parameters
    ----------
    tstart: str
        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
        Pastas response function used to simulate the effect of the step.
        Default is rfunc.One()

    Notes
    -----
github pastas / pastas / pastas / stressmodels.py View on Github external
_name = "Constant"

    def __init__(self, name="constant", initial=0.0):
        StressModelBase.__init__(self, One, name, pd.Timestamp.min,
                                 pd.Timestamp.max, None, initial, 0)
        self.set_init_parameters()

    def set_init_parameters(self):
        self.parameters = self.rfunc.get_init_parameters(self.name)

    @staticmethod
    def simulate(p=None):
        return p


class WellModel(StressModelBase):
    """Time series model consisting of the convolution of one or more
    stresses with one response function. The distance from an influence to
    the location of the oseries has to be provided for each stress.

    Parameters
    ----------
    stress : list
        list containing the stresses timeseries.
    rfunc : pastas.rfunc
        WellModel only works with Hantush!
    name : str
        Name of the stressmodel.
    distances : list or list-like
        list of distances to oseries, must be ordered the same as the
        stresses.
    up : bool, optional
github pastas / pastas / pastas / stressmodels.py View on Github external
return self.nsplit
        else:
            return len(self.stress)

    def get_block(self, p, dt, tmin, tmax):
        """Internal method to get the block-response from the respnse function"""
        if tmin is not None and tmax is not None:
            day = pd.to_timedelta(1, 'd')
            maxtmax = (pd.Timestamp(tmax) - pd.Timestamp(tmin)) / day
        else:
            maxtmax = None
        b = self.rfunc.block(p, dt, maxtmax=maxtmax)
        return b


class StressModel(StressModelBase):
    """Time series model consisting of the convolution of one stress with one
    response function.

    Parameters
    ----------
    stress: pandas.Series
        pandas Series object containing the stress.
    rfunc: rfunc class
        Response function used in the convolution with the stress.
    name: str
        Name of the stress.
    up: Boolean or None, optional
        True if response function is positive (default), False if negative.
        None if you don't want to define if response is positive or negative.
    cutoff: float, optional
        float between 0 and 1 to determine how long the response is (default
github pastas / pastas / pastas / stressmodels.py View on Github external
Returns
        -------
        data: dict
            dictionary with all necessary information to reconstruct the
            StressModel object.

        """
        data = {
            "stressmodel": self._name,
            "name": self.name,
            "stress": self.dump_stress(series)
        }
        return data


class RechargeModel(StressModelBase):
    """Stressmodel simulating the effect of groundwater recharge on the
    groundwater head.

    Parameters
    ----------
    prec: pandas.Series or pastas.TimeSeries
        pandas.Series or pastas.TimeSeries objects containing the
        precipitation series.
    evap: pandas.Series or pastas.TimeSeries
        pandas.Series or pastas.TimeSeries objects containing the
        evaporation series.
    rfunc: pastas.rfunc instance, optional
        Response function used in the convolution with the stress. Default
        is Exponential.
    name: str, optional
        Name of the stress. Default is "recharge".
github pastas / pastas / pastas / stressmodels.py View on Github external
def set_init_parameters(self):
        self.parameters = self.rfunc.set_parameters(self.name)

    def simulate(self, p=None, tindex=None, dt=1):
        h = pd.Series(data=0, index=self.stress[0].index, name=self.name)
        for i in self.stress:
            self.npoints = self.stress.index.size
            b = self.rfunc.block(p, self.r[i])  # nparam-1 depending on rfunc
            h += fftconvolve(self.stress[i], b, 'full')[:self.npoints]
        if tindex is not None:
            h = h[tindex]
        return h


class StepModel(StressModelBase):
    _name = "StepModel"
    __doc__ = """A stress consisting of a step resonse from a specified time. The
    amplitude and form (if rfunc is not One) of the step is calibrated. Before
    t_step the response is zero.

    """

    def __init__(self, t_step, name, rfunc=One, up=True):
        assert t_step is not None, 'Error: Need to specify time of step (for now this will not be optimized)'
        StressModelBase.__init__(self, rfunc, name, pd.Timestamp.min,
                                 pd.Timestamp.max, up, 1.0, None)
        self.t_step = t_step
        self.set_init_parameters()

    def set_init_parameters(self):
        self.parameters = self.rfunc.set_parameters(self.name)
github pastas / pastas / pastas / stressmodels.py View on Github external
dictionary with all necessary information to reconstruct the
            StressModel object.

        """
        data = {
            "stressmodel": self._name,
            "rfunc": self.rfunc._name,
            "name": self.name,
            "up": self.rfunc.up,
            "cutoff": self.rfunc.cutoff,
            "stress": self.dump_stress(series)
        }
        return data


class StressModel2(StressModelBase):
    """Time series model consisting of the convolution of two stresses with one
    response function. The first stress causes the head to go up and the second
    stress causes the head to go down.

    Parameters
    ----------
    stress: list of pandas.Series or list of pastas.TimeSeries
        list of pandas.Series or pastas.TimeSeries objects containing the
        stresses.
    rfunc: pastas.rfunc instance
        Response function used in the convolution with the stress.
    name: str
        Name of the stress
    up: Boolean or None, optional
        True if response function is positive (default), False if negative.
        None if you don't want to define if response is positive or negative.
github pastas / pastas / pastas / stressmodels.py View on Github external
"""
        data = {
            "stressmodel": self._name,
            "rfunc": self.rfunc._name,
            "name": self.name,
            "up": True if self.rfunc.up is 1 else False,
            "distances": self.distances,
            "cutoff": self.rfunc.cutoff,
            "stress": self.dump_stress(series),
            "sort_wells": self.sort_wells
        }
        return data


class FactorModel(StressModelBase):
    """Model that multiplies a stress by a single value. The indepedent series
    do not have to be equidistant and are allowed to have gaps.

    Parameters
    ----------
    stress: pandas.Series or pastas.TimeSeries
        Stress which will be multiplied by a factor. The stress does not
        have to be equidistant.
    name: str
        String with the name of the stressmodel.
    settings: dict or str
        Dict or String that is forwarded to the TimeSeries object created
        from the stress.
    metadata: dict
        Dictionary with metadata, forwarded to the TimeSeries object created
        from the stress.