bw_temporalis.temporal_distribution

Attributes

RESOLUTION_LABELS

Classes

FixedTD

An absolute TemporalDistribution that ignores other temporal information.

FixedTimeOfYearTD

Instead of creating a relative shift in time, regardless of the starting datetime or the properties of the system being modeled, create an absolute period in the first available year.

TDAware

Base class for functions which can be multiplied by temporal distributions

TemporalDistribution

A container for a series of amount spread over time.

TemporalDistributionBase

Base class for temporal distributions

Module Contents

class bw_temporalis.temporal_distribution.FixedTD(date: numpy.typing.NDArray[numpy.datetime64 | numpy.timedelta64], amount: numpy.typing.NDArray)[source]

Bases: TemporalDistribution

An absolute TemporalDistribution that ignores other temporal information.

to_json() str[source]
_mul_comes_first = True[source]
class bw_temporalis.temporal_distribution.FixedTimeOfYearTD(date: numpy.typing.NDArray[numpy.timedelta64], amount: numpy.typing.NDArray, allow_overlap: bool | None = False)[source]

Bases: TemporalDistribution

Instead of creating a relative shift in time, regardless of the starting datetime or the properties of the system being modeled, create an absolute period in the first available year.

The fixed time of year is a relative temporal distribution, and must already be constructed as such.

When multiplied by another temporal distribution, the entire period of the FixedTimeOfYear must lie before the other distribution, or else the FixedTimeOfYear is shifted back a year. In other words, a FixedTimeOfYear of March to May could be multiplied by August 2020 and result in March to May 2020, but if multiplied by April 2020 it would result in March to May 2019. To allow partial overlaps and stay in the same year, set allow_overlap to True. In any case, the start of the FixedTimeOfYear must be before the start of the temporal distribution being multiplied or it is shifted back a year.

classmethod from_json(json_obj)[source]
to_json() str[source]
_mul_comes_first = True[source]
allow_overlap = False[source]
amount[source]
base_time_type[source]
date[source]
class bw_temporalis.temporal_distribution.TDAware[source]

Base class for functions which can be multiplied by temporal distributions

class bw_temporalis.temporal_distribution.TemporalDistribution(date: numpy.typing.NDArray[numpy.datetime64 | numpy.timedelta64], amount: numpy.typing.NDArray)[source]

Bases: TemporalDistributionBase

A container for a series of amount spread over time. :param * date: 1D array containg temporal info of amount with type timedelta64 or datetime64 . :type * date: ndarray :param * amount: 1D array containg amount with type float :type * amount: ndarray :param Times and amount must have same length and element of amount must correspond to the element of date: :param with the same index.:

classmethod from_json(json_obj: str | collections.abc.Mapping) TemporalDistributionBase[source]
nonzero()[source]
simplify(threshhold: int | None = 1000, num_clusters: int | None = None, iterations: int | None = 30) TemporalDistribution[source]

Use clustering to simplify a TemporalDistribution with more than threshhold number of points.

Uses the kmeans2 implementation of KNN from [scipy.cluster.vq](https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.vq.kmeans2.html). Subclass and override this method to get a custom clustering algorithm.

This isn’t perfect, kmeans2 produces “lumpy” distributions - to see this graph the simplification of a uniform distribution with many points.

Parameters:
  • threshhold (int, optional) – The number of date points above which simplification is triggered

  • iterations (int, optional) – iter parameters to feed to kmeans2

Return type:

Either self (if no simplification) or a new instance of TemporalDistribution.

to_json()[source]
amount[source]
property total: float[source]
class bw_temporalis.temporal_distribution.TemporalDistributionBase[source]

Base class for temporal distributions

graph(style: str | None = 'fivethirtyeight', resolution: str | None = None)[source]

Graph the temporal distribution.

resolution is one of YMWDhms.

This isn’t too difficult, if you need more customization write your own :)

_mul_comes_first = False[source]
bw_temporalis.temporal_distribution.RESOLUTION_LABELS[source]