0 votes
632 views

Hi, I'm trying to create a flow (eg, 316steel) and I want to categorize the flow with the existing  category (eg, manufacture of metal material) using olca-ipc.

But I couldn't achieve it. The code didn't report an error, but the 316steel wasn't still in the manufacture of metal material. 

The code:

import olca

import uuid

client=olca.Client(8080)

category = olca.Category()

category.id = str(uuid.uuid4())

category.name = 'manufacture of metal material'

category.model_type = olca.ModelType.FLOW

client.insert(category)

steel = olca.Flow()

steel.category = category

steel.id = str(uuid.uuid4())

steel.flow_type = olca.FlowType.PRODUCT_FLOW

steel.name = "steel316"

steel.description = "Added from the olca-ipc python API..."

mass=client.find(olca.FlowProperty, 'Mass')

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]

client.insert(steel)

I believe something is wrong with my code. I hope to find the errors in the code.

Thanks!

in openLCA by (150 points)

1 Answer

+1 vote
by (5.2k points)
selected by
 
Best answer

Sorry if this answer is a little convoluted - a flow in olca-ipc is a categorized entity. And the category for a categorized entity is of type Ref, but you are trying to pass a category type (olca.Category()) . You could first define a Ref and then assign it as below. I believe there are ways to assign the category without the uuid, but I've always found it problematic. I should also note that this was done in olca-ipc version 0.0.10.

...
client.insert(category)
#I found as I was running your original code that openLCA
#is ignoring the UUID you assigned when it inserts, so
#I'm first finding the category in openLCA
#so that I can grab the UUID that was created upon insert.
found_category=client.find(model_type=olca.Category,name=category.name)
category_ref = olca.Ref()
category_ref.id = found_category.id
steel = olca.Flow()
steel.category = category_ref
by (1.0k points)
my approach is...
1. to insert a category with using "category.id = str(uuid.uuid4())"
2. Then querying all categories from the db through: "descriptor = client.get_descriptors(olca.Category)", and filtering for my newly inserted category, extracting the UUID which was created on the system-side
3. using "sub_cat = client.get(olca.Category, UUID)" to get the category object
4. assigning "new_flow.category = sub_cat"
...