Skip to contents

Introduction

This vignette demonstrates the features of the PFUPipeline package.

Load PFUPipeline

PFUPipeline is a package that runs a targets pipeline and stores data in Dropbox using the pins package.

To retrieve data, one needs

  • access to the Dropbox folder containing pipeline releases and
  • a valid pin name.

One valid pin name is “psut” and a valid pin release is “20220828T174526Z-60a07”. “20220828T174526Z-60a07” contains data for all countries (155) and all years (1960–2019).

folder <- PFUSetup::get_abs_paths()[["pipeline_releases_folder"]]
folder
#> [1] "/Users/mkh2/Dropbox/Fellowship 1960-2015 PFU database/OutputData/PipelineReleases"
# version <- "20220828T174526Z-60a07" # All countries
version <- "20220909T125050Z-e5a95" # Only GHA
psut_mats <- folder %>% 
  pins::board_folder(versioned = TRUE) %>% 
  pins::pin_read("psut", version = version)

Data structure

psut_mats is an R data frame. Let’s look at its contents.

dplyr::glimpse(psut_mats)
#> Rows: 588
#> Columns: 14
#> $ Country     <chr> "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "G…
#> $ Method      <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "P…
#> $ Energy.type <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E"…
#> $ Last.stage  <chr> "Final", "Final", "Final", "Final", "Final", "Final", "Fin…
#> $ Year        <dbl> 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980…
#> $ IEAMW       <chr> "IEA", "IEA", "IEA", "IEA", "IEA", "IEA", "IEA", "IEA", "I…
#> $ V           <list> <<matrix[12 x 14]>>, <<matrix[10 x 14]>>, <<matrix[10 x 1…
#> $ Y           <list> <<matrix[12 x 22]>>, <<matrix[12 x 23]>>, <<matrix[12 x 2…
#> $ S_units     <list> <<matrix[16 x 1]>>, <<matrix[16 x 1]>>, <<matrix[16 x 1]>…
#> $ R           <list> <<matrix[2 x 2]>>, <<matrix[2 x 2]>>, <<matrix[2 x 2]>>, …
#> $ U_feed      <list> <<matrix[6 x 5]>>, <<matrix[6 x 5]>>, <<matrix[6 x 5]>>, …
#> $ U_EIOU      <list> <<matrix[2 x 2]>>, <<matrix[2 x 2]>>, <<matrix[2 x 2]>>, …
#> $ U           <list> <<matrix[8 x 5]>>, <<matrix[8 x 5]>>, <<matrix[8 x 5]>>, …
#> $ r_EIOU      <list> <<matrix[8 x 5]>>, <<matrix[8 x 5]>>, <<matrix[8 x 5]>>, …

The metadata columns contain the following values.

psut_mats$Country %>% unique()
#> [1] "GHA"
psut_mats$Method %>% unique()
#> [1] "PCM"
psut_mats$Energy.type %>% unique()
#> [1] "E" "X"
psut_mats$Last.stage %>% unique()
#> [1] "Final"  "Useful"
c(psut_mats$Year %>% min(), psut_mats$Year %>% max())
#> [1] 1971 2019
psut_mats$IEAMW %>% unique()
#> [1] "IEA"  "MW"   "Both"

Example ECC matrices

Let’s look at a few of matrices using Ghana 1971 as an example. Simple matrices can be found in the muscle work data frames.

GHA1971_MW_final <- psut_mats %>% 
  dplyr::filter(Country == "GHA", Year == 1971, Energy.type == "E", 
                Last.stage == "Final", IEAMW == "MW")
