unifhy.TimeDomain.from_start_end_step

classmethod TimeDomain.from_start_end_step(start, end, step, units=None, calendar=None)

Instantiate a TimeDomain from start, end, and step for period.

Parameters
start: datetime object

The start of the sequence to be generated for the initialisation of the TimeDomain. Must be any datetime object (except numpy.datetime64).

Note: this is the start of the first timestep.

Parameter example:

start=datetime.datetime(1970, 1, 1, 9, 0, 0)

Parameter example:

start=cftime.DatetimeAllLeap(2000, 1, 6)
end: datetime object

The end of the sequence to be generated for the initialisation of the TimeDomain. Must be any datetime object (except numpy.datetime64).

Note: this is the end of the last timestep (not its start).

Parameter example:

end=datetime.datetime(1970, 1, 1, 0, 0, 4)

Parameter example:

end=cftime.DatetimeAllLeap(2000, 1, 10)
step: timedelta object

The step separating items in the sequence to be generated for the initialisation of the TimeDomain. Must be datetime.timedelta object.

Parameter example:

step=datetime.timedelta(seconds=1)

Parameter example:

step=datetime.timedelta(days=1)
units: str, optional

Reference in time for the timestamps that will be generated. Must follow the format ‘unit_of_time since reference_datetime’. If not provided, set to default value ‘seconds since 1970-01-01 00:00:00Z’.

Parameter example:

units='seconds since 1970-01-01'

Parameter example:

units='days since 2000-01-01 00:00:00'
calendar: str, optional

Calendar to be used for the reference in time of units. If not provided, set to default ‘gregorian’.

Parameter example:

calendar='standard'

Parameter example:

calendar='all_leap'
Returns

TimeDomain

Examples

>>> from datetime import datetime, timedelta
>>> td = TimeDomain.from_start_end_step(
...     start=datetime(2020, 1, 1),
...     end=datetime(2020, 3, 1),
...     step=timedelta(days=1),
...     units='seconds since 1970-01-01 00:00:00',
...     calendar='standard'
... )
>>> print(td)
TimeDomain(
    time (60,): [2020-01-01 00:00:00, ..., 2020-02-29 00:00:00] standard
    bounds (60, 2): [[2020-01-01 00:00:00, ..., 2020-03-01 00:00:00]] standard
    calendar: standard
    units: seconds since 1970-01-01 00:00:00
    period: 60 days, 0:00:00
    timedelta: 1 day, 0:00:00
)
>>> from datetime import datetime, timedelta
>>> td = TimeDomain.from_start_end_step(
...     start=datetime(2020, 1, 1),
...     end=datetime(2020, 3, 1),
...     step=timedelta(days=1),
...     units='seconds since 1970-01-01 00:00:00',
...     calendar='noleap'
... )
>>> print(td)
TimeDomain(
    time (59,): [2020-01-01 00:00:00, ..., 2020-02-28 00:00:00] noleap
    bounds (59, 2): [[2020-01-01 00:00:00, ..., 2020-03-01 00:00:00]] noleap
    calendar: noleap
    units: seconds since 1970-01-01 00:00:00
    period: 59 days, 0:00:00
    timedelta: 1 day, 0:00:00
)