Skip to content

Commit

Permalink
Update tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Mar 14, 2024
1 parent 801ec77 commit 8887d29
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions tutorial/westeros/westeros_sankey.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\")"
]
},
{
Expand All @@ -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 ``\"\"``.)"
]
},
{
Expand All @@ -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\": {\"-\": \"\"}})"
Expand All @@ -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!"
]
Expand 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\")"
]
},
{
Expand All @@ -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()"
]
},
{
Expand Down Expand Up @@ -153,7 +191,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.10.12"
},
"orig_nbformat": 4
},
Expand Down

0 comments on commit 8887d29

Please sign in to comment.