dplyr::glimpse(GHA1971_MW_final)
#> Rows: 1
#> Columns: 14
#> $ Country     <chr> "GHA"
#> $ Method      <chr> "PCM"
#> $ Energy.type <chr> "E"
#> $ Last.stage  <chr> "Final"
#> $ Year        <dbl> 1971
#> $ IEAMW       <chr> "MW"
#> $ V           <list> <<matrix[3 x 3]>>
#> $ Y           <list> <<matrix[2 x 4]>>
#> $ S_units     <list> <<matrix[3 x 1]>>
#> $ R           <list> <matrix[1 x 1]>
#> $ U_feed      <list> <<matrix[2 x 3]>>
#> $ U_EIOU      <list> <<matrix[2 x 3]>>
#> $ U           <list> <<matrix[2 x 3]>>
#> $ r_EIOU      <list> <<matrix[2 x 3]>>
GHA1971_MW_final$R[[1]]
#>                        Biomass [from Resources]
#> Resources [of Biomass]                 1026.386
#> attr(,"rowtype")
#> [1] "Industry"
#> attr(,"coltype")
#> [1] "Product"
GHA1971_MW_final$U[[1]]
#>                             Farms Feed production Food production
#> Biomass                     0.000        119.1334        907.2526
#> Biomass [from Resources] 1026.386          0.0000          0.0000
#> attr(,"rowtype")
#> [1] "Product"
#> attr(,"coltype")
#> [1] "Industry"
GHA1971_MW_final$V[[1]]
#>                  Biomass     Feed     Food
#> Farms           1026.386  0.00000   0.0000
#> Feed production    0.000 53.61001   0.0000
#> Food production    0.000  0.00000 471.7713
#> attr(,"rowtype")
#> [1] "Industry"
#> attr(,"coltype")
#> [1] "Product"
GHA1971_MW_final$Y[[1]]
#>      Agriculture/forestry Commercial and public services
#> Feed             26.50066                        0.00000
#> Food            367.65411                       49.19114
#>      Industry not elsewhere specified Transport not elsewhere specified
#> Feed                          0.00000                          27.10935
#> Food                         54.92608                           0.00000
#> attr(,"rowtype")
#> [1] "Product"
#> attr(,"coltype")
#> [1] "Industry"

These matrices can be dumped to an Excel file for easier browsing.

gha_mw_file <- file.path("~", "GHA1971_MW_final.xlsx")
Recca::write_ecc_to_excel(GHA1971_MW_final, path = gha_mw_file, overwrite_file = TRUE)

Or a Sankey diagram can be created.

GHA1971_MW_final %>% 
  Recca::make_sankey() %>% 
  magrittr::extract2("Sankey") %>% 
  magrittr::extract2(1)

When useful energy is the last stage, we see the food and feed creating muscle work.

GHA1971_MW_useful <- psut_mats %>% 
  dplyr::filter(Country == "GHA", Year == 1971, Energy.type == "E", 
                Last.stage == "Useful", IEAMW == "MW")
GHA1971_MW_useful %>% 
  Recca::make_sankey() %>% 
  magrittr::extract2("Sankey") %>% 
  magrittr::extract2(1)

The IEA data give rise to more complicated matrices. This one is has the last stage being final energy.

GHA1971_IEA_final <- psut_mats %>% 
  dplyr::filter(Country == "GHA", Year == 1971, Energy.type == "E", 
                Last.stage == "Final", IEAMW == "IEA")
gha_iea_file <- file.path("~", "GHA1971_IEA_final.xlsx")
Recca::write_ecc_to_excel(GHA1971_IEA_final, path = gha_iea_file, overwrite_file = TRUE)
GHA1971_IEA_final %>% 
  Recca::make_sankey() %>% 
  magrittr::extract2("Sankey") %>% 
  magrittr::extract2(1)

When we push to useful energy, the matrices become more complex.

GHA1971_IEA_useful <- psut_mats %>% 
  dplyr::filter(Country == "GHA", Year == 1971, Energy.type == "E", 
                Last.stage == "Useful", IEAMW == "IEA")
gha_iea_file <- file.path("~", "GHA1971_IEA_useful.xlsx")
Recca::write_ecc_to_excel(GHA1971_IEA_useful, path = gha_iea_file, overwrite_file = TRUE)

