bw_graph_tools.graph_traversal.utils

Classes

CachingSolver

Class which caches expensive linear algebra solution vectors.

Counter

Custom counter to have easy access to current value

Functions

get_demand_vector_for_activity(node, skip_coproducts, ...)

Get input matrix indices and amounts for a given activity. Ignores the reference production

Module Contents

class bw_graph_tools.graph_traversal.utils.CachingSolver(lca: bw2calc.LCA)[source]

Class which caches expensive linear algebra solution vectors.

_calculate(index: int) numpy.ndarray[source]
add_to_cache(index: int, result: numpy.ndarray) None[source]

Store a pre-computed supply vector. Result must be for a demand amount of 1.

calculate(index: int) numpy.ndarray[source]

Compute cumulative LCA score for one unit of a given activity.

in_cache(indices: set[int]) set[int][source]

Return all indices values which are in the cache.

_cache[source]
lca[source]
class bw_graph_tools.graph_traversal.utils.Counter[source]

Custom counter to have easy access to current value

value = -1[source]
bw_graph_tools.graph_traversal.utils.get_demand_vector_for_activity(node: bw_graph_tools.graph_traversal.graph_objects.Node, skip_coproducts: bool, matrix: scipy.sparse.spmatrix)[source]

Get input matrix indices and amounts for a given activity. Ignores the reference production exchanges and optionally other co-production exchanges.

Parameters:
  • node (Node) – Activity whose inputs we are iterating over

  • skip_coproducts (bool) – Whether or not to ignore positive production exchanges other than the reference product, which is always ignored

  • matrix (scipy.sparse.spmatrix) – Technosphere matrix

Returns:

  • row indices (list) – Integer row indices for products consumed by Node

  • amounts (list) – The amount of each product consumed, scaled to Node.supply_amount. Same order as row indices.