def frag_flow_lcia(fragmentflows, quantity_ref, scenario=None, refresh=False, ignore_uncached=True): """ Recursive function to compute LCIA of a traversal record contained in a set of Fragment Flows. :param fragmentflows: :param quantity_ref: :param scenario: necessary if any remote traversals are required :param refresh: whether to refresh the LCIA CFs :param ignore_uncached: [True] whether to allow zero scores for un-cached, un-computable fragments :return: """ result = LciaResult(quantity_ref) for ff in fragmentflows: if ff.term.is_null: continue node_weight = ff.node_weight if node_weight == 0: continue try: v = ff.term.score_cache(quantity=quantity_ref, refresh=refresh, ignore_uncached=ignore_uncached) except SubFragmentAggregation: # if we were given interior fragments, recurse on them. otherwise ask remote. if len(ff.subfragments) == 0: v = ff.term.term_node.fragment_lcia(quantity_ref, scenario=scenario, refresh=refresh) else: v = frag_flow_lcia(ff.subfragments, quantity_ref, refresh=refresh) if v.is_null: continue if ff.term.direction == ff.fragment.direction: # if the directions collide (rather than complement), the term is getting run in reverse node_weight *= -1 result.add_summary(ff.fragment.uuid, ff, node_weight, v) return result
def add_lcia_score(self, quantity, score, scenario=None): res = LciaResult(quantity, scenario=scenario) res.add_summary(self._parent.uuid, self._parent, 1.0, score) self._score_cache.add(res)