Ejemplo n.º 1
0
    def reset(self, start=None):
        """ Reset the timestepper

        If start is None it resets to the original self.start, otherwise
        start is used as the new starting point.
        """
        self._current = None
        current_length = len(self)

        if start is None:
            current_index = 0
        else:
            # Determine which period the start time is within
            for index, period in enumerate(self._periods):
                if period.start_time <= start < period.end_time:
                    current_index = index
                    break
            else:
                raise ValueError(
                    'New starting position is outside the range of the model timesteps.'
                )

        self._next = _core.Timestep(self._periods[current_index],
                                    current_index, self._deltas[current_index])
        length_changed = self._last_length != current_length
        self._last_length = current_length
        return length_changed
Ejemplo n.º 2
0
    def next(self, ):
        self._current = current = self._next
        if current.datetime > self.end:
            raise StopIteration()

        # Increment to next timestep
        self._next = _core.Timestep(current.datetime + self.delta,
                                    current.index + 1, self.delta.days)

        # Return this timestep
        return current
Ejemplo n.º 3
0
    def next(self, ):
        self._current = current = self._next

        if current.index >= len(self._periods):
            raise StopIteration()

        # Increment to next timestep
        next_index = current.index + 1
        if next_index >= len(self._periods):
            # The final time-step is one offset beyond the end of the model.
            # Here we compute its delta and create the object.
            final_period = current.period + self.offset
            delta = final_period.end_time - final_period.start_time
            delta = np.round(delta.total_seconds())
            delta = delta / SECONDS_IN_DAY
            self._next = _core.Timestep(final_period, next_index, delta)
        else:
            self._next = _core.Timestep(self._periods[next_index], next_index,
                                        self._deltas[next_index])

        # Return this timestep
        return current
Ejemplo n.º 4
0
    def reset(self, start=None):
        """ Reset the timestepper

        If start is None it resets to the original self.start, otherwise
        start is used as the new starting point.
        """
        self._current = None
        current_length = len(self)

        if start is None:
            self._next = _core.Timestep(self.start, 0, self.delta.days)
        else:
            # Calculate actual index from new position
            diff = start - self.start
            if diff.days % self.delta.days != 0:
                raise ValueError(
                    'New starting position is not compatible with the existing starting position and timestep.'
                )
            index = diff.days / self.delta.days
            self._next = _core.Timestep(start, index, self.delta.days)

        length_changed = self._last_length != current_length
        self._last_length = current_length
        return length_changed