And the Sankey diagram is unsurprisingly busier, but the matrices keep everything organized.

GHA1971_IEA_useful %>% 
  Recca::make_sankey() %>% 
  magrittr::extract2("Sankey") %>% 
  magrittr::extract2(1)

Example calculations

The following subsections illustrate example calculations.

Matrix math

Here we calculate the value added matrix (W) within the data frame using dplyr::mutate().

with_W <- GHA1971_MW_final %>% 
  dplyr::mutate(
    W = matsbyname::transpose_byname(GHA1971_MW_final$V) %>%
      matsbyname::difference_byname(GHA1971_MW_final$U)
  )
dplyr::glimpse(with_W)
#> Rows: 1
#> Columns: 15
#> $ Country     <chr> "GHA"
#> $ Method      <chr> "PCM"
#> $ Energy.type <chr> "E"
#> $ Last.stage  <chr> "Final"
#> $ Year        <dbl> 1971
#> $ IEAMW       <chr> "MW"
#> $ V           <list> <<matrix[3 x 3]>>
#> $ Y           <list> <<matrix[2 x 4]>>
#> $ S_units     <list> <<matrix[3 x 1]>>
#> $ R           <list> <matrix[1 x 1]>
#> $ U_feed      <list> <<matrix[2 x 3]>>
#> $ U_EIOU      <list> <<matrix[2 x 3]>>
#> $ U           <list> <<matrix[2 x 3]>>
#> $ r_EIOU      <list> <<matrix[2 x 3]>>
#> $ W           <list> <<matrix[4 x 3]>>
with_W$W[[1]]
#>                              Farms Feed production Food production
#> Biomass                   1026.386      -119.13336       -907.2526
#> Biomass [from Resources] -1026.386         0.00000          0.0000
#> Feed                         0.000        53.61001          0.0000
#> Food                         0.000         0.00000        471.7713
#> attr(,"rowtype")
#> [1] "Product"
#> attr(,"coltype")
#> [1] "Industry"

Upstream swim

The PSUT framework allows upstream and downstream “swims.”

Here is the final demand matrix for the IEA data.

# View(GHA1971_IEA_final$Y[[1]])

Let’s say we wanted to know the energy (at all stages) required to provide residential energy in the country. We can use an input-output ``upstream swim’’ for that analysis.

First, we calculate all the input-output matrices.

with_io_mats <- GHA1971_IEA_final %>% 
  Recca::calc_io_mats()
dplyr::glimpse(with_io_mats)
#> Rows: 1
#> Columns: 34
#> $ Country     <chr> "GHA"
#> $ Method      <chr> "PCM"
#> $ Energy.type <chr> "E"
#> $ Last.stage  <chr> "Final"
#> $ Year        <dbl> 1971
#> $ IEAMW       <chr> "IEA"
#> $ V           <list> <<matrix[12 x 14]>>
#> $ Y           <list> <<matrix[12 x 22]>>
#> $ S_units     <list> <<matrix[16 x 1]>>
#> $ R           <list> <<matrix[2 x 2]>>
#> $ U_feed      <list> <<matrix[6 x 5]>>
#> $ U_EIOU      <list> <<matrix[2 x 2]>>
#> $ U           <list> <<matrix[8 x 5]>>
#> $ r_EIOU      <list> <<matrix[8 x 5]>>
#> $ y           <list> <<matrix[12 x 1]>>
#> $ q           <list> <<matrix[16 x 1]>>
#> $ f           <list> <<matrix[5 x 1]>>
#> $ g           <list> <<matrix[12 x 1]>>
#> $ h           <list> <<matrix[2 x 1]>>
#> $ r           <list> <<matrix[2 x 1]>>
#> $ W           <list> <<matrix[16 x 12]>>
#> $ Z           <list> <<matrix[8 x 12]>>
#> $ K           <list> <<matrix[8 x 5]>>
#> $ C           <list> <<matrix[14 x 12]>>
#> $ D           <list> <<matrix[12 x 16]>>
#> $ A           <list> <<matrix[8 x 16]>>
#> $ O           <list> <<matrix[2 x 2]>>
#> $ L_pxp       <list> <<matrix[16 x 16]>>
#> $ L_ixp       <list> <<matrix[12 x 16]>>
#> $ Z_feed      <list> <<matrix[6 x 12]>>
#> $ K_feed      <list> <<matrix[6 x 5]>>
#> $ A_feed      <list> <<matrix[6 x 16]>>
#> $ L_pxp_feed  <list> <<matrix[16 x 16]>>
#> $ L_ixp_feed  <list> <<matrix[12 x 16]>>

