apparun.impact_tree#

Classes#

ImpactTreeNode

Impact Model tree node representing the impacts of an activity as well as its

Module Contents#

class apparun.impact_tree.ImpactTreeNode#

Bases: pydantic.BaseModel

Impact Model tree node representing the impacts of an activity as well as its children.

class Config#
arbitrary_types_allowed = True#
compile_models()#

Replace descendants symbols in node’s model by their corresponding model. Result is stored in “compiled_model” node’s attribute.

compute(transformed_params: Dict[str, List[str | float] | str | float], direct_impacts: bool = False) apparun.score.LCIAScores#

Compute node’s impacts with given parameters values. Multithreading is used to compute different impact methods in parallel. :param transformed_params: parameters, transformed by ImpactModelParam’s transform method. :param direct_impacts: if True, direct_impacts will be computed instead of full impacts (i.e. sum of direct impacts and children direct impacts) :return: a dict mapping impact’s name with corresponding score, or list of scores.

static from_dict(impact_model_tree_node: dict) ImpactTreeNode#

Convert dict to ImpactTreeNode object. :param impact_model_tree_node: dict containing construction parameters of the node. :return: constructed node

name_already_in_tree(name: str) bool#

Check if a node exists in descendants by comparing names. :param name: name to check presence in descendants :return: a boolean indicating if a descendant already has requested name.

new_child(**args) ImpactTreeNode#

Build a new node as a child. :param args: construction parameters of new node. :return: constructed node

new_child_from_dict(child: dict) ImpactTreeNode#

Build a new node as a child. :param child: dict containing construction parameters of new node. :return: constructed node

static node_name_to_symbol_name(node_name: str) str#

Convert node name to symbol name by replacing everything which is not an alphanumerical character by an underscore. :param node_name: node’s name :return: symbol’s name

to_dict() dict#

Convert self to dict. :param compile: if True, all models in tree nodes will be compiled. ImpactModel will be bigger, but its execution will be faster at first use. :return: self as a dict

amount: sympy.Expr | float | None = None#
children: List[ImpactTreeNode] | None = []#
property combined_amount: float | sympy.Expr#
direct_impacts: Dict[str, sympy.Expr] | None#
models: Dict[str, sympy.Expr] | None#
property models_compiled#
name: str#
parent: ImpactTreeNode | None = None#
properties: apparun.tree_node.NodeProperties#
scaled_direct_impacts: Dict[str, sympy.Expr] | None#
property unnested_descendants: List[ImpactTreeNode]#

Walk recursively through node’s children to return a list of all its descendants. :return: a list containing current node and all its descendants.