import pandas as pd
import numpy as np
import bqplot
import ipywidgets
ghg = pd.read_csv('WA_GHG_Reporting_Multi-Year_Dataset(county_mod).csv',
na_values = {'2016 total emissions (MTCO2e)': ''})
ghg = ghg.dropna(axis=0, subset=['2016 total emissions (MTCO2e)'])
ghg
# I have modified the ghg dataset as follows:
# In the "County" column, "NA" is changed to "(Statewide)".
# This allows data not ascribed to a given county to be included in the heatmap below.
# Citation: Method for removing nulls in selected column adapted from:
# https://stackoverflow.com/questions/49291740/delete-rows-if-there-are-null-values-in-a-specific-column-in-pandas-dataframe
# (viewed 4/13/19)
Source | Sector | Subsector | City | County | Local Air Authority | 2012 total emissions (MTCO2e) | 2012 biogenic carbon dioxide (MTCO2e) | 2013 total emissions (MTCO2e) | 2013 biogenic carbon dioxide (MTCO2e) | 2014 total emissions (MTCO2e) | 2014 biogenic carbon dioxide (MTCO2e) | 2015 total emissions (MTCO2e) | 2015 biogenic carbon dioxide (MTCO2e) | 2016 total emissions (MTCO2e) | 2016 biogenic carbon dioxide (MTCO2e) | 2017 total emissions (MTCO2e) | 2017 biogenic carbon dioxide (MTCO2e) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Agrium Kennewick Fertilizer Operations (KFO) -... | Chemicals | Nitric Acid Production | Kennewick | Benton | Benton Clean Air Agency | 146926.0 | 0.0 | 154497.0 | 0.0 | 132249.0 | 0.0 | 155888.0 | 0.0 | 151371.0 | 0.0 | 144290.0 | 0.0 |
1 | Air Liquide - Anacortes | Chemicals | Hydrogen Production | Anacortes | Skagit | Northwest Clean Air Agency | 63356.0 | 0.0 | 58995.0 | 0.0 | 64110.0 | 0.0 | 64413.0 | 0.0 | 60209.0 | 0.0 | 63461.0 | 0.0 |
2 | Alcoa Intalco Works - Ferndale | Metals | Aluminum Production | Ferndale | Whatcom | Ecology: Industrial Section | 1146835.0 | 0.0 | 1234637.0 | 0.0 | 1326684.0 | 0.0 | 1195786.0 | 0.0 | 1261364.0 | 0.0 | 1091665.0 | 0.0 |
3 | Alcoa Wenatchee Works - Malaga | Metals | Aluminum Production | Malaga | Chelan | Ecology: Industrial Section | 306333.0 | 0.0 | 318542.0 | 0.0 | 354692.0 | 0.0 | 331207.0 | 0.0 | 898.0 | 0.0 | 0.0 | 0.0 |
4 | Alon Asphalt Company - Seattle | Petroleum and Natural Gas Systems | Other Petroleum and Natural Gas Systems | Seattle | King | Puget Sound Clean Air Agency | 15138.0 | 0.0 | 14336.0 | 0.0 | 16004.0 | 0.0 | 13688.0 | 0.0 | 14096.0 | 0.0 | 14818.0 | 0.0 |
5 | Ardagh Glass Inc. - Seattle | Minerals | Glass Production | Seattle | King | Puget Sound Clean Air Agency | 76257.0 | 0.0 | 80745.0 | 0.0 | 78044.0 | 0.0 | 76674.0 | 0.0 | 77845.0 | 0.0 | 75338.0 | 0.0 |
6 | Ascensus Specialties LLC - Elma | Chemicals | Other Chemicals | Elma | Grays Harbor | Olympic Region Clean Air Agency | 16809.0 | 0.0 | 17966.0 | 0.0 | 21231.0 | 0.0 | 17600.0 | 0.0 | 20802.0 | 0.0 | 21310.0 | 0.0 |
7 | Ash Grove Cement Company - Seattle | Minerals | Cement Production | Seattle | King | Puget Sound Clean Air Agency | 305298.0 | 0.0 | 354808.0 | 0.0 | 522982.0 | 0.0 | 495030.0 | 0.0 | 383836.0 | 0.0 | 355513.0 | 0.0 |
8 | Avista Corporation - WA State DOE Reporting - ... | Petroleum and Natural Gas Systems | Natural Gas Local Distribution Companies | Spokane | Spokane | Spokane Regional Clean Air Agency | 20992.0 | 0.0 | 16127.0 | 0.0 | 16420.0 | 0.0 | 22858.0 | 0.0 | 21120.0 | 0.0 | 23757.0 | 0.0 |
9 | Basic American Foods - Moses Lake | Food Production | Potato Products | Moses Lake | Grant | Ecology: Eastern Regional Office | 28205.0 | 0.0 | 28312.0 | 0.0 | 28982.0 | 0.0 | 31063.0 | 0.0 | 28977.0 | 0.0 | 30576.0 | 0.0 |
10 | Bio Energy Washington, LLC - Maple Valley | Power Plants | Other Power, Heating, or Cooling Plants | Maple Valley | King | Puget Sound Clean Air Agency | 13697.0 | 12800.0 | 28341.0 | 27018.0 | 28302.0 | 27006.0 | 30802.0 | 29306.0 | 29216.0 | 27510.0 | 28391.0 | 26962.0 |
11 | Boeing Commercial Airplanes - Everett | Manufacturing | Transportation | Everett | Snohomish | Puget Sound Clean Air Agency | 71463.0 | 0.0 | 73643.0 | 0.0 | 73522.0 | 0.0 | 66276.0 | 0.0 | 76191.0 | 0.0 | 80529.0 | 0.0 |
12 | Boeing Commercial Airplanes - Fabrication (Fre... | Manufacturing | Transportation | Puyallup | Pierce | Puget Sound Clean Air Agency | 22582.0 | 0.0 | 21969.0 | 0.0 | 21442.0 | 0.0 | 20833.0 | 0.0 | 19831.0 | 0.0 | 19893.0 | 0.0 |
13 | Boise Cascade Wood Products, LLC. Kettle Fall... | Wood Products | Lumber Mills | Kettle Falls | Stevens | Ecology: Eastern Regional Office | 41052.0 | 40173.0 | 56886.0 | 56136.0 | 57413.0 | 56656.0 | 57294.0 | 56539.0 | 53752.0 | 53043.0 | 54397.0 | 53680.0 |
14 | Boise Cascade Wood Products, LLC. Kettle Fall... | Wood Products | Engineered Wood | Kettle Falls | Stevens | Ecology: Eastern Regional Office | 68360.0 | 64637.0 | 71186.0 | 68156.0 | 71069.0 | 68040.0 | 71151.0 | 68501.0 | 73564.0 | 70714.0 | 70889.0 | 54924.0 |
15 | Boise Paper - Wallula | Pulp and Paper | Kraft Mills | Wallula | Walla Walla | Ecology: Industrial Section | 925349.0 | 791371.0 | 830754.0 | 727045.0 | 887912.0 | 765685.0 | 855520.0 | 717427.0 | 804657.0 | 645182.0 | 681208.0 | 528740.0 |
16 | Bonneville Power Administration - WA Only - st... | Power Plants | Use of Electrical Equipment | Vancouver | Clark | Southwest Clean Air Agency | 26927.0 | 0.0 | 42114.0 | 0.0 | 12800.0 | 0.0 | 14245.0 | 0.0 | 17121.0 | 0.0 | 15069.0 | 0.0 |
17 | Boulder Park Generating Station - Spokane Valley | Power Plants | Other Power, Heating, or Cooling Plants | Spokane Valley | Spokane | Spokane Regional Clean Air Agency | 2700.0 | 0.0 | 10795.0 | 0.0 | 7552.0 | 0.0 | 10952.0 | 0.0 | 9009.0 | 0.0 | 13286.0 | 0.0 |
18 | BP Cherry Point Refinery - Blaine | Refineries | Petroleum Refineries | Blaine | Whatcom | Northwest Clean Air Agency | 2223518.0 | 0.0 | 2552655.0 | 0.0 | 2301576.0 | 0.0 | 2093437.0 | 0.0 | 2418086.0 | 0.0 | 2131918.0 | 0.0 |
19 | Cardinal FG Company - Winlock | Minerals | Glass Production | Winlock | Lewis | Southwest Clean Air Agency | 92356.0 | 0.0 | 102904.0 | 0.0 | 102813.0 | 0.0 | 105009.0 | 0.0 | 107291.0 | 0.0 | 107590.0 | 0.0 |
20 | Cascade Natural Gas Corporation LDC - statewide | Petroleum and Natural Gas Systems | Natural Gas Local Distribution Companies | Kennewick | Benton | Benton Clean Air Agency | 12622.0 | 0.0 | 12940.0 | 0.0 | 13506.0 | 0.0 | 22852.0 | 0.0 | 23616.0 | 0.0 | 26227.0 | 0.0 |
21 | Cathcart Landfill - Snohomish | Waste | Municipal Landfills | Snohomish | Snohomish | Puget Sound Clean Air Agency | 27653.0 | 0.0 | 23893.0 | 0.0 | 22454.0 | 0.0 | 23520.0 | 0.0 | 17417.0 | 0.0 | 28273.0 | 0.0 |
22 | Central Washington University - Ellensburg | Government | Education | Ellensburg | Kittitas | Ecology: Central Regional Office | 13358.0 | 0.0 | 13451.0 | 0.0 | 13673.0 | 0.0 | 12838.0 | 0.0 | 12449.0 | 0.0 | 13669.0 | 0.0 |
23 | CertainTeed Gypsum - Seattle | Manufacturing | Gypsum Manufacturing | Seattle | King | Puget Sound Clean Air Agency | 35650.0 | 0.0 | 35465.0 | 0.0 | 36299.0 | 0.0 | 38141.0 | 0.0 | 47948.0 | 0.0 | 50452.0 | 0.0 |
24 | Cheyne Landfill - Zillah | Waste | Municipal Landfills | Zillah | Yakima | Yakima Regional Clean Air Agency | 30500.0 | 0.0 | 31807.0 | 0.0 | 33147.0 | 0.0 | 34450.0 | 0.0 | 35837.0 | 0.0 | 37331.0 | 0.0 |
26 | City of Tacoma Solid Waste Facility - Tacoma | Waste | Municipal Landfills | Tacoma | Pierce | Puget Sound Clean Air Agency | 31986.0 | 0.0 | 26643.0 | 0.0 | 20396.0 | 0.0 | 14812.0 | 0.0 | 14513.0 | 0.0 | 16417.0 | 0.0 |
27 | ConAgra Foods Lamb Weston - Connell | Food Production | Potato Products | Connell | Franklin | Ecology: Eastern Regional Office | 39714.0 | 0.0 | 39841.0 | 0.0 | 38810.0 | 0.0 | 36801.0 | 0.0 | 37212.0 | 0.0 | 35862.0 | 0.0 |
28 | ConAgra Foods Lamb Weston - Quincy | Food Production | Potato Products | Quincy | Grant | Ecology: Eastern Regional Office | 39693.0 | 0.0 | 39846.0 | 0.0 | 38324.0 | 0.0 | 37922.0 | 0.0 | 40468.0 | 0.0 | 34928.0 | 0.0 |
29 | Cosmo Specialty Fibers Inc - Cosmopolis | Pulp and Paper | Sulfite Mills | Cosmopolis | Grays Harbor | Ecology: Industrial Section | 1186972.0 | 1150934.0 | 1105362.0 | 1078626.0 | 1185707.0 | 1152820.0 | 1170393.0 | 1144912.0 | 989316.0 | 963065.0 | 701686.0 | 676644.0 |
30 | Cowlitz County Headquarters Landfill - Castle ... | Waste | Municipal Landfills | Castle Rock | Cowlitz | Southwest Clean Air Agency | 121597.0 | 659.0 | 129060.0 | 556.0 | 154619.0 | 1205.0 | 190202.0 | 2097.0 | 178854.0 | 7724.0 | 218522.0 | 11096.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
152 | Waste Management Greater Wenatchee Regional La... | Waste | Municipal Landfills | East Wenatchee | Douglas | Ecology: Central Regional Office | 36141.0 | 0.0 | 31854.0 | 0.0 | 32740.0 | 0.0 | 31208.0 | 0.0 | 30653.0 | 0.0 | 27951.0 | 0.0 |
153 | WestRock CP, LLC - Tacoma | Pulp and Paper | Kraft Mills | Tacoma | Pierce | Ecology: Industrial Section | 1082809.0 | 940615.0 | 1039284.0 | 925083.0 | 1173531.0 | 1059608.0 | 1135442.0 | 1011954.0 | 1134873.0 | 1011165.0 | 1124426.0 | 1000676.0 |
154 | Weyerhaeuser Raymond Lumber - Raymond | Wood Products | Lumber Mills | Raymond | Pacific | Olympic Region Clean Air Agency | 45768.0 | 44790.0 | 47339.0 | 46369.0 | 48445.0 | 47806.0 | 46229.0 | 45632.0 | 46747.0 | 46747.0 | 48561.0 | 47921.0 |
156 | Ascent Aviation Group Inc | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 18223.0 | 0.0 | 15728.0 | 0.0 | 44724.0 | 0.0 | 66762.0 | 0.0 | 66269.0 | 0.0 | 45678.0 | 0.0 |
157 | Associated Petroleum Products, Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 1003689.0 | 0.0 | 1054993.0 | 36292.0 | 1325248.0 | 45274.0 | 1686102.0 | 58808.0 | 1990731.0 | 65716.0 | 2330279.0 | 76484.0 |
158 | Avfuel Corporation | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 41989.0 | 0.0 | 67999.0 | 0.0 | 83459.0 | 0.0 | 75236.0 | 0.0 | 32347.0 | 0.0 | 103100.0 | 0.0 |
159 | BP West Coast Products LLC | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 7291311.0 | 0.0 | 6053769.0 | 0.0 | 5866602.0 | 0.0 | 6092051.0 | 0.0 | 5544958.0 | 0.0 | 4814803.0 | 0.0 |
160 | Chevron U.S.A. Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 2921033.0 | 180260.0 | 3096698.0 | 190620.0 | 3154826.0 | 193502.0 | 3093693.0 | 190217.0 | 3079994.0 | 190121.0 | 3028590.0 | 187837.0 |
161 | CHS INC. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 618830.0 | 29251.0 | 613851.0 | 9449.0 | 691788.0 | 37979.0 | 705927.0 | 0.0 | 713406.0 | 0.0 | 707879.0 | 0.0 |
162 | CityServiceValcon LLC | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 174415.0 | 394.0 | 325002.0 | 15275.0 | 358213.0 | 17373.0 | 384845.0 | 19040.0 | 396231.0 | 17935.0 | 396100.0 | 1905.0 |
167 | Equilon Enterprises LLC dba Shell Oil Products US | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 3115901.0 | 163141.0 | 3566781.0 | 0.0 | 3813545.0 | 0.0 | 4523704.0 | 0.0 | 5292512.0 | 0.0 | 5985748.0 | 0.0 |
168 | ExxonMobil Oil Corporation | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 789950.0 | 47558.0 | 963246.0 | 61463.0 | 859726.0 | 54950.0 | 903301.0 | 58167.0 | 831233.0 | 53419.0 | 867077.0 | 55933.0 |
171 | IPC (USA), Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 198273.0 | 0.0 | 321387.0 | 0.0 | 395591.0 | 0.0 | 33803.0 | 0.0 | 14772.0 | 14.0 | NaN | NaN |
172 | PetroCard Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 529844.0 | 0.0 | 191708.0 | 7558.0 | 1066990.0 | 34044.0 |
174 | Phillips 66 Company | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 4416054.0 | 218663.0 | 4941002.0 | 268520.0 | 5276097.0 | 290281.0 | 5252409.0 | 285529.0 | 4761013.0 | 266360.0 | 3907576.0 | 225513.0 |
176 | RPMG, Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 452188.0 | 452188.0 | 371271.0 | 371271.0 | 338028.0 | 338028.0 | 401017.0 | 401017.0 | 448981.0 | 448981.0 | 97522.0 | 97522.0 |
177 | SEI Fuel Services, Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 381994.0 | 25484.0 | 358202.0 | 23907.0 | 396729.0 | 26479.0 | 312704.0 | 20572.0 | 346741.0 | 20812.0 | 316171.0 | 20344.0 |
178 | Sinclair Oil Corporation | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 15653.0 | 0.0 | 21056.0 | 0.0 | 57314.0 | 0.0 | 89794.0 | 0.0 | 122139.0 | 0.0 | 163446.0 | 0.0 |
179 | Southern Counties Oil Co Ltd | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 111922.0 | 5812.0 | 119268.0 | 6290.0 | 96845.0 | 4022.0 | 106342.0 | 2231.0 | 97613.0 | 3327.0 | 68529.0 | 1554.0 |
180 | Targa Sound Terminal | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 81445.0 | 27441.0 | 19092.0 | 7800.0 | 19757.0 | 6378.0 | 14436.0 | 8114.0 | 17924.0 | 8021.0 | 14527.0 | 3411.0 |
181 | Tesoro Refining & Marketing Company LLC | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 6158377.0 | 0.0 | 5740456.0 | 0.0 | 5713367.0 | 0.0 | 5604007.0 | 266252.0 | 5228903.0 | 273546.0 | 5081912.0 | 273012.0 |
182 | The Boeing Company | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 107661.0 | 0.0 | 126519.0 | 0.0 | 129491.0 | 0.0 | 118525.0 | 0.0 | 120830.0 | 0.0 | 129232.0 | 0.0 |
183 | U.S. Oil & Refining Co. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 1159448.0 | 0.0 | 1175482.0 | 0.0 | 1310797.0 | 0.0 | 1292825.0 | 0.0 | 1288944.0 | 0.0 | 1177990.0 | 0.0 |
184 | United Parcel Service Co | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 62859.0 | 0.0 | 47767.0 | 0.0 | 50987.0 | 0.0 | 50052.0 | 0.0 | 56975.0 | 0.0 | 62975.0 | 0.0 |
185 | UPS Fuel Services, Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 31398.0 | 0.0 | 31599.0 | 0.0 | 32640.0 | 0.0 | 32845.0 | 0.0 | 33450.0 | 0.0 | 34518.0 | 0.0 |
186 | Valero Marketing and Supply Company | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 162579.0 | 10502.0 | 126614.0 | 8077.0 | 111391.0 | 7758.0 | 110012.0 | 6829.0 | 33485.0 | 2205.0 | 27291.0 | 1797.0 |
187 | Vitol Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 725057.0 | 42882.0 | 466188.0 | 27546.0 | 14658.0 | 921.0 | 12307.0 | 788.0 | 1551.0 | 104.0 | 98.0 | 7.0 |
188 | Western Petroleum Company | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 63500.0 | 457.0 | 19420.0 | 685.0 | 21216.0 | 463.0 | 11132.0 | 48.0 | 19449.0 | 478.0 | 12906.0 | 239.0 |
189 | Wilson Oil Inc | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 1232072.0 | 50925.0 | 1197669.0 | 46854.0 | 1193047.0 | 47740.0 | 1157609.0 | 46220.0 | 1207292.0 | 49518.0 | 1251997.0 | 51446.0 |
190 | World Fuel Services, Inc. | Transportation Fuel Supplier | Transportation Fuel Supplier | NaN | (Statewide) | NaN | 262127.0 | 4796.0 | 235658.0 | 5443.0 | 242219.0 | 5476.0 | 326040.0 | 5479.0 | 401673.0 | 5634.0 | 314725.0 | 3016.0 |
177 rows × 18 columns
x = ghg['Sector']
y = ghg['2016 total emissions (MTCO2e)']
xnames = x.unique()
ynames = y.unique()
for i,xn in enumerate(xnames):
mask = (x == xn)
ynames[i] = y[mask].sum()
x_sc = bqplot.OrdinalScale()
y_sc = bqplot.LinearScale()
x_ax = bqplot.Axis(scale = x_sc,
label = 'Sector',
label_offset = '60px',
tick_rotate = 70,
tick_style = {'font-size':'12px'},
offset = {'scale':x_sc, 'value':'60px'})
y_ax = bqplot.Axis(scale = y_sc,
orientation = 'vertical',
side = 'left',
label = 'Emissions (MT CO2e)',
label_offset = '50px')
sect_bar = bqplot.Bars(x = xnames,
y = ynames,
color_mode = 'element',
scales = {'x': x_sc, 'y': y_sc},
opacities = [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],
interactions = {'click': 'select'},
anchor_style = {'fill':'red'},
selected_style = {'fill':'red','opacity': 0.5},
unselected_style = {'opacity': 1.0})
fig_sect = bqplot.Figure(marks = [sect_bar],
axes = [x_ax, y_ax],
fig_margin = {'top':60, 'bottom':120, 'left':70, 'right':40},
title = "WA greenhouse gas emissions by sector, 2016")
# I have set "opacities" in bqplot.Bars to 0.5 for each of the 13 bars
# (apparently you need to do them individually), to make the intruding tick labels visible.
# But this has not worked: the bars remain fully opaque.
# Setting "opacity" to 0.5 under "unselected style" does make the selected bar translucent.
x2 = ghg['Subsector'].values
y2 = ghg['2016 total emissions (MTCO2e)'].values
x2_sc = bqplot.OrdinalScale()
y2_sc = bqplot.LinearScale()
x2_ax = bqplot.Axis(scale = x2_sc,
label = 'Subsector',
label_offset = '70px',
tick_values = x2,
tick_rotate = 45,
tick_style = {'font-size':'12px'})
y2_ax = bqplot.Axis(scale = y2_sc,
label = 'Emissions (MT CO2e)',
label_offset = '50px',
orientation = 'vertical',
side = 'left')
i = 0
mask = (x.values == xnames[i])
subsect = x2[mask]
emis2 = y2[mask]
emis2 = emis2[~pd.isnull(subsect)]
subsect = subsect[~pd.isnull(subsect)]
subsectu = np.unique(subsect)
emis2u = [emis2[subsect == subsect[i]].sum() for i in range(len(subsectu)) ]
subsect_bar = bqplot.Bars(x = subsectu,
y = emis2u,
color_mode = 'element',
scales = {'x': x2_sc, 'y': y2_sc})
fig_subsect = bqplot.Figure(marks = [subsect_bar],
axes = [x2_ax, y2_ax],
fig_margin = {'top':60, 'bottom':120, 'left':70, 'right':60},
title = "Emissions by subsector")
emis_tot = ghg['2016 total emissions (MTCO2e)'].sum()
emis_tot
63948300.0
mySelectedLabel1a = ipywidgets.Label()
mySelectedLabel1b = ipywidgets.Label()
def get_data_value(change):
if change['owner'].selected is not None:
i = change['owner'].selected[0]
mask = (x.values == xnames[i])
subsect = x2[mask]
emis2 = y2[mask]
emis2 = emis2[~pd.isnull(subsect)]
subsect = subsect[~pd.isnull(subsect)]
subsectu = np.unique(subsect)
emis2 = [emis2[subsect == subsectu[b]].sum() for b in range(len(subsectu)) ]
emis2 = np.array(emis2)
v = emis2.sum()
pct = v/emis_tot*100
mySelectedLabel1a.value = 'Sector GHG emissions = ' + str(v)
mySelectedLabel1b.value = 'Percentage of total = ' + str(round(pct,1))
subsect_bar.x = subsectu
subsect_bar.y = emis2
sect_bar.observe(get_data_value, 'selected')
fig_sect.layout.max_width = '500px'
fig_sect.layout.max_height= '500px'
fig_subsect.layout.max_width='300px'
fig_subsect.layout.max_height='400px'
epa_raw = pd.read_csv('EPA sectors 1990-2017.csv')
exclude = ['Total', 'U.S. territories']
epa = epa_raw[~epa_raw['Economic Sector'].isin(exclude)]
# Citation: Pandas dataframe filter method adapted from:
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.isin.html
# (viewed 4/18/19)
xE = epa['Economic Sector']
yE = epa['2016']
xEnames = xE.unique()
yEnames = yE.unique()
for i,xEn in enumerate(xEnames):
maskE = (xE == xEn)
yEnames[i] = yE[maskE].sum()
xE_sc = bqplot.OrdinalScale()
yE_sc = bqplot.LinearScale()
xE_ax = bqplot.Axis(scale = xE_sc,
label = 'Sector',
label_offset = '60px',
tick_rotate = 45,
# tick_style = {'font-size':'10px', 'tick_offset':'100px','text_anchor':'top'})
tick_style = {'font-size':'12px'},
offset = {'scale':x_sc, 'value':'60px'})
yE_ax = bqplot.Axis(scale = yE_sc,
orientation = 'vertical',
side = 'left',
label = 'Emissions (MT CO2e)',
label_offset = '50px')
epa_bar = bqplot.Bars(x = xEnames,
y = yEnames,
color_mode = 'element',
scales = {'x': xE_sc, 'y': yE_sc},
interactions = {'click': 'select'},
anchor_style = {'fill':'red'},
selected_style = {'fill':'red','opacity': 0.5},
unselected_style = {'opacity': 1.0})
fig_epa = bqplot.Figure(marks = [epa_bar],
axes = [xE_ax, yE_ax],
fig_margin = {'top':60, 'bottom':120, 'left':70, 'right':60},
title = "US greenhouse gas emissions by sector, 2016")
fig_epa.layout.max_width = '500px'
fig_epa.layout.max_height= '500px'
emisE_tot = epa['2016'].sum()
emisE_tot
mySelectedLabelEa = ipywidgets.Label()
mySelectedLabelEb = ipywidgets.Label()
def get_data_valueE(change):
if change['owner'].selected is not None:
i = change['owner'].selected[0]
maskE = (xE.values == xEnames[i])
sectE = xE[maskE]
emisE = yE[maskE]
emisE = emisE[~pd.isnull(sectE)]
sectE = sectE[~pd.isnull(sectE)]
sectEu = np.unique(sectE)
emisEu = [emisE[sectE == sectEu[b]].sum() for b in range(len(sectEu)) ]
emisEu = np.array(emisEu)
vE = emisEu.sum()
pctE = vE/emisE_tot*100
mySelectedLabelEa.value = 'US sector GHG emissions = ' + str(vE)
mySelectedLabelEb.value = 'Percentage of total = ' + str(round(pctE,1))
epa_bar.observe(get_data_valueE, 'selected')
x3 = ghg['Sector']
y3 = ghg['County']
z3 = ghg['2016 total emissions (MTCO2e)']
x3names = x3.unique()
y3names = y3.unique()
z3names = np.zeros([len(x3names),len(y3names)])
for i,x3n in enumerate(x3names):
for j, y3n in enumerate(y3names):
mask3 = (x3 == x3n) & (y3 == y3n)
z3names[i,j] = z3[mask3].sum()
col_sc = bqplot.ColorScale(scheme="RdPu")
x3_sc = bqplot.OrdinalScale()
y3_sc = bqplot.OrdinalScale()
c_ax = bqplot.ColorAxis(scale = col_sc,
orientation = 'vertical',
side = 'right')
x3_ax = bqplot.Axis(scale = x3_sc,
label='County',
label_offset = '50px',
tick_rotate=90,
tick_style = {'font-size':'12px'},
offset = {'scale':x3_sc, 'value':'50'})
y3_ax = bqplot.Axis(scale = y3_sc,
orientation = 'vertical',
label = 'Sector',
label_offset = '120px',
tick_style = {'font-size':'12px'})
heat_map = bqplot.GridHeatMap(color = np.log10(z3names),
row = x3names,
column = y3names,
scales = {'color': col_sc,
'row': y3_sc,
'column': x3_sc},
interactions = {'click': 'select'},
anchor_style = {'fill':'blue'},
selected_style = {'opacity': 1.0},
unselected_style = {'opacity': 1.0})
fig_hm = bqplot.Figure(marks = [heat_map],
axes = [c_ax, y3_ax, x3_ax],
fig_margin = dict(top=60, bottom=80, left=200, right=50),
title = "WA greenhouse gas emissions by sector and county, 2016")
fig_hm.layout.width = '900px'
fig_hm.layout.height= '500px'
C:\Users\Ian\Anaconda3\lib\site-packages\ipykernel_launcher.py:21: RuntimeWarning: divide by zero encountered in log10
x4 = ghg['Subsector'].values
y4 = ghg['2016 total emissions (MTCO2e)'].values
x4_sc = bqplot.OrdinalScale()
y4_sc = bqplot.LinearScale()
x4_ax = bqplot.Axis(scale=x4_sc,
label='Subsector',
label_offset = '40px',
tick_rotate=10,
tick_style={'font-size':'12px'})
y4_ax = bqplot.Axis(scale=y4_sc,
label='Emissions (MT CO2e)',
label_offset = '50px',
orientation='vertical')
i,j = 0,0
mask3 = (x3.values == x3names[i]) & (y3.values == y3names[j])
subsect4 = x4[mask3]
emis4 = y4[mask3]
emis4 = emis4[~pd.isnull(subsect4)]
subsect4 = subsect4[~pd.isnull(subsect4)]
subsect4u = np.unique(subsect4)
emis4u = [emis4[subsect4 == subsect4[i]].sum() for i in range(len(subsect4u)) ]
bar4 = bqplot.Bars(x = subsect4u,
y = emis4u,
color_mode = 'element',
scales = {'x': x4_sc, 'y': y4_sc})
fig_bar4 = bqplot.Figure(marks = [bar4],
axes = [x4_ax, y4_ax],
fig_margin = {'top':60, 'bottom':120, 'left':70, 'right':50},
title = 'County emissions by subsector')
fig_bar4.layout.max_width='300px'
fig_bar4.layout.max_height='400px'
mySelectedLabel2 = ipywidgets.Label()
def get_data_value3(change):
i,j = change['owner'].selected[0]
mask3 = (x3.values == x3names[i]) & (y3.values == y3names[j])
subsect4 = x4[mask3]
emis4 = y4[mask3]
emis4 = emis4[~pd.isnull(subsect4)]
subsect4 = subsect4[~pd.isnull(subsect4)]
subsect4u = np.unique(subsect4)
emis4u = [emis4[subsect4 == subsect4u[b]].sum() for b in range(len(subsect4u)) ]
emis4u = np.array(emis4u)
v = emis4u.sum(),
mySelectedLabel2.value = 'Sector GHG emissions for county = ' + str(v)
bar4.x = subsect4u
bar4.y = emis4u
heat_map.observe(get_data_value3, 'selected')
Nationally, power generation through fossil fuels is a major contributor to global warming. What impact might we expect from the wide scale adoption of renewable power sources? We look at the data from Washington, a state in which renewables - largely hydroelectricity - already account for 90% of electricity production.
All data is from the year 2016, the most recent for which comparative datasets are available. Emissions are calculated in metric tons (MT) of carbon dioxide equivalents (CO2e), a measure which converts all greenhouse gases to an equivalent volume of carbon dioxide, to provide a basis for direct comparison.
We begin by looking at Washington state's greenhouse gas emission profile. The visualization shows that electricity generation (power plants) accounts for almost 16% of the state's greenhouse gas production. This is a distant second to transportation fuel supply (51%); combined with the related industry of refining (10%), oil production and use production account for 61% of the state's emissions.
How much variation is there within each sector? Click on the bar for a given sector to see the contributions of individual subsectors. For example, the "Power plants" breakdown shows that coal plants still account for the largest proportion of fossil-fuel power generation, though natural gas plants are catching up.
Data is provided by the Washington Department of Ecology (available at: https://data.wa.gov/Natural-Resources-Environment/WA-GHG-Reporting-Multi-Year-Dataset/jbe2-ek4r).
ipywidgets.VBox([mySelectedLabel1a, mySelectedLabel1b, ipywidgets.HBox([fig_sect, fig_subsect])])
VBox(children=(Label(value=''), Label(value=''), HBox(children=(Figure(axes=[Axis(label='Sector', label_offset…
How does Washington state's greenhouse gas profile compare with the US average? Differences in the structure of state and national datasets make precise comparison difficult. But one stark point of contrast leaps out: whereas in Washington state the carbon footprint of power plants is less than a third of that of the transport industry, nationally the two sectors run head-to-head as the biggest greenhouse gas emitters. This demonstrates the sizable scale of emissions reduction made possible by switching to green power generation.
Data is provided by the United States Environmental Protection Agency (EPA) (available at: https://cfpub.epa.gov/ghgdata/inventoryexplorer/)
ipywidgets.VBox([mySelectedLabelEa, mySelectedLabelEb, fig_epa])
VBox(children=(Label(value=''), Label(value=''), Figure(axes=[Axis(label='Sector', label_offset='60px', offset…
How consistent are industry practices across the state? Which regions and sectors should be targeted for further carbon footprint reductions? This heatmap and accompanying bar chart reveal considerable regional variation. If we look at power plants, we can see from the heatmap that Lewis county has the highest emissions. The interactive bar chart reveals this county is home to state's last surviving coal plant. Checking again the breakdown of power plant emissions statewide (first visualization), we see this single coal plant produces higher emissions than all other fossil-fuel power plants combined.
Data is again from the Washington Department of Ecology dataset, cited above.
ipywidgets.VBox([mySelectedLabel2, ipywidgets.HBox([fig_hm, fig_bar4])])
VBox(children=(Label(value=''), HBox(children=(Figure(axes=[ColorAxis(orientation='vertical', scale=ColorScale…
These visualizations adapt design features and a substantial amount of code from class examples and from the solution to the Assignment 6 problem provided by Dr. Jill Naiman ("hwex.ipynb", personal communication, 3/15/2019). I also thank Dr. Naiman for helping with numerous individual problems, and 590 DVO classmates for their valuable suggestions.
Washington county map: http://www.dva.wa.gov/benefits/county-map (accessed 4/23/19)
Code for embedding git file adapted from: https://stackoverflow.com/questions/51527868/how-do-i-embed-a-gif-in-jupyter-notebook (accessed 4/23/19)