anuga.Domain.set_starttime

Domain.set_starttime(timestamp=0.0)[source]

Set the starttime for the evolution

Parameters:

timestamp – Either a float or a datetime object

Essentially we use unix time as our absolute time. So time = 0 corresponds to Jan 1st 1970 UTC

Use naive datetime which will be localized to the domain timezone or or use zoneinfo.ZoneInfo to set the timezone of datetime. Don’t use the tzinfo argument of datetime to set timezone as this does not work!

Example:

Without setting timezone for the domain and the starttime then time calculations are all based on UTC. Note the timestamp, which is time in seconds from 1st Jan 1970 UTC.

>>> import anuga
>>> from zoneinfo import ZoneInfo
>>> from datetime import datetime
>>> 
>>> domain = anuga.rectangular_cross_domain(10,10)
>>> dt = datetime(2021,3,21,18,30)
>>> domain.set_starttime(dt)
>>> print(domain.get_datetime(), 'TZ', domain.get_timezone(), 'Timestamp: ', domain.get_time())
2021-03-21 18:30:00+00:00 TZ UTC Timestamp:  1616351400.0

Example:

Setting timezone for the domain, then naive datetime will be localizes to the domain timezone. Note the timestamp, which is time in seconds from 1st Jan 1970 UTC.

>>> import anuga
>>> from zoneinfo import ZoneInfo
>>> from datetime import datetime
>>> 
>>> domain = anuga.rectangular_cross_domain(10,10)
>>> AEST = ZoneInfo('Australia/Sydney')
>>> domain.set_timezone(AEST)
>>> 
>>> dt = datetime(2021,3,21,18,30)
>>> domain.set_starttime(dt)
>>> print(domain.get_datetime(), 'TZ', domain.get_timezone(), 'Timestamp: ', domain.get_time())
2021-03-21 18:30:00+11:00 TZ Australia/Sydney Timestamp:  1616311800.0

Example:

Setting timezone for the domain, and setting the timezone for the datetime. Note the timestamp, which is time in seconds from 1st Jan 1970 UTC is the same as the previous example.

>>> import anuga
>>> from zoneinfo import ZoneInfo
>>> from datetime import datetime
>>> 
>>> domain = anuga.rectangular_cross_domain(10,10)
>>> 
>>> ACST = ZoneInfo('Australia/Adelaide')
>>> domain.set_timezone(ACST)
>>> 
>>> AEST = ZoneInfo('Australia/Sydney')
>>> dt = datetime(2021,3,21,18,30, tzinfo=AEST)
>>> 
>>> domain.set_starttime(dt)
>>> print(domain.get_datetime(), 'TZ', domain.get_timezone(), 'Timestamp: ', domain.get_time())
2021-03-21 18:00:00+10:30 TZ Australia/Adelaide Timestamp:  1616311800.0