diff --git a/adcircpy/forcing/base.py b/adcircpy/forcing/base.py index 5fbf0573..ccc97134 100644 --- a/adcircpy/forcing/base.py +++ b/adcircpy/forcing/base.py @@ -1,8 +1,22 @@ from abc import ABC, abstractmethod +from datetime import timedelta from os import PathLike class Forcing(ABC): + def __init__(self, interval: timedelta): + self.interval = interval + @abstractmethod def write(self, directory: PathLike, overwrite: bool = False): raise NotImplementedError + + @property + def interval(self) -> timedelta: + return self.__interval + + @interval.setter + def interval(self, interval: timedelta): + if not isinstance(interval, timedelta): + interval = timedelta(seconds=interval) + self.__interval = interval diff --git a/adcircpy/forcing/waves/base.py b/adcircpy/forcing/waves/base.py index 57fcff46..d0b44f58 100644 --- a/adcircpy/forcing/waves/base.py +++ b/adcircpy/forcing/waves/base.py @@ -6,8 +6,8 @@ class WaveForcing(Forcing, ABC): def __init__(self, nrs: int, interval_seconds: int): + super().__init__(interval_seconds) self.NRS = nrs - self.RSTIMINC = interval_seconds @abstractmethod def write(self, directory: PathLike, overwrite: bool = False): diff --git a/adcircpy/forcing/winds/base.py b/adcircpy/forcing/winds/base.py index a623e7f0..518a94e6 100644 --- a/adcircpy/forcing/winds/base.py +++ b/adcircpy/forcing/winds/base.py @@ -6,8 +6,8 @@ class WindForcing(Forcing, ABC): def __init__(self, nws: int, interval_seconds: int): + super().__init__(interval_seconds) self.NWS = nws - self.WTIMINC = interval_seconds @abstractmethod def write(self, directory: PathLike, overwrite: bool = False): diff --git a/adcircpy/fort15.py b/adcircpy/fort15.py index 968db8ca..ccc9e20a 100644 --- a/adcircpy/fort15.py +++ b/adcircpy/fort15.py @@ -987,7 +987,7 @@ def REFTIM(self): @property def WTIMINC(self): if self.NWS not in [0, 1, 9, 11]: - return self.wind_forcing.WTIMINC + return int(self.wind_forcing.interval / timedelta(seconds=1)) else: return 0 @@ -995,7 +995,7 @@ def WTIMINC(self): def RSTIMINC(self): if self.NRS in [1, 3, 4, 5]: if self.wave_forcing is not None: - return self.wave_forcing.RSTIMINC + return int(self.wave_forcing.interval / timedelta(seconds=1)) else: return self.WTIMINC else: