Results Formulas
E4ST.jl produces a lot of data to comb through. There are often some complex calculations for welfare that we may want to compute in different ways over different regions without necessarily storing every possible combination of every calculation. The goal of the results formula is to give E4ST a way to calculate different results so that they can be calculated quickly on demand rather than always be calculated for every run. It also provides a way to specify custom result calculations that might not be standard to E4ST.
E4ST.setup_results_formulas!
— Functionsetup_results_formulas!(config, data)
Sets up the results formulas from config[:results_formulas_file]
, if provided, or loads a default set of formulas. See summarize_table(::Val{:results_formulas})
.
E4ST.summarize_table
— Methodsummarize_table(::Val{:results_formulas})
column_name | data_type | unit | required | description |
---|---|---|---|---|
table_name | Symbol | E4ST.NA | true | The name of the table that the result is for. |
result_name | Symbol | E4ST.NA | true | The name of the result that the formula is for. |
formula | String | E4ST.NA | true | The string representing the formula for the table. See add_results_formula! for more info on this. |
unit | Type{<:E4ST.Unit} | E4ST.NA | true | The unit for the result. |
description | String | E4ST.NA | true | A description of the result. |
E4ST.filter_results_formulas!
— Functionfilter_results_formulas!(data)
Filters any results formulas that depend on columns that do not exist.
E4ST.add_results_formula!
— Functionadd_results_formula!(data, table_name::Symbol, result_name::Symbol, formula::String, unit::Type{<:Unit}, description::String)
Adds a formula that can be used to compute results. See compute_result
. This is also used by AggregationTemplate
and YearlyTable
.
Arguments:
data
table_name
- the name of the table that the result is calculated from, either directly or as a combination of other resultsresult_name
- the name of the result being calculated. Cannot be a column name within the table.formula
-formula
can take two different forms.- it can be a combination of columns to be aggregated directly from
table_name
. SeeSum
,SumHourly
,SumYearly
,AverageYearly
,MinHourly
. - it can also be a combination of other results. I.e.
(vom_cost + fuel_cost) / egen_total
.
- it can be a combination of columns to be aggregated directly from
unit
- theUnit
of the resulting numberdescription
- a short description of the calculation.
E4ST.get_results_formulas
— Functionget_results_formulas(data)
Returns a dictionary mapping (table_name, result_name)
to ResultsFormula
.
get_results_formulas(data, table_name)
Returns only the results formulas corresponding to table table_name
.
E4ST.get_results_formula
— Functionget_results_formula(data, table_name, result_name) -> rf::ResultsFormula
E4ST.compute_result
— Functioncompute_result(data, table_name, result_name, idxs=(:), yr_idxs=(:), hr_idxs=(:))
Computes result result_name
for table table_name
for table indexes idxs
, year indexes yr_idxs
and hour indexes hr_idxs
. See add_results_formula!
to add other results formulas for computing results.
Note that this will recursively compute results for any derived result, as needed.
E4ST.ResultsFormula
— Typestruct ResultsFormula
This is a type used to store a formula for computing a result.
E4ST.Sum
— TypeSum(cols...) <: Function
Function used in results formulas. Computes the sum of the product of the column for each index in idxs
\[\sum_{i \in \text{idxs}} \prod_{c \in \text{cols}} \text{table}[i, c]\]
E4ST.SumYearly
— TypeSumYearly(cols...) <: Function
Function used in results formulas. This is a function that adds up the product of each of the values given to it for each year given.
\[\sum_{i \in \text{idxs}} \sum_{y \in \text{yr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y]\]
E4ST.SumHourly
— TypeSumHourly(cols...) <: Function
This is a function that adds up the product of each of the values given to it for each of the years and hours given.
\[\sum_{i \in \text{idxs}} \sum_{y \in \text{yr\_idxs}} \sum_{h \in \text{hr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
E4ST.MinHourly
— TypeMinHourly(cols...) <: Function
This function returns the minimum hourly value.
\[\min_{y \in \text{yr\_idxs}, h \in \text{hr\_idxs}} \sum_{i \in \text{idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
E4ST.AverageYearly
— TypeAverageYearly(cols...) <: Function
Function used in results formulas. Computes the sum of the products of the columns for each index in idxs for each year, divided by the number of years.
\[\frac{\sum_{i \in \text{idxs}} \sum_{y \in \text{yr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y]}{\text{length(yr\_idxs)}}\]
When specifying in a formula, looks like average_yearly(cols...)