Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sankey Graphs

This method returns a graph data structure with which Sankey diagrams can be constructed.

MethodParametersReturns
sankeyconfig: SankeyRequestSankeyGraph

Via REST, it is a POST request with the Sankey request as body: POST result/{result-id}/sankey. In Python, the method is Result.get_sankey_graph.

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");

const client = o.RestClient.on("http://localhost:8080");

// calculate the result
const result = await client.calculate(o.CalculationSetup.of({
  target: o.Ref.of({
    refType: o.RefType.ProductSystem,
    id: "7d1cbce0-b5b3-47ba-95b5-014ab3c7f569",
  }),
  impactMethod: o.Ref.of({ id: "99b9d86b-ec6f-4610-ba9f-68ebfe5691dd" }),
}));
await result.untilReady();

const g = await result.getSankeyGraph(o.SankeyRequest.of({
  impactCategory: o.Ref.of({ id: "b8658d7c-9c6e-4361-acbf-3bd6d9fef8c9" }),
  maxNodes: 10,
}));
console.log(
  `loaded a graph with ${g.nodes?.length} nodes and ${g.edges?.length} edges`,
);
result.dispose();

Python IPC

import olca_ipc.rest as ipc
import olca_schema as o

# in this example we use the REST client
client = ipc.RestClient("http://localhost:8080")

# calculate a result for the default quantitative reference of a product system
result = client.calculate(
    o.CalculationSetup(
        target=o.Ref(
            ref_type=o.RefType.ProductSystem,
            id="7d1cbce0-b5b3-47ba-95b5-014ab3c7f569",
        ),
        impact_method=o.Ref(id="99b9d86b-ec6f-4610-ba9f-68ebfe5691dd"),
    )
)
result.wait_until_ready()

# get the Sankey graph for an impact category
g = result.get_sankey_graph(
    o.SankeyRequest(
        impact_category=o.Ref(id="b8658d7c-9c6e-4361-acbf-3bd6d9fef8c9"),
        max_nodes=10,
    )
)
print(f"loaded a graph with {len(g.nodes)} nodes and {len(g.edges)} edges")
# prints something like: loaded a graph with 10 nodes and 14 edges

# finally, dispose the result
result.dispose()