Skip to content

Commit

Permalink
Update to wbgapi package and year updates
Browse files Browse the repository at this point in the history
-Moved away from the world_bank_data python package and use the wbgapi package instead and the world_bank_data package seems like it is no longer supported.

-Now pulls data from all years after 1990 whereas previously it was only between 1990-2020. Will automatically update if data for the latest year becomes available through the WB api.
  • Loading branch information
maartenbrinkerink committed Sep 3, 2024
1 parent 21a2394 commit c3ebceb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion workflow/envs/osemosys-global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- glpk>=5.0

- pip:
- world-bank-data>=0.1.3
- wbgapi>=1.0.12
- otoole==1.1.2
- dash==2.17
- ../../. # path to setup.py
40 changes: 23 additions & 17 deletions workflow/scripts/osemosys_global/demand_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# Script for electricity demand projection and downscaling

import pandas as pd
import world_bank_data as wb
import wbgapi as wb
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
import itertools
Expand Down Expand Up @@ -195,25 +196,30 @@

# ### Creates historic relationships based on World Bank and Our World In Data datasets.

# Extracts historical GDPppp per capita (constant 2017 international $) from the World Bank API
Country_GDPppp_WB = wb.get_series(
"NY.GDP.PCAP.PP.KD", date="1985:2020", id_or_value="id"
)
# Extracts historical GDPppp per capita from the World Bank API
Country_GDPppp_WB_raw = wb.data.DataFrame(['NY.GDP.PCAP.PP.KD'], mrv= datetime.now().year - 1990
).reset_index().rename(columns = {'economy' : 'Country'}
).set_index('Country')

Country_GDPppp_WB = (
Country_GDPppp_WB.reset_index()
.rename(columns={"NY.GDP.PCAP.PP.KD": "WB_GDPppp"})
.set_index("Country")
)
Country_GDPppp_WB = pd.DataFrame()

# Extracts Urban population (% of total population) from the World Bank API.
Country_Urb_WB = wb.get_series("SP.URB.TOTL.IN.ZS", date="1985:2020", id_or_value="id")
Country_Urb_WB_raw = wb.data.DataFrame(['SP.URB.TOTL.IN.ZS'], mrv= datetime.now().year - 1990
).reset_index().rename(columns = {'economy' : 'Country'}
).set_index('Country')

Country_Urb_WB = (
Country_Urb_WB.reset_index()
.rename(columns={"SP.URB.TOTL.IN.ZS": "WB_Urb"})
.set_index("Country")
)
Country_Urb_WB = pd.DataFrame()

# Transforms WB df's into long format.

for year in Country_GDPppp_WB_raw.columns:
data = Country_GDPppp_WB_raw [[year]].rename(columns = {year : 'WB_GDPppp'})
data['Year'] = year.replace('YR', '')
Country_GDPppp_WB = pd.concat([Country_GDPppp_WB, data])

data = Country_Urb_WB_raw [[year]].rename(columns = {year : 'WB_Urb'})
data['Year'] = year.replace('YR', '')
Country_Urb_WB = pd.concat([Country_Urb_WB, data])

# Extracts data from Our World In Data per capita electricity consumption dataset. Original data is based on sources from BP and Ember.
# Dataset retreived through (https://ourworldindata.org/energy-production-consumption).
Expand Down Expand Up @@ -548,7 +554,7 @@
b = Country_Regression_Grouped_plot["intercept"].unique()
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.scatter(x, y, color="grey", alpha=0.5, label="1985-2020")
ax1.scatter(x, y, color="grey", alpha=0.5, label= f'1990 - {datetime.now().year}')
ax1.scatter(x2, y2, color="green", alpha=0.5, label="2035")
ax1.scatter(x3, y3, color="blue", alpha=0.5, label="2050")
ax1.scatter(x4, y4, color="red", alpha=0.5, label="2100")
Expand Down

0 comments on commit c3ebceb

Please sign in to comment.