cascade.utils.time_series#

class cascade.utils.time_series.Align(dataset: TimeSeriesDataset, time: Iterable[datetime], *args: Any, **kwargs: Any)[source]#

Given dataset and some time scale selects data from dataset using time scale. Works only if dataset has data in given points in time.

__init__(dataset: TimeSeriesDataset, time: Iterable[datetime], *args: Any, **kwargs: Any) None[source]#
Parameters:
  • time (Iterable[datetime], optional) – The time dimension. Should be represented subclasses of datetime

  • data (Iterable, optional) – The data dimension. Should be 1D array or list.

class cascade.utils.time_series.Average(dataset: TimeSeriesDataset, unit: str = 'years', amount: int = 1, *args: Any, **kwargs: Any)[source]#

Averages values over some time step.

__init__(dataset: TimeSeriesDataset, unit: str = 'years', amount: int = 1, *args: Any, **kwargs: Any) None[source]#
Parameters:
  • dataset (TimeSeriesDataset,) – A dataset to average

  • unit (str, optional) – Time unit over which to average - years, month, etc.

  • amount – The amount of units over which to average. For example for six month periods use unit='months' and amount=6.

get_meta() List[Dict[Any, Any]][source]#

Overrides base method enabling cascade-like calls to previous datasets. The metadata of a pipeline that consist of several modifiers can be easily obtained with get_meta of the last block.

class cascade.utils.time_series.Interpolate(dataset: TimeSeriesDataset, method: str = 'linear', limit_direction: str = 'both', **kwargs: Any)[source]#

The wrapper around pd.Series.interpolate.

__init__(dataset: TimeSeriesDataset, method: str = 'linear', limit_direction: str = 'both', **kwargs: Any) None[source]#
Parameters:
  • time (Iterable[datetime], optional) – The time dimension. Should be represented subclasses of datetime

  • data (Iterable, optional) – The data dimension. Should be 1D array or list.

get_meta() List[Dict[Any, Any]][source]#

Overrides base method enabling cascade-like calls to previous datasets. The metadata of a pipeline that consist of several modifiers can be easily obtained with get_meta of the last block.

class cascade.utils.time_series.TimeSeriesDataset(*args: Any, time: Iterable[datetime] | None = None, data: Iterable[Any] | None = None, **kwargs: Any)[source]#

Dataset to simplify the work with time series. Manages the time and data. Reflects the list API and implements access by index and by datetime also. More than that, slices with indices and with datetimes can also be used.

__init__(*args: Any, time: Iterable[datetime] | None = None, data: Iterable[Any] | None = None, **kwargs: Any) None[source]#
Parameters:
  • time (Iterable[datetime], optional) – The time dimension. Should be represented subclasses of datetime

  • data (Iterable, optional) – The data dimension. Should be 1D array or list.

get_data() Tuple[ndarray, ndarray][source]#
Returns:

data – Time and data as np.array

Return type:

tuple

get_meta() List[Dict[Any, Any]][source]#
Returns:

meta – A list where last element is this dataset’s metadata. Meta can be anything that is worth to document about the dataset and its data. This is done in form of list to enable cascade-like calls in Modifiers and Samplers.

Return type:

Meta

to_numpy() ndarray[source]#

Returns only data without time in numpy array format.

Returns:

data – np.array of data.

Return type:

np.ndarray

to_pandas() DataFrame[source]#
Returns:

data – table with time as index

Return type:

pd.DataFrame