TimeDomain

class unifhy.TimeDomain(timestamps, units, calendar=None)

TimeDomain characterises a temporal dimension that is needed by a Component.

Instantiation

Parameters
timestamps: one-dimensional array-like object

The array of timestamps defining the temporal dimension. May be any type that can be cast to a numpy.ndarray. Must contain numerical values.

Note: the first timestamp of the array is the beginning of the first timestep, and the last timestamp is the end of the last timestep (not its start).

Parameter example:

timestamps=[0, 1, 2, 3]

Parameter example:

timestamps=(5, 7, 9)

Parameter example:

timestamps=numpy.arange(0, 10, 3)
units: str

Reference in time for the timestamps following the format ‘unit_of_time since reference_datetime’.

Parameter example:

units='seconds since 1970-01-01'

Parameter example:

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

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

Parameter example:

calendar='all_leap'

Parameter example:

calendar='365_day'

Examples

>>> td = TimeDomain(timestamps=[0, 1, 2, 3],
...                 units='seconds since 1970-01-01 00:00:00',
...                 calendar='standard')
>>> print(td)
TimeDomain(
    time (3,): [1970-01-01 00:00:00, 1970-01-01 00:00:01, 1970-01-01 00:00:02] standard
    bounds (3, 2): [[1970-01-01 00:00:00, ..., 1970-01-01 00:00:03]] standard
    calendar: standard
    units: seconds since 1970-01-01 00:00:00
    period: 0:00:03
    timedelta: 0:00:01
)

Methods

Construction

from_datetime_sequence

Instantiate a TimeDomain from a sequence of datetime objects.

from_start_end_step

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

from_field

Instantiate a TimeDomain from temporal dimension coordinate of a cf.Field.

Comparison

is_time_equal_to

Compare equality between the TimeDomain and the 'time' dimension coordinate in a cf.Field.

spans_same_period_as

Compare equality in period spanned between the TimeDomain and another instance of TimeDomain.

Attributes

time

Return the time series of the TimeDomain instance as a cf.Data instance.

bounds

Return the bounds of the time series of the TimeDomain instance as a cf.Data instance.

units

Return the units of the time series of the TimeDomain instance as a str.

calendar

Return the calendar of the time series of the TimeDomain instance as a str.

period

Return the period that the TimeDomain is covering as a datetime.timedelta.

timedelta

Return the time duration separating time steps in the time series of the TimeDomain instance as a datetime.timedelta instance.