bw_temporalis.timeline

Exceptions

EmptyTimeline

Operation on empty timeline

Classes

FlowTD

Class for storing a temporal distribution associated with a flow and activity.

NodeTD

Class for storing a temporal distribution associated only with an activity.

Timeline

Sum and group elements over time.

Module Contents

exception bw_temporalis.timeline.EmptyTimeline[source]

Bases: Exception

Operation on empty timeline

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

class bw_temporalis.timeline.FlowTD[source]

Class for storing a temporal distribution associated with a flow and activity.

distribution[source]
Type:

TemporalDistribution

flow[source]
Type:

int

activity[source]
Type:

int

See also

bw_temporalis.temporal_distribution.TemporalDistribution

A container for a series of values spread over time.

activity: int[source]
distribution: bw_temporalis.temporal_distribution.TemporalDistribution[source]
flow: int[source]
class bw_temporalis.timeline.NodeTD[source]

Class for storing a temporal distribution associated only with an activity.

distribution[source]
Type:

TemporalDistribution

flow[source]
Type:

int. Only included for compatibility with FlowTD. Always -1.

activity[source]
Type:

int

num_flows[source]
Type:

int. Number of biosphere flow edges from this node.

num_flows_td[source]
Type:

int. Number of biosphere flow edges from this node with temporal distributions.

See also

bw_temporalis.temporal_distribution.TemporalDistribution

A container for a series of values spread over time.

activity: int[source]
distribution: bw_temporalis.temporal_distribution.TemporalDistribution[source]
flow: int[source]
num_flows: int[source]
num_flows_td: int[source]
class bw_temporalis.timeline.Timeline(data: list[FlowTD] | None = None)[source]

Sum and group elements over time. Timeline calculations produce a list of [(datetime, amount)] tuples.

self.data
Type:

list[FlowTD]

add_flow_temporal_distribution(td: bw_temporalis.temporal_distribution.TemporalDistribution, flow: int, activity: int) None[source]

Append a TemporalDistribution object to the Timeline.data object.

Parameters:
  • td (TemporalDistribution) – Temporal distribution to add.

  • flow (int) – Associated flow.

  • activity (int) – Associated activity.

See also

bw_temporalis.temporal_distribution.TemporalDistribution

A container for a series of values spread over time.

add_metadata_to_dataframe(database_labels: list[str], fields: List[str] = ['name', 'unit', 'location', 'categories']) pandas.DataFrame[source]

Add additional columns with metadata to the dataframe. Returns a new dataframe.

Parameters:
  • database_labels (list[str]) – List of all databases to load and add metadata from

  • fields (list[str]) – Metadata fields to add.

add_node_temporal_distribution(td: bw_temporalis.temporal_distribution.TemporalDistribution, activity: int, num_flows: int, num_flows_td: int) None[source]

Append a TemporalDistribution object to the Timeline.data object.

Parameters:
  • td (TemporalDistribution) – Temporal distribution to add.

  • activity (int) – Associated activity.

  • num_flows (int) – Number of biosphere flow edges from this node.

  • num_flows_td (int) – Number of biosphere flow edges from this node with temporal distributions.

See also

bw_temporalis.temporal_distribution.TemporalDistribution

A container for a series of values spread over time.

build_dataframe() None[source]

Build a Pandas DataFrame from the Timeline.data object and store it as a Timeline.pd object.

Returns:

  • None, creates class attribute Pandas DataFrame df with the following columns

  • - date (datetime64[s])

  • - amount (float64)

  • - flow (int)

  • - activity (int)

characterize_dataframe(characterization_function: Callable, flow: set[int] | None = None, activity: set[int] | None = None, cumsum: bool | None = True) pandas.DataFrame[source]

Applies a characterization function to a Timeline Pandas DataFrame.

The characterization function is expected to take a row from the input Timeline of the form

date | amount | flow | activity |

|-------|——-|------|———-| | 101 | 33 | 1 | 2 | | 312 | 21 | 4 | 2 |

and transform it for a given time period. The output for a very simple function could look like:

date | amount | flow | activity |

|------|——–|------|———-| | 101 | 33 | 1 | 2 | | 102 | 31 | 1 | 2 | | 103 | 31 | 1 | 2 | | 312 | 21 | 4 | 2 | | 313 | 20 | 4 | 2 | | 314 | 19 | 4 | 2 |

Each row of the input Timeline corresponds to a single day (date) and the associated value (amount). The characterization_function is applied to each row of the input Timeline for a given period of days. The new rows are appended to the Timeline Pandas DataFrame.

Parameters:
  • characterization_function (Callable) – Characterization function to apply to the values Timeline Pandas DataFrame.

  • period (int) – Period in days.

  • flow (int)

  • activity (int)

Returns:

  • A Pandas DataFrame with the following columns

  • - date (datetime64[s])

  • - amount (float64)

  • - flow (int)

  • - activity (int)

sum_days_to_years() pandas.DataFrame[source]

Sums the day-resolution amount of the Timeline Pandas DataFrame to years.

An input Timeline of the form

date | amount | flow | activity |

|------|——–|------|———-| | 101 | 33 | 1 | 2 | | 102 | 32 | 1 | 2 | | 103 | 31 | 1 | 2 | | 412 | 21 | 4 | 2 | | 413 | 20 | 4 | 2 | | 514 | 19 | 4 | 2 |

is transformed into

year | amount | flow | activity |

|------|——–|------|———-| | 1 | 96 | 1 | 2 | | 2 | 60 | 4 | 2 |

Returns:

  • A Pandas DataFrame with the following columns

  • - year (int)

  • - amount (float64)

  • - flow (int)

  • - activity (int)

data = [][source]