Ejemplo n.º 1
0
    def _write_flows(self, pw: pack.Writer):
        for _, row in self.flow_list.iterrows():

            description = "From FedElemFlowList_%s." % self.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 = self.version
            flow.last_change = datetime.datetime.now().isoformat()
            flow.category = olca.ref(olca.Category, row["Compartment UUID"])
            flow.flow_type = olca.FlowType.ELEMENTARY_FLOW
            fp = olca.FlowPropertyFactor()
            fp.reference_flow_property = True
            fp.conversion_factor = 1.0
            fp.flow_property = olca.ref(olca.FlowProperty, row["Quality UUID"])
            flow.flow_properties = [fp]
            pw.write(flow)
Ejemplo n.º 2
0
def _flow(d: dict, flowprop: olca.Ref, writer: pack.Writer,
          created_ids: set) -> Optional[olca.Ref]:
    if not isinstance(d, dict):
        return None
    uid = _val(d, 'id')
    name = _val(d, 'name')
    if isinstance(uid, str) and uid != '':
        return olca.ref(olca.Flow, uid, name)
    category_path = _val(d, 'category', default='')
    uid = _uid(olca.ModelType.FLOW, category_path, name)
    if uid not in created_ids:
        flow = olca.Flow()
        flow.id = uid
        flow.name = name
        flow.flow_type = olca.FlowType[_val(d,
                                            'flowType',
                                            default='ELEMENTARY_FLOW')]
        #Do not assign flows a location
        #flow.location = _location(_val(d, 'location'),
        #                          writer, created_ids)
        flow.category = _category(category_path, olca.ModelType.FLOW, writer,
                                  created_ids)
        propfac = olca.FlowPropertyFactor()
        propfac.conversion_factor = 1.0
        propfac.flow_property = flowprop
        propfac.reference_flow_property = True
        flow.flow_properties = [propfac]
        writer.write(flow)
        created_ids.add(uid)
    return olca.ref(olca.Flow, uid, name)
Ejemplo n.º 3
0
    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
    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)
Ejemplo n.º 5
0
def _flow(dict_d: dict, flowprop: olca.Ref, writer: pack.Writer,
          created_ids: set) -> Optional[olca.Ref]:
    if not isinstance(dict_d, dict):
        return None
    uid = _val(dict_d, 'id')
    name = _val(dict_d, 'name')
    orig_uid = None
    # Checking for technosphere or third party flows that were mapped in
    # an openLCA model, but these flows must be created in the json-ld here.
    if (isinstance(uid, str) and uid != ''
            and ("technosphere" in _val(dict_d, 'category').lower()
                 or "third party" in _val(dict_d, 'category').lower()
                 or "waste" in _val(dict_d, 'category').lower())):
        orig_uid = uid
        uid = ''

    if isinstance(uid, str) and uid != '':
        return olca.ref(olca.Flow, uid, name)
    category_path = _val(dict_d, 'category', default='')
    if orig_uid is None:
        uid = _uid(olca.ModelType.FLOW, category_path, name)
    else:
        uid = orig_uid
    if uid not in created_ids:
        flow = olca.Flow()
        flow.id = uid
        flow.name = name
        flow.flow_type = olca.FlowType[_val(dict_d,
                                            'flowType',
                                            default='ELEMENTARY_FLOW')]
        if "waste" in _val(dict_d, 'category').lower():
            dict_d['flowType'] = "WASTE_FLOW"
            flow.flow_type = olca.FlowType[_val(dict_d,
                                                'flowType',
                                                default='WASTE_FLOW')]
        # Do not assign flows a location
        # flow.location = _location(_val(dict_d, 'location'),
        #                          writer, created_ids)
        flow.category = _category(category_path, olca.ModelType.FLOW, writer,
                                  created_ids)
        propfac = olca.FlowPropertyFactor()
        propfac.conversion_factor = 1.0
        propfac.flow_property = flowprop
        propfac.reference_flow_property = True
        flow.flow_properties = [propfac]
        writer.write(flow)
        created_ids.add(uid)
    return olca.ref(olca.Flow, uid, name)
Ejemplo n.º 6
0
 def test_type_tags(self):
     instances = [
         olca.Actor(),
         olca.Source(),
         olca.Unit(),
         olca.UnitGroup(),
         olca.FlowProperty(),
         olca.SocialIndicator(),
         olca.Flow(),
         olca.Process(),
         olca.ImpactCategory(),
         olca.ImpactMethod(),
         olca.ProductSystem(),
         olca.Project(),
     ]
     for i in instances:
         json = i.to_json()
         self.assertEqual(type(i).__name__, json['@type'])
Ejemplo n.º 7
0
def create_flow(client: olca.Client,
                name: str,
                flow_property: olca.FlowProperty,
                flow_type=olca.FlowType.PRODUCT_FLOW) -> olca.Flow:
    """ Create a new flow with the given name and insert it into the database.
    """
    flow = olca.Flow()
    flow.id = str(uuid.uuid4())
    flow.name = name
    flow.flow_type = flow_type

    # A flow has one ore more quantities in which amounts of the flow can be
    # specified. In openLCA (and the ILCD format) these quantities are named
    # `flow properties` and they have flow specific conversion factors. Each
    # flow has at least one reference flow property and thus one flow property
    # factor:
    factor = olca.FlowPropertyFactor()
    factor.flow_property = flow_property
    factor.conversion_factor = 1.0
    factor.reference_flow_property = True
    flow.flow_properties = [factor]
    client.insert(flow)
    return flow
Ejemplo n.º 8
0
Archivo: ipc.py Proyecto: paulemms/LCA
import olca
import uuid

client = olca.Client(8080)

# find the flow property 'Mass' from the database
mass = client.find(olca.FlowProperty, 'Mass')

# create a flow that has 'Mass' as reference flow property
steel = olca.Flow()
steel.id = str(uuid.uuid4())
steel.flow_type = olca.FlowType.PRODUCT_FLOW
steel.name = "Steel"
steel.description = "Added from the olca-ipc python API..."
# in openLCA, conversion factors between different
# properties/quantities of a flow are stored in
# FlowPropertyFactor objects. Every flow needs at
# least one flow property factor for its reference
# flow property.
mass_factor = olca.FlowPropertyFactor()
mass_factor.conversion_factor = 1.0
mass_factor.flow_property = mass
mass_factor.reference_flow_property = True
steel.flow_properties = [mass_factor]

# save it in openLCA, you may have to refresh
# (close & reopen the database to see the new flow)
client.insert(steel)
Ejemplo n.º 9
0
 def test_type_tag(self):
     flow = olca.Flow()
     self.assertEqual('Flow', flow.olca_type)
     json_dict = flow.to_json()
     self.assertEqual('Flow', json_dict['@type'])