{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting Started\n", "\n", "This is a simple example of the basic capabilities of `aneris`.\n", "\n", "First, model and history data are read in. The model is then harmonized. Finally, output is analyzed." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "\n", "import aneris\n", "from aneris.tutorial import load_data\n", "\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `driver` is used to execute the harmonization. It will handle the data formatting needed to execute the harmonizaiton operation and stores the harmonized results until they are needed.\n", "\n", "Some logging output is provided. It can be suppressed with \n", "\n", "```\n", "aneris.logger().setLevel('WARN')\n", "```" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:root:Downselecting prefix|suffix variables\n", "INFO:root:Translating to standard format\n", "c:\\users\\gidden\\work_tmp\\aneris\\aneris\\utils.py:634: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`\n", " df.loc[where, numcols(df)] *= 1e3\n", "INFO:root:Aggregating historical values to native regions\n", "INFO:root:Harmonizing (with example methods):\n", "INFO:root: method default \\\n", "region gas sector \n", "regionc BC prefix|sector1|suffix reduce_ratio_2100 reduce_ratio_2050 \n", " prefix|sector2|suffix reduce_ratio_2050 reduce_ratio_2050 \n", " prefix|suffix reduce_ratio_2050 reduce_ratio_2050 \n", "\n", " override \n", "region gas sector \n", "regionc BC prefix|sector1|suffix reduce_ratio_2100 \n", " prefix|sector2|suffix NaN \n", " prefix|suffix NaN \n", "INFO:root:and override methods:\n", "INFO:root:region sector gas\n", "regionc prefix|sector1|suffix BC reduce_ratio_2100\n", "Name: method, dtype: object\n", "INFO:root:Harmonizing with reduce_ratio_2100\n", "INFO:root:Harmonizing with reduce_ratio_2050\n", "WARNING:root:Removing sector aggregates. Recalculating with harmonized totals.\n", "c:\\users\\gidden\\work_tmp\\aneris\\aneris\\utils.py:447: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n", " rows = self.df.groupby(grp_idx).sum().reset_index()\n", "INFO:root:Translating to IAMC template\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "BAZ\n", "region sector gas\n", "regionc prefix|sector1|suffix BC reduce_ratio_2100\n", "Name: method, dtype: object\n", "BAZZ\n", " method default \\\n", "region gas sector \n", "regionc BC prefix|sector1|suffix reduce_ratio_2100 reduce_ratio_2050 \n", " prefix|sector2|suffix reduce_ratio_2050 reduce_ratio_2050 \n", " prefix|suffix reduce_ratio_2050 reduce_ratio_2050 \n", "\n", " override \n", "region gas sector \n", "regionc BC prefix|sector1|suffix reduce_ratio_2100 \n", " prefix|sector2|suffix NaN \n", " prefix|suffix NaN \n" ] } ], "source": [ "model, hist, driver = load_data()\n", "for scenario in driver.scenarios():\n", " driver.harmonize(scenario)\n", "harmonized, metadata, diagnostics = driver.harmonized_results()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All data of interest is combined in order to easily view it. We will specifically investigate output for the `World` in this example. A few operations are performed in order to get the data into a plotting-friendly format." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "data = pd.concat([hist, model, harmonized])\n", "df = data[data.Region.isin(['World'])]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "df = pd.melt(df, id_vars=aneris.iamc_idx, value_vars=aneris.numcols(df), \n", " var_name='Year', value_name='Emissions')\n", "df['Label'] = df['Model'] + ' ' + df['Variable']" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Model | \n", "Scenario | \n", "Region | \n", "Variable | \n", "Year | \n", "Emissions | \n", "Label | \n", "
|---|---|---|---|---|---|---|---|
| 0 | \n", "History | \n", "scen | \n", "World | \n", "prefix|Emissions|BC|sector1|suffix | \n", "2000 | \n", "4.0 | \n", "History prefix|Emissions|BC|sector1|suffix | \n", "
| 1 | \n", "History | \n", "scen | \n", "World | \n", "prefix|Emissions|BC|sector2|suffix | \n", "2000 | \n", "6.0 | \n", "History prefix|Emissions|BC|sector2|suffix | \n", "
| 2 | \n", "History | \n", "scen | \n", "World | \n", "prefix|Emissions|BC|suffix | \n", "2000 | \n", "10.0 | \n", "History prefix|Emissions|BC|suffix | \n", "
| 3 | \n", "model | \n", "sspn | \n", "World | \n", "prefix|Emissions|BC|sector1|suffix | \n", "2000 | \n", "NaN | \n", "model prefix|Emissions|BC|sector1|suffix | \n", "
| 4 | \n", "model | \n", "sspn | \n", "World | \n", "prefix|Emissions|BC|sector2|suffix | \n", "2000 | \n", "NaN | \n", "model prefix|Emissions|BC|sector2|suffix | \n", "