bw_temporalis.timeline ====================== .. py:module:: bw_temporalis.timeline Exceptions ---------- .. autoapisummary:: bw_temporalis.timeline.EmptyTimeline Classes ------- .. autoapisummary:: bw_temporalis.timeline.FlowTD bw_temporalis.timeline.NodeTD bw_temporalis.timeline.Timeline Module Contents --------------- .. py:exception:: EmptyTimeline Bases: :py:obj:`Exception` Operation on empty timeline Initialize self. See help(type(self)) for accurate signature. .. py:class:: FlowTD Class for storing a temporal distribution associated with a flow and activity. .. attribute:: distribution :type: TemporalDistribution .. attribute:: flow :type: int .. attribute:: activity :type: int .. seealso:: :py:obj:`bw_temporalis.temporal_distribution.TemporalDistribution` A container for a series of values spread over time. .. py:attribute:: activity :type: int .. py:attribute:: distribution :type: bw_temporalis.temporal_distribution.TemporalDistribution .. py:attribute:: flow :type: int .. py:class:: NodeTD Class for storing a temporal distribution associated only with an activity. .. attribute:: distribution :type: TemporalDistribution .. attribute:: flow :type: int. Only included for compatibility with `FlowTD`. Always -1. .. attribute:: activity :type: int .. attribute:: num_flows :type: int. Number of biosphere flow edges from this node. .. attribute:: num_flows_td :type: int. Number of biosphere flow edges from this node with temporal distributions. .. seealso:: :py:obj:`bw_temporalis.temporal_distribution.TemporalDistribution` A container for a series of values spread over time. .. py:attribute:: activity :type: int .. py:attribute:: distribution :type: bw_temporalis.temporal_distribution.TemporalDistribution .. py:attribute:: flow :type: int .. py:attribute:: num_flows :type: int .. py:attribute:: num_flows_td :type: int .. py:class:: Timeline(data: list[FlowTD] | None = None) Sum and group elements over time. Timeline calculations produce a list of [(datetime, amount)] tuples. .. attribute:: self.data :type: list[FlowTD] .. py:method:: add_flow_temporal_distribution(td: bw_temporalis.temporal_distribution.TemporalDistribution, flow: int, activity: int) -> None Append a TemporalDistribution object to the Timeline.data object. :param td: Temporal distribution to add. :type td: TemporalDistribution :param flow: Associated flow. :type flow: int :param activity: Associated activity. :type activity: int .. seealso:: :py:obj:`bw_temporalis.temporal_distribution.TemporalDistribution` A container for a series of values spread over time. .. py:method:: add_metadata_to_dataframe(database_labels: list[str], fields: List[str] = ['name', 'unit', 'location', 'categories']) -> pandas.DataFrame Add additional columns with metadata to the dataframe. Returns a new dataframe. :param database_labels: List of all databases to load and add metadata from :type database_labels: list[str] :param fields: Metadata fields to add. :type fields: list[str] .. py:method:: add_node_temporal_distribution(td: bw_temporalis.temporal_distribution.TemporalDistribution, activity: int, num_flows: int, num_flows_td: int) -> None Append a TemporalDistribution object to the Timeline.data object. :param td: Temporal distribution to add. :type td: TemporalDistribution :param activity: Associated activity. :type activity: int :param num_flows: Number of biosphere flow edges from this node. :type num_flows: int :param num_flows_td: Number of biosphere flow edges from this node with temporal distributions. :type num_flows_td: int .. seealso:: :py:obj:`bw_temporalis.temporal_distribution.TemporalDistribution` A container for a series of values spread over time. .. py:method:: build_dataframe() -> None 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*) .. py:method:: characterize_dataframe(characterization_function: Callable, flow: set[int] | None = None, activity: set[int] | None = None, cumsum: bool | None = True) -> pandas.DataFrame 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. :param characterization_function: Characterization function to apply to the values Timeline Pandas DataFrame. :type characterization_function: Callable :param period: Period in days. :type period: int :param flow: :type flow: int :param activity: :type activity: int :returns: * *A Pandas DataFrame with the following columns* * **- date** (*datetime64[s]*) * **- amount** (*float64*) * **- flow** (*int*) * **- activity** (*int*) .. py:method:: sum_days_to_years() -> pandas.DataFrame 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*) .. py:attribute:: data :value: []