View source: R/table_functions.R
assemble_phi_u_tables | R Documentation |
This function is used in the drake workflow to assemble completed phi (exergy-to-energy ratio) tables given a set of phi tables read from machine data files and a phi constants table. The algorithm gives priority in this order:
phi values from the incomplete_phi_u_table
argument
phi values from climatic temperatures
phi values from the phi_constants_table
argument
assemble_phi_u_tables(
incomplete_phi_u_table,
phi_constants_table,
completed_efficiency_table = NULL,
countries,
years = NULL,
country = IEATools::iea_cols$country,
year = IEATools::iea_cols$year,
product = IEATools::iea_cols$product,
machine = IEATools::template_cols$machine,
quantity = IEATools::template_cols$quantity,
phi_u = IEATools::template_cols$phi_u,
.values = IEATools::template_cols$.values,
eu_product = IEATools::template_cols$eu_product,
eta_fu_source = IEATools::template_cols$eta_fu_source,
phi_colname = IEATools::phi_constants_names$phi_colname,
phi_source_colname = IEATools::phi_constants_names$phi_source_colname,
is_useful = IEATools::phi_constants_names$is_useful_colname,
eta_fu_tables = PFUPipeline::phi_sources$eta_fu_tables,
phi_constants = PFUPipeline::phi_sources$phi_constants
)
incomplete_phi_u_table |
A data frame of phi values read from machine efficiency and phi data files.
This data frame can be "incomplete," i.e., it can be missing
phi values.
The phi values from |
phi_constants_table |
A data frame of constant phi values with reasonable default values for all energy products. |
completed_efficiency_table |
A data frame containing completed efficiency tables.
This data frame identifies all useful products
for which we need phi values.
Default is |
countries |
A vector of countries for which completed phi tables are to be assembled. |
years |
The years for which analysis is desired. Default is |
country, year, product |
See |
machine, quantity, phi_u, .values, eu_product, eta_fu_source |
See |
phi_colname, phi_source_colname, is_useful |
See |
eta_fu_tables, phi_constants |
See |
Note that the needed phi values are taken from completed_efficiency_table
(when not NULL
).
If completed_efficiency_table
is NULL
,
the needed phi values are taken from incomplete_phi_u_table
,
meaning that any empty (NA
) phi values are obtained from climatic temperatures or phi_constants_table
.
A data frame of phi values for every combination of country, year, machine, destination, etc.
library(dplyr)
library(IEATools)
library(magrittr)
phi_constants_table <- IEATools::load_phi_constants_table()
# Load a phi_u_table.
phi_table <- IEATools::load_eta_fu_data() %>%
# Convert to tidy format.
dplyr::mutate(
"{IEATools::template_cols$maximum_values}" := NULL,
"{IEATools::iea_cols$unit}" := NULL
) %>%
tidyr::pivot_longer(cols = IEATools::year_cols(.),
names_to = IEATools::iea_cols$year,
values_to = IEATools::template_cols$.values) %>%
# Convert to a table of phi values only
dplyr::filter(.data[[IEATools::template_cols$quantity]] == IEATools::template_cols$phi_u)
# Set a value to NA (Charcoal stoves, MTH.100.C, GHA, 1971) in the phi table.
incomplete_phi_table <- phi_table %>%
dplyr::mutate(
"{IEATools::template_cols$.values}" := dplyr::case_when(
.data[[IEATools::iea_cols$country]] == "GHA" &
.data[[IEATools::iea_cols$year]] == 1971 &
.data[[IEATools::template_cols$machine]] == "Charcoal stoves" ~ NA_real_,
TRUE ~ .data[[IEATools::template_cols$.values]]
)
)
# Run through the assemble_phi_u_tables function
completed_phi_u_table <- assemble_phi_u_tables(incomplete_phi_table,
phi_constants_table,
countries = "GHA")
# Show that Charcoal stoves was filled
completed_phi_u_table %>%
dplyr::filter(.data[[IEATools::template_cols$machine]] == "Charcoal stoves")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.