knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(dplyr) library(EROITools)
Primary stage EROIs can be simply aggregated with the aggregate_primary_stage_erois
. The function calculates, for each fossil fuel group (all fossil fuels, coal products, natural gas, oil and gas products, and oil products), the shares of each product in the primary extraction phase (which is why the tidy_AB_dta
is passed as argument). Then, EROIs are computed by calculating the weighted average of EROIs. So, for country A, the share of coal in the group "Coal products" will be one, and the aggregated EROI for "Coal products" will be equal to the one of coal.
# Aggregating primary stage EROIs: aggregated_primary_stage_erois <- aggregate_primary_stage_erois( .tidy_erois_df = tidy_AB_erois_dta, .tidy_iea_df = tidy_AB_dta, eroi_calc_method = "dta" ) %>% dplyr::glimpse()
Likewise, aggregated final stage EROIs are calculated with the aggregate_final_stage_erois
. This function calculates, for each fossil fuel group, the shares of each product in the final use of a given country. It does so for the different final energy carriers: electricity, heat, fuel, and all carriers together. Then, aggregated final stage EROIs are calculated according to those shares.
# Aggregating final stage EROIs: aggregated_final_stage_erois <- aggregate_final_stage_erois( .tidy_erois_df = tidy_AB_erois_dta, .tidy_iea_df = tidy_AB_dta, eroi_calc_method = "dta" ) %>% dplyr::glimpse()
Aggregating EROIs at the useful stage of energy use requires the analyst to provide the average final-to-useful energy efficiencies with which each energy product is used, in each country. Indeed, the Recca
package that we have used to calculate EROIs is used on a data frame describing the Energy Conversion Chain until the final energy stage, so that EROIs can only be calculated for products corresponding to the primary extraction and final energy stages.
Alternatively, the Recca
package could also be used to calculate useful stage EROIs, but the matrices used should then describe the Energy Conversion Chain until the useful energy stage, which would require some preliminary work from the analyst anyway. To see an example of how the Physical Supply Use Table and Input-Output matrices can be used to describe an Energy Conversion Chain until the useful energy stage, see @Heun:2018.
Here, we will create an artificial ad-hoc data frame containing made-up final-to-useful efficiencies to demonstrate the package.
# Aggregating final stage EROIs: # Pushing to tidy useful stage EROIs length_to_use <- tidy_AB_erois_dta %>% dplyr::select(Country, Method, Energy.type, Year, Product) %>% dplyr::distinct() %>% nrow() tidy_FU_efficiencies_dta <- tidy_AB_erois_dta %>% dplyr::select(Country, Method, Energy.type, Year, Product) %>% dplyr::distinct() %>% dplyr::mutate( Average_Efficiency_Col = seq(0.15, 1, 0.85/(length_to_use-1)) ) %>% dplyr::glimpse()
The analyst should provide the final-to-useful efficiencies in a format similar to the tidy_FU_efficiencies_dta
data frame introduced here. Then, we can calculate the useful stage EROIs at the product level using the push_to_useful_erois
as:
# Binding efficiencies to Input-Output EROIs tidy_useful_erois_dta <- push_to_useful_erois( .tidy_io_erois = tidy_AB_erois_dta, tidy_FU_efficiencies = tidy_FU_efficiencies_dta, eroi_calc_method = "dta" ) %>% dplyr::glimpse() #dplyr::filter(! is.na(Useful_Stage_EROI))
Finally, we can aggregate useful stage EROIs in a similar way than at the primary and final stages using the aggregate_useful_stage_erois
function. The function also uses the final use shares of each product within each fossil fuel group, as for the aggregate_final_stage_erois
function.
# Aggregating final stage EROIs: useful_stage_erois <- aggregate_useful_stage_erois( .tidy_erois_df = tidy_useful_erois_dta, .tidy_iea_df = tidy_AB_dta, eroi_calc_method = "dta" ) %>% dplyr::glimpse()
To perform the aggregations when using a multi-regional perspective, the tidy data frame describing the Energy Conversion Chain needs to be adapted first, so that the country of location of each flow is added to the country column, and removed from the flow column. This step is important to allow the function to calculate the share of supply (primary stage) and use (final and useful stages) for each country. The prepare_gma_for_shares
function is used to this effect.
# Aggregating final stage EROIs: tidy_AB_data_gma_prepared <- tidy_AB_data_gma %>% prepare_gma_for_shares() %>% dplyr::glimpse()
Note the difference with the previous data frame (Country and Flow):
# Aggregating final stage EROIs: dplyr::glimpse(tidy_AB_data_gma)
Then the aggregation is simply conducted as:
# Aggregating final stage EROIs: aggregated_primary_stage_erois_gma <- aggregate_primary_stage_erois( .tidy_erois_df = tidy_AB_erois_gma, .tidy_iea_df = tidy_AB_data_gma_prepared, eroi_calc_method = "gma" ) %>% dplyr::glimpse()
and likewise, at the final stage, as:
# Aggregating final stage EROIs: aggregated_final_stage_erois_gma <- aggregate_final_stage_erois( .tidy_erois_df = tidy_AB_erois_gma, .tidy_iea_df = tidy_AB_data_gma_prepared, eroi_calc_method = "gma" ) %>% dplyr::glimpse()
Note that each product is specified by its location of production in the Multi-Regional version of the framework. The implication is that at the final and useful stage, when aggregating EROIs, the use shares of each product are determined for products which are specific by region of production. So the aggregations we conduct at the final and useful stage are based on the consumption mix of a country, not on its production mix (conversely to the primary stage, for which aggregations only make sense based on the production mix).
As for the demonstration at the domestic level, we build a made-up data frame containing the average final-to-useful efficiencies of each energy product to expand the EROI calculations at the useful stage for each energy product.
# Building a data frame containing average final-to-useful efficiencies for each energy product length_to_use <- tidy_AB_erois_gma %>% dplyr::select(Country, Method, Energy.type, Year, Product) %>% dplyr::distinct() %>% nrow() tidy_FU_efficiencies_gma <- tidy_AB_erois_gma %>% dplyr::mutate( Country = stringr::str_extract(Product, "\\{.*\\}") %>% stringr::str_remove("\\{") %>% stringr::str_remove("\\}"), Product = stringr::str_remove(Product, "\\{.*\\}_") ) %>% dplyr::select(Country, Method, Energy.type, Year, Product) %>% dplyr::distinct() %>% dplyr::mutate( Average_Efficiency_Col = seq(0.15, 1, 0.85/(length_to_use-1)) ) %>% dplyr::glimpse()
Then, we expand the EROI calculations to the useful stage by applying the final-to-useful efficiencies of each energy product using the push_to_useful_erois
function:
# Pushing to tidy useful stage EROIs tidy_useful_erois_gma <- push_to_useful_erois( .tidy_io_erois = tidy_AB_erois_gma, tidy_FU_efficiencies = tidy_FU_efficiencies_gma, eroi_calc_method = "gma" ) %>% dplyr::glimpse()
Last, we can aggregate the useful stage EROIs using the aggregate_useful_stage_erois
function:
# Calculating aggregated useful stage EROIs: aggregated_useful_stage_erois <- aggregate_useful_stage_erois( .tidy_erois_df = tidy_useful_erois_gma, .tidy_iea_df = tidy_AB_data_gma_prepared, eroi_calc_method = "gma" ) %>% dplyr::glimpse()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.