Next, we define a Y_prime matrix that contains only final demand from residences.

with_Y_prime <- with_io_mats %>% 
  dplyr::mutate(
    Y_prime = Y %>% 
      matsbyname::select_cols_byname("Residential")
  )
with_Y_prime$Y_prime[[1]]
#>                                       Residential
#> Aviation gasoline                               0
#> Charcoal                                      119
#> Crude oil                                       0
#> Electricity                                    14
#> Fuel oil                                        0
#> Gas/diesel oil excl. biofuels                   0
#> Kerosene type jet fuel excl. biofuels           0
#> Liquefied petroleum gases (LPG)                 3
#> Lubricants                                      0
#> Motor gasoline excl. biofuels                   0
#> Other kerosene                                 84
#> Primary solid biofuels                       1464
#> attr(,"rowtype")
#> [1] "Product"
#> attr(,"coltype")
#> [1] "Industry"

Now let’s swim upstream from the Y_prime matrix to see what upstream energy is needed to supply Residential final demand.

residential_ecc <- with_Y_prime %>% 
  Recca::new_Y()
dplyr::glimpse(residential_ecc)
#> Rows: 1
#> Columns: 41
#> $ Country      <chr> "GHA"
#> $ Method       <chr> "PCM"
#> $ Energy.type  <chr> "E"
#> $ Last.stage   <chr> "Final"
#> $ Year         <dbl> 1971
#> $ IEAMW        <chr> "IEA"
#> $ V            <list> <<matrix[12 x 14]>>
#> $ Y            <list> <<matrix[12 x 22]>>
#> $ S_units      <list> <<matrix[16 x 1]>>
#> $ R            <list> <<matrix[2 x 2]>>
#> $ U_feed       <list> <<matrix[6 x 5]>>
#> $ U_EIOU       <list> <<matrix[2 x 2]>>
#> $ U            <list> <<matrix[8 x 5]>>
#> $ r_EIOU       <list> <<matrix[8 x 5]>>
#> $ y            <list> <<matrix[12 x 1]>>
#> $ q            <list> <<matrix[16 x 1]>>
#> $ f            <list> <<matrix[5 x 1]>>
#> $ g            <list> <<matrix[12 x 1]>>
#> $ h            <list> <<matrix[2 x 1]>>
#> $ r            <list> <<matrix[2 x 1]>>
#> $ W            <list> <<matrix[16 x 12]>>
#> $ Z            <list> <<matrix[8 x 12]>>
#> $ K            <list> <<matrix[8 x 5]>>
#> $ C            <list> <<matrix[14 x 12]>>
#> $ D            <list> <<matrix[12 x 16]>>
#> $ A            <list> <<matrix[8 x 16]>>
#> $ O            <list> <<matrix[2 x 2]>>
#> $ L_pxp        <list> <<matrix[16 x 16]>>
#> $ L_ixp        <list> <<matrix[12 x 16]>>
#> $ Z_feed       <list> <<matrix[6 x 12]>>
#> $ K_feed       <list> <<matrix[6 x 5]>>
#> $ A_feed       <list> <<matrix[6 x 16]>>
#> $ L_pxp_feed   <list> <<matrix[16 x 16]>>
#> $ L_ixp_feed   <list> <<matrix[12 x 16]>>
#> $ Y_prime      <list> <<matrix[12 x 1]>>
#> $ R_prime      <list> <<matrix[2 x 16]>>
#> $ U_prime      <list> <<matrix[8 x 12]>>
#> $ U_feed_prime <list> <<matrix[6 x 12]>>
#> $ U_EIOU_prime <list> <<matrix[8 x 12]>>
#> $ r_EIOU_prime <list> <<matrix[8 x 12]>>
#> $ V_prime      <list> <<matrix[12 x 16]>>

