Final to Useful Analysis
Matthew Kuperus Heun
2024-12-09
final_to_useful.Rmd
Introduction
Extended energy balance data from the International Energy Agency (IEA) provides both primary and final energy information. (Primary energy is extracted from the biosphere, and final energy is sold to consumers.) But consumers don’t buy final energy for its own sake. They buy final energy so they can convert it to useful energy (heat, light, work) that, when combined with infrastructure (buildings, roads, etc.), provides energy services (heated and cooled space, passenger and freight transport, etc.).
So some energy conversion chain analyses extend the final energy provided by the IEA to useful energy through a process that involves
- allocating final energy to final-to-useful energy conversion machines,
- defining the efficiency of those final-to-useful energy conversion machines, and
- calculating the useful energy injected into the the final demand economic sectors.
The IEATools
package provides several functions to
assist the process of pushing from final energy to useful energy. This
vignette demonstrates their use and suggests a workflow for this
process.
Allocation
Extending the IEA’s extended energy balance data to the useful stage begins with defining allocations of final energy carriers to final-to-useful energy conversion machines. To demonstrate this process, we’ll use the sample IEA data bundled with this package.
library(dplyr)
library(IEATools)
Tidy_iea_data <- load_tidy_iea_df() %>%
specify_all() %>%
glimpse()
#> Rows: 429
#> Columns: 11
#> $ Country <chr> "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", …
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", …
#> $ EnergyType <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "E",…
#> $ LastStage <chr> "Final", "Final", "Final", "Final", "Final", "Fin…
#> $ Year <dbl> 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1…
#> $ LedgerSide <chr> "Consumption", "Consumption", "Consumption", "Con…
#> $ FlowAggregationPoint <chr> "Industry", "Industry", "Industry", "Industry", "…
#> $ Flow <chr> "Industry not elsewhere specified", "Industry not…
#> $ Product <chr> "Electricity", "Fuel oil", "Gas/diesel oil excl. …
#> $ Unit <chr> "TJ", "TJ", "TJ", "TJ", "TJ", "TJ", "TJ", "TJ", "…
#> $ Edot <dbl> 918.0020, 3698.4014, 1645.3998, 6100.0001, 698.40…
The next step is to develop a blank template in which the analyst can
provide final-to-useful allocation values (C
) in
percentages. fu_allocation_template()
builds a
final-to-useful allocation template.
FU_allocation_template <- load_tidy_iea_df() %>%
specify_all() %>%
fu_allocation_template()
FU_allocation_template %>%
glimpse()
#> Rows: 906
#> Columns: 15
#> $ Country <chr> "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", …
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", …
#> $ EnergyType <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "E",…
#> $ LastStage <chr> "Final", "Final", "Final", "Final", "Final", "Fin…
#> $ LedgerSide <chr> "Supply", "Supply", "Supply", "Supply", "Supply",…
#> $ FlowAggregationPoint <chr> "Energy industry own use", "Energy industry own u…
#> $ Unit <chr> "TJ", "TJ", "TJ", "TJ", "TJ", "TJ", "TJ", "TJ", "…
#> $ EfProduct <chr> "Refinery gas", "Refinery gas", "Refinery gas", "…
#> $ Machine <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ EuProduct <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ Destination <chr> "Oil refineries", "Oil refineries", "Oil refineri…
#> $ Quantity <chr> "Edot", "Edot [%]", "C_1 [%]", "C_2 [%]", "C_3 [%…
#> $ MaximumValues <dbl> 1.106299e+03, 8.867781e-01, NA, NA, NA, NA, 1.583…
#> $ `1971` <dbl> 8.176988e+02, 8.867781e-01, NA, NA, NA, NA, 1.044…
#> $ `2000` <dbl> 1106.2991000, 0.8747534, NA, NA, NA, NA, 158.3992…
To obtain a nicely-formatted Excel spreadsheet, use the
write_fu_allocation_template()
function.
# FU_allocation_template %>%
# write_fu_allocation_template("~/Desktop/Test_FU_allocation_template.xlsx")
The analyst should complete all of the unshaded cells in the
Machine
and Eu.product
columns.
Machine
should contain names of final-to-useful machines
such as “Automobiles,” “Industrial heat/furnace,” etc.
Eu.product
should be filled with names of useful energy
carriers such as “HTH.600.C”, “MD”, or “Light”. Note that later
processing will parse the heat categories for their temperature, and the
required format is *TH.nnn.U
, where
-
*
(the first character) is arbitrary, butH
,M
, andL
are typical for high, medium, and low temperature heat, respectively, -
TH.
is required, -
nnn
can be any number of digits, optionally preceded by a negative sign, -
.
is required, and -
U
is the temperature unit, one ofC
,F
,R
, orK
for degrees Celsius, degrees Fahrenheit, rankine, or kelvin, respectively.
The C
rows representation allocations of
Edot
energy to final-to-useful machines for each year of
available IEA data. Three allocation rows (C_1 [%]
,
C_2 [%]
, and C_3 [%]
) are provided for each
combination of Flow.aggregation.point
,
Ef.product
, and Destination
. Not all
C_i [%]
rows need to be filled, and the analyst can add
more allocation rows (C_4 [%]
, C_5 [%]
, …) as
required.
The rows are in IEA order for Flow.aggregation.point
,
Ef.product
, and Destination
.
The Maximum.values
column provides an indication of
which Destination
s receive more energy than others,
allowing the analyst to focus more attention on larger energy flows, as
desired.
Final-to-useful efficiencies and useful exergy-to-energy ratios
After completing the final-to-useful allocation table, the analyst
must specify the efficiencies of the final-to-useful machines. To assist
with this task, the eta_fu_template()
function can be
invoked. To demonstrate, we’ll use
load_fu_allocation_data()
, a function that reads a
completed allocation table out of an excel file. The default
path
argument of load_fu_allocation_data()
points to a completed final-to-useful allocation table that is provided
with IEATools
.
Eta_fu_template <- load_fu_allocation_data() %>%
eta_fu_template()
Eta_fu_template %>%
glimpse()
#> Rows: 276
#> Columns: 11
#> $ Country <chr> "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", "GHA", …
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", …
#> $ EnergyType <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "…
#> $ LastStage <chr> "Final", "Final", "Final", "Final", "Final", "Final", "F…
#> $ Unit <chr> "ktoe", "ktoe", "ktoe", "ktoe", "ktoe", "ktoe", "ktoe", …
#> $ Machine <chr> "Automobiles", "Automobiles", "Automobiles", "Automobile…
#> $ EuProduct <chr> "MD", "MD", "MD", "MD", "MD", "MD", "MD", "MD", "MD", "M…
#> $ Quantity <chr> "Edot_machine", "Edot_machine [%]", "etafu", "phiu", "Ed…
#> $ MaximumValues <dbl> 6.192510e+02, 1.141842e-01, NA, NA, 1.877078e+02, 3.4611…
#> $ `1971` <dbl> 2.172315e+02, 8.333158e-02, NA, 1.000000e+00, 5.946665e+…
#> $ `2000` <dbl> 6.192510e+02, 1.141842e-01, NA, 1.000000e+00, 1.877078e+…
To obtain a nicely-formatted Excel spreadsheet, use the
write_fu_allocation_template()
function.
# Eta_fu_template %>%
# write_eta_fu_template("~/Desktop/Test_eta_fu_template.xlsx")
The analyst should fill all unshaded cells in eta.fu
rows with final-to-useful energy efficiency values (in %).
phi.u
rows should be completed with exergy-to-energy ratios
for the useful stage energy carrier. Note that many phi.u
values are already filled for cases where the phi value is known or
easily calculable, specifically mechanical drive (phi = 1) and heat (phi
= 1 - T_0/T_H, where T_H is the heat temperature embedded in the
*TH.nnn.U
useful exergy string).
The Maximum.values
column provides an indication of
which Destination
s receive more energy than others,
allowing the analyst to focus more attention on larger energy flows, as
desired. The Edot_machine
and Edot_machine [%]
rows indicate energy flows and percentages into each final-to-useful
machine in each year.
After allocations and efficiencies are specified (by completing the templates), functions can be used to move the last stage of an energy conversion chain from final energy to useful energy.
Allocation (C) matrices
Next, the C
values from the allocation table must be
arranged into
matrices using the form_C_mats()
function.
C_mats <- load_fu_allocation_data() %>%
form_C_mats()
glimpse(C_mats)
#> Rows: 4
#> Columns: 7
#> $ Country <chr> "GHA", "GHA", "ZAF", "ZAF"
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM"
#> $ EnergyType <chr> "E", "E", "E", "E"
#> $ LastStage <chr> "Final", "Final", "Final", "Final"
#> $ Year <dbl> 1971, 2000, 1971, 2000
#> $ C_EIOU <list> <<matrix[2 x 3]>>, <<matrix[2 x 3]>>, <<matrix[3 x 3]>>, <<…
#> $ C_Y <list> <<matrix[23 x 21]>>, <<matrix[24 x 20]>>, <<matrix[45 x 30]…
Note that two types of matrices are formed, and . Both are needed later.
Efficiency and exergy-to-energy ratio vectors
Next, vectors containing final-to-useful energy efficiencies
()
and exergy-to-energy ratios
()
must be formed using the form_eta_fu_phi_u_vecs()
function.
eta_fu_vecs <- load_eta_fu_data() %>%
form_eta_fu_phi_u_vecs()
glimpse(eta_fu_vecs)
#> Rows: 4
#> Columns: 7
#> $ Country <chr> "GHA", "GHA", "ZAF", "ZAF"
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM"
#> $ EnergyType <chr> "E", "E", "E", "E"
#> $ LastStage <chr> "Final", "Final", "Final", "Final"
#> $ Year <dbl> 1971, 2000, 1971, 2000
#> $ etafu <list> <<matrix[22 x 1]>>, <<matrix[21 x 1]>>, <<matrix[31 x 1]>>,…
#> $ phiu <list> <<matrix[6 x 1]>>, <<matrix[6 x 1]>>, <<matrix[7 x 1]>>, <<…
Extend to useful
To extend an energy conversion chain (ECC) to the useful stage, first convert the IEA data into physical supply-use table format with final energy being the last stage of the energy conversion chain. Thereafter, join the matrices and vectors to the data frame of PSUT matrices.
# Get a list of the metadata columns.
# This list will be the same for C_mats.
m_cols <- eta_fu_vecs %>%
meta_cols(return_names = TRUE,
years_to_keep = IEATools::iea_cols$year,
not_meta = c(IEATools::template_cols$eta_fu, IEATools::template_cols$phi_u))
m_cols
#> [1] "Country" "Method" "EnergyType" "LastStage" "Year"
psut_mats_final <- load_tidy_iea_df() %>%
specify_all() %>%
prep_psut() %>%
dplyr::full_join(C_mats, by = m_cols) %>%
dplyr::full_join(eta_fu_vecs, by = m_cols)
glimpse(psut_mats_final)
#> Rows: 4
#> Columns: 17
#> $ Country <chr> "GHA", "GHA", "ZAF", "ZAF"
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM"
#> $ EnergyType <chr> "E", "E", "E", "E"
#> $ LastStage <chr> "Final", "Final", "Final", "Final"
#> $ Year <dbl> 1971, 2000, 1971, 2000
#> $ Y <list> <<matrix[12 x 21]>>, <<matrix[13 x 20]>>, <<matrix[18 x 26]…
#> $ S_units <list> <<matrix[16 x 1]>>, <<matrix[18 x 1]>>, <<matrix[24 x 1]>>,…
#> $ R <list> <<matrix[9 x 8]>>, <<matrix[13 x 12]>>, <<matrix[6 x 6]>>, …
#> $ U <list> <<matrix[8 x 5]>>, <<matrix[7 x 5]>>, <<matrix[11 x 11]>>, …
#> $ U_feed <list> <<matrix[6 x 5]>>, <<matrix[5 x 5]>>, <<matrix[9 x 11]>>, <…
#> $ U_EIOU <list> <<matrix[2 x 2]>>, <<matrix[2 x 2]>>, <<matrix[2 x 3]>>, <…
#> $ r_EIOU <list> <<matrix[8 x 5]>>, <<matrix[7 x 5]>>, <<matrix[11 x 11]>>,…
#> $ V <list> <<matrix[5 x 11]>>, <<matrix[5 x 11]>>, <<matrix[11 x 20]>…
#> $ C_EIOU <list> <<matrix[2 x 3]>>, <<matrix[2 x 3]>>, <<matrix[3 x 3]>>, <…
#> $ C_Y <list> <<matrix[23 x 21]>>, <<matrix[24 x 20]>>, <<matrix[45 x 30…
#> $ etafu <list> <<matrix[22 x 1]>>, <<matrix[21 x 1]>>, <<matrix[31 x 1]>>…
#> $ phiu <list> <<matrix[6 x 1]>>, <<matrix[6 x 1]>>, <<matrix[7 x 1]>>, <…
Then use the allocation and efficiency matrices to extend to the
useful stage with the extend_to_useful()
function.
psut_mats_useful <- psut_mats_final %>%
extend_to_useful()
psut_mats_useful <- stack_final_useful_df(psut_mats_useful, psut_mats_final)
glimpse(psut_mats_useful)
#> Rows: 8
#> Columns: 15
#> $ Country <chr> "GHA", "GHA", "ZAF", "ZAF", "GHA", "GHA", "ZAF", "ZA…
#> $ Method <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PC…
#> $ EnergyType <chr> "E", "E", "E", "E", "E", "E", "E", "E"
#> $ LastStage <chr> "Final", "Final", "Final", "Final", "Useful", "Usefu…
#> $ Year <dbl> 1971, 2000, 1971, 2000, 1971, 2000, 1971, 2000
#> $ Y <list> <<matrix[12 x 21]>>, <<matrix[13 x 20]>>, <<matrix[1…
#> $ S_units <list> <<matrix[16 x 1]>>, <<matrix[18 x 1]>>, <<matrix[24 …
#> $ R <list> <<matrix[9 x 8]>>, <<matrix[13 x 12]>>, <<matrix[6 …
#> $ U <list> <<matrix[8 x 5]>>, <<matrix[7 x 5]>>, <<matrix[11 x…
#> $ U_feed <list> <<matrix[6 x 5]>>, <<matrix[5 x 5]>>, <<matrix[9 x …
#> $ U_EIOU <list> <<matrix[2 x 2]>>, <<matrix[2 x 2]>>, <<matrix[2 x …
#> $ r_EIOU <list> <<matrix[8 x 5]>>, <<matrix[7 x 5]>>, <<matrix[11 x…
#> $ V <list> <<matrix[5 x 11]>>, <<matrix[5 x 11]>>, <<matrix[11…
#> $ Y_fu_details <list> <NULL>, <NULL>, <NULL>, <NULL>, <<matrix[23 x 21]>>…
#> $ U_EIOU_fu_details <list> <NULL>, <NULL>, <NULL>, <NULL>, <<matrix[2 x 3]>>, …
Notice that several additional rows have been created in the data frame. The additional rows contain versions of ECC matrices wherein the last stage of the ECC is useful energy. Extending to the useful stage means many additional energy products are included in the energy conversion chain. For example, the matrix includes additional rows for mechanical drive (MD), heat (MTH.100.C, e.g.), and light.
# A Y matrix where final energy is the last stage of the energy conversion chain
rownames(psut_mats_useful$Y[[1]])
#> [1] "Aviation gasoline"
#> [2] "Charcoal"
#> [3] "Crude oil"
#> [4] "Electricity"
#> [5] "Fuel oil"
#> [6] "Gas/diesel oil excl. biofuels"
#> [7] "Kerosene type jet fuel excl. biofuels"
#> [8] "Liquefied petroleum gases (LPG)"
#> [9] "Lubricants"
#> [10] "Motor gasoline excl. biofuels"
#> [11] "Other kerosene"
#> [12] "Primary solid biofuels"
# A Y matrix where useful energy is the last stage of the energy conversion chain
rownames(psut_mats_useful$Y[[5]])
#> [1] "Aviation gasoline"
#> [2] "Charcoal"
#> [3] "Crude oil"
#> [4] "Electricity"
#> [5] "Fuel oil"
#> [6] "Gas/diesel oil excl. biofuels"
#> [7] "HTH.600.C [from Electric heaters]"
#> [8] "Kerosene type jet fuel excl. biofuels"
#> [9] "Light [from Electric lights]"
#> [10] "Liquefied petroleum gases (LPG)"
#> [11] "Lubricants"
#> [12] "MD [from Automobiles]"
#> [13] "MD [from Boat engines]"
#> [14] "MD [from Diesel cars]"
#> [15] "MD [from Diesel trains]"
#> [16] "MD [from Diesel trucks]"
#> [17] "MD [from Electric motors]"
#> [18] "MD [from Fans]"
#> [19] "MD [from Trucks]"
#> [20] "Motor gasoline excl. biofuels"
#> [21] "MTH.100.C [from Charcoal stoves]"
#> [22] "MTH.100.C [from Electric stoves]"
#> [23] "MTH.100.C [from Kerosene stoves]"
#> [24] "MTH.100.C [from LPG stoves]"
#> [25] "MTH.100.C [from Wood cookstoves]"
#> [26] "MTH.200.C [from Electric heaters]"
#> [27] "MTH.200.C [from Electric stoves]"
#> [28] "MTH.200.C [from Industrial furnaces]"
#> [29] "MTH.200.C [from Irons]"
#> [30] "MTH.200.C [from Wood stoves]"
#> [31] "NEU [from Non-energy consumption]"
#> [32] "Other kerosene"
#> [33] "Primary solid biofuels"