%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
import os
from os.path import join
import sys
import json
import geopandas as gpd
idx = pd.IndexSlice
# Load the "autoreload" extension
%load_ext autoreload
# always reload modules marked with "%aimport"
%autoreload 1
# add the 'src' directory as one where we can import modules
src_dir = join(os.getcwd(), os.pardir, 'src')
sys.path.append(src_dir)
%aimport Data.make_data
from Data.make_data import states_in_nerc
%aimport Analysis.index
from Analysis.index import facility_emission_gen, group_facility_data
%aimport Analysis.index
from Analysis.index import facility_co2, adjust_epa_emissions, group_fuel_cats
from Analysis.index import reduce_emission_factors, add_datetime
%aimport util.utils
from util.utils import rename_cols, add_facility_location
cwd = os.getcwd()
path = join(cwd, '..', 'Data storage', 'NERC extra gen fuels_rev.csv')
extra_nerc = pd.read_csv(path, index_col=[0, 1, 2, 3])
extra_nerc.head()
generation (mwh) | total fuel (mmbtu) | elec fuel (mmbtu) | ||||
---|---|---|---|---|---|---|
year | nerc | month | type | |||
2016 | - | 1 | COW | 44530.552769 | 1.256166e+06 | 305845.103161 |
HYC | 100305.919463 | NaN | NaN | |||
NG | 15902.441875 | 3.557801e+05 | 181511.765555 | |||
PEL | 134.565687 | 1.559407e+03 | 1486.940103 | |||
WND | 575.163764 | NaN | NaN |
path = join(cwd, '..', 'Data storage', 'Final emission factors.csv')
ef = pd.read_csv(path, index_col=0)
ef.head()
Fuel | Fossil Factor | Notes | Link | Total Factor | |
---|---|---|---|---|---|
EIA Fuel Code | |||||
BIT | Bituminous Coal | 93.30 | NaN | https://www.eia.gov/electricity/annual/html/ep... | 93.30 |
DFO | Distillate Fuel Oil | 73.16 | NaN | https://www.eia.gov/electricity/annual/html/ep... | 73.16 |
GEO | Geothermal | 7.71 | NaN | https://www.eia.gov/electricity/annual/html/ep... | 7.71 |
JF | Jet Fuel | 70.90 | NaN | https://www.eia.gov/electricity/annual/html/ep... | 70.90 |
KER | Kerosene | 72.30 | NaN | https://www.eia.gov/electricity/annual/html/ep... | 72.30 |
ef_type = reduce_emission_factors(ef)
ef_type = pd.Series(ef_type, name='type')
ef_type
COW 95.250 NG 53.070 OOG 59.000 PC 102.100 PEL 75.975 Name: type, dtype: float64
extra_nerc.loc[:, 'total co2 (kg)'] = (extra_nerc
.loc[:, 'total fuel (mmbtu)']
.multiply(ef_type, 'type'))
extra_nerc.loc[:, 'elec co2 (kg)'] = (extra_nerc
.loc[:, 'elec fuel (mmbtu)']
.multiply(ef_type, 'type'))
extra_nerc.sort_index(inplace=True)
extra_nerc.head()
generation (mwh) | total fuel (mmbtu) | elec fuel (mmbtu) | total co2 (kg) | elec co2 (kg) | ||||
---|---|---|---|---|---|---|---|---|
year | nerc | month | type | |||||
2016 | - | 1 | COW | 44530.552769 | 1.256166e+06 | 305845.103161 | 1.196498e+08 | 2.913175e+07 |
HYC | 100305.919463 | NaN | NaN | NaN | NaN | |||
NG | 15902.441875 | 3.557801e+05 | 181511.765555 | 1.888125e+07 | 9.632829e+06 | |||
PEL | 134.565687 | 1.559407e+03 | 1486.940103 | 1.184759e+05 | 1.129703e+05 | |||
WND | 575.163764 | NaN | NaN | NaN | NaN |
%aimport Analysis.state2nerc
from Analysis.state2nerc import fraction_state2nerc, add_region
fuel_cat_folder = join(cwd, '..', 'Data storage', 'Fuel categories')
state_cats_path = join(fuel_cat_folder, 'State_facility.json')
with open(state_cats_path, 'r') as f:
state_fuel_cat = json.load(f)
custom_cats_path = join(fuel_cat_folder, 'Custom_results.json')
with open(custom_cats_path, 'r') as f:
custom_fuel_cat = json.load(f)
path = join(cwd, '..', 'Data storage', 'Derived data',
'Monthly EPA emissions 2017-08-31.csv')
epa = pd.read_csv(path)
path = join(cwd, '..', 'Data storage', 'Facility labels',
'Facility locations.csv')
facility_labels = pd.read_csv(path)
path = join(cwd, '..', 'Data storage',
'Facility gen fuels and CO2 2017-08-31.zip')
eia_fac = pd.read_csv(path)
eia_fac.head()
f | fuel | month | plant id | total fuel (mmbtu) | year | generation (MWh) | elec fuel (mmbtu) | geography | last_updated | lat | lon | prime mover | datetime | quarter | all fuel fossil CO2 (kg) | elec fuel fossil CO2 (kg) | all fuel total CO2 (kg) | elec fuel total CO2 (kg) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | M | SUB | 6 | 10360 | 0.0 | 2017 | 0.0 | 0.0 | USA-WI | 2017-08-24T11:46:12-04:00 | 44.4936 | -88.0303 | ALL | 2017-06-01 | 2 | 0.0 | 0.0 | 0.0 | 0.0 |
1 | M | SUB | 5 | 10360 | 0.0 | 2017 | 0.0 | 0.0 | USA-WI | 2017-08-24T11:46:12-04:00 | 44.4936 | -88.0303 | ALL | 2017-05-01 | 2 | 0.0 | 0.0 | 0.0 | 0.0 |
2 | M | SUB | 4 | 10360 | 0.0 | 2017 | 0.0 | 0.0 | USA-WI | 2017-08-24T11:46:12-04:00 | 44.4936 | -88.0303 | ALL | 2017-04-01 | 2 | 0.0 | 0.0 | 0.0 | 0.0 |
3 | M | SUB | 3 | 10360 | 0.0 | 2017 | 0.0 | 0.0 | USA-WI | 2017-08-24T11:46:12-04:00 | 44.4936 | -88.0303 | ALL | 2017-03-01 | 1 | 0.0 | 0.0 | 0.0 | 0.0 |
4 | M | SUB | 2 | 10360 | 0.0 | 2017 | 0.0 | 0.0 | USA-WI | 2017-08-24T11:46:12-04:00 | 44.4936 | -88.0303 | ALL | 2017-02-01 | 1 | 0.0 | 0.0 | 0.0 | 0.0 |
co2, gen_fuels_state = facility_emission_gen(eia_facility=eia_fac, epa=epa,
state_fuel_cat=state_fuel_cat,
custom_fuel_cat=custom_fuel_cat,
export_state_cats=True)
Renaming columns Grouping facilities Adjusting EPA emissions Caculating CO2 Gen/fuels to state categories
co2 = add_facility_location(co2, facility_labels, labels=['lat', 'lon', 'state', 'nerc'])
co2_nerc = co2.groupby(['year', 'nerc', 'month'])['final co2 (kg)'].sum()
co2_nerc.tail()
year nerc month 2017 WECC 2 1.797939e+10 3 1.622878e+10 4 1.410046e+10 5 1.635295e+10 6 1.998163e+10 Name: final co2 (kg), dtype: float64
gen_fuels_nerc = add_facility_location(gen_fuels_state, facility_labels, labels=['nerc'])
gen_fuels_nerc = (gen_fuels_nerc
.groupby(['year', 'nerc', 'month', 'type'])
['generation (mwh)'].sum())
gen_fuels_nerc.head()
year nerc month type 2001 - 1 COW 4984145.332 HYC 278484.523 NG 245740.990 NUC 1599398.000 PEL 77892.543 Name: generation (mwh), dtype: float64
gen_fuels_nerc.tail()
year nerc month type 2017 WECC 6 PEL 19776.466 SUN 1502622.000 WAS 42851.264 WND 1048324.000 WWW 163238.315 Name: generation (mwh), dtype: float64
gen_fuels_nerc.loc[idx[2015, 'NPCC', :, :]].groupby(['year', 'nerc', 'month']).sum()
year nerc month 2015 NPCC 1 2.018215e+07 2 1.908706e+07 3 1.912367e+07 4 1.730879e+07 5 1.920187e+07 6 1.981127e+07 7 2.319538e+07 8 2.314866e+07 9 1.990933e+07 10 1.815993e+07 11 1.776335e+07 12 1.891339e+07 Name: generation (mwh), dtype: float64
extra_nerc.head()
generation (mwh) | total fuel (mmbtu) | elec fuel (mmbtu) | total co2 (kg) | elec co2 (kg) | ||||
---|---|---|---|---|---|---|---|---|
year | nerc | month | type | |||||
2016 | - | 1 | COW | 44530.552769 | 1.256166e+06 | 305845.103161 | 1.196498e+08 | 2.913175e+07 |
HYC | 100305.919463 | NaN | NaN | NaN | NaN | |||
NG | 15902.441875 | 3.557801e+05 | 181511.765555 | 1.888125e+07 | 9.632829e+06 | |||
PEL | 134.565687 | 1.559407e+03 | 1486.940103 | 1.184759e+05 | 1.129703e+05 | |||
WND | 575.163764 | NaN | NaN | NaN | NaN |
extra_nerc.loc[idx[2016, 'NPCC', :, 'COW']].groupby(['year', 'nerc', 'month']).sum()
generation (mwh) | total fuel (mmbtu) | elec fuel (mmbtu) | total co2 (kg) | elec co2 (kg) | |||
---|---|---|---|---|---|---|---|
year | nerc | month | |||||
2016 | NPCC | 1 | 1781.562 | 88952.0 | 7736.0 | 8472678.00 | 736854.00 |
2 | 1680.032 | 85485.0 | 7306.0 | 8142446.25 | 695896.50 | ||
3 | 1610.380 | 85365.0 | 6993.0 | 8131016.25 | 666083.25 | ||
4 | 1260.518 | 32032.0 | 5471.0 | 3051048.00 | 521112.75 | ||
5 | 1385.227 | 64252.0 | 6017.0 | 6120003.00 | 573119.25 | ||
6 | 1387.299 | 67960.0 | 6025.0 | 6473190.00 | 573881.25 | ||
7 | 1550.543 | 68289.0 | 6737.0 | 6504527.25 | 641699.25 | ||
8 | 1613.620 | 71513.0 | 7006.0 | 6811613.25 | 667321.50 | ||
9 | 1269.469 | 56081.0 | 5521.0 | 5341715.25 | 525875.25 | ||
10 | 1217.762 | 41952.0 | 5296.0 | 3995928.00 | 504444.00 | ||
11 | 1244.608 | 56773.0 | 5408.0 | 5407628.25 | 515112.00 | ||
12 | 1547.192 | 62436.0 | 6723.0 | 5947029.00 | 640365.75 |
total_gen = gen_fuels_nerc.copy()
# total_gen.loc[idx[2015:, 'RFC', :, :]]
total_gen.loc[idx[2016:, :, :, :]] = (total_gen.loc[2016:]
.add(extra_nerc.loc[:, 'generation (mwh)']
, fill_value=0))
total_gen = total_gen.reset_index()
add_datetime(total_gen)
# total_gen.set_index(['year', 'nerc', ''])
total_gen.head()
year | nerc | month | type | generation (mwh) | datetime | |
---|---|---|---|---|---|---|
0 | 2001 | - | 1 | COW | 4984145.332 | 2001-01-01 |
1 | 2001 | - | 1 | HYC | 278484.523 | 2001-01-01 |
2 | 2001 | - | 1 | NG | 245740.990 | 2001-01-01 |
3 | 2001 | - | 1 | NUC | 1599398.000 | 2001-01-01 |
4 | 2001 | - | 1 | PEL | 77892.543 | 2001-01-01 |
final = group_fuel_cats(total_gen,
custom_fuel_cat, 'type',
'fuel category', extra_group_cols=['nerc', 'datetime'])
final.set_index(['nerc', 'fuel category', 'datetime'], inplace=True)
final.head()
year | month | generation (mwh) | |||
---|---|---|---|---|---|
nerc | fuel category | datetime | |||
- | Coal | 2001-01-01 | 2001 | 1 | 4.984145e+06 |
FRCC | Coal | 2001-01-01 | 2001 | 1 | 5.667654e+06 |
MRO | Coal | 2001-01-01 | 2001 | 1 | 1.135828e+07 |
NPCC | Coal | 2001-01-01 | 2001 | 1 | 4.033044e+06 |
RFC | Coal | 2001-01-01 | 2001 | 1 | 5.187368e+07 |
final.tail()
year | month | generation (mwh) | |||
---|---|---|---|---|---|
nerc | fuel category | datetime | |||
RFC | Wind | 2017-06-01 | 2017 | 6 | 1.818066e+06 |
SERC | Wind | 2017-06-01 | 2017 | 6 | 5.696994e+05 |
SPP | Wind | 2017-06-01 | 2017 | 6 | 4.640585e+06 |
TRE | Wind | 2017-06-01 | 2017 | 6 | 3.744850e+06 |
WECC | Wind | 2017-06-01 | 2017 | 6 | 3.270391e+06 |
total = final.groupby(['nerc', 'datetime']).sum()
# total.reset_index(inplace=True)
# add_datetime(total)
# total['fuel category'] = 'Total'
total.head()
year | month | generation (mwh) | ||
---|---|---|---|---|
nerc | datetime | |||
- | 2001-01-01 | 10005 | 5 | 7185661.388 |
2001-02-01 | 10005 | 10 | 6526739.453 | |
2001-03-01 | 10005 | 15 | 6304139.884 | |
2001-04-01 | 10005 | 20 | 6624660.323 | |
2001-05-01 | 10005 | 25 | 7045482.729 |
nercs = total.index.get_level_values('nerc').unique()
df_list = []
for nerc in nercs:
percent_gen = final.loc[nerc].divide(total.loc[nerc], level='datetime')
percent_gen['nerc'] = nerc
percent_gen.set_index('nerc', append=True, inplace=True)
df_list.append(percent_gen)
percent_gen = pd.concat(df_list)
percent_gen.head()
year | month | generation (mwh) | |||
---|---|---|---|---|---|
fuel category | datetime | nerc | |||
Coal | 2001-01-01 | - | 0.2 | 0.2 | 0.693624 |
2001-02-01 | - | 0.2 | 0.2 | 0.616249 | |
2001-03-01 | - | 0.2 | 0.2 | 0.601500 | |
2001-04-01 | - | 0.2 | 0.2 | 0.621707 | |
2001-05-01 | - | 0.2 | 0.2 | 0.637201 |
percent_gen.sort_index().loc[idx['Wind', :, 'SPP'], :]
year | month | generation (mwh) | |||
---|---|---|---|---|---|
fuel category | datetime | nerc | |||
Wind | 2001-12-01 | SPP | 0.142857 | 0.142857 | 0.005887 |
2002-01-01 | SPP | 0.142857 | 0.142857 | 0.004947 | |
2002-02-01 | SPP | 0.142857 | 0.142857 | 0.006261 | |
2002-03-01 | SPP | 0.142857 | 0.142857 | 0.007232 | |
2002-04-01 | SPP | 0.142857 | 0.142857 | 0.007401 | |
2002-05-01 | SPP | 0.142857 | 0.142857 | 0.006550 | |
2002-06-01 | SPP | 0.142857 | 0.142857 | 0.005424 | |
2002-07-01 | SPP | 0.142857 | 0.142857 | 0.003348 | |
2002-08-01 | SPP | 0.142857 | 0.142857 | 0.003897 | |
2002-09-01 | SPP | 0.142857 | 0.142857 | 0.004384 | |
2002-10-01 | SPP | 0.142857 | 0.142857 | 0.004164 | |
2002-11-01 | SPP | 0.142857 | 0.142857 | 0.004939 | |
2002-12-01 | SPP | 0.142857 | 0.142857 | 0.004464 | |
2003-01-01 | SPP | 0.142857 | 0.142857 | 0.004509 | |
2003-02-01 | SPP | 0.142857 | 0.142857 | 0.004457 | |
2003-03-01 | SPP | 0.142857 | 0.142857 | 0.006589 | |
2003-04-01 | SPP | 0.142857 | 0.142857 | 0.007398 | |
2003-05-01 | SPP | 0.142857 | 0.142857 | 0.005075 | |
2003-06-01 | SPP | 0.142857 | 0.142857 | 0.003633 | |
2003-07-01 | SPP | 0.142857 | 0.142857 | 0.004024 | |
2003-08-01 | SPP | 0.142857 | 0.142857 | 0.003105 | |
2003-09-01 | SPP | 0.142857 | 0.142857 | 0.004753 | |
2003-10-01 | SPP | 0.142857 | 0.142857 | 0.004609 | |
2003-11-01 | SPP | 0.142857 | 0.142857 | 0.005895 | |
2003-12-01 | SPP | 0.142857 | 0.142857 | 0.010790 | |
2004-01-01 | SPP | 0.142857 | 0.142857 | 0.007913 | |
2004-02-01 | SPP | 0.142857 | 0.142857 | 0.009474 | |
2004-03-01 | SPP | 0.142857 | 0.142857 | 0.011745 | |
2004-04-01 | SPP | 0.142857 | 0.142857 | 0.011129 | |
2004-05-01 | SPP | 0.142857 | 0.142857 | 0.012586 | |
... | ... | ... | ... | ... | |
2015-01-01 | SPP | 0.125000 | 0.125000 | 0.187193 | |
2015-02-01 | SPP | 0.125000 | 0.125000 | 0.192527 | |
2015-03-01 | SPP | 0.125000 | 0.125000 | 0.188374 | |
2015-04-01 | SPP | 0.125000 | 0.125000 | 0.268758 | |
2015-05-01 | SPP | 0.125000 | 0.125000 | 0.216918 | |
2015-06-01 | SPP | 0.125000 | 0.125000 | 0.172844 | |
2015-07-01 | SPP | 0.125000 | 0.125000 | 0.146173 | |
2015-08-01 | SPP | 0.125000 | 0.125000 | 0.141569 | |
2015-09-01 | SPP | 0.125000 | 0.125000 | 0.208782 | |
2015-10-01 | SPP | 0.125000 | 0.125000 | 0.222819 | |
2015-11-01 | SPP | 0.125000 | 0.125000 | 0.291164 | |
2015-12-01 | SPP | 0.125000 | 0.125000 | 0.263839 | |
2016-01-01 | SPP | 0.125000 | 0.125000 | 0.223987 | |
2016-02-01 | SPP | 0.125000 | 0.125000 | 0.300322 | |
2016-03-01 | SPP | 0.125000 | 0.125000 | 0.330366 | |
2016-04-01 | SPP | 0.125000 | 0.125000 | 0.310516 | |
2016-05-01 | SPP | 0.125000 | 0.125000 | 0.277977 | |
2016-06-01 | SPP | 0.125000 | 0.125000 | 0.191688 | |
2016-07-01 | SPP | 0.125000 | 0.125000 | 0.207956 | |
2016-08-01 | SPP | 0.125000 | 0.125000 | 0.168900 | |
2016-09-01 | SPP | 0.125000 | 0.125000 | 0.241730 | |
2016-10-01 | SPP | 0.125000 | 0.125000 | 0.340282 | |
2016-11-01 | SPP | 0.125000 | 0.125000 | 0.290063 | |
2016-12-01 | SPP | 0.125000 | 0.125000 | 0.274152 | |
2017-01-01 | SPP | 0.125000 | 0.125000 | 0.310940 | |
2017-02-01 | SPP | 0.125000 | 0.125000 | 0.375097 | |
2017-03-01 | SPP | 0.125000 | 0.125000 | 0.398500 | |
2017-04-01 | SPP | 0.125000 | 0.125000 | 0.421802 | |
2017-05-01 | SPP | 0.125000 | 0.125000 | 0.356472 | |
2017-06-01 | SPP | 0.125000 | 0.125000 | 0.288476 |
187 rows × 3 columns
path = join(cwd, '..', 'Data storage', 'Final NERC data', 'NERC percent gen.csv')
percent_gen.to_csv(path)
g = sns.FacetGrid(final.reset_index(), col='nerc', col_wrap=3, hue='fuel category')
g.map(plt.plot, 'datetime', 'generation (mwh)')
<seaborn.axisgrid.FacetGrid at 0x11c4a4b38>
g = sns.FacetGrid(percent_gen.reset_index(), col='nerc', col_wrap=3, hue='fuel category')
g.map(plt.plot, 'datetime', 'generation (mwh)').add_legend()
<seaborn.axisgrid.FacetGrid at 0x11de72400>
total_monthly_gen = final.groupby(['fuel category', 'year', 'nerc', 'month']).sum()
total_monthly_gen.sort_index(inplace=True)
total_monthly_gen.head()
generation (mwh) | ||||
---|---|---|---|---|
fuel category | year | nerc | month | |
Coal | 2001 | - | 1 | 4984145.332 |
2 | 4022096.265 | |||
3 | 3791937.999 | |||
4 | 4118597.061 | |||
5 | 4489386.854 |
nercs
Index(['-', 'FRCC', 'MRO', 'NPCC', 'RFC', 'SERC', 'SPP', 'TRE', 'WECC'], dtype='object', name='nerc')
New
total_monthly_gen.loc[idx['Wind', 2016:, 'SPP', :]]
generation (mwh) | ||||
---|---|---|---|---|
fuel category | year | nerc | month | |
Wind | 2016 | SPP | 1 | 3.374981e+06 |
2 | 4.155250e+06 | |||
3 | 4.553445e+06 | |||
4 | 4.001287e+06 | |||
5 | 3.978637e+06 | |||
6 | 3.281935e+06 | |||
7 | 3.978728e+06 | |||
8 | 2.985067e+06 | |||
9 | 3.662123e+06 | |||
10 | 4.839691e+06 | |||
11 | 3.926539e+06 | |||
12 | 4.311541e+06 | |||
2017 | SPP | 1 | 4.731162e+06 | |
2 | 4.897194e+06 | |||
3 | 5.955759e+06 | |||
4 | 5.908594e+06 | |||
5 | 5.221956e+06 | |||
6 | 4.640585e+06 |
Old
total_monthly_gen.loc[idx['Wind', 2016:, 'SPP', :]]
generation (mwh) | ||||
---|---|---|---|---|
fuel category | year | nerc | month | |
Wind | 2016 | SPP | 1 | 3.408207e+06 |
2 | 4.193141e+06 | |||
3 | 4.598598e+06 | |||
4 | 4.040583e+06 | |||
5 | 4.019386e+06 | |||
6 | 3.314925e+06 | |||
7 | 4.020584e+06 | |||
8 | 3.015184e+06 | |||
9 | 3.693485e+06 | |||
10 | 4.879534e+06 | |||
11 | 3.958848e+06 | |||
12 | 4.346685e+06 | |||
2017 | SPP | 1 | 5.770468e+06 | |
2 | 5.910061e+06 | |||
3 | 7.154622e+06 | |||
4 | 7.099981e+06 | |||
5 | 6.277379e+06 | |||
6 | 5.488991e+06 |
New
total_monthly_gen.loc[idx['Wind', 2016:, 'TRE', :]]
generation (mwh) | ||||
---|---|---|---|---|
fuel category | year | nerc | month | |
Wind | 2016 | TRE | 1 | 3.677563e+06 |
2 | 4.149466e+06 | |||
3 | 4.640353e+06 | |||
4 | 3.831255e+06 | |||
5 | 4.051057e+06 | |||
6 | 2.998224e+06 | |||
7 | 4.613942e+06 | |||
8 | 2.930203e+06 | |||
9 | 3.012464e+06 | |||
10 | 4.209576e+06 | |||
11 | 3.624554e+06 | |||
12 | 4.191488e+06 | |||
2017 | TRE | 1 | 4.765199e+06 | |
2 | 4.620816e+06 | |||
3 | 5.567327e+06 | |||
4 | 5.478493e+06 | |||
5 | 4.892300e+06 | |||
6 | 3.744850e+06 |
national = total_monthly_gen.groupby(['fuel category', 'year', 'month']).sum()
national.loc['Wind']
generation (mwh) | ||
---|---|---|
year | month | |
2001 | 1 | 3.333854e+05 |
2 | 3.180357e+05 | |
3 | 4.641913e+05 | |
4 | 5.964168e+05 | |
5 | 5.508860e+05 | |
6 | 5.921092e+05 | |
7 | 5.637226e+05 | |
8 | 5.232015e+05 | |
9 | 4.400808e+05 | |
10 | 5.482939e+05 | |
11 | 4.402245e+05 | |
12 | 5.876466e+05 | |
2002 | 1 | 8.096774e+05 |
2 | 7.122176e+05 | |
3 | 8.501622e+05 | |
4 | 1.022825e+06 | |
5 | 1.076013e+06 | |
6 | 1.124236e+06 | |
7 | 8.880868e+05 | |
8 | 9.744372e+05 | |
9 | 7.337742e+05 | |
10 | 7.325252e+05 | |
11 | 6.542521e+05 | |
12 | 7.533280e+05 | |
2003 | 1 | 6.320539e+05 |
2 | 7.450431e+05 | |
3 | 1.035804e+06 | |
4 | 1.092412e+06 | |
5 | 1.006074e+06 | |
6 | 1.046792e+06 | |
... | ... | ... |
2015 | 1 | 1.513446e+07 |
2 | 1.486940e+07 | |
3 | 1.525001e+07 | |
4 | 1.776832e+07 | |
5 | 1.706237e+07 | |
6 | 1.335309e+07 | |
7 | 1.360589e+07 | |
8 | 1.301915e+07 | |
9 | 1.387127e+07 | |
10 | 1.632488e+07 | |
11 | 1.958666e+07 | |
12 | 2.001270e+07 | |
2016 | 1 | 1.848814e+07 |
2 | 2.014599e+07 | |
3 | 2.191629e+07 | |
4 | 2.065752e+07 | |
5 | 1.872730e+07 | |
6 | 1.623909e+07 | |
7 | 1.752073e+07 | |
8 | 1.348392e+07 | |
9 | 1.635427e+07 | |
10 | 2.028793e+07 | |
11 | 1.925545e+07 | |
12 | 2.291829e+07 | |
2017 | 1 | 1.884219e+07 |
2 | 2.037892e+07 | |
3 | 2.406894e+07 | |
4 | 2.387828e+07 | |
5 | 2.102590e+07 | |
6 | 1.822083e+07 |
198 rows × 1 columns
total_monthly_gen.head()
generation (mwh) | ||||
---|---|---|---|---|
fuel category | year | nerc | month | |
Coal | 2001 | - | 1 | 4984145.332 |
2 | 4022096.265 | |||
3 | 3791937.999 | |||
4 | 4118597.061 | |||
5 | 4489386.854 |
path = join(cwd, '..', 'Data storage', 'Final NERC data', 'NERC generation.csv')
total_monthly_gen.to_csv(path)
co2_nerc.head()
year nerc month 2001 - 1 5.476076e+09 2 4.349473e+09 3 4.223575e+09 4 4.544873e+09 5 4.972656e+09 Name: final co2 (kg), dtype: float64
type(co2_nerc), type(total_monthly_gen)
(pandas.core.series.Series, pandas.core.frame.DataFrame)
total_monthly_gen = total_monthly_gen.groupby(['year', 'nerc', 'month']).sum()
nerc_index = pd.concat([co2_nerc.sort_index(), total_monthly_gen.sort_index()], axis=1)
nerc_index['index'] = nerc_index['final co2 (kg)'] / nerc_index['generation (mwh)']
nerc_index = nerc_index.reset_index()
add_datetime(nerc_index)
nerc_index.tail()
year | nerc | month | final co2 (kg) | generation (mwh) | index | datetime | |
---|---|---|---|---|---|---|---|
1777 | 2017 | WECC | 2 | 1.797939e+10 | 5.157630e+07 | 348.597800 | 2017-02-01 |
1778 | 2017 | WECC | 3 | 1.622878e+10 | 5.574559e+07 | 291.122175 | 2017-03-01 |
1779 | 2017 | WECC | 4 | 1.410046e+10 | 5.230338e+07 | 269.589771 | 2017-04-01 |
1780 | 2017 | WECC | 5 | 1.635295e+10 | 5.667574e+07 | 288.535365 | 2017-05-01 |
1781 | 2017 | WECC | 6 | 1.998163e+10 | 6.309302e+07 | 316.701151 | 2017-06-01 |
nerc_index.head()
year | nerc | month | final co2 (kg) | generation (mwh) | index | datetime | |
---|---|---|---|---|---|---|---|
0 | 2001 | - | 1 | 5.476076e+09 | 7185661.388 | 762.083771 | 2001-01-01 |
1 | 2001 | - | 2 | 4.349473e+09 | 6526739.453 | 666.408193 | 2001-02-01 |
2 | 2001 | - | 3 | 4.223575e+09 | 6304139.884 | 669.968545 | 2001-03-01 |
3 | 2001 | - | 4 | 4.544873e+09 | 6624660.323 | 686.053817 | 2001-04-01 |
4 | 2001 | - | 5 | 4.972656e+09 | 7045482.729 | 705.793523 | 2001-05-01 |
path = join(cwd, '..', 'Data storage', 'Final NERC data',
'NERC gen emissions and index.csv')
nerc_index.to_csv(path, index=False)
g = sns.FacetGrid(nerc_index, col='nerc', col_wrap=3, hue='nerc')
g.map(plt.plot, 'datetime', 'index')
g.set(ylim=(0, 1000))
<seaborn.axisgrid.FacetGrid at 0x11eddf8d0>
g = sns.FacetGrid(nerc_index, col='nerc', col_wrap=3, hue='nerc')
g.map(plt.plot, 'datetime', 'index')
g.set(ylim=(0, 1000))
<seaborn.axisgrid.FacetGrid at 0x1277d1940>
nerc_index.set_index(['nerc', 'year', 'month'], inplace=True)
nerc_index.sort_index(inplace=True)
nerc_index.head()
final co2 (kg) | generation (mwh) | index | datetime | |||
---|---|---|---|---|---|---|
nerc | year | month | ||||
- | 2001 | 1 | 5.476076e+09 | 7185661.388 | 762.083771 | 2001-01-01 |
2 | 4.349473e+09 | 6526739.453 | 666.408193 | 2001-02-01 | ||
3 | 4.223575e+09 | 6304139.884 | 669.968545 | 2001-03-01 | ||
4 | 4.544873e+09 | 6624660.323 | 686.053817 | 2001-04-01 | ||
5 | 4.972656e+09 | 7045482.729 | 705.793523 | 2001-05-01 |
nerc_index.loc[idx['RFC', [2015, 2016], :]]
final co2 (kg) | generation (mwh) | index | datetime | |||
---|---|---|---|---|---|---|
nerc | year | month | ||||
RFC | 2015 | 1 | 4.306783e+10 | 7.783863e+07 | 553.296296 | 2015-01-01 |
2 | 4.263669e+10 | 7.343447e+07 | 580.608713 | 2015-02-01 | ||
3 | 3.679073e+10 | 6.970127e+07 | 527.834464 | 2015-03-01 | ||
4 | 2.828605e+10 | 5.710803e+07 | 495.307651 | 2015-04-01 | ||
5 | 3.231308e+10 | 6.272971e+07 | 515.116141 | 2015-05-01 | ||
6 | 3.677572e+10 | 6.869253e+07 | 535.367126 | 2015-06-01 | ||
7 | 4.232129e+10 | 7.648261e+07 | 553.345283 | 2015-07-01 | ||
8 | 4.159511e+10 | 7.505784e+07 | 554.174043 | 2015-08-01 | ||
9 | 3.837479e+10 | 6.971716e+07 | 550.435332 | 2015-09-01 | ||
10 | 3.023574e+10 | 6.177795e+07 | 489.426034 | 2015-10-01 | ||
11 | 2.935812e+10 | 6.109637e+07 | 480.521521 | 2015-11-01 | ||
12 | 2.883434e+10 | 6.308340e+07 | 457.082838 | 2015-12-01 | ||
2016 | 1 | 3.626499e+10 | 7.411975e+07 | 489.275724 | 2016-01-01 | |
2 | 3.226399e+10 | 6.618790e+07 | 487.460489 | 2016-02-01 | ||
3 | 2.617552e+10 | 6.120764e+07 | 427.651158 | 2016-03-01 | ||
4 | 2.656983e+10 | 5.762905e+07 | 461.049263 | 2016-04-01 | ||
5 | 2.706978e+10 | 6.038847e+07 | 448.260692 | 2016-05-01 | ||
6 | 3.520189e+10 | 6.987611e+07 | 503.775732 | 2016-06-01 | ||
7 | 4.294938e+10 | 8.074331e+07 | 531.924999 | 2016-07-01 | ||
8 | 4.409355e+10 | 8.366931e+07 | 526.997935 | 2016-08-01 | ||
9 | 3.513746e+10 | 6.976534e+07 | 503.652138 | 2016-09-01 | ||
10 | 2.906225e+10 | 6.198996e+07 | 468.821809 | 2016-10-01 | ||
11 | 2.727237e+10 | 6.111087e+07 | 446.276917 | 2016-11-01 | ||
12 | 3.530546e+10 | 7.224450e+07 | 488.694083 | 2016-12-01 |
extra_nerc.head()
generation (mwh) | total fuel (mmbtu) | elec fuel (mmbtu) | total co2 (kg) | elec co2 (kg) | ||||
---|---|---|---|---|---|---|---|---|
year | nerc | month | type | |||||
2016 | - | 1 | COW | 41906.627497 | 1.191174e+06 | 282550.319599 | 1.134594e+08 | 2.691292e+07 |
HYC | 41084.477887 | NaN | NaN | NaN | NaN | |||
NG | 4616.426184 | 1.396837e+05 | 43306.395889 | 7.413013e+06 | 2.298270e+06 | |||
PEL | 229.742217 | 1.099033e+03 | 965.454965 | 8.349906e+04 | 7.335044e+04 | |||
WND | 1154.326185 | NaN | NaN | NaN | NaN |
extra_nerc.loc[idx[[2015, 2016], 'RFC', :, :]].groupby(['month']).sum()
generation (mwh) | total fuel (mmbtu) | elec fuel (mmbtu) | total co2 (kg) | elec co2 (kg) | |
---|---|---|---|---|---|
month | |||||
1 | 2.975293e+06 | 2.654826e+07 | 1.746824e+07 | 1.851243e+09 | 1.240129e+09 |
2 | 2.330573e+06 | 2.369033e+07 | 1.400473e+07 | 1.707539e+09 | 1.016863e+09 |
3 | 2.348359e+06 | 2.398724e+07 | 1.417536e+07 | 1.691622e+09 | 9.937365e+08 |
4 | 2.174804e+06 | 2.102326e+07 | 1.268165e+07 | 1.456520e+09 | 8.732754e+08 |
5 | 2.278637e+06 | 2.194446e+07 | 1.359598e+07 | 1.537301e+09 | 9.452902e+08 |
6 | 2.633743e+06 | 2.501806e+07 | 1.638540e+07 | 1.766071e+09 | 1.153384e+09 |
7 | 3.049505e+06 | 2.975092e+07 | 2.038828e+07 | 2.046732e+09 | 1.396636e+09 |
8 | 3.174413e+06 | 3.092805e+07 | 2.145855e+07 | 2.112901e+09 | 1.458313e+09 |
9 | 2.474695e+06 | 2.455273e+07 | 1.621045e+07 | 1.703640e+09 | 1.127224e+09 |
10 | 2.012946e+06 | 2.071169e+07 | 1.250891e+07 | 1.474052e+09 | 8.773869e+08 |
11 | 2.010420e+06 | 2.100414e+07 | 1.291635e+07 | 1.479431e+09 | 9.196113e+08 |
12 | 2.319937e+06 | 2.419603e+07 | 1.524913e+07 | 1.740267e+09 | 1.109141e+09 |