The _prime matrices are what we want. So we keep those and make a new Sankey diagram.

residential_ecc_trimmed <- residential_ecc %>% 
  dplyr::select(Country, Method, Energy.type, Last.stage, Year, IEAMW,
                R_prime, U_prime, U_feed_prime, U_EIOU_prime, 
                r_EIOU_prime, V_prime, Y_prime, S_units) %>% 
  dplyr::rename(
    R = R_prime, 
    U = U_prime, 
    U_feed = U_feed_prime,
    U_EIOU = U_EIOU_prime,
    r_EIOU = r_EIOU_prime,
    V = V_prime, 
    Y = Y_prime
  ) %>% 
  dplyr::mutate(Sector = "Residential")
dplyr::glimpse(residential_ecc_trimmed)
#> Rows: 1
#> Columns: 15
#> $ Country     <chr> "GHA"
#> $ Method      <chr> "PCM"
#> $ Energy.type <chr> "E"
#> $ Last.stage  <chr> "Final"
#> $ Year        <dbl> 1971
#> $ IEAMW       <chr> "IEA"
#> $ R           <list> <<matrix[2 x 16]>>
#> $ U           <list> <<matrix[8 x 12]>>
#> $ U_feed      <list> <<matrix[6 x 12]>>
#> $ U_EIOU      <list> <<matrix[8 x 12]>>
#> $ r_EIOU      <list> <<matrix[8 x 12]>>
#> $ V           <list> <<matrix[12 x 16]>>
#> $ Y           <list> <<matrix[12 x 1]>>
#> $ S_units     <list> <<matrix[16 x 1]>>
#> $ Sector      <chr> "Residential"

Make a Sankey diagram of energy required to supply Residential demand only.

residential_ecc_trimmed %>% 
  Recca::make_sankey() %>% 
  magrittr::extract2("Sankey") %>% 
  magrittr::extract2(1)

From the Sankey diagram, we can see all the ways in which Ghanaian residences demanded upstream primary energy in 1971.

Efficiencies

With the Residential sector isolated, we can calculate the efficiency of energy use in residences.

