コード例 #1
0
    def validate_flow_conversion(self):
        try:
            a = self.flow_conversion
            if a == 42:
                print('you are so lucky!')
        except FlowConversionError:
            print('Flow %s ' % self._parent.flow)
            print('Provide conversion factor %s (fragment) to %s (termination)' % (self._parent.flow.unit(),
                                                                                   self.term_flow.unit()))
            cf = parse_math(input('Enter conversion factor: '))
            self._parent.flow.add_characterization(self.term_flow.reference_entity, value=cf)

            # this is surely a hack!
            if not isinstance(self._process_ref, LcFragment):
                # if it's a fragment, then its flow's quantities are already in catalog[0]
                self._process_ref.catalog[0].add(self.term_flow.reference_entity)
コード例 #2
0
    def _create_flow(self, exch):
        """
        An ecospold01 exchange is really just a long attribute list, plus an inputGroup or outputGroup (ignored here)
        :param exch:
        :return:
        """
        number = int(exch.get('number'))
        uid = self._key_to_nsuuid(number)
        try_f = self[uid]
        if try_f is not None:
            f = try_f
            assert f.entity_type == 'flow', "Expected flow, found %s" % f.entity_type

        else:
            # generate flow
            n = exch.get("name")
            q = self._create_quantity(exch.get("unit"))
            c = not_none(exch.get("generalComment"))
            cas = not_none(exch.get("CASNumber"))
            cat = [exch.get('category'), exch.get('subCategory')]

            f = LcFlow(uid, Name=n, CasNumber=cas, Comment=c, Compartment=cat)
            f.add_characterization(q, reference=True)
            f.set_external_ref(number)
            self.add(f)

        if exch.get("unit") != f.unit():
            local_q = self._create_quantity(exch.get("unit"))
            if not f.has_characterization(local_q):
                if (f.unit(), local_q.unit()) in conversion_dict:
                    val = conversion_dict[(f.unit(), local_q.unit())]
                elif (local_q.unit(), f.unit()) in conversion_dict:
                    val = 1.0 / conversion_dict[(local_q.unit(), f.unit())]
                else:
                    print('Flow %s needs characterization for unit %s' % (f, local_q))
                    val = parse_math(input('Enter conversion factor 1 %s = x %s' % (f.unit(), local_q)))
                f.add_characterization(local_q, value=val)
        return f
コード例 #3
0
ファイル: manager.py プロジェクト: bkuczenski/lca-tools
    def _observe(c, scenario):
        if scenario is None:
            prompt = 'Observed value'
        else:
            prompt = 'Scenario value'

        print('%s' % c)
        print(' Cached EV: %6.4g\n Observed EV: %6.4g [%s]' % (c.cached_ev, c.observed_ev, c.flow.unit()))
        if scenario is None:
            string_ev = '%10g' % c.observed_ev
        else:
            string_ev = '%10g' % c.exchange_value(scenario)
            print(' Scenario EV: %s [%s]' % (string_ev,
                                             c.flow.unit()))
        val = ifinput('%s ("=" to use cached): ' % prompt, string_ev)
        if val != string_ev:
            if val == '=':
                new_val = c.cached_ev
            else:
                new_val = parse_math(val)
            if scenario is None:
                c.observed_ev = new_val
            else:
                c.set_exchange_value(scenario, new_val)
コード例 #4
0
ファイル: ecospold.py プロジェクト: bkuczenski/lca-tools
    def _create_flow(self, exch):
        """
        An ecospold01 exchange is really just a long attribute list, plus an inputGroup or outputGroup (ignored here)
        :param exch:
        :return:
        """
        number = int(exch.get('number'))
        uid = self._key_to_id(number)
        try_f = self[uid]
        if try_f is not None:
            f = try_f
            assert f.entity_type == 'flow', "Expected flow, found %s" % f.entity_type

        else:
            # generate flow
            n = exch.get("name")
            q = self._create_quantity(exch.get("unit"))
            c = not_none(exch.get("generalComment"))
            cas = not_none(exch.get("CASNumber"))
            cat = [exch.get('category'), exch.get('subCategory')]

            f = LcFlow(uid, Name=n, CasNumber=cas, Comment=c, Compartment=cat)
            f.add_characterization(q, reference=True)
            f.set_external_ref(number)
            self.add(f)

        if exch.get("unit") != f.unit():
            local_q = self._create_quantity(exch.get("unit"))
            if not f.has_characterization(local_q):
                if (f.unit(), local_q.unit()) not in conversion_dict:
                    print('Flow %s needs characterization for unit %s' % (f, local_q))
                    val = parse_math(input('Enter conversion factor 1 %s = x %s' % (f.unit(), local_q)))
                else:
                    val = conversion_dict[(f.unit(), local_q.unit())]
                f.add_characterization(local_q, value=val)
        return f
コード例 #5
0
ファイル: editor.py プロジェクト: scope3/lca-tools
    def new_flow(self,
                 flow=None,
                 name=None,
                 cas=None,
                 quantity=None,
                 comment=None,
                 compartment=None,
                 local_unit=None,
                 **kwargs):
        if flow is None:
            name = name or self.input('Enter flow name: ', 'New flow')
            cas = cas or self.ifinput('Enter CAS number (or none): ', '')
            if quantity is None:
                if self._interactive:
                    print('Choose reference quantity or none to create new: ')
                    q = pick_one([fp for fp in self._qdb.flow_properties])
                    if q is None:
                        q = self.new_quantity()
                    quantity = q
                else:
                    print('Using mass as reference quantity')
                    quantity = self._qdb.get_canonical('mass')
            comment = comment or self.input('Enter flow comment: ', '')
            if compartment is None:
                if self._interactive:
                    print('Choose compartment:')
                    compartment = pick_compartment(
                        self._qdb.c_mgr.compartments).to_list()
                else:
                    print('Designating Intermediate flow')
                    compartment = self._qdb.c_mgr.find_matching(
                        'Intermediate Flows').to_list()
            else:
                compartment = self._qdb.c_mgr.find_matching(
                    compartment).to_list()
            if local_unit is not None:
                local_conv = quantity.convert(to=local_unit)
                if local_conv is None:
                    print('Falling back to default unit: %s' % quantity.unit())
                    local_unit = None

            flow = LcFlow.new(name,
                              quantity,
                              CasNumber=cas,
                              Compartment=compartment,
                              Comment=comment,
                              local_unit=local_unit,
                              **kwargs)
        else:
            quantity = flow.reference_entity

        if self._interactive:
            flow.profile()
            while ifinput('Add characterizations for this flow? y/n',
                          'n') != 'n':
                ch = cyoa('[n]ew or [e]xisting quantity? ', 'en', 'e')
                if ch == 'n':
                    cq = self.new_quantity()
                else:
                    cq = pick_one(self._qdb.quantities())
                    if cq is None:
                        cq = self.new_quantity()
                val = parse_math(
                    input('Value (1 %s = x %s): ' %
                          (quantity.unit(), cq.unit())))
                flow.add_characterization(cq, value=val)

        return flow