assemble_eta_fu_tables: Assemble completed final-to-useful efficiency tables

View source: R/table_functions.R

assemble_eta_fu_tablesR Documentation

Assemble completed final-to-useful efficiency tables

Description

This function is used in a drake workflow to assemble completed final-to-useful efficiency tables given a set of incomplete efficiency tables. Information from exemplar countries is used to complete incomplete final-to-useful efficiency tables. See examples for how to construct exemplar_lists.

Usage

assemble_eta_fu_tables(
  incomplete_eta_fu_tables,
  exemplar_lists,
  completed_fu_allocation_tables,
  countries,
  max_year = NULL,
  which_quantity = c(IEATools::template_cols$eta_fu),
  country = IEATools::iea_cols$country,
  method = IEATools::iea_cols$method,
  energy_type = IEATools::iea_cols$energy_type,
  last_stage = IEATools::iea_cols$last_stage,
  unit = IEATools::iea_cols$unit,
  year = IEATools::iea_cols$year,
  e_dot = IEATools::iea_cols$e_dot,
  machine = IEATools::template_cols$machine,
  eu_product = IEATools::template_cols$eu_product,
  eta_fu = IEATools::template_cols$eta_fu,
  phi_u = IEATools::template_cols$phi_u,
  c_source = IEATools::template_cols$c_source,
  eta_fu_source = IEATools::template_cols$eta_fu_source,
  e_dot_machine = IEATools::template_cols$e_dot_machine,
  e_dot_machine_perc = IEATools::template_cols$e_dot_machine_perc,
  quantity = IEATools::template_cols$quantity,
  maximum_values = IEATools::template_cols$maximum_values,
  e_dot_perc = IEATools::template_cols$e_dot_perc,
  exemplars = PFUWorkflow::exemplar_names$exemplars,
  exemplar_tables = PFUWorkflow::exemplar_names$exemplar_tables,
  alloc_data = PFUWorkflow::exemplar_names$alloc_data,
  incomplete_eta_tables = PFUWorkflow::exemplar_names$incomplete_eta_table,
  complete_eta_tables = PFUWorkflow::exemplar_names$complete_eta_table,
  .values = IEATools::template_cols$.values
)

Arguments

incomplete_eta_fu_tables

An incomplete data frame of final-to-useful efficiencies for all Machines in completed_fu_allocation_tables.

exemplar_lists

A data frame containing country and year columns along with a column of ordered vectors of strings telling which countries should be considered exemplars for the country and year of this row.

completed_fu_allocation_tables

A data frame containing completed final-to-useful allocation data, typically the result of calling assemble_fu_allocation_tables.

countries

A vector of countries for which completed final-to-useful allocation tables are to be assembled.

max_year

The latest year for which analysis is desired. Default is NULL, meaning analyze all years.

which_quantity

A vector of quantities to be completed in the eta_FU table. Default is c(IEATools::template_cols$eta_fu, IEATools::template_cols$phi_u). Must be one or both of the default values.

country, method, energy_type, last_stage, year, unit, e_dot

See IEATools::iea_cols.

machine, eu_product, eta_fu, phi_u, c_source, eta_fu_source, e_dot_machine, e_dot_machine_perc, quantity, maximum_values, e_dot_perc, .values

See IEATools::template_cols.

exemplars, exemplar_tables, alloc_data, incomplete_eta_tables, complete_eta_tables

See PFUWorkflow::exemplar_names.

Details

Note that this function can accept tidy or wide by year data frames. The return value is a tidy data frame.

Note that the .values argument applies for both incomplete_eta_fu_tables and completed_fu_allocation_tables. Callers should ensure that value columns in both data frames (incomplete_eta_fu_tables and completed_fu_allocation_tables) are named identically and that name is passed into the .values argument.

Note that the which_quantity argument is an accident of history. At one time, this function also assembled tables of phi.u (useful exergy-to-energy ratio) values. At present, the function only assembles eta.fu (final-to-useful efficiency) tables, so the only valid value for which_quantity is IEATools::template_cols$eta_fu.

Value

A tidy data frame containing completed final-to-useful efficiency tables.

Examples

# Make some incomplete efficiency tables for GHA by removing Wood cookstoves.
# Information from the exemplar, ZAF, will supply efficiency for Wood cookstoves for GHA.
incomplete_eta_fu_tables <- IEATools::load_eta_fu_data() %>%
  dplyr::filter(! (Country == "GHA" & Machine == "Wood cookstoves"))
# The rows for Wood cookstoves are missing.
incomplete_eta_fu_tables %>%
  dplyr::filter(Country == "GHA", Machine == "Wood cookstoves")
# Set up exemplar list
el <- tibble::tribble(
  ~Country, ~Year, ~Exemplars,
  "GHA", 1971, c("ZAF"),
  "GHA", 2000, c("ZAF"))
# Load FU allocation data.
# An efficiency is needed for each machine in FU allocation data.
fu_allocation_data <- IEATools::load_fu_allocation_data()
# Assemble complete allocation tables
completed <- assemble_eta_fu_tables(incomplete_eta_fu_tables = incomplete_eta_fu_tables,
                                    exemplar_lists = el,
                                    completed_fu_allocation_tables = fu_allocation_data,
                                    countries = "GHA")
# Show that the missing rows have been picked up from the exemplar country, ZAF.
completed %>%
  dplyr::filter(Country == "GHA", Machine == "Wood cookstoves")

MatthewHeun/SEAPSUTWorkflow documentation built on April 22, 2022, 2:21 p.m.