Who Has Power and Who Doesn't? Mapping The World Electrical Power Plants with Python and Basemap
Introduction
Let's use two great, frequently curated data sets to map the power plants from around the world by both country and population and identify who still doesn't have access to this essential and life-altering source of energy.
Code
from IPython.display import Image
Image(filename='../energy for all.png', width='60%')
Who Does and Doesn't Have Access to Electricity Around the World?¶
Hello Freinds,
Let's talk about power! More precisely, electrical power! I'm going to walk you through two great, frequently curated data sets and we'll create a series of maps to see who has and who doesn't have access to electrical energy.
Image(filename='../world-capacity.png')
Tell me this, what would go through you head if you just hauled you luggage to your hotel room and couldn't get connected to the interent using the supplied address and password, or worse, the place doesn't offer wifi??? You'd wonder what antiquated century you just walked into... in my family, it would be an instant mutiny, they'd probalby have me walk to the plank if i couldn't find a close by internet cafe or even another hotel...
But did you konw on this planet, 1 in 10 of our bothers and sisters, right now, don't have access to electricity??? It is mind boggling - wifi, for those unfortnuate folks is the least of their worries, they're like stuck on a never ending camping trip, a very rough and unsafe one...
Less that 1 Billion without Electricy¶
https://www.iea.org/commentaries/population-without-access-to-electricity-falls-below-1-billion
But there is progress, according to the IEA, The Paris-based International Energy Agency, for the first time ever, the total number of people without access to electriciy fell below 1 billion, I guess that's great, but 1 billion??
And, am sure you can guess where these that still don't have it are - 67% of the developing world, mostly rural areas, again mind boggling.
So, if you are thinking about getting into the energy generating field and what to konw what are the in-demand areas, this will tell you whwere thery are. We really need smart and motivated people to lower that one billion down to zero as quickly as possible.
Two Great Data Sets¶
We'll use two great data sets, one the World Resources Institute - it is a research organization focusing on different critical issues like climate, energy, food, pollution. We'll use their Global Power Plant Database which lists some 30,000 power plants from 164 countries broken down by types - Hydro, Solar, Wind, Gas, Coal, Oil and more.
WE'll look at power per country and also power per captia. For that we'll join a second great data set from United Nations Department of Economic and Social Affairs which gives current population estimates per country and even extrapolites those number well into the future, some 80 years out - though we won't need this here.
Countries With The Lowest Access To Electricity https://www.worldatlas.com/articles/countries-with-the-lowest-access-to-electricity.html
- Tanzania (15.3% of population) ...
- Niger (14.4% of population) ...
- Sierra Leone (14.2% of population) ...
- Burkina Faso (13.1% of population) ...
- Central African Republic (10.8% of population) ...
- Liberia (9.8% of population) ...
- Malawi (9.8% of population) ...
- Burundi (6.5% of population)
https://en.wikipedia.org/wiki/Solar_power_in_Africa
Problems with solar, skeptism and lack of grid to funnel all this power...
Let's see who has energy and who doesn't.
Global Power Plant Database - World Resources Institute¶
A comprehensive, global, open source database of power plants
http://datasets.wri.org/dataset/globalpowerplantdatabase
Logan Byers - logan.byers@wri.org
World Population Prospects 2019 - United Nations Department of Economic and Social Affairs¶
Population Dynamics
Total population by sex, annually from 1950 to 2100.
import pandas as pd
global_power_plant_database = pd.read_csv('global_power_plant_database.csv')
global_power_plant_database.shape
global_power_plant_database.head()
If you are going to work on aggregates, make sure you are not working on duplicated fields¶
print(len(global_power_plant_database['gppd_idnr']))
print(len(set(global_power_plant_database['gppd_idnr'])))
# how much capacity per country?
# Maximum Power Output - megawatts (MW)
power_per_country = global_power_plant_database.groupby('country_long')['capacity_mw'].sum().reset_index()
power_per_country = power_per_country.sort_values('capacity_mw', ascending=False)
power_per_country.head(20)
power_per_country.tail(20)
# map the ip addresses
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(16, 8))
ax.set_facecolor('xkcd:black')
plt.plot(global_power_plant_database['longitude'],
global_power_plant_database['latitude'],
linestyle='none', marker='.', color='white')
plt.suptitle('World Power Plants')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.grid()
plt.show()
Hydropower is considered a renewable energy¶
https://www.energy.gov/eere/water/how-hydropower-works
"Hydropower uses a fuel—water—that is not reduced or used up in the process. Because the water cycle is an endless, constantly recharging system, hydropower is considered a renewable energy. When flowing water is captured and turned into electricity, it is called hydroelectric power or hydropower."
global_power_plant_database['primary_fuel'].value_counts()
# just one type of power please
tmp_power_df = \
global_power_plant_database[global_power_plant_database['primary_fuel']=='Solar']
fig, ax = plt.subplots(figsize=(16, 8))
ax.set_facecolor('xkcd:black')
plt.plot(tmp_power_df['longitude'],
tmp_power_df['latitude'],
linestyle='none', marker='.', color='white')
print('fig size=', 5 * fig.dpi, 'x', 4 * fig.dpi)
plt.suptitle('My Visitors')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.grid()
plt.show()
#You can use agg:
data = global_power_plant_database.groupby('country_long').agg({'capacity_mw':'sum' ,
'latitude':'mean',
'longitude':'mean'}).reset_index()
data.head()
# you will need to pip install Basemap - https://matplotlib.org/basemap/users/installing.html
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# Set the dimension of the figure
my_dpi=96
plt.figure(figsize=(2600/my_dpi, 1800/my_dpi), dpi=my_dpi)
# Make the background map
m=Basemap(llcrnrlon=-180, llcrnrlat=-65,urcrnrlon=180,urcrnrlat=80)
m.drawmapboundary(fill_color='#A6CAE0', linewidth=0)
m.fillcontinents(color='grey', alpha=0.3)
m.drawcoastlines(linewidth=0.1, color="white")
# prepare a color for each point depending on the continent.
data['labels_enc'] = pd.factorize(data['country_long'])[0]
# Add a point per position
m.scatter(data['longitude'], data['latitude'],
s=data['capacity_mw']/100, alpha=0.4,
c=data['labels_enc'], cmap="Set1")
# copyright and source data info
plt.text( -170, -58,'Total Power Capacity\nBy Country', ha='left', va='bottom', size=9, color='#555555' )
plt.title('Total Power Capacity By Country' , fontsize=50)
# Throw in population by countries
global_pop = pd.read_csv('WPP2019_TotalPopulationBySex.csv')
global_pop = global_pop[['Location', 'PopTotal', 'Time']]
set(global_pop['Time'])
global_pop = global_pop[global_pop['Time'] == 2020]
global_pop = global_pop.drop_duplicates(keep='last')
global_pop = global_pop.sort_values('Location', ascending=True)
global_pop.head()
# pd.merge(global_pop, data['homecontinent'], on ['Location']
common_df = pd.merge(global_pop, data, how='inner', left_on='Location', right_on='country_long')
common_df['ration_power_pop'] = common_df ['capacity_mw']/ common_df['PopTotal']
common_df.sort_values('ration_power_pop', ascending=False)
Map out power to inhabitant per country¶
#You can use agg:
data = common_df.groupby('country_long').agg({'ration_power_pop':'sum' ,
'latitude':'mean',
'longitude':'mean'}).reset_index()
data.head()
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# Set the dimension of the figure
my_dpi=96
plt.figure(figsize=(2600/my_dpi, 1800/my_dpi), dpi=my_dpi)
# Make the background map
m=Basemap(llcrnrlon=-180, llcrnrlat=-65,urcrnrlon=180,urcrnrlat=80)
m.drawmapboundary(fill_color='#A6CAE0', linewidth=0)
m.fillcontinents(color='grey', alpha=0.3)
m.drawcoastlines(linewidth=0.1, color="white")
# prepare a color for each point depending on the continent.
data['labels_enc'] = pd.factorize(data['country_long'])[0]
# Add a point per position
m.scatter(data['longitude'], data['latitude'],
s=data['ration_power_pop']*1000, alpha=0.4,
c=data['labels_enc'], cmap="Set1")
plt.title('Total Power Capacity By Person', fontsize=50)
plt.text( -170, -58,'Total Power Capacity\nBy Person', ha='left', va='bottom', size=9, color='#555555' )
Show Notes
(pardon typos and formatting -these are the notes I use to make the videos)
Let's use two great, frequently curated data sets to map the power plants from around the world by both country and population and identify who still doesn't have access to this essential and life-altering source of energy.