diff --git a/tutorial/westeros/westeros_sankey.ipynb b/tutorial/westeros/westeros_sankey.ipynb index cda97290d..a172a9d7e 100644 --- a/tutorial/westeros/westeros_sankey.ipynb +++ b/tutorial/westeros/westeros_sankey.ipynb @@ -25,11 +25,10 @@ "source": [ "import ixmp\n", "\n", - "import message_ix\n", - "from message_ix.report import Reporter\n", + "from message_ix import Scenario\n", "\n", "mp = ixmp.Platform()\n", - "scenario = message_ix.Scenario(mp, model=\"Westeros Electrified\", scenario=\"baseline\")" + "scenario = Scenario(mp, model=\"Westeros Electrified\", scenario=\"baseline\")" ] }, { @@ -51,7 +50,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Create the reporter object. (Since \"-\" is not a unit, we replace it by \"\".)" + "Create the reporter object. (Since ``\"-\"`` is not a unit, we replace it by ``\"\"``.)" ] }, { @@ -60,6 +59,8 @@ "metadata": {}, "outputs": [], "source": [ + "from message_ix.report import Reporter\n", + "\n", "rep = Reporter.from_scenario(scenario)\n", "\n", "rep.configure(units={\"replace\": {\"-\": \"\"}})" @@ -85,7 +86,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The utility function `sankey_mapper(df, year, region, flows_not_needed=[], variables_not_needed=[])` can be used to create the required mapping for the `plot.sankey()` function of the `pyam` package.\n", + "The utility function `sankey_mapper(df, year, region, exclude=[])` can be used to create the required mapping for the `figures.sankey()` function of the `pyam` package.\n", "\n", "In some models it might be necessary to exclude variables and flow to get meaningful sankey diagrams. But let´s try with all!" ] @@ -96,7 +97,9 @@ "metadata": {}, "outputs": [], "source": [ - "mapping = message_ix.util.sankey_mapper(df, year=700, region=\"Westeros\")" + "from message_ix.util.sankey import sankey_mapper\n", + "\n", + "mapping = sankey_mapper(df, year=700, region=\"Westeros\")" ] }, { @@ -114,10 +117,45 @@ "metadata": {}, "outputs": [], "source": [ - "import plotly.offline as pof\n", + "from pyam.figures import sankey\n", "\n", - "fig = df.filter(year=700).plot.sankey(mapping=mapping)\n", - "pof.plot(fig) # opens a new window in your browser" + "fig = sankey(df=df.filter(year=700), mapping=mapping)\n", + "fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mapping_without_final_electricity = sankey_mapper(\n", + " df, year=700, region=\"Westeros\", exclude=[\"final|electricity\"]\n", + ")\n", + "mapping_without_final_electricity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig = sankey(df=df.filter(year=700), mapping=mapping_without_final_electricity)\n", + "fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mapping_without_wind_ppl_standard = sankey_mapper(\n", + " df, year=700, region=\"Westeros\", exclude=[\"wind_ppl|standard\"]\n", + ")\n", + "fig = sankey(df=df.filter(year=700), mapping=mapping_without_wind_ppl_standard)\n", + "fig.show()" ] }, { @@ -153,7 +191,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.18" + "version": "3.10.12" }, "orig_nbformat": 4 },