|
23 | 23 |
|
24 | 24 |
|
25 | 25 | 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): |
27 | 27 | """
|
28 | 28 | :param folder_path: [string] the path to the folder with the economic data (e.g. /../Detail level/)
|
29 | 29 | :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
|
56 | 56 | self.level_of_detail = [i for i in os.path.normpath(folder_path).split(os.sep) if 'level' in i][-1]
|
57 | 57 | self.exiobase_folder = exiobase_folder
|
58 | 58 | self.endogenizing = endogenizing_capitals
|
59 |
| - self.aggregated_ghgs = aggregated_ghgs |
60 | 59 |
|
61 | 60 | # values
|
62 | 61 | self.V = pd.DataFrame()
|
@@ -127,15 +126,20 @@ def __init__(self, folder_path, exiobase_folder, endogenizing_capitals=False, ag
|
127 | 126 | files.sort()
|
128 | 127 | self.year = int(files[0].split('SUT_C')[1].split('_')[0])
|
129 | 128 |
|
| 129 | + if self.year in [2018, 2019, 2020]: |
| 130 | + self.aggregated_ghgs = False |
| 131 | + else: |
| 132 | + self.aggregated_ghgs = True |
| 133 | + |
130 | 134 | try:
|
131 | 135 | self.NPRI = pd.read_excel(pkg_resources.resource_stream(
|
132 | 136 | __name__, '/Data/Environmental_data/NPRI-INRP_DataDonnées_' + str(self.year) + '.xlsx'), None)
|
133 | 137 | self.NPRI_file_year = self.year
|
134 |
| - # 2016 by default (for older years) |
| 138 | + # 2018 by default (for older years) |
135 | 139 | except FileNotFoundError:
|
136 | 140 | 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 |
139 | 143 |
|
140 | 144 | logger.info("Formatting the Supply and Use tables...")
|
141 | 145 | for province_data in files:
|
@@ -1270,9 +1274,13 @@ def extract_environmental_data(self):
|
1270 | 1274 | # somehow the NPRI manages to have entries without NAICS codes... Remove them
|
1271 | 1275 | no_naics_code_entries = emissions.loc[:, 'NAICS 6 Code'][emissions.loc[:, 'NAICS 6 Code'] == 0].index
|
1272 | 1276 | 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) |
1273 | 1280 |
|
1274 |
| - # NAICS codes as strings and not integers |
| 1281 | + # NAICS codes as strings and not floats |
1275 | 1282 | 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']] |
1276 | 1284 |
|
1277 | 1285 | # extracting metadata for substances
|
1278 | 1286 | temp_df = emissions.copy()
|
@@ -1800,15 +1808,12 @@ def characterization_matrix(self):
|
1800 | 1808 | __name__, '/Data/Concordances/openIO_IW_concordance.xlsx'), str(self.NPRI_file_year))
|
1801 | 1809 | except ValueError:
|
1802 | 1810 | 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') |
1804 | 1812 | concordance.set_index('OpenIO flows', inplace=True)
|
1805 | 1813 |
|
1806 | 1814 | # applying concordance
|
1807 | 1815 | hfcs = ['CF4', 'C2F6', 'SF6', 'NF3', 'c-C4F8', 'C3F8', 'HFC-125', 'HFC-134a', 'HFC-143', 'HFC-143a', 'HFC-152a',
|
1808 | 1816 | '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' |
1812 | 1817 |
|
1813 | 1818 | hfcs_idx = pd.MultiIndex.from_product(
|
1814 | 1819 | [hfcs, [i for i in self.matching_dict.keys()], ['Air']]).swaplevel(0, 1)
|
@@ -2916,10 +2921,10 @@ def differentiate_biogenic_carbon_emissions(self):
|
2916 | 2921 | # identify biogenic in Exiobase
|
2917 | 2922 | CO2_bio = [i for i in self.F_exio.index if 'CO2' in i and 'biogenic' in i or 'peat decay' in i]
|
2918 | 2923 | # 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) |
2923 | 2928 | share_fossil = pd.DataFrame(
|
2924 | 2929 | pd.concat([share_fossil] * len([i for i in self.S.columns.levels[0] if 'CA-' in i])),
|
2925 | 2930 | columns=['GHG emissions'])
|
@@ -3043,7 +3048,7 @@ def balance_flows(self, concordance):
|
3043 | 3048 | # adjust characterization matrix too
|
3044 | 3049 | self.C = self.C.drop([i for i in self.C.columns if i[1] in rest_of_voc], axis=1)
|
3045 | 3050 |
|
3046 |
| - if self.year >= 2018: |
| 3051 | + if self.NPRI_file_year >= 2018: |
3047 | 3052 | # PMs, only take highest value flow as suggested by the NPRI team:
|
3048 | 3053 | # [https://www.canada.ca/en/environment-climate-change/services/national-pollutant-release-inventory/using-interpreting-data.html]
|
3049 | 3054 | for sector in F_multiindex.columns:
|
@@ -3102,10 +3107,7 @@ def split_private_public_sectors(self, NAICS_code, IOIC_code):
|
3102 | 3107 | """
|
3103 | 3108 | try:
|
3104 | 3109 | 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]]) |
3109 | 3111 | self.F = pd.concat([self.F, df / 2], axis=1)
|
3110 | 3112 | self.F.loc(axis=1)[:, NAICS_code] /= 2
|
3111 | 3113 | except KeyError:
|
|
0 commit comments