PowerAnalytics
API documentation
Index
PowerAnalytics.AGG_META_KEY
PowerAnalytics.DATETIME_COL
PowerAnalytics.META_COL_KEY
PowerAnalytics.RESULTS_COL
PowerAnalytics.SYSTEM_COL
PowerAnalytics.ComponentSelectorTimedMetric
PowerAnalytics.ComponentTimedMetric
PowerAnalytics.CustomTimedMetric
PowerAnalytics.EntryType
PowerAnalytics.Metric
PowerAnalytics.NoResultError
PowerAnalytics.ResultsTimelessMetric
PowerAnalytics.SystemEntryType
PowerAnalytics.SystemTimedMetric
PowerAnalytics.TimedMetric
PowerAnalytics.TimelessMetric
PowerAnalytics.aggregate_time
PowerAnalytics.categorize_data
PowerAnalytics.combine_categories
PowerAnalytics.compose_metrics
PowerAnalytics.compute
PowerAnalytics.compute
PowerAnalytics.compute
PowerAnalytics.compute
PowerAnalytics.compute
PowerAnalytics.compute
PowerAnalytics.compute
PowerAnalytics.compute_all
PowerAnalytics.compute_all
PowerAnalytics.compute_all
PowerAnalytics.create_problem_results_dict
PowerAnalytics.get_agg_meta
PowerAnalytics.get_agg_meta
PowerAnalytics.get_data_cols
PowerAnalytics.get_data_df
PowerAnalytics.get_data_mat
PowerAnalytics.get_data_vec
PowerAnalytics.get_generator_category
PowerAnalytics.get_generator_mapping
PowerAnalytics.get_time_df
PowerAnalytics.get_time_vec
PowerAnalytics.hcat_timed_dfs
PowerAnalytics.is_col_meta
PowerAnalytics.lookup_gentype
PowerAnalytics.make_component_metric_from_entry
PowerAnalytics.make_entry_kwargs
PowerAnalytics.make_fuel_dictionary
PowerAnalytics.make_key
PowerAnalytics.make_system_metric_from_entry
PowerAnalytics.metric_selector_to_string
PowerAnalytics.parse_generator_categories
PowerAnalytics.parse_generator_mapping_file
PowerAnalytics.parse_injector_categories
PowerAnalytics.read_component_result
PowerAnalytics.read_system_result
PowerAnalytics.rebuild_metric
PowerAnalytics.set_agg_meta!
PowerAnalytics.set_agg_meta!
PowerAnalytics.set_col_meta!
PowerAnalytics.unweighted_sum
PowerAnalytics.weighted_mean
Exported
PowerAnalytics.AGG_META_KEY
— ConstantColumn metadata key whose value, if any, is additional information to be passed to aggregation functions. Values of nothing
are equivalent to absence of the entry.
PowerAnalytics.DATETIME_COL
— ConstantName of the column that represents the time axis in computed DataFrames
PowerAnalytics.META_COL_KEY
— ConstantColumn metadata key whose value signifies whether the column is metadata. Metadata columns are excluded from get_data_cols
and similar and can be used to represent things like a time aggregation.
PowerAnalytics.RESULTS_COL
— ConstantName of a column that represents whole-of-Results
data
PowerAnalytics.SYSTEM_COL
— ConstantName of a column that represents whole-of-System
data
PowerAnalytics.ComponentSelectorTimedMetric
— TypeTime series Metrics
defined on ComponentSelector
s.
PowerAnalytics.ComponentTimedMetric
— TypeComponentSelectorTimedMetrics
implemented by evaluating a function on each Component
.
Arguments
name::String
: the name of theMetric
eval_fn
: a function with signature(::IS.Results, ::Component; start_time::Union{Nothing, DateTime}, len::Union{Int, Nothing})
that returns a DataFrame representing the results for thatComponent
component_agg_fn
: optional, a function to aggregate results betweenComponent
s/ComponentSelector
s, defaults tosum
time_agg_fn
: optional, a function to aggregate results across time, defaults tosum
component_meta_agg_fn
: optional, a callable to aggregate metadata across components, defaults tosum
time_meta_agg_fn
: optional, a callable to aggregate metadata across time, defaults tosum
eval_zero
: optional and rarely filled in, specifies what to do in the case where there are no components to contribute to a particular group; defaults tonothing
, in which case the data is filled in from the identity element ofcomponent_agg_fn
PowerAnalytics.CustomTimedMetric
— TypeComponentSelectorTimedMetrics
implemented without drilling down to the base Component
s, just call the eval_fn
directly.
Arguments
name::String
: the name of theMetric
eval_fn
: a callable with signature(::IS.Results, ::Union{ComponentSelector, Component}; start_time::Union{Nothing, DateTime}, len::Union{Int, Nothing})
that returns a DataFrame representing the results for thatComponent
time_agg_fn
: optional, a callable to aggregate results across time, defaults tosum
time_meta_agg_fn
: optional, a callable to aggregate metadata across time, defaults tosum
PowerAnalytics.Metric
— TypeThe basic type for all Metrics
.
PowerAnalytics.ResultsTimelessMetric
— TypeTimeless Metrics with a single value per IS.Results
instance
Arguments
- `name::String`: the name of the `Metric`
- `eval_fn`: a callable with signature `(::IS.Results,)` that returns a `DataFrame`
representing the results
PowerAnalytics.SystemTimedMetric
— TypeTime series Metrics
defined on Systems
.
Arguments
name::String
: the name of theMetric
eval_fn
: a callable with signature(::IS.Results; start_time::Union{Nothing, DateTime}, len::Union{Int, Nothing})
that returns a DataFrame representing the resultstime_agg_fn
: optional, a callable to aggregate results across time, defaults tosum
time_meta_agg_fn
: optional, a callable to aggregate metadata across time, defaults tosum
PowerAnalytics.TimedMetric
— TypeTime series Metrics
.
PowerAnalytics.TimelessMetric
— TypeScalar-in-time Metrics
.
PowerAnalytics.aggregate_time
— MethodGiven a DataFrame like that produced by compute_all
, group by a function of the time axis, apply a reduction, and report the resulting aggregation indexed by the first timestamp in each group.
Arguments
df::DataFrames.AbstractDataFrame
: the DataFrame to operate upongroupby_fn = nothing
: a callable that can be passed a DateTime; two rows will be in the same group iff their timestamps produce the same result undergroupby_fn
. Note thatgroupby_fn = month
puts January 2023 and January 2024 into the same group whereasgroupby_fn=(x -> (year(x), month(x)))
does not.groupby_col::Union{Nothing, AbstractString, Symbol} = nothing
: specify a column name to report the result ofgroupby_fn
in the output DataFrame, ornothing
to notagg_fn = nothing
: by default, the aggregation function (sum
/mean
/etc.) is specified by the Metric, which is read from the metadata of each column. If this metadata isn't found, one can specify a default aggregation function likesum
here; if nothing, an error will be thrown.
PowerAnalytics.categorize_data
— MethodRe-categorizes data according to an aggregation dictionary
- makes no guarantee of complete data collection *
Example
aggregation = PA.make_fuel_dictionary(results_uc.system)
categorize_data(gen_uc.data, aggregation)
PowerAnalytics.compose_metrics
— FunctionGiven a list of metrics and a function that applies to their results to produce one result, create a new metric that computes the sub-metrics and applies the function to produce its own result.
Arguments
name::String
: the name of the newMetric
reduce_fn
: a callable that takes one value from each of the inputMetric
s and returns a single value that will be the result of thisMetric
. "Value" means a vector (not aDataFrame
) in the case ofTimedMetrics
and a scalar forTimelessMetrics
.metrics
: the inputMetrics
. It is currently not possible to combineTimedMetrics
withTimelessMetrics
, though it is possible to combineComponentSelectorTimedMetrics
withSystemTimedMetrics
.
PowerAnalytics.compute
— MethodCompute the given metric on the groups of the given ComponentSelector
within the given set of results, returning a DataFrame
with a DateTime
column and a data column for each group. Exclude components marked as not available.
Arguments
metric::ComponentTimedMetric
: the metric to computeresults::IS.Results
: the results from which to fetch dataselector::ComponentSelector
: theComponentSelector
on whose subselectors to compute the metricstart_time::Union{Nothing, DateTime} = nothing
: the time at which the resulting time series should beginlen::Union{Int, Nothing} = nothing
: the number of steps in the resulting time series
PowerAnalytics.compute
— MethodCompute the given metric on the given component within the given set of results, returning a DataFrame
with a DateTime
column and a data column labeled with the component's name.
Arguments
metric::ComponentTimedMetric
: the metric to computeresults::IS.Results
: the results from which to fetch datacomp::Component
: the component on which to compute the metricstart_time::Union{Nothing, DateTime} = nothing
: the time at which the resulting time series should beginlen::Union{Int, Nothing} = nothing
: the number of steps in the resulting time series
PowerAnalytics.compute
— MethodCompute the given metric on the given component within the given set of results, returning a DataFrame
with a DateTime
column and a data column labeled with the component's name. Exclude components marked as not available.
Arguments
metric::CustomTimedMetric
: the metric to computeresults::IS.Results
: the results from which to fetch datacomp::Component
: the component on which to compute the metricstart_time::Union{Nothing, DateTime} = nothing
: the time at which the resulting time series should beginlen::Union{Int, Nothing} = nothing
: the number of steps in the resulting time series
PowerAnalytics.compute
— MethodConvenience method for compute_all
; returns compute(metric, results)
PowerAnalytics.compute
— MethodCompute the given metric on the given set of results, returning a DataFrame with a single cell. Exclude components marked as not available.
Arguments
metric::ResultsTimelessMetric
: the metric to computeresults::IS.Results
: the results from which to fetch data
PowerAnalytics.compute
— MethodConvenience method for compute_all
; returns compute(metric, results; kwargs...)
PowerAnalytics.compute
— MethodCompute the given metric on the System
associated with the given set of results, returning a DataFrame
with a DateTime
column and a data column.
Arguments
metric::SystemTimedMetric
: the metric to computeresults::IS.Results
: the results from which to fetch datastart_time::Union{Nothing, DateTime} = nothing
: the time at which the resulting time series should beginlen::Union{Int, Nothing} = nothing
: the number of steps in the resulting time series
PowerAnalytics.compute_all
— FunctionFor each (metric, selector, col_name)
tuple in zip(metrics, selectors, col_names)
, call compute
and collect the results in a DataFrame
with a single DateTime
column. All selectors must yield exactly one group.
Arguments
results::IS.Results
: the results from which to fetch datametrics::Vector{<:TimedMetric}
: the metrics to computeselectors
: either a scalar or vector ofNothing
/Component
/ComponentSelector
: the selectors on which to compute the metrics, or nothing for system/results metrics; broadcast if scalarcol_names::Union{Nothing, Vector{<:Union{Nothing, AbstractString}}} = nothing
: a vector of names for the columns of ouput data. Entries ofnothing
default to the result ofmetric_selector_to_string
;names = nothing
is equivalent to an entire vector ofnothing
kwargs...
: pass through to eachcompute
call
PowerAnalytics.compute_all
— FunctionFor each (metric, colname) tuple in `zip(metrics, colnames), call [
compute`](@ref) and collect the results in a DataFrame.
Arguments
results::IS.Results
: the results from which to fetch datametrics::Vector{<:TimelessMetric}
: the metrics to computeselectors
: either a scalar or vector ofNothing
/Component
/ComponentSelector
: the selectors on which to compute the metrics, or nothing for system/results metrics; broadcast if scalarcol_names::Union{Nothing, Vector{<:Union{Nothing, AbstractString}}} = nothing
: a vector of names for the columns of ouput data. Entries ofnothing
default to the result ofmetric_selector_to_string
;names = nothing
is equivalent to an entire vector ofnothing
kwargs...
: pass through to eachcompute
call
PowerAnalytics.compute_all
— MethodFor each (metric, selector, col_name) tuple in computations
, call compute
and collect the results in a DataFrame with a single DateTime
column. All selectors must yield exactly one group.
Arguments
results::IS.Results
: the results from which to fetch datacomputations::(Tuple{<:T, Any, Any} where T <: Union{TimedMetric, TimelessMetric})...
: a list of the computations to perform, where each element is a(metric, selector, col_name)
where
metricis the metric to compute,
selectoris the ComponentSelector on which to compute the metric or
nothingif not relevant, and
col_name` is the name for the output column of data or nothing to use the defaultkwargs...
: pass through to eachcompute
call
PowerAnalytics.create_problem_results_dict
— FunctionAccept a directory that contains several results subdirectories (that each contain results
, problems
, etc. sub-subdirectories) and construct a sorted dictionary from String
to SimulationProblemResults
where the keys are the subdirectory names and the values are loaded results datasets.
Arguments
results_dir::AbstractString
: the directory where results subdirectories can be foundproblem::String
: the name of the problem to load (e.g., "UC", "ED")scenarios::Union{Vector{AbstractString}, Nothing} = nothing
: a list of scenario subdirectories to load, ornothing
to load all the subdirectorieskwargs...
: keyword arguments to pass through toPSI.get_decision_problem_results
PowerAnalytics.get_agg_meta
— MethodGet the column's aggregation metadata; return nothing
if there is none.
PowerAnalytics.get_agg_meta
— MethodGet the single data column's aggregation metadata; error on multiple data columns.
PowerAnalytics.get_data_cols
— MethodSelect the names of the data columns of the DataFrame
, i.e., those that are not DateTime
and not metadata.
PowerAnalytics.get_data_df
— MethodSelect the data columns of the DataFrame
as a DataFrame
without copying.
PowerAnalytics.get_data_mat
— MethodSelect the data columns of the DataFrame
as a Matrix
with copying.
PowerAnalytics.get_data_vec
— MethodSelect the data column of the DataFrame
as a vector without copying, errors if more than one.
PowerAnalytics.get_time_df
— MethodSelect the DateTime
column of the DataFrame
as a one-column DataFrame
without copying.
PowerAnalytics.get_time_vec
— MethodSelect the DateTime
column of the DataFrame
as a Vector
without copying.
PowerAnalytics.hcat_timed_dfs
— MethodIf the time axes match across all the DataFrames
, horizontally concatenate them and remove the duplicate time axes. If not, throw an error
PowerAnalytics.is_col_meta
— MethodCheck whether a column is metadata
PowerAnalytics.make_fuel_dictionary
— Methodgenerators = make_fuel_dictionary(system::PSY.System, mapping::Dict{NamedTuple, String})
This function makes a dictionary of fuel type and the generators associated.
Arguments
sys::PSY.System
: the system that is used to create the resultsresults::IS.Results
: results
Key Words
categories::Dict{String, NamedTuple}
: if stacking by a different category is desired
Example
results = solveopmodel!(OpModel) generators = makefueldictionary(sys)
PowerAnalytics.metric_selector_to_string
— MethodCanonical way to represent a (Metric, ComponentSelector)
or (Metric, Component)
pair as a string.
PowerAnalytics.parse_generator_categories
— MethodUse parse_generator_mapping_file
to parse a generator_mapping.yaml
file into a dictionary of ComponentSelector
, excluding categories in the 'non_generators' list in metadata
PowerAnalytics.parse_generator_mapping_file
— MethodParse a generator_mapping.yaml
file into a dictionary of ComponentSelector
s and a dictionary of metadata if present
PowerAnalytics.parse_injector_categories
— MethodUse parse_generator_mapping_file
to parse a generator_mapping.yaml
file into a dictionary of all ComponentSelector
s
PowerAnalytics.rebuild_metric
— MethodReturns a Metric
identical to the input metric
except with the changes to its fields specified in the keyword arguments.
Examples
Make a variant of calc_active_power
that averages across components rather than summing:
using PowerAnalytics.Metrics
calc_active_power_mean = rebuild_metric(calc_active_power; component_agg_fn = mean)
# (now calc_active_power_mean works as a standalone, callable metric)
PowerAnalytics.set_agg_meta!
— MethodSet the column's aggregation metadata.
PowerAnalytics.set_agg_meta!
— MethodSet the single data column's aggregation metadata; error on multiple data columns.
PowerAnalytics.set_col_meta!
— FunctionMark a column as metadata
PowerAnalytics.unweighted_sum
— MethodA version of sum
that ignores a second argument, for use where aggregation metadata is at play
PowerAnalytics.weighted_mean
— MethodCompute the mean of values
weighted by the corresponding entries of weights
. Arguments may be vectors or vectors of vectors. A weight of 0 cancels out a value of NaN.
Internal
PowerAnalytics.EntryType
— TypeThe various key entry types that can be used to make a PSI.OptimizationContainerKey
PowerAnalytics.SystemEntryType
— TypeThe various key entry types that can work with a System
PowerAnalytics.NoResultError
— TypeThe metric does not have a result for the Component
/ComponentSelector
/etc. on which it is being called.
PowerAnalytics.combine_categories
— Methodaggregates and combines data into single DataFrame
Example
PG.combine_categories(gen_uc.data)
PowerAnalytics.get_generator_category
— MethodReturn the generator category for this fuel and unit_type.
PowerAnalytics.get_generator_mapping
— FunctionReturn a dict where keys are a tuple of input parameters (fuel, unit_type) and values are generator types.
PowerAnalytics.lookup_gentype
— MethodParse the gentype
to a type. This is done by first checking whether gentype is qualified (ModuleName.TypeName
). If so, the module is fetched from the Main
scope and the type name is fetched from the module. If not, we default to fetching from PowerSystems
for convenience.
PowerAnalytics.make_component_metric_from_entry
— MethodConvenience function to convert an EntryType to a function and make a ComponentTimedMetric from it
PowerAnalytics.make_entry_kwargs
— MethodSort a vector of key tuples into variables, parameters, etc. like PSI.load_results! wants
PowerAnalytics.make_key
— FunctionCreate a PSI.OptimizationContainerKey from the given key entry type and component.
Arguments
entry::Type{<:EntryType}
: the key entrycomponent
(::Type{<:Union{Component, PSY.System}}
or::Type{<:Component}
depending on the key type): the component type
PowerAnalytics.make_system_metric_from_entry
— MethodConvenience function to convert a SystemEntryType to a function and make a SystemTimedMetric from it
PowerAnalytics.read_component_result
— MethodGiven an EntryType and a Component, fetch a single column of results
PowerAnalytics.read_system_result
— MethodGiven an EntryType that applies to the System, fetch a single column of results