sankey: generate Sankey diagrams

See Reporter.add_sankey() and the westeros_sankey.ipynb tutorial.

API reference

message_ix.tools.sankey.exclude_flow(flow: tuple[str, str], exclude: list[str]) bool[source]

Return True if either the source or target of flow is in exclude.

message_ix.tools.sankey.get_source_and_target(variable: str) tuple[str, str][source]

Get source and target for the variable flow.

message_ix.tools.sankey.get_start_and_end_index(variable: str) tuple[list[int], list[int]][source]

Get indices of source and target in variable name.

message_ix.tools.sankey.map_for_sankey(iam_df: pyam.IamDataFrame, node: str, exclude: list[str] = []) dict[str, tuple[str, str]][source]

Maps input to output flows to enable Sankey diagram.

Parameters:
  • iam_df (pyam.IamDataframe) – Data to plot as Sankey diagram.

  • node (str) – The node (MESSAGEix) or region (pyam) to plot.

  • exclude (list[str], optional) – Flows to omit from the diagram. By default, nothing is excluded.

Returns:

mapping from variable names to 2-tuples of their (inputs, output) flows.

Return type:

dict