Skip to content

Commit

Permalink
pull exio industry output
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-young committed Feb 23, 2024
1 parent bf995e5 commit c57f617
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions import_factors_exio/Exiobase_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def process_exiobase(year_start=2012, year_end=2022, download=False):
d = {}
d['M'] = e.satellite.M # raw satellite multipliers
d['N'] = e.impacts.M # characterized multipliers
d['output'] = e.x
d['Trade Total'] = trade[1]
# ^^ df with gross total imports and exports per sector and region
d['Bilateral Trade'] = trade[0]
Expand Down
2 changes: 2 additions & 0 deletions import_factors_exio/data/exio_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ fields:
sector: Exiobase Sector
exports:
US: Exports to US
output:
indout: Output
flows: # if using satellite.M
# entries that start with the following keys
CO2: Carbon dioxide
Expand Down
30 changes: 19 additions & 11 deletions import_factors_exio/generate_import_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def generate_exio_factors(years: list):
## by exports to US when sector mappings are not clean
e_u = get_exio_to_useeio_concordance()
e_d = pull_exiobase_multipliers(year)
e_bil = pull_exiobase_bilateral_trade(year)
e_bil = pull_exiobase_data(year, opt = "bilateral")
export_field = list(config.get('exports').values())[0]
e_d = (e_d.merge(e_bil, on=['CountryCode','Exiobase Sector'], how='left')
.merge(e_u, on='Exiobase Sector', how='left')
Expand Down Expand Up @@ -322,24 +322,32 @@ def pull_exiobase_multipliers(year):
return M_df


def pull_exiobase_bilateral_trade(year):
def pull_exiobase_data(year, opt):
'''
Extracts bilateral trade data by industry from countries to the U.S.
Extracts bilateral trade data (opt = "bilateral") by industry from
countries to the U.S. or industry output (opt = "output")
from stored Exiobase model.
'''
file = resource_Path / f'exio_all_resources_{year}.pkl'
if not file.exists():
print(f"Exiobase data not found for {year}")
process_exiobase(year_start=year, year_end=year, download=True)
exio = pkl.load(open(file,'rb'))
fields = {**config['fields'], **config['exports']}
t_df = exio['Bilateral Trade']
t_df = (t_df
.filter(['US'])
.reset_index()
.rename(columns=fields)
)
return t_df
fields = {**config['fields'], **config['exports'], **config['output']}
if opt == "bilateral":
df = exio['Bilateral Trade']
df = (df
.filter(['US'])
.reset_index()
.rename(columns=fields)
)
elif opt == "output":
df = exio['output']
df = (df
.reset_index()
.rename(columns=fields)
)
return df


def calc_contribution_coefficients(df):
Expand Down

0 comments on commit c57f617

Please sign in to comment.