Skip to content

Instantly share code, notes, and snippets.

@barronh
Last active April 24, 2025 22:41
Show Gist options
  • Save barronh/f07453f20665c0ebcb3f5d8aaec5aad8 to your computer and use it in GitHub Desktop.
Save barronh/f07453f20665c0ebcb3f5d8aaec5aad8 to your computer and use it in GitHub Desktop.
Summary of Criteria or Hazardous Air Pollutants by 60 EIS sectors.
__doc__ = """
NEI Emission Summary
====================
---
author: Barron H. Henderson
last updated: 2025-04-17
---
Simple script to get Criteria or Hazardous Air Pollutants by 60 EIS emission
sectors for the 2020 NEI. The results allow you to calculate fractions of
sectors and/or fractions of sector aggregates.
The data is embedded and was created by:
1. Going to link https://enviro.epa.gov/envirofacts/embed/nei?pType=SECTOR&pReport=nation&pState=&pPollutant=&pPollutant=NOX&pSector=&pYear=2020&pCounty=&pTier=&pWho=NEI
2. Clicking copy
3. Pasting in csvstr between quotes
Note that the link also supports different:
* years: 2008, 2011, 2014, 2017, 2020
* species: NOX, CO, VOC, SO2, NH3, PM25-PRI, PM10-PRI
"""
__version__ = '1.0.0'
import io
import pandas as pd
csvstr = """SECTOR,POLLUTANT,POLLUTANT TYPE,EMISSIONS,UNIT OF MEASURE
Mobile - On-Road Diesel Heavy Duty Vehicles,Nitrogen Oxides,CAP,1324144,TON
Biogenics - Vegetation and Soil,Nitrogen Oxides,CAP,1028568,TON
Mobile - On-Road non-Diesel Light Duty Vehicles,Nitrogen Oxides,CAP,846917,TON
Mobile - Non-Road Equipment - Diesel,Nitrogen Oxides,CAP,654389,TON
Industrial Processes - Oil & Gas Production,Nitrogen Oxides,CAP,613236,TON
"Fuel Comb - Industrial Boilers, ICEs - Natural Gas",Nitrogen Oxides,CAP,577959,TON
Fuel Comb - Electric Generation - Coal,Nitrogen Oxides,CAP,575037,TON
Mobile - Locomotives,Nitrogen Oxides,CAP,462507,TON
Fires - Wildfires,Nitrogen Oxides,CAP,246135,TON
Mobile - Commercial Marine Vessels,Nitrogen Oxides,CAP,240086,TON
Fuel Comb - Residential - Natural Gas,Nitrogen Oxides,CAP,215690,TON
Mobile - Non-Road Equipment - Gasoline,Nitrogen Oxides,CAP,187448,TON
Fuel Comb - Electric Generation - Natural Gas,Nitrogen Oxides,CAP,177953,TON
Fires - Prescribed Fires,Nitrogen Oxides,CAP,148752,TON
Mobile - On-Road Diesel Light Duty Vehicles,Nitrogen Oxides,CAP,142732,TON
Fuel Comb - Comm/Institutional - Natural Gas,Nitrogen Oxides,CAP,140180,TON
"Fuel Comb - Industrial Boilers, ICEs - Biomass",Nitrogen Oxides,CAP,133970,TON
Industrial Processes - NEC,Nitrogen Oxides,CAP,131434,TON
Industrial Processes - Cement Manuf,Nitrogen Oxides,CAP,106709,TON
Waste Disposal,Nitrogen Oxides,CAP,83640,TON
Mobile - Aircraft,Nitrogen Oxides,CAP,83423,TON
"Fuel Comb - Industrial Boilers, ICEs - Oil",Nitrogen Oxides,CAP,74908,TON
Industrial Processes - Pulp & Paper,Nitrogen Oxides,CAP,68190,TON
Industrial Processes - Petroleum Refineries,Nitrogen Oxides,CAP,60980,TON
Industrial Processes - Chemical Manuf,Nitrogen Oxides,CAP,59211,TON
Fuel Comb - Electric Generation - Oil,Nitrogen Oxides,CAP,55427,TON
Fuel Comb - Residential - Wood,Nitrogen Oxides,CAP,49794,TON
"Fuel Comb - Industrial Boilers, ICEs - Other",Nitrogen Oxides,CAP,47600,TON
Industrial Processes - Ferrous Metals,Nitrogen Oxides,CAP,44490,TON
Fuel Comb - Comm/Institutional - Oil,Nitrogen Oxides,CAP,43585,TON
"Fuel Comb - Industrial Boilers, ICEs - Coal",Nitrogen Oxides,CAP,41858,TON
Mobile - Non-Road Equipment - Other,Nitrogen Oxides,CAP,37334,TON
Fuel Comb - Residential - Other,Nitrogen Oxides,CAP,36694,TON
Mobile - On-Road non-Diesel Heavy Duty Vehicles,Nitrogen Oxides,CAP,31178,TON
Fires - Agricultural Field Burning,Nitrogen Oxides,CAP,30460,TON
Fuel Comb - Residential - Oil,Nitrogen Oxides,CAP,28379,TON
Fuel Comb - Electric Generation - Other,Nitrogen Oxides,CAP,22971,TON
Fuel Comb - Comm/Institutional - Other,Nitrogen Oxides,CAP,15981,TON
Industrial Processes - Non-ferrous Metals,Nitrogen Oxides,CAP,12388,TON
Fuel Comb - Comm/Institutional - Biomass,Nitrogen Oxides,CAP,10141,TON
Fuel Comb - Electric Generation - Biomass,Nitrogen Oxides,CAP,8733,TON
Industrial Processes - Mining,Nitrogen Oxides,CAP,4185,TON
Solvent - Industrial Surface Coating & Solvent Use,Nitrogen Oxides,CAP,2433,TON
Miscellaneous Non-Industrial NEC,Nitrogen Oxides,CAP,2174,TON
Industrial Processes - Storage and Transfer,Nitrogen Oxides,CAP,2044,TON
Fuel Comb - Comm/Institutional - Coal,Nitrogen Oxides,CAP,2008,TON
Bulk Gasoline Terminals,Nitrogen Oxides,CAP,366,TON
Solvent - Graphic Arts,Nitrogen Oxides,CAP,72,TON
Gas Stations,Nitrogen Oxides,CAP,36,TON
Solvent - Dry Cleaning,Nitrogen Oxides,CAP,4,TON
Solvent - Degreasing,Nitrogen Oxides,CAP,4,TON
Agriculture - Livestock Waste,Nitrogen Oxides,CAP,2,TON
Dust - Construction Dust,Nitrogen Oxides,CAP,0,TON"""
df = pd.read_csv(io.StringIO(csvstr), index_col=0)[['EMISSIONS']]
df.columns = [k.replace(' ', '_') for k in df.columns]
sumscts = list(df.index)
totalemis = df.loc[sumscts, 'EMISSIONS'].sum()
df['Major'] = df.index.str.partition(' - ').map(lambda x: x[0])
mdf = df.groupby('Major').sum()
# Add a custom subset
onroadscts = [k for k in df.index if k.startswith('Mobile - On-Road')]
mdf.loc['Mobile - On-Road Total', 'EMISSIONS'] = df.loc[onroadscts, "EMISSIONS"].sum()
# Add a total
mdf.loc['Total', 'EMISSIONS'] = totalemis
df['PCT'] = df['EMISSIONS'] / totalemis * 100
df['KTON'] = df['EMISSIONS'] / 1000.
mdf['PCT'] = (mdf['EMISSIONS'] / totalemis * 100)
mdf['KTON'] = mdf['EMISSIONS'] / 1000.
print(mdf.loc[:, ['KTON', 'PCT']].round(1).to_markdown())
@barronh
Copy link
Author

barronh commented Apr 17, 2025

Expected output:

| Major                            |   KTON |   PCT |
|:---------------------------------|-------:|------:|
| Agriculture                      |    0   |   0   |
| Biogenics                        | 1028.6 |  11.5 |
| Bulk Gasoline Terminals          |    0.4 |   0   |
| Dust                             |    0   |   0   |
| Fires                            |  425.3 |   4.8 |
| Fuel Comb                        | 2258.9 |  25.3 |
| Gas Stations                     |    0   |   0   |
| Industrial Processes             | 1102.9 |  12.4 |
| Miscellaneous Non-Industrial NEC |    2.2 |   0   |
| Mobile                           | 4010.2 |  45   |
| Solvent                          |    2.5 |   0   |
| Waste Disposal                   |   83.6 |   0.9 |
| Mobile - On-Road Total           | 2345   |  26.3 |
| Total                            | 8914.5 | 100   |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment