Skip to content

Commit fab2664

Browse files
committed
Final corrections for 2.9 release.
1 parent 7e4aa30 commit fab2664

5 files changed

+21
-19
lines changed
-14.4 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

openIO.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
class IOTables:
26-
def __init__(self, folder_path, exiobase_folder, endogenizing_capitals=False, aggregated_ghgs=True):
26+
def __init__(self, folder_path, exiobase_folder, endogenizing_capitals=False):
2727
"""
2828
:param folder_path: [string] the path to the folder with the economic data (e.g. /../Detail level/)
2929
:param exiobase_folder: [string] path to exiobase folder for international imports (optional)
@@ -56,7 +56,6 @@ def __init__(self, folder_path, exiobase_folder, endogenizing_capitals=False, ag
5656
self.level_of_detail = [i for i in os.path.normpath(folder_path).split(os.sep) if 'level' in i][-1]
5757
self.exiobase_folder = exiobase_folder
5858
self.endogenizing = endogenizing_capitals
59-
self.aggregated_ghgs = aggregated_ghgs
6059

6160
# values
6261
self.V = pd.DataFrame()
@@ -127,15 +126,20 @@ def __init__(self, folder_path, exiobase_folder, endogenizing_capitals=False, ag
127126
files.sort()
128127
self.year = int(files[0].split('SUT_C')[1].split('_')[0])
129128

129+
if self.year in [2018, 2019, 2020]:
130+
self.aggregated_ghgs = False
131+
else:
132+
self.aggregated_ghgs = True
133+
130134
try:
131135
self.NPRI = pd.read_excel(pkg_resources.resource_stream(
132136
__name__, '/Data/Environmental_data/NPRI-INRP_DataDonnées_' + str(self.year) + '.xlsx'), None)
133137
self.NPRI_file_year = self.year
134-
# 2016 by default (for older years)
138+
# 2018 by default (for older years)
135139
except FileNotFoundError:
136140
self.NPRI = pd.read_excel(pkg_resources.resource_stream(
137-
__name__, '/Data/Environmental_data/NPRI-INRP_DataDonnées_2016.xlsx'), None)
138-
self.NPRI_file_year = 2016
141+
__name__, '/Data/Environmental_data/NPRI-INRP_DataDonnées_2018.xlsx'), None)
142+
self.NPRI_file_year = 2018
139143

140144
logger.info("Formatting the Supply and Use tables...")
141145
for province_data in files:
@@ -1270,9 +1274,13 @@ def extract_environmental_data(self):
12701274
# somehow the NPRI manages to have entries without NAICS codes... Remove them
12711275
no_naics_code_entries = emissions.loc[:, 'NAICS 6 Code'][emissions.loc[:, 'NAICS 6 Code'] == 0].index
12721276
emissions.drop(no_naics_code_entries, inplace=True)
1277+
# same for Provinces
1278+
no_province_code_entries = emissions.loc[:, 'Province'][emissions.loc[:, 'Province'] == 0].index
1279+
emissions.drop(no_province_code_entries, inplace=True)
12731280

1274-
# NAICS codes as strings and not integers
1281+
# NAICS codes as strings and not floats
12751282
emissions.loc[:, 'NAICS 6 Code'] = emissions.loc[:, 'NAICS 6 Code'].astype('str')
1283+
emissions.loc[:, 'NAICS 6 Code'] = [i.split('.0')[0] for i in emissions.loc[:, 'NAICS 6 Code']]
12761284

12771285
# extracting metadata for substances
12781286
temp_df = emissions.copy()
@@ -1800,15 +1808,12 @@ def characterization_matrix(self):
18001808
__name__, '/Data/Concordances/openIO_IW_concordance.xlsx'), str(self.NPRI_file_year))
18011809
except ValueError:
18021810
concordance = pd.read_excel(pkg_resources.resource_stream(
1803-
__name__, '/Data/Concordances/openIO_IW_concordance.xlsx'), '2016')
1811+
__name__, '/Data/Concordances/openIO_IW_concordance.xlsx'), '2018')
18041812
concordance.set_index('OpenIO flows', inplace=True)
18051813

18061814
# applying concordance
18071815
hfcs = ['CF4', 'C2F6', 'SF6', 'NF3', 'c-C4F8', 'C3F8', 'HFC-125', 'HFC-134a', 'HFC-143', 'HFC-143a', 'HFC-152a',
18081816
'HFC-227ea', 'HFC-23', 'HFC-32', 'HFC-41', 'HFC-134', 'HFC-245fa', 'HFC-43-10mee', 'HFC-365mfc', 'HFC-236fa']
1809-
if self.year in [2016, 2017]:
1810-
hfcs.append('C5F12')
1811-
self.emission_metadata.loc['C5F12', 'CAS Number'] = '678-26-2'
18121817

18131818
hfcs_idx = pd.MultiIndex.from_product(
18141819
[hfcs, [i for i in self.matching_dict.keys()], ['Air']]).swaplevel(0, 1)
@@ -2916,10 +2921,10 @@ def differentiate_biogenic_carbon_emissions(self):
29162921
# identify biogenic in Exiobase
29172922
CO2_bio = [i for i in self.F_exio.index if 'CO2' in i and 'biogenic' in i or 'peat decay' in i]
29182923
# determine the share of fossil emissions impact
2919-
share_fossil = 1 - (self.F_exio.loc[CO2_bio, 'CA'].dot(ioic_exio.T).sum() /
2920-
self.C_exio.dot(self.F_exio).loc[
2921-
('Climate change, short term', 'kg CO2 eq (short)'), 'CA'].dot(
2922-
ioic_exio.T)).fillna(0)
2924+
total = self.C_exio.dot(self.F_exio).loc[
2925+
('Climate change, short term', 'kg CO2 eq (short)'), 'CA'].dot(ioic_exio.T)
2926+
total = total[total != 0]
2927+
share_fossil = 1 - (self.F_exio.loc[CO2_bio, 'CA'].dot(ioic_exio.T).sum() / total).fillna(0)
29232928
share_fossil = pd.DataFrame(
29242929
pd.concat([share_fossil] * len([i for i in self.S.columns.levels[0] if 'CA-' in i])),
29252930
columns=['GHG emissions'])
@@ -3043,7 +3048,7 @@ def balance_flows(self, concordance):
30433048
# adjust characterization matrix too
30443049
self.C = self.C.drop([i for i in self.C.columns if i[1] in rest_of_voc], axis=1)
30453050

3046-
if self.year >= 2018:
3051+
if self.NPRI_file_year >= 2018:
30473052
# PMs, only take highest value flow as suggested by the NPRI team:
30483053
# [https://www.canada.ca/en/environment-climate-change/services/national-pollutant-release-inventory/using-interpreting-data.html]
30493054
for sector in F_multiindex.columns:
@@ -3102,10 +3107,7 @@ def split_private_public_sectors(self, NAICS_code, IOIC_code):
31023107
"""
31033108
try:
31043109
df = self.F.loc(axis=1)[:, NAICS_code].copy()
3105-
if type(NAICS_code) == list:
3106-
df.columns = pd.MultiIndex.from_product([self.matching_dict, [IOIC_code] * len(NAICS_code)])
3107-
elif type(NAICS_code) == str:
3108-
df.columns = pd.MultiIndex.from_product([self.matching_dict, [IOIC_code]])
3110+
df.columns = pd.MultiIndex.from_product([self.matching_dict, [IOIC_code]])
31093111
self.F = pd.concat([self.F, df / 2], axis=1)
31103112
self.F.loc(axis=1)[:, NAICS_code] /= 2
31113113
except KeyError:

0 commit comments

Comments
 (0)