Time¶
Sub-commands to support time definition
Time ¶
Bases: BaseSubComponent
Time specification in SWAN.
.. code-block:: text
[time]
Time is rendered in one of the following formats:
- 1: ISO-notation 19870530.153000
- 2: (as in HP compiler) '30-May-87 15:30:00'
- 3: (as in Lahey compiler) 05/30/87.15:30:00
- 4: 15:30:00
- 5: 87/05/30 15:30:00'
- 6: as in WAM 8705301530
Note¶
The time field can be specified as:
- existing datetime object
- int or float, assumed as Unix time, i.e. seconds (if >= -2e10 or <= 2e10) or milliseconds (if < -2e10 or > 2e10) since 1 January 1970.
- ISO 8601 time string.
Examples¶
.. ipython:: python :okwarning:
from rompy_swan.subcomponents.time import Time
from datetime import datetime
time = Time(time=datetime(1990, 1, 1))
print(time.render())
time = Time(time="2012-01-01T00:00:00", tfmt=2)
print(time.render())
Source code in src/rompy_swan/subcomponents/time.py
Attributes¶
model_type
class-attribute
instance-attribute
¶
model_type: Literal['time', 'Time', 'TIME'] = Field(default='time', description='Model type discriminator')
time
class-attribute
instance-attribute
¶
tfmt
class-attribute
instance-attribute
¶
tfmt: Union[Literal[1, 2, 3, 4, 5, 6], str] = Field(default=1, description='Format to render time specification', validate_default=True)
Functions¶
set_time_format
classmethod
¶
Delt ¶
Bases: BaseSubComponent
Time interval specification in SWAN.
.. code-block:: text
[delt] SEC|MIN|HR|DAY
Note¶
The tdelta field can be specified as:
- existing timedelta object
- int or float, assumed as seconds
-
ISO 8601 duration string, following formats work:
-
[-][DD ][HH:MM]SS[.ffffff] [±]P[DD]DT[HH]H[MM]M[SS]S(ISO 8601 format for timedelta)
Examples¶
.. ipython:: python :okwarning:
from rompy_swan.subcomponents.time import Delt
from datetime import timedelta
delt = Delt(delt=timedelta(minutes=30))
print(delt.render())
delt = Delt(delt="PT1H", dfmt="hr")
print(delt.render())
Source code in src/rompy_swan/subcomponents/time.py
TimeRangeOpen ¶
Bases: BaseSubComponent
Regular times with an open boundary.
.. code-block:: text
[tbeg] [delt] SEC|MIN|HR|DAY
Time is rendered in one of the following formats:
- 1: ISO-notation 19870530.153000
- 2: (as in HP compiler) '30-May-87 15:30:00'
- 3: (as in Lahey compiler) 05/30/87.15:30:00
- 4: 15:30:00
- 5: 87/05/30 15:30:00'
- 6: as in WAM 8705301530
Note¶
The tbeg field can be specified as:
- existing datetime object
- int or float, assumed as Unix time, i.e. seconds (if >= -2e10 or <= 2e10) or milliseconds (if < -2e10 or > 2e10) since 1 January 1970.
- ISO 8601 time string.
Note¶
The tdelta field can be specified as:
- existing timedelta object
- int or float, assumed as seconds
-
ISO 8601 duration string, following formats work:
[-][DD ][HH:MM]SS[.ffffff][±]P[DD]DT[HH]H[MM]M[SS]S(ISO 8601 format for timedelta)
Note¶
Default values for the time specification fields are provided for the case where the user wants to set times dynamically after instantiating this subcomponent.
Examples¶
.. ipython:: python :okwarning:
from rompy_swan.subcomponents.time import TimeRangeOpen
from datetime import datetime, timedelta
times = TimeRangeOpen(
tbeg=datetime(1990, 1, 1), delt=timedelta(minutes=30), dfmt="min"
)
print(times.render())
times = TimeRangeOpen(
tbeg="2012-01-01T00:00:00", delt="PT1H", tfmt=2, dfmt="hr", suffix="blk"
)
print(times.render())
Source code in src/rompy_swan/subcomponents/time.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
Attributes¶
model_type
class-attribute
instance-attribute
¶
tbeg
class-attribute
instance-attribute
¶
delt
class-attribute
instance-attribute
¶
tfmt
class-attribute
instance-attribute
¶
tfmt: Union[Literal[1, 2, 3, 4, 5, 6], str] = Field(default=1, description='Format to render time specification')
dfmt
class-attribute
instance-attribute
¶
dfmt: Literal['sec', 'min', 'hr', 'day'] = Field(default='sec', description='Format to render time interval specification')
suffix
class-attribute
instance-attribute
¶
Functions¶
cmd ¶
Render subcomponent cmd.
TimeRangeClosed ¶
Bases: TimeRangeOpen
Regular times with a closed boundary.
.. code-block:: text
[tbeg] [delt] SEC|MIN|HR|DAY [tend]
Note¶
Default values for the time specification fields are provided for the case where the user wants to set times dynamically after instantiating this subcomponent.
Examples¶
.. ipython:: python :okwarning:
from rompy_swan.subcomponents.time import TimeRangeClosed
from datetime import datetime, timedelta
times = TimeRangeClosed(
tbeg=datetime(1990, 1, 1),
tend=datetime(1990, 1, 7),
delt=timedelta(minutes=30),
dfmt="min",
)
print(times.render())
times = TimeRangeClosed(
tbeg="2012-01-01T00:00:00",
tend="2012-02-01T00:00:00",
delt="PT1H",
tfmt=2,
dfmt="hr",
suffix="blk",
)
print(times.render())
Source code in src/rompy_swan/subcomponents/time.py
NONSTATIONARY ¶
Bases: TimeRangeClosed
Nonstationary time specification.
.. code-block:: text
NONSTATIONARY [tbeg] [delt] SEC|MIN|HR|DAY [tend]
Note¶
Default values for the time specification fields are provided for the case where the user wants to set times dynamically after instantiating this subcomponent.
Examples¶
.. ipython:: python :okwarning:
from rompy_swan.subcomponents.time import NONSTATIONARY
nonstat = NONSTATIONARY(
tbeg="2012-01-01T00:00:00",
tend="2012-02-01T00:00:00",
delt="PT1H",
dfmt="hr",
)
print(nonstat.render())
from datetime import datetime, timedelta
nonstat = NONSTATIONARY(
tbeg=datetime(1990, 1, 1),
tend=datetime(1990, 1, 7),
delt=timedelta(minutes=30),
tfmt=1,
dfmt="min",
suffix="tbl",
)
print(nonstat.render())
Source code in src/rompy_swan/subcomponents/time.py
Attributes¶
model_type
class-attribute
instance-attribute
¶
model_type: Literal['nonstationary', 'NONSTATIONARY'] = Field(default='nonstationary', description='Model type discriminator')
tbeg
class-attribute
instance-attribute
¶
tend
class-attribute
instance-attribute
¶
delt
class-attribute
instance-attribute
¶
Functions¶
STATIONARY ¶
Bases: BaseSubComponent
Stationary time specification.
.. code-block:: text
STATIONARY [time]
Note¶
The field time is optional to allow for the case where the user wants to set the
time dynamically after instantiating this component.
Examples¶
.. ipython:: python :okwarning:
from rompy_swan.subcomponents.time import STATIONARY
stat = STATIONARY(time="2012-01-01T00:00:00")
print(stat.render())
Source code in src/rompy_swan/subcomponents/time.py
Attributes¶
model_type
class-attribute
instance-attribute
¶
model_type: Literal['stationary', 'STATIONARY'] = Field(default='stationary', description='Model type discriminator')
time
class-attribute
instance-attribute
¶
tfmt
class-attribute
instance-attribute
¶
tfmt: Union[Literal[1, 2, 3, 4, 5, 6], str] = Field(default=1, description='Format to render time specification')