I'd like to automatize the process of generating product system calculations using the olca-ipc python package. The excel with calculations results contains tabs like:
The only tab I don't know how to recreate is the last one: total upstream impacts. I use olca-ipc 2.4.0 (
https://github.com/GreenDelta/olca-ipc.py/tree/v2.4.0) and OpenLCA 2.4. It seems to me that I should use function
get_upstream_impacts_of but it produces wrong values for some processes. It also produces many good values which gives me impression that I am close but it's not clear to me what I do wrong that not all of them are correct. Could you tell what's the logic behind the "total upstream impacts" tab, which olca-ipc function should be used to recreate it?
client = ipc.Client(endpoint=<port>)
impact_method = client.find(model_type=o.ImpactMethod, name=<impact category name>)
setup = o.CalculationSetup(
target=o.Ref(ref_type=o.RefType.ProductSystem, id=<product system id>),
impact_method=impact_method,
nw_set=None,
with_costs=False,
with_regionalization=False,
allocation=AllocationType.USE_DEFAULT_ALLOCATION)
result: ipc.Result = client.calculate(setup)
result.wait_until_ready()
impact_categories = result.get_impact_categories()
result.wait_until_ready()
tech_flows = result.get_tech_flows()
result.wait_until_ready()
rows = []
for impact_category in impact_categories:
for tech_flow in tech_flows:
items = result.get_upstream_impacts_of(
impact_category=impact_category,
path=[tech_flow])
for item in items:
row = [
impact_category.id,
impact_category.name,
impact_category.ref_unit,
item.tech_flow.provider.id,
item.tech_flow.provider.name,
item.tech_flow.provider.location,
item.result,
]
rows.append(row)