Skip to contents

This function is used in a drake workflow to assemble completed final-to-useful allocation tables given a set of incomplete allocation tables.

Usage

assemble_fu_allocation_tables(
  incomplete_allocation_tables,
  exemplar_lists,
  specified_iea_data,
  countries,
  years = NULL,
  country = IEATools::iea_cols$country,
  year = IEATools::iea_cols$year,
  exemplars = PFUPipeline::exemplar_names$exemplars,
  exemplar_tables = PFUPipeline::exemplar_names$exemplar_tables,
  iea_data = PFUPipeline::exemplar_names$iea_data,
  incomplete_alloc_tables = PFUPipeline::exemplar_names$incomplete_alloc_table,
  complete_alloc_tables = PFUPipeline::exemplar_names$complete_alloc_table
)

Arguments

incomplete_allocation_tables

A data frame containing (potentially) incomplete final-to-useful allocation tables. This data frame may be tidy or wide by years.

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.

specified_iea_data

A data frame containing specified IEA data.

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.

country, year

See IEATools::iea_cols.

exemplars, exemplar_tables, iea_data, incomplete_alloc_tables, complete_alloc_tables

See PFUPipeline::exemplar_names.

Value

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

Details

Note that this function can accept tidy or wide by year data frames. The return value is a tidy data frame. Information from exemplar countries is used to complete incomplete final-to-useful efficiency tables. See examples for how to construct exemplar_lists.

Examples

# Load final-to-useful allocation tables, but eliminate one category of consumption,
# Residential consumption of Primary solid biofuels,
# which will be filled by the exemplar for GHA, ZAF.
incomplete_fu_allocation_tables <- IEATools::load_fu_allocation_data() %>%
  dplyr::filter(! (Country == "GHA" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential"))
# Show that those rows are gone.
incomplete_fu_allocation_tables %>%
  dplyr::filter(Country == "GHA" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential")
#>  [1] Country                Method                 Energy.type           
#>  [4] Last.stage             Ledger.side            Flow.aggregation.point
#>  [7] Unit                   Ef.product             Machine               
#> [10] Eu.product             Destination            Quantity              
#> [13] Maximum.values         1971                   2000                  
#> <0 rows> (or 0-length row.names)
# But the missing rows of GHA are present in allocation data for ZAF.
incomplete_fu_allocation_tables %>%
  dplyr::filter(Country == "ZAF" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential")
#>   Country Method Energy.type Last.stage Ledger.side Flow.aggregation.point Unit
#> 1     ZAF    PCM           E      Final Consumption                  Other ktoe
#> 2     ZAF    PCM           E      Final Consumption                  Other ktoe
#> 3     ZAF    PCM           E      Final Consumption                  Other ktoe
#> 4     ZAF    PCM           E      Final Consumption                  Other ktoe
#> 5     ZAF    PCM           E      Final Consumption                  Other ktoe
#>               Ef.product         Machine Eu.product Destination  Quantity
#> 1 Primary solid biofuels            <NA>       <NA> Residential     E.dot
#> 2 Primary solid biofuels            <NA>       <NA> Residential E.dot [%]
#> 3 Primary solid biofuels Wood cookstoves  MTH.100.C Residential   C_1 [%]
#> 4 Primary solid biofuels   Wood furnaces   LTH.20.C Residential   C_2 [%]
#> 5 Primary solid biofuels            <NA>       <NA> Residential   C_3 [%]
#>   Maximum.values         1971         2000
#> 1   5574.9498000 3869.3035000 5574.9498000
#> 2      0.1198823    0.1198823    0.1139165
#> 3             NA    0.5000000    0.5000000
#> 4             NA    0.5000000    0.5000000
#> 5             NA           NA           NA
# Set up exemplar list
el <- tibble::tribble(
  ~Country, ~Year, ~Exemplars,
  "GHA", 1971, c("ZAF"),
  "GHA", 2000, c("ZAF"))
el
#> # A tibble: 2 × 3
#>   Country  Year Exemplars
#>   <chr>   <dbl> <chr>    
#> 1 GHA      1971 ZAF      
#> 2 GHA      2000 ZAF      
# Load IEA data
iea_data <- IEATools::load_tidy_iea_df() %>%
  IEATools::specify_all()
# Assemble complete allocation tables
completed <- assemble_fu_allocation_tables(incomplete_allocation_tables =
                                             incomplete_fu_allocation_tables,
                                           exemplar_lists = el,
                                           specified_iea_data = iea_data,
                                           countries = "GHA")
# Missing data for GHA has been picked up from ZAF.
completed %>%
  dplyr::filter(Country == "GHA" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential")
#> # A tibble: 4 × 14
#>   Country Method Energy.type Last.stage Ledger.side Flow.aggregation.point
#>   <chr>   <chr>  <chr>       <chr>      <chr>       <chr>                 
#> 1 GHA     PCM    E           Final      Consumption Other                 
#> 2 GHA     PCM    E           Final      Consumption Other                 
#> 3 GHA     PCM    E           Final      Consumption Other                 
#> 4 GHA     PCM    E           Final      Consumption Other                 
#> # ℹ 8 more variables: Ef.product <chr>, Machine <chr>, Eu.product <chr>,
#> #   Destination <chr>, Quantity <chr>, Year <dbl>, .values <dbl>,
#> #   C.source <chr>