How to use the pastas.utils.get_dt 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 / model.py View on Github external
if tmax is None:
            tmax = self.settings['tmax']
        if freq is None:
            freq = self.settings["freq"]
        if warmup is None:
            warmup = self.settings["warmup"]
        elif isinstance(warmup, str):
            warmup = get_dt(warmup)

        # use warmup
        if tmin:
            tmin_warm = pd.Timestamp(tmin) - pd.DateOffset(days=warmup)
        else:
            tmin_warm = None

        dt = get_dt(freq)

        kwargs = dict(tmin=tmin_warm, tmax=tmax, freq=freq, dt=dt)
        if istress is not None:
            kwargs['istress'] = istress
        contrib = self.stressmodels[name].simulate(parameters, **kwargs)

        # Respect provided tmin/tmax at this point, since warmup matters for
        # simulation but should not be returned, unless return_warmup=True.
        if not return_warmup:
            contrib = contrib.loc[tmin:tmax]

        return contrib
github pastas / pastas / pastas / model.py View on Github external
if tmin is None and self.settings['tmin']:
            tmin = self.settings['tmin']
        else:
            tmin = self.get_tmin(tmin, freq, use_oseries=False,
                                 use_stresses=True)
        if tmax is None and self.settings['tmax']:
            tmax = self.settings['tmax']
        else:
            tmax = self.get_tmax(tmax, freq, use_oseries=False,
                                 use_stresses=True)
        if freq is None:
            freq = self.settings["freq"]
        if warmup is None:
            warmup = self.settings["warmup"]
        elif isinstance(warmup, str):
            warmup = get_dt(warmup)

        # Get the simulation index and the time step
        sim_index = self.get_sim_index(tmin, tmax, freq, warmup)
        dt = get_dt(freq)

        # Get parameters if none are provided
        if parameters is None:
            parameters = self.get_parameters()

        sim = pd.Series(data=np.zeros(sim_index.size, dtype=float),
                        index=sim_index, fastpath=True)

        istart = 0  # Track parameters index to pass to stressmodel object
        for sm in self.stressmodels.values():
            contrib = sm.simulate(parameters[istart: istart + sm.nparam],
                                  sim_index.min(), sim_index.max(), freq, dt)
github pastas / pastas / pastas / model.py View on Github external
use_stresses=True)
        if tmax is None and self.settings['tmax']:
            tmax = self.settings['tmax']
        else:
            tmax = self.get_tmax(tmax, freq, use_oseries=False,
                                 use_stresses=True)
        if freq is None:
            freq = self.settings["freq"]
        if warmup is None:
            warmup = self.settings["warmup"]
        elif isinstance(warmup, str):
            warmup = get_dt(warmup)

        # Get the simulation index and the time step
        sim_index = self.get_sim_index(tmin, tmax, freq, warmup)
        dt = get_dt(freq)

        # Get parameters if none are provided
        if parameters is None:
            parameters = self.get_parameters()

        sim = pd.Series(data=np.zeros(sim_index.size, dtype=float),
                        index=sim_index, fastpath=True)

        istart = 0  # Track parameters index to pass to stressmodel object
        for sm in self.stressmodels.values():
            contrib = sm.simulate(parameters[istart: istart + sm.nparam],
                                  sim_index.min(), sim_index.max(), freq, dt)
            sim = sim + contrib
            istart += sm.nparam
        if self.constant:
            sim = sim + self.constant.simulate(parameters[istart])
