Skip to content

Commit

Permalink
Harmonize compilation notebooks with new chapter structure
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed May 21, 2024
1 parent 6c3f47c commit 901f542
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 60 deletions.
150 changes: 90 additions & 60 deletions data/chapter-7-compilation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,158 +3,188 @@
{
"cell_type": "code",
"execution_count": null,
"id": "abcb8379-6e4d-4ba6-bfda-69f579bec0d0",
"id": "71cc26bd-ed7a-4f8b-b43a-9744b32990d5",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import pyam\n",
"import nomenclature"
"import nomenclature\n",
"import ixmp4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a205e35e-9d6e-439a-90a7-4c7b828efebf",
"id": "f421d77e-952f-4946-ac33-7237b4a731af",
"metadata": {},
"outputs": [],
"source": [
"df_1 = pyam.IamDataFrame(\"source/7/Chapter7_Fig1_final_data.xlsx\")\n",
"df_2 = pyam.IamDataFrame(\"source/7/Chapter7_Fig2_final_data.xlsx\")\n",
"df_4 = pyam.IamDataFrame(\"source/7/Chapter7_Fig4_final_data.xlsx\")"
"iamc_args = dict(\n",
" model=\"State of CDR (2024) - Current CDR\",\n",
" scenario=\"Observed Data\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f87d2bce-9ae2-4802-b109-6ba7ac14edea",
"id": "e08ace55-3cc2-49b6-b03a-91f45be2d8fc",
"metadata": {},
"outputs": [],
"source": [
"df = pyam.concat(\n",
" [df_1, df_2, df_4]\n",
")"
"dsd = nomenclature.DataStructureDefinition(\"../definitions/\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68e07283-1cda-4634-9c51-27aeb9f56a51",
"id": "c5b3ee23-f07d-4832-a154-0ed8d7de796d",
"metadata": {},
"outputs": [],
"source": [
"df_2.variable"
"data = pd.read_excel(\n",
" \"source/7_Deployment/Indicator 15_Novel CDR volumes by method, year, and country.xlsx.xlsx\",\n",
" sheet_name=\"Dashboard\",\n",
" header=28,\n",
" nrows=8,\n",
" usecols=\"B:J\",\n",
").set_index(\"Year\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cef50a9f-1604-487b-b7e3-b83fea922231",
"id": "ae8810c4-2d4d-432c-afdf-f1763d8c5641",
"metadata": {},
"outputs": [],
"source": [
"dsd = nomenclature.DataStructureDefinition(\"../definitions/\")"
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4a1b0acf-2fa0-45fb-ae73-7de8121740d8",
"id": "e95a8933-448f-4c15-ab22-82a9a79a8fb5",
"metadata": {},
"outputs": [],
"source": [
"mapping = dict(\n",
" [\n",
" (i, (\n",
" i\n",
" .replace(\"Direct\", \"Conventional CDR\")\n",
" .replace(\"AR6 climate diagnostics\", \"AR6 Climate Diagnostics\")\n",
" .replace(\"Gross Emissions\", \"Gross Emissions|CO2 [Reductions relative to 2020]\")\n",
" .replace(\"CO2|CO2\", \"CO2\")\n",
" .replace(\"AR6 Reanalysis|OSCARv3.2|Carbon Removal|Land|Conventional CDR\", \"Carbon Removal|Land\")\n",
" )\n",
" )\n",
" for i in df.variable\n",
" ]\n",
")\n",
"\n",
"df.rename(variable=mapping, inplace=True)"
"df = pyam.IamDataFrame(\n",
" data,\n",
" **iamc_args,\n",
" value=data.columns,\n",
" unit=\"t CO2\",\n",
" region=\"World\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3f0baadb-561b-4b9f-af17-23673f6cecb4",
"id": "f553c9ee-b625-4dbc-b8d0-24839f1ef677",
"metadata": {},
"outputs": [],
"source": [
"df.rename(\n",
" model={\"SoCDR_v2\": \"State of CDR (2024) - Paris-Consistent Pathways\"},\n",
" inplace=True\n",
")"
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62c2796d-bf53-4d27-a382-bdcb2b7856ab",
"id": "689b261a-9002-4f7a-8f12-beee22796910",
"metadata": {},
"outputs": [],
"source": []
"source": [
"df.variable"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c76177ea-b936-4dac-bb9b-0122c286dd86",
"id": "fb8a5635-38ca-4074-879e-a27fdd95792a",
"metadata": {},
"outputs": [],
"source": [
"dsd.validate(df)"
"df.rename(\n",
" variable={\n",
" \"BECCS\": \"Bioenergy with CCS\",\n",
" \"Bio-oil Storage\": \"Bio-Oil Storage\",\n",
" \"DACCS\": \"Direct Air Capture with CCS\",\n",
" \"ERW\": \"Enhanced Weathering\",\n",
" \"Macroalgae\": \"Ocean Fertilization\",\n",
" \"Mineralisation\": \"Ocean Alkalinity Enhancement\",\n",
" },\n",
" inplace=True,\n",
")\n",
"df.rename(\n",
" variable=dict([(i, f\"Carbon Removal|Novel|{i}\") for i in df.variable]),\n",
" inplace=True,\n",
")\n",
"df.aggregate(f\"Carbon Removal|Novel\", append=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1d8ff3e1-1544-4de8-af9c-3fda301503e9",
"id": "10c3d999-5b68-4039-80a1-995bcbd15855",
"metadata": {},
"outputs": [],
"source": [
"df.to_excel(\"Chapter8_all_data.xlsx\")"
"df.rename(unit={\"t CO2\": \"t CO2/yr\"}, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "427623ef-7adf-466e-b80d-bbc5743d4a6b",
"id": "cafced12-86c6-4eeb-a40f-c784cf64f837",
"metadata": {},
"outputs": [],
"source": [
"df"
"df.convert_unit(\"t CO2/yr\", \"Mt CO2/yr\", inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fac58a68-aef7-4af2-802a-b0a73fb1ee5c",
"id": "51c6d43e-0f09-45c8-80e6-26be94fb9ccd",
"metadata": {},
"outputs": [],
"source": [
"df.to_ixmp4(\"socdr-dev\")"
"dsd.validate(df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c65308cd-ec11-44fd-8b17-8c903068be84",
"id": "c343ae17-15bf-47df-92b9-7f00597ffa69",
"metadata": {},
"outputs": [],
"source": [
"import ixmp4"
"df.set_meta(\"Chapter 7\", \"Chapter\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "02c8fbaa-7ad1-464b-8807-a58739ee5f52",
"metadata": {},
"outputs": [],
"source": [
"# df.to_ixmp4(\"socdr-dev\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75a641a4-0a7e-4494-8fd8-96376fb6066a",
"id": "23fc8727-3430-418c-a5d8-391412b6b6c4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "01c77b75-1116-4c63-a79c-35997dc791a3",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -164,57 +194,57 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5d7ebf49-1969-4370-b5ed-70932dbfddf4",
"id": "20d99902-8e56-4118-9bae-3dc31892d4ae",
"metadata": {},
"outputs": [],
"source": [
"platform.regions.create(\"World\", hierarchy=\"common\")"
"run = platform.runs.get(**iamc_args)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14eed714-893c-4bdb-8bca-6c9df27eaed1",
"id": "99fc724b-2be3-4246-9b90-db0e51ec8124",
"metadata": {},
"outputs": [],
"source": [
"platform.units.create(\"Gt CO2/yr\")"
"run.iamc.remove(run.iamc.tabulate())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "105233ad-b446-4a0a-8824-76465f2e7713",
"id": "97f4e475-96fc-4c3c-8e79-06d3fe14cda7",
"metadata": {},
"outputs": [],
"source": [
"df.set_meta(meta=\"Chapter 8\", name=\"Chapter\")"
"run.iamc.add(df.data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "778224ef-1007-4d2c-acbc-3352b17c943e",
"id": "1d232404-f13b-4022-baed-3af9c8641986",
"metadata": {},
"outputs": [],
"source": [
"pyam.iiasa.platforms()"
"platform.units.create(\"Mt CO2/yr\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf861090-ded2-4735-949e-306deab9fe21",
"id": "aac4503b-a057-472b-bade-78ab4088ffcc",
"metadata": {},
"outputs": [],
"source": [
"df"
"run.meta"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c1dc853d-b309-4929-87e0-79ebfb9f0dae",
"id": "26b699bb-39fb-434a-aa4b-230891f35661",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit 901f542

Please sign in to comment.