Skip to content

Commit

Permalink
Latest updates to OnSSET code
Browse files Browse the repository at this point in the history
New "onsset_replication" folder required from Zenodo for new code to work.
  • Loading branch information
GregoryIreland committed Oct 6, 2023
1 parent b5508d9 commit eef7b7b
Show file tree
Hide file tree
Showing 5 changed files with 1,685 additions and 1,190 deletions.
53 changes: 18 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@

onsset/onsset_replication/clusters/clusters_zambia_220k_geo_input.csv
onsset/onsset_replication/clusters/zambia_onsset_input_calibrated.csv
onsset/onsset_replication/mled/nest_clusters/zambia_nest_clusters_with_mled_loads_ssp2_rcp60_0.998_0.248_0.1_tot_lat_d.gpkg
onsset/onsset_replication/mled/nest_clusters/zambia_nest_clusters_with_mled_loads_ssp2_rcp60_1_0.5_0.5_tot_lat_d.gpkg
onsset/onsset_replication/mled/nest_clusters/zambia_nest_clusters_with_mled_loads_UR_ssp2_rcp60_0.998_0.248_0.1_tot_lat_d.gpkg
onsset/onsset_replication/mled/nest_clusters/zambia_nest_clusters_with_mled_loads_UR_ssp2_rcp60_1_0.5_0.5_tot_lat_d.gpkg
onsset/onsset_replication/mled/onsset_clusters/zambia_onsset_clusters_with_mled_loads_ssp2_rcp60_0.998_0.248_0.1_tot_lat_d.gpkg
onsset/onsset_replication/mled/onsset_clusters/zambia_onsset_clusters_with_mled_loads_ssp2_rcp60_1_0.5_0.5_tot_lat_d.gpkg
onsset/onsset_replication/mled/zambia_el_acc_baseline_trend_targets.xlsm
onsset/onsset_replication/mled/~$zambia_el_acc_baseline_trend_targets.xlsm
onsset/onsset_replication/onsset_input_files/zambia_onsset_specifications_calibrated_baseline.xlsx
onsset/onsset_replication/onsset_input_files/zambia_onsset_specifications_calibrated_moderate_development.xlsx
onsset/results/onsset_full_results/baseline_zm-2-0_0_0_0_0_0.csv
onsset/results/onsset_full_results/moderate_development_zm-2-0_0_0_0_0_0.csv
onsset/results/onsset_summary_results/baseline_zm-2-0_0_0_0_0_0_summary.csv
onsset/results/onsset_summary_results/moderate_development_zm-2-0_0_0_0_0_0_summary.csv
onsset/mled_processed_input_files/zambia_onsset_input_mled_demands_moderate_development.csv
onsset/mled_processed_input_files/zambia_onsset_input_mled_demands_baseline.csv
onsset/onsset_replication/mled/nest_clusters/zambia_nest_clusters_with_mled_loads_ssp2_rcp26_1_0.75_0.75_tot_lat_d.gpkg
onsset/onsset_replication/mled/nest_clusters/zambia_nest_clusters_with_mled_loads_UR_ssp2_rcp26_1_0.75_0.75_tot_lat_d.gpkg
onsset/onsset_replication/mled/onsset_clusters/1_zambia_onsset_clusters_with_mled_loads_ssp2_rcp60_0.998_0.248_0.1_tot_lat_d.gpkg
onsset/onsset_replication/mled/onsset_clusters/2_zambia_onsset_clusters_with_mled_loads_ssp2_rcp60_1_0.5_0.5_tot_lat_d.gpkg
onsset/onsset_replication/mled/onsset_clusters/3_zambia_onsset_clusters_with_mled_loads_ssp2_rcp26_1_0.75_0.75_tot_lat_d.gpkg
onsset/onsset_replication/onsset_input_files/zambia_onsset_specifications_calibrated_sustainable_development.xlsx
onsset/onsset_replication/zambia_el_acc_baseline_trend_targets.xlsm
onsset/results/onsset_full_results/sustainable_development_zm-2-0_0_0_0_0_0.csv
onsset/results/onsset_summary_results/sustainable_development_zm-2-0_0_0_0_0_0_summary.csv
onsset/mled_processed_input_files/zambia_onsset_input_mled_demands_sustainable_development.csv
onsset/onsset_replication/mled_processed_input_files_reference/.gitkeep
onsset/onsset_replication/mled_processed_input_files_reference/mled_processed_input_files/.gitkeep
onsset/onsset_replication/mled_processed_input_files_reference/mled_processed_input_files/ReadMe.md
onsset/onsset_replication/mled_processed_input_files_reference/mled_processed_input_files/zambia_onsset_input_mled_demands_baseline.csv
onsset/onsset_replication/mled_processed_input_files_reference/mled_processed_input_files/zambia_onsset_input_mled_demands_moderate_development.csv
onsset/onsset_replication/mled_processed_input_files_reference/mled_processed_input_files/zambia_onsset_input_mled_demands_sustainable_development.csv
onsset/onsset_replication/mled_processed_input_files_reference/zambia_onsset_input_mled_demands_baseline.csv
onsset/onsset_replication/mled_processed_input_files_reference/zambia_onsset_input_mled_demands_moderate_development.csv
onsset/onsset_replication/mled_processed_input_files_reference/zambia_onsset_input_mled_demands_sustainable_development.csv
onsset/onsset_replication/nest_summaries/energy_allocation_results_for_nest.csv
mled/gadm36_ZMB_0_sp.rds
mled/gadm36_ZMB_1_sp.rds
mled/gadm36_ZMB_2_sp.rds
Expand Down Expand Up @@ -107,3 +72,21 @@ wiki/Wiki RE4AFAGRI_ideas.docx
wiki/wiki_logo.drawio
nest/message_ix_models/data/water/demands/harmonized/Thumbs.db
mled/desktop.ini
onsset/mled_processed_input_files/1_zambia_onsset_input_mled_demands_baseline.csv
onsset/mled_processed_input_files/2_zambia_onsset_input_mled_demands_improved_access.csv
onsset/mled_processed_input_files/3_zambia_onsset_input_mled_demands_ambitious_development.csv
onsset/onsset_replication/clusters/clusters_zambia_220k_geo_input.csv
onsset/onsset_replication/clusters/zambia_onsset_input_calibrated.csv
onsset/onsset_replication/mled_processed_input_files_reference/1_zambia_onsset_input_mled_demands_baseline.csv
onsset/onsset_replication/mled_processed_input_files_reference/2_zambia_onsset_input_mled_demands_improved_access.csv
onsset/onsset_replication/mled_processed_input_files_reference/3_zambia_onsset_input_mled_demands_ambitious_development.csv
onsset/onsset_replication/nest_summaries/energy_allocation_results_for_nest.csv
onsset/onsset_replication/onsset_input_files/1_zambia_onsset_specifications_calibrated_baseline.xlsx
onsset/onsset_replication/onsset_input_files/2_zambia_onsset_specifications_calibrated_improved_access.xlsx
onsset/onsset_replication/onsset_input_files/3_zambia_onsset_specifications_calibrated_ambitious_development.xlsx
onsset/results/onsset_full_results/1_baseline_zm-2-0_0_0_0_0_0.csv
onsset/results/onsset_full_results/2_improved_access_zm-2-0_0_0_0_0_0.csv
onsset/results/onsset_full_results/3_ambitious_development_zm-2-0_0_0_0_0_0.csv
onsset/results/onsset_summary_results/1_baseline_zm-2-0_0_0_0_0_0_summary.csv
onsset/results/onsset_summary_results/2_improved_access_zm-2-0_0_0_0_0_0_summary.csv
onsset/results/onsset_summary_results/3_ambitious_development_zm-2-0_0_0_0_0_0_summary.csv
153 changes: 78 additions & 75 deletions onsset/MLED_extraction_to_OnSSET.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"id": "ff9c35e3-2a30-4f9c-a4d4-f94566be2c4f",
"metadata": {
"tags": []
Expand All @@ -29,15 +29,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"id": "fd252149-c96e-41da-aa9b-1cbeb70077b0",
"metadata": {},
"outputs": [],
"source": [
"#Important! this code will not run unless the \"onsset_replication\" data folder is downloaded and included in the file structure as in the instructions\n",
"\n",
"years = [2020, 2030, 2040, 2050, 2060]\n",
"scenarios = [\"baseline\", \"moderate_development\", \"sustainable_development\"]\n",
"years = [2020, 2030, 2040, 2050, 2060] #all years with data are included, even though only 2030 and 2060 are used as future milestone years.\n",
"scenarios = [\"baseline\", \"improved_access\", \"ambitious_development\"]\n",
"#scenarios = [\"baseline\"] #uncomment this is you only want to run the single baseline scenario (sometimes easier for testing)\n",
"\n",
"mled_scenario_directory = r\"onsset_replication/mled/onsset_clusters\"\n",
"mled_scenario_filenames = list(pathlib.Path(mled_scenario_directory).glob('*.gpkg'))\n",
Expand All @@ -48,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "111491a1-23f4-4134-ba70-4168d904bd6d",
"metadata": {},
"outputs": [],
Expand All @@ -60,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 4,
"id": "8f00a32a-7e0b-4851-977b-c1d47ccbe4e4",
"metadata": {
"tags": []
Expand All @@ -73,84 +74,87 @@
"\n",
"\n",
"MLED Scenario processing into OnSSET input files for: ' baseline '...\n",
"Taken from file at: onsset_replication\\mled\\onsset_clusters\\1_zambia_onsset_clusters_with_mled_loads_ssp2_rcp60_0.998_0.248_0.1_tot_lat_d.gpkg\n",
"Total Demand--2020: 13.12 TWh\n",
"Total Demand--2030: 40.47 TWh\n",
"Total Demand--2040: 46.55 TWh\n",
"Total Demand--2050: 58.27 TWh\n",
"Total Demand--2060: 75.08 TWh\n",
"Per Capita Demand--2020: 1340.96 kWh/cap/year\n",
"Per Capita Demand--2030: 2060.43 kWh/cap/year\n",
"Per Capita Demand--2040: 2172.49 kWh/cap/year\n",
"Per Capita Demand--2050: 2336.74 kWh/cap/year\n",
"Per Capita Demand--2060: 2636.78 kWh/cap/year\n",
"Population--2020: 19255577.0\n",
"Population--2030: 24179801.0\n",
"Population--2040: 29271172.0\n",
"Population--2050: 34015019.0\n",
"Population--2060: 38279939.0\n",
"Taken from file at: onsset_replication\\mled\\onsset_clusters\\1_zambia_onsset_clusters_with_mled_loads_baseline_tot_lat_d.gpkg\n",
"Total Demand--2020: 13.44 TWh\n",
"Total Demand--2030: 38.08 TWh\n",
"Total Demand--2040: 48.83 TWh\n",
"Total Demand--2050: 63.14 TWh\n",
"Total Demand--2060: 82.1 TWh\n",
"Per Capita Demand--2020: 1385.09 kWh/cap/year\n",
"Per Capita Demand--2030: 2097.12 kWh/cap/year\n",
"Per Capita Demand--2040: 2230.1 kWh/cap/year\n",
"Per Capita Demand--2050: 2430.23 kWh/cap/year\n",
"Per Capita Demand--2060: 2746.72 kWh/cap/year\n",
"Population--2020: 19234648.0\n",
"Population--2030: 24175461.0\n",
"Population--2040: 29289410.0\n",
"Population--2050: 34055014.0\n",
"Population--2060: 38341584.0\n",
"Urban Pop Percentage--2020: 0.4187\n",
"Urban Pop Percentage--2030: 0.4762\n",
"Urban Pop Percentage--2040: 0.53\n",
"Urban Pop Percentage--2050: 0.5787\n",
"Urban Pop Percentage--2060: 0.6221\n",
"Urban Pop Percentage--2040: 0.5299\n",
"Urban Pop Percentage--2050: 0.5786\n",
"Urban Pop Percentage--2060: 0.622\n",
"\n",
"\n",
"MLED Scenario processing into OnSSET input files for: ' moderate_development '...\n",
"Taken from file at: onsset_replication\\mled\\onsset_clusters\\2_zambia_onsset_clusters_with_mled_loads_ssp2_rcp60_1_0.5_0.5_tot_lat_d.gpkg\n",
"Total Demand--2020: 13.16 TWh\n",
"Total Demand--2030: 40.54 TWh\n",
"Total Demand--2040: 46.66 TWh\n",
"Total Demand--2050: 58.46 TWh\n",
"Total Demand--2060: 75.42 TWh\n",
"Per Capita Demand--2020: 1349.56 kWh/cap/year\n",
"Per Capita Demand--2030: 2071.5 kWh/cap/year\n",
"Per Capita Demand--2040: 2187.25 kWh/cap/year\n",
"Per Capita Demand--2050: 2357.52 kWh/cap/year\n",
"Per Capita Demand--2060: 2667.59 kWh/cap/year\n",
"Population--2020: 19255577.0\n",
"Population--2030: 24179801.0\n",
"Population--2040: 29271172.0\n",
"Population--2050: 34015019.0\n",
"Population--2060: 38279939.0\n",
"MLED Scenario processing into OnSSET input files for: ' improved_access '...\n",
"Taken from file at: onsset_replication\\mled\\onsset_clusters\\2_zambia_onsset_clusters_with_mled_loads_improved_access_tot_lat_d.gpkg\n",
"Total Demand--2020: 13.47 TWh\n",
"Total Demand--2030: 37.89 TWh\n",
"Total Demand--2040: 48.74 TWh\n",
"Total Demand--2050: 63.17 TWh\n",
"Total Demand--2060: 82.21 TWh\n",
"Per Capita Demand--2020: 1393.39 kWh/cap/year\n",
"Per Capita Demand--2030: 2081.45 kWh/cap/year\n",
"Per Capita Demand--2040: 2226.76 kWh/cap/year\n",
"Per Capita Demand--2050: 2439.76 kWh/cap/year\n",
"Per Capita Demand--2060: 2763.57 kWh/cap/year\n",
"Population--2020: 19234648.0\n",
"Population--2030: 24175461.0\n",
"Population--2040: 29289410.0\n",
"Population--2050: 34055014.0\n",
"Population--2060: 38341584.0\n",
"Urban Pop Percentage--2020: 0.4187\n",
"Urban Pop Percentage--2030: 0.4762\n",
"Urban Pop Percentage--2040: 0.53\n",
"Urban Pop Percentage--2050: 0.5787\n",
"Urban Pop Percentage--2060: 0.6221\n",
"Urban Pop Percentage--2040: 0.5299\n",
"Urban Pop Percentage--2050: 0.5786\n",
"Urban Pop Percentage--2060: 0.622\n",
"\n",
"\n",
"MLED Scenario processing into OnSSET input files for: ' sustainable_development '...\n",
"Taken from file at: onsset_replication\\mled\\onsset_clusters\\3_zambia_onsset_clusters_with_mled_loads_ssp2_rcp26_1_0.75_0.75_tot_lat_d.gpkg\n",
"Total Demand--2020: 13.19 TWh\n",
"Total Demand--2030: 40.58 TWh\n",
"Total Demand--2040: 46.76 TWh\n",
"Total Demand--2050: 58.66 TWh\n",
"Total Demand--2060: 75.81 TWh\n",
"Per Capita Demand--2020: 1355.14 kWh/cap/year\n",
"Per Capita Demand--2030: 2078.53 kWh/cap/year\n",
"Per Capita Demand--2040: 2199.29 kWh/cap/year\n",
"Per Capita Demand--2050: 2376.39 kWh/cap/year\n",
"Per Capita Demand--2060: 2699.31 kWh/cap/year\n",
"Population--2020: 19255577.0\n",
"Population--2030: 24179801.0\n",
"Population--2040: 29271172.0\n",
"Population--2050: 34015019.0\n",
"Population--2060: 38279939.0\n",
"MLED Scenario processing into OnSSET input files for: ' ambitious_development '...\n",
"Taken from file at: onsset_replication\\mled\\onsset_clusters\\3_zambia_onsset_clusters_with_mled_loads_ambitious_development_tot_lat_d.gpkg\n",
"Total Demand--2020: 13.5 TWh\n",
"Total Demand--2030: 38.17 TWh\n",
"Total Demand--2040: 48.98 TWh\n",
"Total Demand--2050: 63.37 TWh\n",
"Total Demand--2060: 82.46 TWh\n",
"Per Capita Demand--2020: 1398.57 kWh/cap/year\n",
"Per Capita Demand--2030: 2113.12 kWh/cap/year\n",
"Per Capita Demand--2040: 2250.68 kWh/cap/year\n",
"Per Capita Demand--2050: 2458.48 kWh/cap/year\n",
"Per Capita Demand--2060: 2785.37 kWh/cap/year\n",
"Population--2020: 19234648.0\n",
"Population--2030: 24175461.0\n",
"Population--2040: 29289410.0\n",
"Population--2050: 34055014.0\n",
"Population--2060: 38341584.0\n",
"Urban Pop Percentage--2020: 0.4187\n",
"Urban Pop Percentage--2030: 0.4762\n",
"Urban Pop Percentage--2040: 0.53\n",
"Urban Pop Percentage--2050: 0.5787\n",
"Urban Pop Percentage--2060: 0.6221\n"
"Urban Pop Percentage--2040: 0.5299\n",
"Urban Pop Percentage--2050: 0.5786\n",
"Urban Pop Percentage--2060: 0.622\n"
]
}
],
"source": [
"#Note: This can take some time. Will also be slower if pyogrio is not used. Will likely need more than 8GB of RAM.\n",
"#Note: This can take some time. Will also be slower if pyogrio is not used. May need more than 8GB of RAM for large countries or many clusters.\n",
"\n",
"#Important! this code will not run unless the \"onsset_replication\" data folder is downloaded and included in the file structure as in the instructions\n",
"\n",
"scenario_number = 1 # used as counter variable for output filenames. Not the number of scenarios to run. This is set in the list in cell 2 above. \n",
"\n",
"for mled_scenario in scenarios:\n",
" \n",
"\n",
" gdf = gpd.read_file(os.path.join(scenario_dictionary[mled_scenario]), engine = \"pyogrio\")\n",
" \n",
Expand Down Expand Up @@ -192,6 +196,9 @@
" onsset[\"GDP\"] = 0\n",
" onsset[\"ResidentialDemandTierCustom\"] = onsset[\"tot_dem_per_capita_2030\"]\n",
" \n",
" GHI_mean = onsset[\"GHI\"].mean()\n",
" onsset[\"GHI\"].fillna(GHI_mean, inplace = True)\n",
" \n",
" onsset[\"PerCapitaDemand2020\"] = onsset[\"tot_dem_per_capita_2020\"]\n",
" onsset[\"PerCapitaDemand2030\"] = onsset[\"tot_dem_per_capita_2030\"]\n",
" onsset[\"PerCapitaDemand2040\"] = onsset[\"tot_dem_per_capita_2040\"]\n",
Expand All @@ -209,17 +216,13 @@
" onsset[\"Pop2050\"] = onsset.population_2050\n",
" onsset[\"Pop2060\"] = onsset.population_2060\n",
" \n",
" onsset.to_csv(os.path.join(output_directory_for_onsset, \"zambia_onsset_input_mled_demands_\"+ str(mled_scenario) + \".csv\"), index = False) \n",
" onsset = onsset[onsset.GridCellArea.notna()]\n",
" \n",
" onsset.to_csv(os.path.join(output_directory_for_onsset, str(scenario_number) + \"_zambia_onsset_input_mled_demands_\"+ str(mled_scenario) + \".csv\"), index = False)\n",
" \n",
" scenario_number = scenario_number + 1\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42adb281-b4c0-4074-ad2d-c7db1057b994",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit eef7b7b

Please sign in to comment.