bw2calc.graph_traversal
#
Module Contents#
Classes#
Traverse a supply chain, following paths of greatest impact. |
Attributes#
- class bw2calc.graph_traversal.GraphTraversal[source]#
Bases:
object
Traverse a supply chain, following paths of greatest impact.
This implementation uses a queue of datasets to assess. As the supply chain is traversed, datasets inputs are added to a list sorted by LCA score. Each activity in the sorted list is assessed, and added to the supply chain graph, as long as its impact is above a certain threshold, and the maximum number of calculations has not been exceeded.
Because the next dataset assessed is chosen by its impact, not its position in the graph, this is neither a breadth-first nor a depth-first search, but rather “importance-first”.
This class is written in a functional style - no variables are stored in self, only methods.
Should be used by calling the
calculate
method.Warning
Graph traversal with multioutput processes only works when other inputs are substituted (see Multioutput processes in LCA for a description of multiputput process math in LCA).
- calculate(demand, method, cutoff=0.005, max_calc=100000.0, skip_coproducts=False)[source]#
Traverse the supply chain graph.
- Parameters
demand (*) – The functional unit. Same format as in LCA class.
method (*) – LCIA method. Same format as in LCA class.
cutoff (*) – Cutoff criteria to stop LCA calculations. Relative score of total, i.e. 0.005 will cutoff if a dataset has a score less than 0.5 percent of the total.
max_calc (*) – Maximum number of LCA calculations to perform.
- Returns
Dictionary of nodes, edges, LCA object, and number of LCA calculations.
- cumulative_score(index, supply, characterized_biosphere, lca)[source]#
Compute cumulative LCA score for a given activity
- initialize_heap(demand, lca, supply, characterized_biosphere)[source]#
Create a priority queue or
heap
to store inventory datasets, sorted by LCA score.Populates the heap with each activity in
demand
. Initial nodes are the functional unit, i.e. the complete demand, and each activity in the functional unit. Initial edges are inputs from each activity into the functional unit.The functional unit is an abstract dataset (as it doesn’t exist in the matrix), and is assigned the index
-1
.
- traverse(heap, nodes, edges, counter, max_calc, cutoff, total_score, supply, characterized_biosphere, lca, skip_coproducts)[source]#
Build a directed graph by traversing the supply chain.
Node ids are actually technosphere row/col indices, which makes lookup easier.
- Returns
(nodes, edges, number of calculations)