Ejemplo n.º 1
0
 def _create_flow(self, row):
     key = self._flow_key(row)
     u = self._key_to_id(key)
     f = self._try_flow(u, key)
     if f is None:
         f = LcFlow(u, Name=row['name'], CasNumber='', Compartment=[row['compartment'], row['subcompartment']],
                    Comment=row['note'])
         self._print('Created new flow with %s ' % self._upstream_flow_key(f))
         f.add_characterization(self._mass, reference=True)
         f.set_external_ref(key)
         self.add(f)
     return f
Ejemplo n.º 2
0
 def _create_flow(self, u, unit, ext_ref, Name=None, Compartment=None, **kwargs):
     if u in self._entities:
         f = self[u]
     else:
         f = LcFlow(u, Name=Name, Compartment=Compartment, **kwargs)
         f.set_external_ref(ext_ref)
         q = self._create_quantity(unit)
         if q is None:
             raise ValueError
         f.add_characterization(quantity=q, reference=True)
         self.add(f)
     f.update(kwargs)
Ejemplo n.º 3
0
    def _create_flow(self, o):
        """

        :param o: objectified flow
        :return: an LcFlow
        """
        ns = find_ns(o.nsmap, 'Flow')
        n = grab_flow_name(o, ns=ns)

        u = str(find_common(o, 'UUID')[0])

        c = str(find_common(o, 'generalComment')[0])

        cas = str(find_tag(o, 'CASNumber', ns=ns)[0])

        cat = find_common(o, 'category')
        if cat == ['']:
            cat = find_common(o, 'class')
        cat = [str(i) for i in cat]

        f = LcFlow(u, Name=n, CasNumber=cas, Comment=c, Compartment=cat)
        f.set_external_ref('%s/%s' % (typeDirs['Flow'], u))

        ref_to_ref = get_reference_flow_property_id(o, ns=ns)
        for fp in o['flowProperties'].getchildren():
            if int(fp.attrib['dataSetInternalID']) == ref_to_ref:
                is_ref = True
            else:
                is_ref = False
            val = float(find_tag(fp, 'meanValue', ns=ns)[0])

            ref = find_tag(fp, 'referenceToFlowPropertyDataSet', ns=ns)[0]
            rfp_uuid = ref.attrib['refObjectId']
            rfp_uri = ref.attrib['uri']

            try:
                q = self._check_or_retrieve_child(rfp_uuid, rfp_uri)
            except (HTTPError, XMLSyntaxError, KeyError):
                continue

            try:
                f.add_characterization(q, reference=is_ref, value=val)
            except DuplicateCharacterizationError:
                print('Duplicate Characterization in entity %s\n %s = %g' % (u, q, val))
                # let it go

        try:
            self.add(f)
        except KeyError:
            print('Found duplicate entity %s' % u)
            raise
        return f
Ejemplo n.º 4
0
 def _create_flow(self, u, unit, ext_ref, Name=None, Compartment=None, **kwargs):
     upstream_key = ', '.join([Name] + Compartment)
     f = self._try_flow(u, upstream_key)
     if f is None:
         f = LcFlow(u, Name=Name, Compartment=Compartment, **kwargs)
         f.set_external_ref(ext_ref)
         q = self._create_quantity(unit)
         if q is None:
             raise ValueError
         f.add_characterization(quantity=q, reference=True)
         self.add(f)
     else:
         f.update(kwargs)
Ejemplo n.º 5
0
 def _create_flow(self, row):
     key = self._flow_key(row)
     u = self._key_to_nsuuid(key)
     if u in self._entities:
         return self[u]
     f = LcFlow(u,
                Name=row['name'],
                CasNumber='',
                Compartment=[row['compartment'], row['subcompartment']],
                Comment=row['note'])
     self._print('Created new flow with %s ' % key)
     f.add_characterization(self._mass, reference=True)
     f.set_external_ref(key)
     self.add(f)
     return f
Ejemplo n.º 6
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
Ejemplo n.º 7
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_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
Ejemplo n.º 8
0
    def _create_flow(self, o):
        """

        :param o: objectified flow
        :return: an LcFlow
        """
        u = str(find_common(o, 'UUID'))
        try_f = self[u]
        if try_f is not None:
            return try_f

        ns = find_ns(o.nsmap, 'Flow')
        n = grab_flow_name(o, ns=ns)

        c = str(find_common(o, 'generalComment'))

        cas = str(find_tag(o, 'CASNumber', ns=ns))

        cat = find_tags(o, 'category', ns='common')
        if cat == ['']:
            cat = find_tags(o, 'class', ns='common')
        cat = [str(i) for i in cat]

        if str(find_tag(o, 'typeOfDataSet', ns=ns)) == 'Elementary flow':
            f = LcFlow(u, Name=n, CasNumber=cas, Comment=c, Compartment=cat)
        else:
            f = LcFlow(u,
                       Name=n,
                       CasNumber=cas,
                       Comment=c,
                       Compartment=['Intermediate flows'],
                       Class=cat)

        f.set_external_ref('%s/%s' % (typeDirs['Flow'], u))

        ref_to_ref = get_reference_flow_property_id(o, ns=ns)
        for fp in o['flowProperties'].getchildren():
            if int(fp.attrib['dataSetInternalID']) == ref_to_ref:
                is_ref = True
            else:
                is_ref = False
            val = float(find_tag(fp, 'meanValue', ns=ns))

            ref = find_tag(fp, 'referenceToFlowPropertyDataSet', ns=ns)
            rfp_uuid = ref.attrib['refObjectId']
            rfp_uri = ref.attrib['uri']

            try:
                q = self._check_or_retrieve_child(rfp_uuid, rfp_uri)
            except (HTTPError, XMLSyntaxError, KeyError):
                continue

            try:
                f.add_characterization(q, reference=is_ref, value=val)
            except DuplicateCharacterizationError:
                print('Duplicate Characterization in entity %s\n %s = %g' %
                      (u, q, val))
                # let it go

        self.add(f)
        return f