Upstream trees
An upstream tree shows the contributions of the processes in the supply chain to the result of a result element. The root of the tree is the reference process (the final demand) of the calculated product system and the child nodes of a node are the providers of the product inputs (or waste outputs) of that node. The result of each node is the total result of that node including its upstream contributions.
The methods below return the child nodes of a given path in such an upstream tree. The path is a sequence of technosphere flows that describe the path to the parent node of the returned nodes. If the path is empty, the root of the tree is returned. Note that such an upstream tree can be infinitely deep when the calculated system has cycles.
| Method | Parameters | Returns |
|---|---|---|
upstream-interventions-of | enviFlow, path | List[UpstreamNode] |
upstream-impacts-of | impactCategory, path | List[UpstreamNode] |
upstream-costs-of | path | List[UpstreamNode] |
With the client libraries, the path is passed as list of
technosphere flows.
Via JSON-RPC, the path is passed as string in the field path; via REST, these
methods are POST requests with the path in the field path of the request
body. In the path string, each technosphere flow is encoded as
<provider-id>::<flow-id> and multiple technosphere flows are separated by /:
<provider-id>::<flow-id>/<provider-id>::<flow-id>/...
Intervention flows
The method upstream-interventions-of returns the upstream tree nodes of an
intervention flow.
Try it
You can edit and execute the example below. Just make sure an openLCA IPC
server is running on port 8080:
const o = await import("https://cdn.jsdelivr.net/npm/olca-ipc@2.6.2/+esm");
// connect to a local server running on port 8080
const client = o.IpcClient.on(8080);
const setup = o.CalculationSetup.of({
target: o.Ref.of({
id: "d3a9a9b2-ec3e-4811-8617-ae853573b50b",
refType: o.RefType.ProductSystem,
}),
});
const result = await client.calculate(setup);
await result.untilReady();
// select the first best inventory flow and expand a tree for it
const flow = (await result.getEnviFlows())[0];
console.log(`upstream tree for ${flow.flow?.name} (${flow.flow?.category})`);
await expand(result, flow, []);
// as always, dispose the result
result.dispose();
async function expand(r, flow, path) {
const level = path.length;
const indent = " ".repeat(level);
const unit = flow.flow?.refUnit;
const nodes = await r.getUpstreamInterventionsOf(flow, path);
for (const node of nodes) {
if (node.result === 0) {
continue;
}
const name = node.techFlow?.provider?.name;
const value = node.result?.toExponential(2);
console.log(`${indent}- ${value} ${unit} :: ${name}`);
// we stop the expansion after 3 levels; you can set other cut-offs like
// result contributions etc.
if (level < 3) {
const next = path.slice();
next.push(node.techFlow);
await expand(r, flow, next);
}
}
}
/*
upstream tree for COD, Chemical Oxygen Demand (Elementary flows/Emission to water/ground water)
- 1.73e-9 t :: ...
- 1.73e-9 t :: ...
- 7.21e-10 t :: ...
- 3.45e-10 t :: ...
- 2.04e-10 t :: ...
- ...
- 5.77e-10 t :: ...
- 4.40e-10 t :: ...
- 7.53e-11 t :: ...
- 3.21e-11 t :: ...
- ...
*/
Python IPC
import olca_ipc as ipc
import olca_schema as o
def main():
# calculate a result
client = ipc.Client(8080)
setup = o.CalculationSetup(
target=o.Ref(
id="d3a9a9b2-ec3e-4811-8617-ae853573b50b",
ref_type=o.RefType.ProductSystem,
)
)
result = client.calculate(setup)
result.wait_until_ready()
# select the first best inventory flow and expand a tree for it
flow = result.get_envi_flows()[0]
print(f"upstream tree for {flow.flow.name} ({flow.flow.category})")
expand(result, flow, [])
# as always, dispose the result
result.dispose()
def expand(r: ipc.IpcResult, flow: o.EnviFlow, path: list[o.TechFlow]):
level = len(path)
indent = " " * level
unit = flow.flow.ref_unit
nodes = r.get_upstream_interventions_of(flow, path)
for node in nodes:
if node.result == 0 or not node.tech_flow:
continue
name = node.tech_flow.provider.name
value = node.result
print(f"{indent}- {value:.2E} {unit} :: {name}")
# we stop the expansion after 3 levels; you can set other cut-offs like
# result contributions etc.
if level < 3:
expand(r, flow, path + [node.tech_flow])
pass
if __name__ == "__main__":
main()
Impact categories
The method upstream-impacts-of returns the upstream tree nodes of an impact
category.
Try it
You can edit and execute the example below. Just make sure an openLCA IPC
server is running on port 8080:
const o = await import("https://cdn.jsdelivr.net/npm/olca-ipc@2.6.2/+esm");
// connect to a local server running on port 8080
const client = o.IpcClient.on(8080);
const setup = o.CalculationSetup.of({
target: o.Ref.of({
id: "d3a9a9b2-ec3e-4811-8617-ae853573b50b",
refType: o.RefType.ProductSystem,
}),
impactMethod: o.Ref.of({
id: "07370e48-dde9-4248-9a9b-7255f701da89",
})
});
const result = await client.calculate(setup);
await result.untilReady();
// select the first best impact category and expand a tree for it
const indicator = (await result.getImpactCategories())[0];
console.log(`upstream tree for ${indicator.name}`);
await expand(result, indicator, []);
// as always, dispose the result
result.dispose();
async function expand(r, indicator, path) {
const level = path.length;
const indent = " ".repeat(level);
const unit = indicator.refUnit;
const nodes = await r.getUpstreamImpactsOf(indicator, path);
for (const node of nodes) {
if (node.result === 0) {
continue;
}
const name = node.techFlow?.provider?.name;
const value = node.result?.toExponential(2);
console.log(`${indent}- ${value} ${unit} :: ${name}`);
// we stop the expansion after 3 levels; you can set other cut-offs like
// result contributions etc.
if (level < 3) {
const next = path.slice();
next.push(node.techFlow);
await expand(r, indicator, next);
}
}
}
/*
upstream tree for Photochemical ozone formation
- 2.66e-2 kg NMVOC eq ...
- 2.66e-2 kg NMVOC eq ...
- 1.13e-2 kg NMVOC eq ...
- 4.69e-3 kg NMVOC eq ...
- 4.53e-3 kg NMVOC eq ...
- 1.41e-3 kg NMVOC eq ...
- 8.72e-3 kg NMVOC eq ...
- 4.18e-3 kg NMVOC eq ...
- 4.18e-3 kg NMVOC eq ...
- 1.01e-4 kg NMVOC eq ...
*/
Python IPC
The Python example below uses the utree module of the olca-ipc.py API which
makes working with upstream trees a bit more convenient:
import olca_schema as o
import olca_ipc as ipc
import olca_ipc.utree as utree
# maximum number of levels and child nodes that should be expanded
MAX_EXPAND_LEVELS = 3
MAX_EXPAND_NODES = 5
def main():
# calculate a result
client = ipc.Client()
setup = o.CalculationSetup(
target=o.Ref(
ref_type=o.RefType.Process,
id="2d1b0c1f-dd8f-3aea-bc50-bbd10acbd86d",
),
impact_method=o.Ref(id="99b9d86b-ec6f-4610-ba9f-68ebfe5691dd"),
)
result = client.calculate(setup)
result.wait_until_ready()
# select the first impact category for the tree
ref = result.get_impact_categories()[0]
print(f"\nTree for {ref.name}, results in {ref.ref_unit}:")
# create the upstream tree and expand it
root = utree.of(result, ref)
expand(root, 0)
# always dispose the result
result.dispose()
def expand(node: utree.Node, level: int):
"""This function recursively expands an upstream tree.
The maximum number of levels and maximum number of child nodes are defined
with the constants above. Note that an upstream tree can be
"""
indent = " " * level
print(f"{indent} - {node.provider.name} : {node.result}")
if level < MAX_EXPAND_LEVELS:
for c in node.childs[0:MAX_EXPAND_NODES]:
expand(c, level + 1)
if __name__ == "__main__":
main()
Costs
The method upstream-costs-of returns the upstream tree nodes of the life cycle
costs.