コード例 #1
0
    def _write_flows(self, pw: pack.Writer):
        altflowlist = fedelemflowlist.get_alt_conversion()
        for _, row in self.flow_list.iterrows():
            description = "From FedElemFlowList_" + flow_list_specs[
                'list_version'] + '.'
            flow_class = row.get("Class")
            if flow_class is not None:
                description += " Flow Class: %s." % flow_class

            preferred = row.get("Preferred", 0)
            if preferred == 1 or preferred == "1":
                description += " Preferred flow."
            else:
                description += " Not a preferred flow."

            flow = olca.Flow()
            flow.description = description
            flow.id = row["Flow UUID"]
            flow.name = row["Flowable"]
            flow.cas = row.get("CAS No", None)
            flow.formula = row.get("Formula", None)
            flow.version = flow_list_specs['list_version']
            flow.last_change = datetime.datetime.now().isoformat()
            flow.flow_type = olca.FlowType.ELEMENTARY_FLOW

            context_uid = self._context_uids.get(row['Context'].lower())
            if context_uid is not None:
                flow.category = olca.ref(olca.Category, context_uid)

            fp = olca.FlowPropertyFactor()
            fp.reference_flow_property = True
            fp.conversion_factor = 1.0
            fp.flow_property = units.property_ref(row["Unit"])
            if fp.flow_property is None:
                log.warning("unknown unit %s in flow %s", row["Unit"],
                            row["Flow UUID"])
            flow.flow_properties = [fp]
            #Add in alternate unit flow propert(ies), if an alternate unit exists
            #in the flows list, uses short list of altflowlist to assign one or more
            #alternate units
            if row["AltUnit"] is not None:
                #create dataframe of all alternate units for this flowable
                altunits = altflowlist[altflowlist['Flowable'] ==
                                       row["Flowable"]]
                for i, alternate in altunits.iterrows():
                    altfp = olca.FlowPropertyFactor()
                    altfp.reference_flow_property = False
                    altfp.conversion_factor = alternate[
                        'AltUnitConversionFactor']
                    altfp.flow_property = units.property_ref(
                        alternate["AltUnit"])
                    if altfp.flow_property is None:
                        log.warning("unknown altunit %s in flow %s",
                                    alternate["AltUnit"], row["Flow UUID"])
                    else:
                        flow.flow_properties.append(altfp)
            pw.write(flow)
コード例 #2
0
def _flow_property(unit_name: str) -> Optional[olca.Ref]:
    """ Get the openLCA object reference to the flow property for the given unit"""
    try:
        ref = units.property_ref(unit_name)
    except:
        log.error('unknown unit %s; no flow property reference', unit_name)
    return ref
コード例 #3
0
    def to_json(self) -> dict:
        """
        Creates a dictionary for an olca json file
        :return: dictionary
        """
        flow_ref = olca.FlowRef()
        flow_ref.name = self.name
        if self.category is not None:
            flow_ref.category_path = self.category.split('/')

        # set the UUID or generate it from the attributes
        if self.uid is None:
            flow_ref.id = make_uuid("Flow",
                                    self.category, self.name)
        else:
            flow_ref.id = self.uid

        json = {
            'flow': flow_ref.to_json()
        }
        if self.unit is not None:
            unit_ref = units.unit_ref(self.unit)
            if unit_ref is not None:
                json['unit'] = unit_ref.to_json()
            prop_ref = units.property_ref(self.unit)
            if prop_ref is not None:
                json['flowProperty'] = prop_ref.to_json()

        return json
コード例 #4
0
ファイル: jsonld.py プロジェクト: sarahcashmanz/LCIAformatter
    def __flow(self, row):
        uid = row[6]
        if not is_non_empty_str(uid):
            uid = make_uuid(row[5], row[7], row[8])

        flow = self.__flows.get(uid)
        if flow is not None:
            return flow
        flow = olca.Flow()
        flow.id = uid
        flow.name = row[5]
        flow.cas = row[6]
        flow.flow_type = olca.FlowType.ELEMENTARY_FLOW

        # flow property
        prop_ref = units.property_ref(row[8])
        if prop_ref is None:
            log.error("could not infer flow property for unit %s", row[8])
        if prop_ref is not None:
            prop_fac = olca.FlowPropertyFactor()
            prop_fac.conversion_factor = 1.0
            prop_fac.reference_flow_property = True
            prop_fac.flow_property = prop_ref
            flow.flow_properties = [prop_fac]

        # category
        c = self.__category(row)
        if c is not None:
            flow.category = olca.ref(olca.Category, c.id)

        self.__flows[uid] = flow
        return flow
コード例 #5
0
ファイル: jsonld.py プロジェクト: sarahcashmanz/LCIAformatter
    def write(self, df: pandas.DataFrame, write_flows=False):
        for _, row in df.iterrows():
            indicator = self.__indicator(row)
            factor = olca.ImpactFactor()
            flow = self.__flow(row)
            unit = row[8]
            factor.flow = olca.ref(olca.Flow, flow.id)
            factor.flow_property = units.property_ref(unit)
            factor.unit = units.unit_ref(unit)
            factor.value = row[12]
            indicator.impact_factors.append(factor)

        log.info("write entities")
        dicts = [self.__indicators, self.__methods]
        if write_flows:
            dicts.append(self.__categories)
            dicts.append(self.__flows)
        for d in dicts:
            for v in d.values():
                self.__writer.write(v)
コード例 #6
0
    def to_json(self) -> dict:
        flow_ref = olca.FlowRef()
        flow_ref.name = self.name
        if self.category is not None:
            flow_ref.category_path = self.category.split('/')

        # set the UUID or generate it from the attributes
        if self.uid is None:
            flow_ref.id = _uid(olca.ModelType.FLOW, self.category, self.name)
        else:
            flow_ref.id = self.uid

        json = {'flow': flow_ref.to_json()}
        if self.unit is not None:
            unit_ref = units.unit_ref(self.unit)
            if unit_ref is not None:
                json['unit'] = unit_ref.to_json()
            prop_ref = units.property_ref(self.unit)
            if prop_ref is not None:
                json['flowProperty'] = prop_ref.to_json()

        return json
コード例 #7
0
 def test_prop_ref(self):
     ref = units.property_ref('m2')
     self.assertEqual('93a60a56-a3c8-19da-a746-0800200c9a66', ref.id),
     self.assertEqual('Area', ref.name)