forked from IAMconsortium/pyam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kaya_variables, kaya_factors, and kaya_lmdi methods to the comput…
…e module. Also add the kaya subdirectory that contains the implementation for the kaya methods. (IAMconsortium#875)
- Loading branch information
1 parent
735c243
commit b741dbb
Showing
13 changed files
with
1,264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
POPULATION = "Population" | ||
GDP_MER = "GDP|MER" | ||
GDP_PPP = "GDP|PPP" | ||
FINAL_ENERGY = "Final Energy" | ||
PRIMARY_ENERGY = "Primary Energy" | ||
PRIMARY_ENERGY_COAL = "Primary Energy|Coal" | ||
PRIMARY_ENERGY_OIL = "Primary Energy|Oil" | ||
PRIMARY_ENERGY_GAS = "Primary Energy|Gas" | ||
EMISSIONS_CO2_INDUSTRIAL_PROCESSES = "Emissions|CO2|Industrial Processes" | ||
EMISSIONS_CO2_CCS = "Emissions|CO2|Carbon Capture and Storage" | ||
EMISSIONS_CO2_CCS_BIOMASS = "Emissions|CO2|Carbon Capture and Storage|Biomass" | ||
EMISSIONS_CO2_FOSSIL_FUELS_AND_INDUSTRY = "Emissions|CO2|Fossil Fuels and Industry" | ||
EMISSIONS_CO2_AFOLU = "Emissions|CO2|AFOLU" | ||
CCS_FOSSIL_ENERGY = "Carbon Sequestration|CCS|Fossil|Energy" | ||
CCS_FOSSIL_INDUSTRY = "Carbon Sequestration|CCS|Fossil|Industrial Processes" | ||
CCS_BIOMASS_ENERGY = "Carbon Sequestration|CCS|Biomass|Energy" | ||
CCS_BIOMASS_INDUSTRY = "Carbon Sequestration|CCS|Biomass|Industrial Processes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
GNP_per_P = "GNP/P" | ||
FE_per_GNP = "FE/GNP" | ||
PEdeq_per_FE = "PEDEq/FE" | ||
PEFF_per_PEDEq = "PEFF/PEDEq" | ||
TFC_per_PEFF = "TFC/PEFF" | ||
NFC_per_TFC = "NFC/TFC" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from functools import reduce | ||
|
||
from pyam.kaya import input_variable_names, kaya_factor_names, kaya_variable_names | ||
|
||
|
||
def kaya_factors(kaya_variables_frame, scenarios): | ||
kaya_factors_frames = [] | ||
for scenario in scenarios: | ||
input = kaya_variables_frame.filter( | ||
model=scenario[0], scenario=scenario[1], region=scenario[2] | ||
) | ||
if input.empty: | ||
break | ||
kaya_factors_frames.append(_calc_gnp_per_p(input)) | ||
kaya_factors_frames.append(_calc_fe_per_gnp(input)) | ||
kaya_factors_frames.append(_calc_pedeq_per_fe(input)) | ||
kaya_factors_frames.append(_calc_peff_per_pedeq(input)) | ||
kaya_factors_frames.append(_calc_tfc_per_peff(input)) | ||
kaya_factors_frames.append(_calc_nfc_per_tfc(input)) | ||
kaya_factors_frames.append( | ||
input.filter( | ||
variable=[kaya_variable_names.TFC, input_variable_names.POPULATION] | ||
) | ||
) | ||
if len(kaya_factors_frames) == 0: | ||
return None | ||
return reduce(lambda x, y: x.append(y), kaya_factors_frames) | ||
|
||
|
||
def _calc_gnp_per_p(input_data): | ||
variable = input_variable_names.GDP_PPP | ||
if input_data.filter(variable=variable).empty: | ||
variable = input_variable_names.GDP_MER | ||
return input_data.divide( | ||
variable, | ||
input_variable_names.POPULATION, | ||
kaya_factor_names.GNP_per_P, | ||
append=False, | ||
) | ||
|
||
|
||
def _calc_fe_per_gnp(input_data): | ||
variable = input_variable_names.GDP_PPP | ||
if input_data.filter(variable=variable).empty: | ||
variable = input_variable_names.GDP_MER | ||
return input_data.divide( | ||
input_variable_names.FINAL_ENERGY, | ||
variable, | ||
kaya_factor_names.FE_per_GNP, | ||
append=False, | ||
) | ||
|
||
|
||
def _calc_pedeq_per_fe(input_data): | ||
return input_data.divide( | ||
input_variable_names.PRIMARY_ENERGY, | ||
input_variable_names.FINAL_ENERGY, | ||
kaya_factor_names.PEdeq_per_FE, | ||
append=False, | ||
) | ||
|
||
|
||
def _calc_peff_per_pedeq(input_data): | ||
return input_data.divide( | ||
kaya_variable_names.PRIMARY_ENERGY_FF, | ||
input_variable_names.PRIMARY_ENERGY, | ||
kaya_factor_names.PEFF_per_PEDEq, | ||
append=False, | ||
) | ||
|
||
|
||
def _calc_tfc_per_peff(input_data): | ||
return input_data.divide( | ||
kaya_variable_names.TFC, | ||
kaya_variable_names.PRIMARY_ENERGY_FF, | ||
kaya_factor_names.TFC_per_PEFF, | ||
ignore_units="Mt CO2/EJ", | ||
append=False, | ||
) | ||
|
||
|
||
def _calc_nfc_per_tfc(input_data): | ||
return input_data.divide( | ||
kaya_variable_names.NFC, | ||
kaya_variable_names.TFC, | ||
kaya_factor_names.NFC_per_TFC, | ||
ignore_units=True, | ||
append=False, | ||
).rename(unit={"unknown": ""}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PRIMARY_ENERGY_FF = "Primary Energy|Fossil" | ||
TFC = "Total Fossil Carbon" | ||
NFC = "Net Fossil Carbon" |
Oops, something went wrong.