Skip to contents

Energy balances are confirmed by Product (within tol) for every row in .sutmats.

Usage

verify_SUT_energy_balance(
  .sutmats = NULL,
  R = "R",
  U = "U",
  V = "V",
  Y = "Y",
  tol = 1e-06,
  SUT_energy_balance = ".SUT_energy_balance"
)

Arguments

.sutmats

an SUT-style data frame with columns of matrices, including U, V, and Y columns.

R

resources (R) matrix or name of the column in .sutmats that contains same. Default is "R".

U

use (U) matrix or name of the column in .sutmats that contains same. Default is "U".

V

make (V) matrix or name of the column in .sutmatsthat contains same. Default is "V".

Y

final demand (Y) matrix or name of the column in .sutmats that contains same. Default is "Y".

tol

the maximum amount by which Supply and Consumption can be out of balance. Default is 1e-6.

SUT_energy_balance

the name for booleans telling if energy is in balance. Default is ".SUT_energy_balance".

Value

a list or data frame saying whether .sutmats are in balance.

Details

If energy is in balance for every row, .sutmats is returned with an additional column, and execution returns to the caller. If energy balance is not observed for one or more of the rows, a warning is emitted, and the additional column (SUT_energy_blance) indicates where the problem occurred, with FALSE showing where energy is not in balance.

Examples

library(dplyr)
library(tidyr)
verify_SUT_energy_balance(UKEnergy2000mats %>%
                            dplyr::filter(Last.stage %in% c("Final", "Useful")) %>%
                            tidyr::spread(key = matrix.name, value = matrix),
                          tol = 1e-4)
#>   Country Year Energy.type Last.stage                  R
#> 1     GBR 2000           E      Final 50000, 0, 0, 43000
#> 2     GBR 2000           E     Useful 50000, 0, 0, 43000
#>                                          S_units
#> 1             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
#> 2 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       U
#> 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     0, 500, 47500, 0, 25, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 15500, 350, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 25, 43000, 0, 2000, 0, 0, 0, 0, 0, 0, 25, 0, 25, 0, 0, 41000, 0, 0, 50000, 0, 2500, 0, 50, 0, 25, 0, 0, 0, 0, 0, 0, 47000, 0, 5000, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 250, 0, 0, 0, 0, 0, 26500, 500, 0, 0, 0, 0, 0, 0, 100, 0, 16000, 0, 0, 0
#> 2 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 26000.0000, 0.0000, 0.0000, 47500.0000, 0.0000, 0.0000, 0.0000, 25.0000, 20.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 15500.0000, 0.0000, 0.0000, 0.0000, 17.9998, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 6400.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 25000.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 50.0000, 0.0000, 25.0000, 0.0000, 43000.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 6000.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 25.0000, 20.0000, 0.0000, 0.0000, 41000.0000, 0.0000, 0.0000, 50000.0000, 0.0000, 0.0000, 0.0000, 50.0000, 0.0000, 25.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 47000.0000, 0.0000, 0.0000, 0.0000, 0.0000, 75.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 26.9997, 0.0000, 0.0000, 0.0000, 26500.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 100.0000, 0.0000, 0.0000, 16000.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 15050.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
#>                                                                                                                                                                                                        U_EIOU
#> 1          500, 0, 0, 25, 25, 0, 0, 0, 0, 0, 350, 0, 0, 0, 0, 0, 0, 50, 25, 2000, 0, 0, 0, 0, 25, 25, 0, 0, 0, 2500, 0, 50, 25, 0, 0, 0, 0, 5000, 0, 75, 0, 0, 0, 0, 0, 250, 0, 0, 500, 0, 0, 0, 0, 100, 0, 0
#> 2 0.0000, 25.0000, 20.0000, 0.0000, 0.0000, 17.9998, 50.0000, 25.0000, 0.0000, 0.0000, 25.0000, 20.0000, 50.0000, 25.0000, 0.0000, 0.0000, 75.0000, 0.0000, 0.0000, 0.0000, 26.9997, 0.0000, 100.0000, 0.0000
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 U_feed
#> 1                                                                                                                                                                                                                                                 0, 0, 47500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41000, 0, 50000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26500, 0, 0, 0, 0, 0, 0, 16000, 0, 0
#> 2 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26000, 0, 0, 47500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41000, 0, 0, 50000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16000, 0, 0, 0, 0, 0, 0, 0, 15050, 0, 0, 0, 0, 0, 0, 0
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       V
#> 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    47500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20500, 0, 0, 0, 15500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6400, 0, 0, 6275, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41000, 0, 0, 0, 0, 0, 0, 0, 43000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26500, 0
#> 2 0.00, 47000.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 47500.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 15500.00, 0.00, 0.00, 0.00, 0.00, 0.00, 15150.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 6400.00, 0.00, 0.00, 0.00, 0.00, 6275.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1200.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20000.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3000.40, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1799.98, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 41000.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 41000.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 26500.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 26000.00, 0.00, 0.00
#>                                                             Y
#> 1                       0, 6000, 25000, 0, 14750, 0, 0, 26000
#> 2 1200.00, 0.00, 3000.40, 0.00, 0.00, 20000.00, 0.00, 1714.98
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      r_EIOU
#> 1                                                                                                                                                                                        0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
#> 2 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#>   .SUT_energy_balance
#> 1                TRUE
#> 2                TRUE