primary_industries <- IEATools::tpes_flows
primary_industries
#> $resources
#> [1] "Resources"
#> 
#> $production
#> [1] "Production"
#> 
#> $imports
#> [1] "Imports"
#> 
#> $exports
#> [1] "Exports"
#> 
#> $international_marine_bunkers
#> [1] "International marine bunkers"
#> 
#> $international_aviation_bunkers
#> [1] "International aviation bunkers"
#> 
#> $exports_to_world_marine_bunkers
#> [1] "Exports to World marine bunkers"
#> 
#> $exports_to_world_aviation_bunkers
#> [1] "Exports to World aviation bunkers"
#> 
#> $stock_changes
#> [1] "Stock changes"
finaldemand_sectors <- IEATools::fd_sectors
finaldemand_sectors
#> $bkb_peat_briquette_plants
#> [1] "BKB/peat briquette plants"
#> 
#> $blast_furnaces
#> [1] "Blast furnaces"
#> 
#> $charcoal_plants
#> [1] "Charcoal production plants"
#> 
#> $coal_liquefaction_plants
#> [1] "Coal liquefaction plants"
#> 
#> $coal_mines
#> [1] "Coal mines"
#> 
#> $coke_ovens
#> [1] "Coke ovens"
#> 
#> $gas_works
#> [1] "Gas works"
#> 
#> $gas_to_liquids_plants
#> [1] "Gas-to-liquids (GTL) plants"
#> 
#> $gasification_plants
#> [1] "Gasification plants for biogases"
#> 
#> $liquefaction_regasification_plants
#> [1] "Liquefaction (LNG) / regasification plants"
#> 
#> $non_specified_eiou
#> [1] "Non-specified (energy)"
#> 
#> $nuclear_industry
#> [1] "Nuclear industry"
#> 
#> $oil_and_gas_extraction
#> [1] "Oil and gas extraction"
#> 
#> $oil_extraction
#> [1] "Oil extraction"
#> 
#> $natural_gas_extraction
#> [1] "Natural gas extraction"
#> 
#> $oil_refineries
#> [1] "Oil refineries"
#> 
#> $own_use_elect_chp_heat_plants
#> [1] "Own use in electricity, CHP and heat plants"
#> 
#> $main_activity_producer_electricity_plants
#> [1] "Main activity producer electricity plants"
#> 
#> $main_activity_producer_chp_plants
#> [1] "Main activity producer CHP plants"
#> 
#> $main_activity_producer_heat_plants
#> [1] "Main activity producer heat plants"
#> 
#> $patent_fuel_plants
#> [1] "Patent fuel plants"
#> 
#> $pumped_storage_plants
#> [1] "Pumped storage plants"
#> 
#> $mining_and_quarrying
#> [1] "Mining and quarrying"
#> 
#> $construction
#> [1] "Construction"
#> 
#> $manufacturing
#> [1] "Manufacturing"
#> 
#> $iron_and_steel
#> [1] "Iron and steel"
#> 
#> $chemical_and_petrochemical
#> [1] "Chemical and petrochemical"
#> 
#> $non_ferrous_metals
#> [1] "Non-ferrous metals"
#> 
#> $non_metallic_minerals
#> [1] "Non-metallic minerals"
#> 
#> $transport_equipment
#> [1] "Transport equipment"
#> 
#> $machinery
#> [1] "Machinery"
#> 
#> $food_and_tobacco
#> [1] "Food and tobacco"
#> 
#> $paper_pulp_and_print
#> [1] "Paper, pulp and print"
#> 
#> $paper_pulp_and_printing
#> [1] "Paper, pulp and printing"
#> 
#> $wood_and_wood_products
#> [1] "Wood and wood products"
#> 
#> $textile_and_leather
#> [1] "Textile and leather"
#> 
#> $non_specified_industry
#> [1] "Non-specified (industry)"
#> 
#> $industry_not_elsewhere_specified
#> [1] "Industry not elsewhere specified"
#> 
#> $oil_extraction
#> [1] "Oil extraction"
#> 
#> $natural_gas_extraction
#> [1] "Natural gas extraction"
#> 
#> $domestic_navigation
#> [1] "Domestic navigation"
#> 
#> $world_marine_bunkers
#> [1] "World marine bunkers"
#> 
#> $international_navigation
#> [1] "International navigation"
#> 
#> $domestic_aviation
#> [1] "Domestic aviation"
#> 
#> $world_aviation_bunkers
#> [1] "World aviation bunkers"
#> 
#> $international_aviation
#> [1] "International aviation"
#> 
#> $road
#> [1] "Road"
#> 
#> $rail
#> [1] "Rail"
#> 
#> $pipeline_transport
#> [1] "Pipeline transport"
#> 
#> $non_specified_transport
#> [1] "Non-specified (transport)"
#> 
#> $transport_not_elsewhere_specified
#> [1] "Transport not elsewhere specified"
#> 
#> $residential
#> [1] "Residential"
#> 
#> $commercial_and_public_services
#> [1] "Commercial and public services"
#> 
#> $agriculture_forestry
#> [1] "Agriculture/forestry"
#> 
#> $fishing
#> [1] "Fishing"
#> 
#> $non_specified_other
#> [1] "Non-specified (other)"
#> 
#> $final_consumption_not_elsewhere_specified
#> [1] "Final consumption not elsewhere specified"
#> 
#> $non_energy_use_industry_transformation_energy
#> [1] "Non-energy use industry/transformation/energy"
#> 
#> $non_energy_use_in_transport
#> [1] "Non-energy use in transport"
#> 
#> $non_energy_use_in_other
#> [1] "Non-energy use in other"
#> 
#> [[61]]
#> [1] "Non-energy use in industry"
#> 
#> [[62]]
#> [1] "Non-energy use in construction"
#> 
#> [[63]]
#> [1] "Non-energy use in mining and quarrying"
#> 
#> [[64]]
#> [1] "Non-energy use in iron and steel"
#> 
#> [[65]]
#> [1] "Non-energy use in chemical/petrochemical"
#> 
#> [[66]]
#> [1] "Non-energy use in non-ferrous metals"
#> 
#> [[67]]
#> [1] "Non-energy use in non-metallic minerals"
#> 
#> [[68]]
#> [1] "Non-energy use in transport equipment"
#> 
#> [[69]]
#> [1] "Non-energy use in machinery"
#> 
#> [[70]]
#> [1] "Non-energy use in food/beverages/tobacco"
#> 
#> [[71]]
#> [1] "Non-energy use in paper/pulp and printing"
#> 
#> [[72]]
#> [1] "Non-energy use in wood and wood products"
#> 
#> [[73]]
#> [1] "Non-energy use in textiles and leather"
#> 
#> [[74]]
#> [1] "Non-energy use in industry not elsewhere specified"
with_efficiencies <- residential_ecc_trimmed %>% 
  Recca::primary_aggregates(p_industries = primary_industries, pattern_type = "leading") %>% 
  Recca::finaldemand_aggregates(fd_sectors = finaldemand_sectors) %>%
  dplyr::mutate(
    eta_pf_net = as.numeric(EX.fd_net) / as.numeric(EX.p),
    eta_pf_gross = as.numeric(EX.fd_gross) / as.numeric(EX.p)
  )
