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
. I.e."SumHourly(vom, egen)"
. SeeSum
,SumHourly
,SumYearly
,AverageYearly
,MinHourly
. Note that the columns here can either be column names or variable names stored withdata
, likedam_co2
- 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.
If any result is computed to be NaN
, returns 0.0
instead, so that the NaN does not "infect" other results.
E4ST.ResultsFormula
— Typestruct ResultsFormula
This is a type used to store a formula for computing a result.
Result Aggregation Functions
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.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)}}\]
E4ST.MinYearly
— TypeMinYearly(cols...) <: Function
This function returns the minimum yearly value.
\[\min_{y \in \text{yr\_idxs}} \sum_{i \in \text{idxs}, h \in \text{hr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
E4ST.MaxYearly
— TypeMaxYearly(cols...) <: Function
This function returns the maximum yearly value.
\[\max_{y \in \text{yr\_idxs}} \sum_{i \in \text{idxs}, h \in \text{hr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
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.SumHourlyWeighted
— TypeSumHourlyWeighted(cols...) <: Function
This is a function that adds up the product of each of the values given to it times the hour weight 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}} w_{h} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
E4ST.AverageHourly
— TypeAverageHourly(cols...) <: Function
Function used in results formulas. Computes the sum of the products of the columns for each index in idxs for each year and hour, divided by the number of hours.
\[\frac{\sum_{i \in \text{idxs}} \sum_{y \in \text{yr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y]}{\sum_{y \in \text{yr\_idxs}, h \in \text{hr\_idxs}} w_{h}}\]
E4ST.AverageHourlyWeighted
— TypeAverageHourlyWeighted(cols...) <: Function
Function used in results formulas. Computes the sum of the products of the columns for each index in idxs for each year and hour weighted by the number of hours, divided by the total number of hours.
\[\frac{\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]}{\sum_{y \in \text{yr\_idxs}}\sum{h \in \text{hr\_idxs}} w_{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.MaxHourly
— TypeMaxHourly(cols...) <: Function
This function returns the maximum aggregated hourly value. Sums up all values for that hour over the given idxs, then takes the maximum. Suited for results like load where you want to know the maximum of the regional load.
\[\max_{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.SumMinHourly
— TypeSumMinHourly(cols...) <: Function
This function returns the sum of each of the minimum hourly values.
\[\sum_{i \in \text{idxs}} \min_{y \in \text{yr\_idxs}, h \in \text{hr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
E4ST.SumMaxHourly
— TypeSumMaxHourly(cols...) <: Function
This function returns the sum of each of the maximum hourly values.
\[\sum_{i \in \text{idxs}} \max_{y \in \text{yr\_idxs}, h \in \text{hr\_idxs}} \prod_{c \in \text{cols}} \text{table}[i, c][y, h]\]
E4ST.CostOfServiceRebate
— TypeCostOfServiceRebate(table_name) <: Function
This is a special function that computes the sum of the net total revenue times the regulatory factor reg_factor
. This only works for the gen table and storage table.