Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproduce 2017 #20

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fied/frs/frs_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@ def find_eis(acrnm):
frs_methods.download_unzip_frs_data(combined=combined)

frs_data_df = frs_methods.import_format_frs(combined=combined)
frs_data_df.to_csv(Path(__file__).parents[1], 'data/FRS/frs_data_formatted.csv')
frs_data_df.to_csv(
os.path.join(
Path(__file__).parents[1],
'data/FRS/frs_data_formatted.csv')
)

# t_stop = time.perf_counter()
# logging.info(f'Program time: {t_stop - t_start:0.2f} seconds')
99 changes: 51 additions & 48 deletions fied/ghgrp/ghgrp_fac_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,77 @@
import logging


class GHGRP_unit_char():
def load_fueltype_dict():
"""
Opens and loads a yaml that specifies the mapping of
GHGRP fuel types to standard fuel types that have
aready been applied to NEI data.

Returns
-------
fuel_dict : dictionary
Dictionary of mappings between GHGRP fuel types and
generic fuel types that have been applied to NEI data.
"""

with open('./tools/type_standardization.yml', 'r') as file:
docs = yaml.safe_load_all(file)

for i, d in enumerate(docs):
if i == 0:
fuel_dict = d
else:
continue

def __init__(self, ghgrp_energy_file, reporting_year):
return fuel_dict

logging.basicConfig(level=logging.INFO)

self._ghgrp_unit_url = 'https://www.epa.gov/system/files/other-files/2022-10/emissions_by_unit_and_fuel_type_c_d_aa_10_2022.zip'
# #TODO make into a tools method
def harmonize_fuel_type(ghgrp_unit_data, fuel_type_column):
"""
Applies fuel type mapping to fuel types reported under GHGRP.

self._data_dir = os.path.abspath('./data/GHGRP/')
Parameters
----------
ghgrp_unit_data : pandas.DataFrame

self._ghgrp_energy_file = ghgrp_energy_file
fuel_type_column : str
Name of column containing fuel types.

self._data_source = 'GHGRP'
Returns
-------
ghgrp_unit_data : pandas.DataFrame

self._reporting_year = reporting_year
"""

def load_fueltype_dict(self):
"""
Opens and loads a yaml that specifies the mapping of
GHGRP fuel types to standard fuel types that have
aready been applied to NEI data.
fuel_dict = load_fueltype_dict()

Returns
-------
fuel_dict : dictionary
Dictionary of mappings between GHGRP fuel types and
generic fuel types that have been applied to NEI data.
"""
ghgrp_unit_data.loc[:, 'fuelTypeStd'] = ghgrp_unit_data[fuel_type_column].map(fuel_dict)

with open('./tools/type_standardization.yml', 'r') as file:
docs = yaml.safe_load_all(file)
# drop any fuelTypes that are null
ghgrp_unit_data = ghgrp_unit_data.where(
ghgrp_unit_data[fuel_type_column] != 'None'
).dropna(how='all')

for i, d in enumerate(docs):
if i == 0:
fuel_dict = d
else:
continue
return ghgrp_unit_data

return fuel_dict

# #TODO make into a tools method
def harmonize_fuel_type(self, ghgrp_unit_data, fuel_type_column):
"""
Applies fuel type mapping to fuel types reported under GHGRP.
class GHGRP_unit_char():

Parameters
----------
ghgrp_unit_data : pandas.DataFrame
def __init__(self, ghgrp_energy_file, reporting_year):

fuel_type_column : str
Name of column containing fuel types.
logging.basicConfig(level=logging.INFO)

Returns
-------
ghgrp_unit_data : pandas.DataFrame
self._ghgrp_unit_url = 'https://www.epa.gov/system/files/other-files/2022-10/emissions_by_unit_and_fuel_type_c_d_aa_10_2022.zip'

"""
self._data_dir = os.path.abspath('./data/GHGRP/')

fuel_dict = self.load_fueltype_dict()
self._ghgrp_energy_file = ghgrp_energy_file

ghgrp_unit_data.loc[:, 'fuelTypeStd'] = ghgrp_unit_data[fuel_type_column].map(fuel_dict)
self._data_source = 'GHGRP'

# drop any fuelTypes that are null
ghgrp_unit_data = ghgrp_unit_data.where(
ghgrp_unit_data[fuel_type_column] != 'None'
).dropna(how='all')
self._reporting_year = reporting_year

return ghgrp_unit_data

def download_unit_data(self):
"""
Expand Down Expand Up @@ -237,7 +240,7 @@ def format_ghgrp_df(self, ghgrp_df):
ghgrp_df = ghgrp_df.query("REPORTING_YEAR==@self._reporting_year")

# Harmonize fuel types for GHGRP data
ghgrp_df = self.harmonize_fuel_type(ghgrp_df, 'FUEL_TYPE_FINAL')
ghgrp_df = harmonize_fuel_type(ghgrp_df, 'FUEL_TYPE_FINAL')

ghgrp_df.to_csv('ghgrp_emissions.csv')

Expand Down
Loading