calc_phi_pf_vecs: Create a data frame of phi_pf vectors

View source: R/extend_to_exergy.R

calc_phi_pf_vecsR Documentation

Create a data frame of phi_pf vectors

Description

This function creates a data frame that contains all the metadata columns from phi_u_vecs and a column of phi_pf vectors. This work is accomplished by creating a vector from phi_constants, adding one instance of the vector to the right side of the phi_constants data frame for each row of the data frame, and deleting phi_u_colname from the data frame.

Usage

calc_phi_pf_vecs(
  phi_constants,
  phi_u_vecs,
  countries,
  country = IEATools::iea_cols$country,
  product = IEATools::iea_cols$product,
  eta_fu = IEATools::template_cols$eta_fu,
  phi_u = IEATools::template_cols$phi_u,
  phi_pf_colname = IEATools::template_cols$phi_pf,
  phi_colname = IEATools::phi_constants_names$phi_colname,
  is_useful_colname = IEATools::phi_constants_names$is_useful_colname
)

Arguments

phi_constants

A data frame of constant phi values (for primary, final, and useful stages) with columns product, phi_colname, and is_useful_colname.

phi_u_vecs

A data frame containing metadata columns and a column of phi_u vectors. A column of phi_pf vectors replaces the column of phi_u vectors on output.

countries

The countries for which you want to perform this task.

country, product

See IEATools::iea_cols.

eta_fu, phi_u, phi_pf_colname

See IEATools::template_cols.

phi_colname, is_useful_colname

See IEATools::phi_constants_colnames.

Value

A version of the phi_constants data frame with the column of useful phi (useful exergy-to-energy ratio) vectors replaced by a column of primary and final phi vectors.

Examples

phi_constants <- IEATools::sample_phi_constants_path() %>%
  IEATools::load_phi_constants_table()
phi_u_vecs <- tibble::tibble(Country = "GHA",
                             Year = 1971,
                             rownames = c("Light", "MD"),
                             colnames = "col",
                             matnames = "phi.u",
                             matvals = c(0.8, 0.9),
                             rowtypes = "rowtype",
                             coltypes = "coltype") %>%
  dplyr::group_by(Country, Year) %>%
  matsindf::collapse_to_matrices() %>%
  dplyr::rename(phi.u = matvals) %>%
  dplyr::mutate(
    Quantity = NULL
  )
calc_phi_pf_vecs(phi_constants, phi_u_vecs, countries = "GHA")

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