bw_temporalis.utils

Exceptions

IncongruentDistribution

The sum of TemporalDistribution values is different than the exchange

Functions

check_database_exchanges(→ None)

Check the sum of an exchange TemporalDistribution.amount is close to its amount value.

easy_datetime_distribution(...)

Generate a datetime TemporalDistribution with a few input parameters.

easy_timedelta_distribution(...)

Generate a timedelta TemporalDistribution with a few input parameters.

get_version_tuple(→ tuple)

normalized_data_array(→ numpy.typing.NDArray[int])

Module Contents

exception bw_temporalis.utils.IncongruentDistribution[source]

Bases: Exception

The sum of TemporalDistribution values is different than the exchange

Initialize self. See help(type(self)) for accurate signature.

bw_temporalis.utils.check_database_exchanges(database_label: str) None[source]

Check the sum of an exchange TemporalDistribution.amount is close to its amount value.

Raises:

IncongruentDistribution – If the two values are more than 1 percent different

Parameters:

database_label (str) – Name of database to check

bw_temporalis.utils.easy_datetime_distribution(start: str, end: str, steps: int | None = 50, kind: str | None = 'uniform', param: float | None = None) bw_temporalis.temporal_distribution.TemporalDistribution[source]

Generate a datetime TemporalDistribution with a few input parameters.

Can generate distributions whose amount values are uniformly, triangularly, or normally distributed. Please build more complicated distributions manually.

Only the amount values are distributed, the resulting distribution date values are uniformly spaced from start to end.

For triangular distributions, param is the mode (optional), and should be given in the same reference system as start and stop. The param value should be in the same format as start and end, e.g. “2023-01-01”.

For normal distributions, param is the standard deviation in relation to a standardized distribution with mu = 0. param is not used for the uniform distribution.

Raises:

ValueError – If the input parameters prevent construction of valide TemporalDistribution.

Parameters:
  • start (str) – Datetime marking the start (inclusive) of the distribution, e.g. “now”, “2023-02-01”, “2023-03-02T12:34:56”

  • end (str) – Datetime marking the end (inclusive) of the distribution, e.g. “now”, “2023-02-01”, “2023-03-02T12:34:56”

  • steps (int, optional) – Number of values in discrete distribution. Normally not more than 50 or 100.

  • kind (str, optional) – Distribution type. Must be one of “uniform”, “triangular”, or “normal”

  • param (float, optional) – Input parameter to define triangular or normal distribution

Return type:

A TemporalDistribution instance.

bw_temporalis.utils.easy_timedelta_distribution(start: int, end: int, resolution: str, steps: int | None = 50, kind: str | None = 'uniform', param: float | None = None) bw_temporalis.temporal_distribution.TemporalDistribution[source]

Generate a timedelta TemporalDistribution with a few input parameters.

Can generate distributions whose amount values are uniformly, triangularly, or normally distributed. Please build more complicated distributions manually.

Only the amount values are distributed, the resulting distribution date values are uniformly spaced from start to end.

For triangular distributions, param is the mode (optional). For lognormal distributions, param is the standard deviation (required). param is not used for the uniform distribution.

Raises:

ValueError – If the input parameters prevent construction of valide TemporalDistribution.

Parameters:
  • start (int) – Start (inclusive) of the distribution in resolution units

  • end (int) – End (inclusive) of the distribution in resolution units

  • resolution (str) – Resolution of the created timedelta64 array. One of Y (year), M (month), D (day), h (hour), m (minute), s (second)

  • steps (int, optional) – Number of values in discrete distribution. Normally not more than 50 or 100.

  • kind (str, optional) – Distribution type. Must be one of “uniform”, “triangular”, or “normal”

  • param (float, optional) – Input parameter to define triangular or normal distribution

Return type:

A TemporalDistribution instance.

bw_temporalis.utils.get_version_tuple() tuple[source]
bw_temporalis.utils.normalized_data_array(steps: int, kind: str, param: float | None) numpy.typing.NDArray[int][source]