Sankey graph

The Sankey diagram visually represents the impacts of processes within the product system on specific flows/impact categories. The diagram shows both the direct contribution and the upstream total contribution of the process.

Source: openLCA 2 manual — Sankey diagram

openLCA provides an API to gather all the data necessary to create a Sankey graph. The Sankey class provides methods to gather this data. The Sankey diagram can be created to show the flow of material as well as impacts in the product system. Here is an example of how to extract the data for a maximum number of nodes MAX_NODES and a minimum share (relative impact of a provider on the total impacts) MIN_SHARE.

from java.util.function import Consumer
from org.openlca.app.util import Labels

# first step is to build the Sankey diagram:
MAX_NODES = 50
MIN_SHARE = 0.1

# retrieve the first impact category
category_descriptor = Descriptor.of(method.impactCategories[0])

# build the Sankey object
sankey = (
    Sankey.of(category_descriptor, result.provider())
    .withMinimumShare(MIN_SHARE)
    .withMaximumNodeCount(MAX_NODES)
    .build()
)

# The Sankey diagram can then be traversed to get the data for each node. For that, we use a
# consumer method (this is quite specific to Java). The consumer method accepts the `Sankey.Node`
# object and execute some operations with it.

class AddNodeConsumer(Consumer):
    def accept(self, node):  # type: (Sankey.Node) -> None
        print("\n %s" % (Labels.name(node.product)))
        print(" ID: %s" % (node.product.provider().id))
        print(" Total impact: %s" % (node.total))
        print(" Direct impact: %s" % (node.direct))
        print(" Relative share: %s" % (node.share))
        print(" Cutoff: %s" % (MIN_SHARE))
        print(" Providers:")
        for n in node.providers:
            print("  %s" % (n.product.provider().id))

sankey.traverse(AddNodeConsumer())