Skip to contents

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,
  years = 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 = PFUPipeline::exemplar_names$exemplars,
  exemplar_tables = PFUPipeline::exemplar_names$exemplar_tables,
  alloc_data = PFUPipeline::exemplar_names$alloc_data,
  incomplete_eta_tables = PFUPipeline::exemplar_names$incomplete_eta_table,
  complete_eta_tables = PFUPipeline::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.

years

The years 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 PFUPipeline::exemplar_names.

Value

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

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.

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")
#>  [1] Country        Method         Energy.type    Last.stage     Unit          
#>  [6] Machine        Eu.product     Quantity       Maximum.values 1971          
#> [11] 2000          
#> <0 rows> (or 0-length row.names)
# 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")
# The missing rows have been picked up from the exemplar country, ZAF.
completed %>%
  dplyr::filter(Country == "GHA", Machine == "Wood cookstoves")
#> # A tibble: 2 × 10
#>   Country Method Energy.type Last.stage Machine        Eu.product Quantity  Year
#>   <chr>   <chr>  <chr>       <chr>      <chr>          <chr>      <chr>    <dbl>
#> 1 GHA     PCM    E           Final      Wood cookstov… MTH.100.C  eta.fu    1971
#> 2 GHA     PCM    E           Final      Wood cookstov… MTH.100.C  eta.fu    2000
#> # ℹ 2 more variables: .values <dbl>, eta.fu.source <chr>