github pastas / pastas / pastas / model.py View on Github external
----------
        name: str
            String with the name of the stressmodel.

        Returns
        -------
        pandas.Series
            Pandas Series with the step response. The index is based on the
            frequency that is present in the model.settings.

        TODO: Make sure an error is thrown when no rfunc is present.

        """
        if parameters is None:
            parameters = self.get_parameters(name)
        dt = get_dt(self.settings["freq"])
        s = self.stressmodels[name].rfunc.step(parameters, dt, **kwargs)
        t = np.linspace(dt, len(s) * dt, len(s))
        s = pd.Series(s, index=t, name=name)
        s.index.name = "Time [days]"
        return s
github pastas / pastas / pastas / plots.py View on Github external
fig = self._get_figure()

        for name in series:
            if name not in self.ml.stressmodels.keys():
                return None
            elif hasattr(self.ml.stressmodels[name], 'rfunc'):
                plt.plot(self.ml.get_step_response(name))
                legend.append(name)
            else:
                pass

        plt.xlim(0)

        # Change xtickers to the correct time
        locs, labels = plt.xticks()
        labels = locs * get_dt(self.ml.settings["freq"])
        plt.xticks(locs, labels)
        plt.xlabel("Time [days]")

        plt.legend(legend)
        fig.suptitle("Step Response(s)")

        if show:
            plt.show()

        return fig.axes
github pastas / pastas / pastas / model.py View on Github external
noise = True
        elif noise is True and self.noisemodel is None:
            self.logger.warning("""Warning, solving with noisemodel while no
                              noisemodel is defined. No noisemodel is used.""")
            noise = False

        self.settings["noise"] = noise
        self.settings["weights"] = weights

        # Set the frequency & warmup
        if freq:
            self.settings["freq"] = frequency_is_supported(freq)

        if warmup is not None:
            if isinstance(warmup, str):
                warmup = get_dt(warmup)
            self.settings["warmup"] = warmup

        # Set the time offset from the frequency (this does not work as expected yet)
        # self._set_time_offset()

        # Set tmin and tmax
        # Only overwrite settings dic if tmin is not None or if 
        # settins['tmin'] is None. Same for tmax
        if tmin is not None:
            self.settings["tmin"] = self.get_tmin(tmin)
        elif self.settings["tmin"] is None:
            self.settings["tmin"] = self.get_tmin(tmin)
        
        if tmax is not None:
            self.settings["tmax"] = self.get_tmax(tmax)
        elif self.settings["tmax"] is None:
github pastas / pastas / pastas / timeseries.py View on Github external
def change_frequency(self, series):
        """Method to change the frequency of the time series.

        """
        freq = self.settings["freq"]

        # 1. If no freq string is present or is provided (e.g. Oseries)
        if not freq:
            return series
        # 2. If original frequency could not be determined
        elif not self.freq_original:
            series = self.sample_weighted(series)
        else:
            dt_new = get_dt(freq)
            dt_org = get_stress_dt(self.freq_original)
            # 3. If new and original frequency are not a multiple of each other
            eps = 1e-10
            if not ((dt_new % dt_org) < eps or (dt_org % dt_new) < eps):
                series = self.sample_weighted(series)
            # 4. If new frequency is lower than its original
            elif dt_new < dt_org:
                series = self.sample_up(series)
            # 5. If new frequency is higher than its original
            elif dt_new > dt_org:
                series = self.sample_down(series)
            # 6. If new frequency is equal to its original
            elif dt_new == dt_org:
                # shouldn't we do this before changing frequency?
                series = self.fill_nan(series)
github pastas / pastas / pastas / model.py View on Github external
Pandas Series with the contribution.

        """
        if parameters is None:
            parameters = self.get_parameters(name)

        if tmin is None:
            tmin = self.settings['tmin']
        if tmax is None:
            tmax = self.settings['tmax']
        if freq is None:
            freq = self.settings["freq"]
        if warmup is None:
            warmup = self.settings["warmup"]
        elif isinstance(warmup, str):
            warmup = get_dt(warmup)

        # use warmup
        if tmin:
            tmin_warm = pd.Timestamp(tmin) - pd.DateOffset(days=warmup)
        else:
            tmin_warm = None

        dt = get_dt(freq)

        kwargs = dict(tmin=tmin_warm, tmax=tmax, freq=freq, dt=dt)
        if istress is not None:
            kwargs['istress'] = istress
        contrib = self.stressmodels[name].simulate(parameters, **kwargs)

        # Respect provided tmin/tmax at this point, since warmup matters for
        # simulation but should not be returned, unless return_warmup=True.