def lcia(self, quantity, ref_flow=None): if not quantity.is_entity: # only works for quantity refs-- in other words, always works return quantity.do_lcia(self.inventory(ref_flow=ref_flow), locale=self['SpatialScope']) else: result = LciaResult(quantity) result.add_component(self.get_uuid(), entity=self) for ex in self.inventory(ref_flow): factor = ex.flow.factor(quantity) result.add_score(self.get_uuid(), ex, factor, self['SpatialScope']) return result
def lcia(self, quantity, ref_flow=None, scenario=None, flowdb=None): result = LciaResult(quantity, scenario) result.add_component(self.get_uuid(), entity=self) for ex in self.allocated_exchanges(scenario or ref_flow): if not ex.flow.has_characterization(quantity): if flowdb is not None: if quantity in flowdb.known_quantities(): factor = flowdb.lookup_single_cf(ex.flow, quantity, self['SpatialScope']) if factor is None: ex.flow.add_characterization(quantity) else: ex.flow.add_characterization(factor) factor = ex.flow.factor(quantity) result.add_score(self.get_uuid(), ex, factor, self['SpatialScope']) return result
def do_lcia(self, quantity, inventory, locale='GLO', refresh=False, debug=False, **kwargs): """ takes a quantity and an exchanges generator; returns an LciaResult for the given quantity. For now, does NOT pre-load quantity LCIA methods. that is a catalog action. the Qdb doesn't do catalog stuff. I am open to re-thinking it, though. :param quantity: :param inventory: generates exchanges :param locale: ['GLO'] :param refresh: [False] whether to rewrite characterization factors from the database :param debug: [False] print extra information to screen :param kwargs: just quell_biogenic_co2 for the moment :return: an LciaResult whose components are the flows of the exchanges """ q = self[quantity.link] q_ind = self._get_q_ind(q) _is_quiet = self._quiet if debug: self._quiet = False self._print('q_ind: %d' % q_ind) r = LciaResult(q) for x in inventory: if refresh or not x.flow.has_characterization(q): try: factor = self.convert(flow=x.flow, query_q_ind=q_ind, locale=locale, **kwargs) except MissingCompartment: self._print('Missing compartment %s; abandoning this exchange' % x.flow['Compartment']) continue except ConversionReferenceMismatch: print('Mismatch %s' % x) factor = None if factor is not None: self._print('factor %g %s' % (factor, x)) x.flow.add_characterization(q, value=factor, overwrite=refresh) else: self._print('factor NONE %s' % x) x.flow.add_characterization(q) if x.flow.cf(q) is not None: r.add_component(x.flow.external_ref, entity=x.flow) fac = x.flow.factor(q) fac.set_natural_direction(self.c_mgr) r.add_score(x.flow.external_ref, x, fac, locale) self._quiet = _is_quiet return r