dplyr::glimpse(with_efficiencies)
#> Rows: 1
#> Columns: 20
#> $ Country      <chr> "GHA"
#> $ Method       <chr> "PCM"
#> $ Energy.type  <chr> "E"
#> $ Last.stage   <chr> "Final"
#> $ Year         <dbl> 1971
#> $ IEAMW        <chr> "IEA"
#> $ R            <list> <<matrix[2 x 16]>>
#> $ U            <list> <<matrix[8 x 12]>>
#> $ U_feed       <list> <<matrix[6 x 12]>>
#> $ U_EIOU       <list> <<matrix[8 x 12]>>
#> $ r_EIOU       <list> <<matrix[8 x 12]>>
#> $ V            <list> <<matrix[12 x 16]>>
#> $ Y            <list> <<matrix[12 x 1]>>
#> $ S_units      <list> <<matrix[16 x 1]>>
#> $ Sector       <chr> "Residential"
#> $ EX.p         <dbl> 0
#> $ EX.fd_net    <dbl> 1684
#> $ EX.fd_gross  <dbl> 1686.151
#> $ eta_pf_net   <dbl> Inf
#> $ eta_pf_gross <dbl> Inf

Pipelines

A different R package (PFUAggDatabase) does the above calculations (and more!) for all countries; all years; energy and exergy; last stage final and useful; IEA, MW, and both; etc. The calculations are parallelized across countries. Despite parallelization, the calculations take several hours on a 10-core laptop, We will (eventually) generating the PFUAggDatabase on a supercomputer.

Conclusion

In combination, the PSUT framework and the R packages matsbyname, matsindf, and Recca provide powerful analysis tools for energy conversion chains.