meridian.data.time_coordinates.TimeCoordinates

A wrapper around time coordinates in Meridian's input data.

Meridian models store time coordinates as untyped strings. It treats them as labels, and they have no intrinsic meaning to the model other than the assumption that they represent some linearly increasing time coordinates.

This wrapper object performs some additional validation and methods for extracting values out of these time coordinates which are treated as numeric "date" values.

datetime_index
The given time coordinates, parsed as indexable DatetimeIndex .
all_dates
The given time coordinates, as a list of Pythonic datetime.date objects.
all_dates_str
The given time coordinates, as a list of Meridian-formatted date strings. This can be used for the model internals, which treat time coordinates as simple labels.
interval_days
Returns the mean interval between two neighboring dates in all_dates .

Methods

expand_selected_time_dims

View source

Validates and returns time dimension values based on the selected times.

If both start_date and end_date are None, returns None. If specified, both start_date and end_date are inclusive, and must be present in the time coordinates of the input data.

Args

start_date
Start date of the selected time period. If None , implies the earliest time dimension value in the input data.
end_date
End date of the selected time period. If None , implies the latest time dimension value in the input data.

Returns
A list of time dimension values (as datetime.date objects) in the input data within the selected time period, or do nothing and pass through None if both arguments are None , or if start_date and end_date correspond to the entire time range in the input data.

Raises
ValueError if start_date or end_date is not in the input data's time dimension coordinates.

from_dates

View source

Creates a TimeCoordinates from a polymorphic series of dates.

Args

dates
A polymorphic series of dates; it can either be a Pandas DatetimeIndex or an Xarray DataArray with "YYYY-mm-dd" string labels.

Returns
A normalized TimeCoordinates dataclass.

get_selected_dates

View source

Creates a sequence of dates containing all points in selected interval.

Args

selected_interval
Tuple of the start and end times, or a DateInterval proto. If None , then all_dates is returned.

Returns
A sequence of dates representing the subset of all_dates between the given start and end dates, as Python's builtin datetime.date objects.

Raises

ValueError
If selected_interval is not a subset of all_dates .

__eq__

Return self==value.

Design a Mobile Site
View Site in Mobile | Classic
Share by: