Skip to content

Commit

Permalink
EODC
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Feb 21, 2024
1 parent 542c483 commit 7ed2c39
Show file tree
Hide file tree
Showing 21 changed files with 146,155 additions and 785,613 deletions.
306 changes: 306 additions & 0 deletions dev/.ipynb_checkpoints/metals-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"id": "c9c8dc83-f048-488b-a8c3-a6c2e212a49e",
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"arr = xr.open_dataarray(\"results_image_SSP2_metals.nc\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "861fedb1-f9cc-4605-ae9e-fe7cbb1fb26c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Coordinates:\n",
" * year (year) int32 2005 2006 2007 2008 ... 2097 2098 2099 2100\n",
" * variable (variable) object 'Biomass CHP' ... 'Wind Onshore'\n",
" * region (region) object 'BRA' 'CAN' 'CEU' ... 'USA' 'WAF' 'WEU'\n",
" * impact_category (impact_category) object 'RELICS - metals extraction - A...\n",
" * act_category (act_category) object 'Manufacture of basic chemicals' ....\n",
" * scenario (scenario) object 'SSP2-RCP19'\n",
" * model (model) object 'image'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.coords"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "0030853e-aa98-4a28-81c0-98c5eb75c798",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>model</th>\n",
" <th>scenario</th>\n",
" <th>region</th>\n",
" <th>impact_category</th>\n",
" <th>variable</th>\n",
" <th>year</th>\n",
" <th>act_category</th>\n",
" <th>value</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>image</td>\n",
" <td>SSP2-RCP19</td>\n",
" <td>BRA</td>\n",
" <td>RELICS - metals extraction - Aluminium</td>\n",
" <td>Biomass CHP</td>\n",
" <td>2005</td>\n",
" <td>Manufacture of basic chemicals</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>image</td>\n",
" <td>SSP2-RCP19</td>\n",
" <td>BRA</td>\n",
" <td>RELICS - metals extraction - Aluminium</td>\n",
" <td>Biomass CHP CCS</td>\n",
" <td>2005</td>\n",
" <td>Manufacture of basic chemicals</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>image</td>\n",
" <td>SSP2-RCP19</td>\n",
" <td>BRA</td>\n",
" <td>RELICS - metals extraction - Aluminium</td>\n",
" <td>Biomass IGCC</td>\n",
" <td>2005</td>\n",
" <td>Manufacture of basic chemicals</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>image</td>\n",
" <td>SSP2-RCP19</td>\n",
" <td>BRA</td>\n",
" <td>RELICS - metals extraction - Aluminium</td>\n",
" <td>Biomass IGCC CCS</td>\n",
" <td>2005</td>\n",
" <td>Manufacture of basic chemicals</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>image</td>\n",
" <td>SSP2-RCP19</td>\n",
" <td>BRA</td>\n",
" <td>RELICS - metals extraction - Aluminium</td>\n",
" <td>Biomass ST</td>\n",
" <td>2005</td>\n",
" <td>Manufacture of basic chemicals</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" model scenario region impact_category \\\n",
"0 image SSP2-RCP19 BRA RELICS - metals extraction - Aluminium \n",
"1 image SSP2-RCP19 BRA RELICS - metals extraction - Aluminium \n",
"2 image SSP2-RCP19 BRA RELICS - metals extraction - Aluminium \n",
"3 image SSP2-RCP19 BRA RELICS - metals extraction - Aluminium \n",
"4 image SSP2-RCP19 BRA RELICS - metals extraction - Aluminium \n",
"\n",
" variable year act_category value \n",
"0 Biomass CHP 2005 Manufacture of basic chemicals NaN \n",
"1 Biomass CHP CCS 2005 Manufacture of basic chemicals NaN \n",
"2 Biomass IGCC 2005 Manufacture of basic chemicals NaN \n",
"3 Biomass IGCC CCS 2005 Manufacture of basic chemicals NaN \n",
"4 Biomass ST 2005 Manufacture of basic chemicals NaN "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = arr.to_dataframe(\"x\").unstack()[\"x\"].reset_index().melt(id_vars=[\n",
" \"model\", \"scenario\", \"region\", \"impact_category\", \"variable\", \"year\"\n",
"])\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "523aa0b7-5f9f-46da-9366-14a6d0631f1f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"704704"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"years = [2005, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090, 2100]\n",
"df = df.loc[df[\"year\"].isin(years)]\n",
"len(df)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "ab9d7898-bea5-42a8-b1ae-79bce25533a9",
"metadata": {},
"outputs": [],
"source": [
"df[\"impact_category\"] = df[\"impact_category\"].str.replace(\"RELICS - metals extraction - \", \"\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "48494068-488f-4682-87ca-cf79768417a8",
"metadata": {},
"outputs": [],
"source": [
"df[\"value\"] /= 1000 # kg to tons"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "6d17f96f-9c08-4770-9712-caf4cf4da41d",
"metadata": {},
"outputs": [],
"source": [
"df = df.loc[~df[\"value\"].isnull()]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "5f8ec078-301a-4e3d-ac99-699b64065867",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"129695"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(df)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d1080e41-2ab2-4e15-81c4-410879f422b8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"100%\"\n",
" height=\"500\"\n",
" src=\"pivottable_all_metals.html\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x1294aeee0>"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from pivottablejs import pivot_ui\n",
"from IPython.display import HTML\n",
"pivot_ui(df, outfile_path='pivottable_all_metals.html')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e270b389-27b8-4c09-a396-2162982e60eb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 7ed2c39

Please sign in to comment.