示例#1
0
 def _quantity_from_json(self, entity_j, uid):
     entity_j.pop('externalId')  # TODO
     # can't move this to entity because we need _create_unit- so we wouldn't gain anything
     unit, _ = self._create_unit(entity_j.pop('referenceUnit'))
     entity_j['referenceUnit'] = unit
     quantity = LcQuantity(uid, **entity_j)
     return quantity
示例#2
0
 def _create_quantity(self, name, unitstring):
     u = self._key_to_nsuuid(name)
     q = self[u]
     if q is None:
         q = LcQuantity(u,
                        external_ref=name,
                        Name=name,
                        ReferenceUnit=self._create_unit(unitstring)[0])
         self.add(q)
     return q
示例#3
0
    def _create_quantity(self, unitstring):
        """
        In ecospold v1, quantities are only units, defined by string
        :param unitstring:
        :return:
        """
        if unitstring in self._q_dict:
            q = self._q_dict[unitstring]
        else:
            ref_unit, _ = self._create_unit(unitstring)
            uid = self._key_to_nsuuid(unitstring)

            q = LcQuantity(uid, Name='EcoSpold Quantity %s' % unitstring,
                           ReferenceUnit=ref_unit, Comment=self.spold_version)
            q.set_external_ref(unitstring)
            self.add(q)

            self._q_dict[unitstring] = q

        return q
示例#4
0
    def _create_quantity(self, exchange):
        """
        In ecospold v2, quantities are still only units, defined by string.  They do get their own uuids, but only
        as 'properties' of the flows- flows themselves are only measured by unit.
        this code is cc'd from ecospold1
        :param exchange:
        :return:
        """
        unitstring = exchange.unitName.text
        unit_uuid = exchange.attrib['unitId']
        try_q = self[unit_uuid]
        if try_q is None:
            ref_unit, _ = self._create_unit(unitstring)

            q = LcQuantity(unit_uuid, Name='EcoSpold Quantity %s' % unitstring, ReferenceUnit=ref_unit,
                           Comment=self.spold_version)
            self.add(q)
        else:
            q = try_q

        return q
示例#5
0
    def _create_quantity(self, unitstring):
        """
        In ecoinvent activity overview spreadsheets, quantities are only units, defined by string. 'properties'
        are additionally defined with name and unit together, but because the prinicpal units don't have names
        (and because for the time being we are neglecting the F-Q relation), we ignore them.
        :param unitstring:
        :return:
        """
        u = self._key_to_nsuuid(unitstring)
        try_q = self[u]
        if try_q is None:
            ref_unit, _ = self._create_unit(unitstring)

            q = LcQuantity(u, Name='Ecoinvent Spreadsheet Quantity %s' % unitstring,
                           ReferenceUnit=ref_unit, Comment=self.version)
            q.set_external_ref(unitstring)
            self.add(q)
        else:
            q = try_q

        return q
示例#6
0
    def _create_lcia_quantity(self, o, ns):

        u = str(find_common(o, 'UUID'))
        try_q = self[u]
        if try_q is not None:
            lcia = try_q
        else:
            n = str(find_common(o, 'name'))

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

            m = '; '.join([str(x) for x in find_tags(o, 'methodology', ns=ns)])
            ic = '; '.join(
                [str(x) for x in find_tags(o, 'impactCategory', ns=ns)])
            ii = '; '.join(
                [str(x) for x in find_tags(o, 'impactIndicator', ns=ns)])

            ry = str(find_tag(o, 'referenceYear', ns=ns))
            dur = str(find_tag(o, 'duration', ns=ns))

            rq = self._make_reference_unit(o, ns=ns)

            lcia = LcQuantity(u,
                              Name=n,
                              Comment=c,
                              Method=m,
                              Category=ic,
                              Indicator=ii,
                              ReferenceYear=ry,
                              Duration=dur,
                              UnitConversion=rq['UnitConversion'])
            lcia.set_external_ref('%s/%s' % (typeDirs['LCIAMethod'], u))
            lcia.reference_entity = LcUnit('%s %s' % (rq.unit(), rq['Name']),
                                           unit_uuid=rq.uuid)

            self.add(lcia)

        return lcia
示例#7
0
    def _create_quantity(self, row):
        """
        here row is a dict from self._xl_rows
        :param row:
        :return:
        """
        key = self._quantity_key(row)
        u = self._key_to_nsuuid(key)
        try_q = self[u]
        if try_q is None:
            unit, _ = self._create_unit(row['unit'])

            q = LcQuantity(u,
                           Name=key,
                           referenceUnit=unit,
                           Comment='Ecoinvent LCIA implementation',
                           Method=row['method'],
                           Category=row['category'],
                           Indicator=row['indicator'])
            q.set_external_ref(key)
            self.add(q)
        else:
            q = try_q
        return q
示例#8
0
文件: ilcd.py 项目: scope3/lca-tools
    def _create_quantity(self, o):
        """

        :param o: objectified FlowProperty
        :return:
        """
        u = str(find_common(o, 'UUID'))
        try_q = self[u]
        if try_q is not None:
            return try_q

        ns = find_ns(o.nsmap, 'FlowProperty')

        n = str(find_common(o, 'name'))

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

        ug, ug_uri = get_reference_unit_group(o, ns=ns)

        ug_path = self._pathtype.join(
            'unitgroups',
            ug)  # need the path without extension- I know- it's all sloppy

        refunit, unitconv = self._create_unit(ug_path)

        q = LcQuantity(u,
                       Name=n,
                       ReferenceUnit=refunit,
                       UnitConversion=unitconv,
                       Comment=c)

        q.set_external_ref('%s/%s' % (typeDirs['FlowProperty'], u))

        self.add(q)

        return q
示例#9
0
 def new_quantity(self, name, ref_unit, **kwargs):
     u = self._check_key_unused(name)
     q = LcQuantity(u, ref_unit=LcUnit(ref_unit), Name=name, origin=self.ref, external_ref=name, **kwargs)
     self.add(q)
     return q