Skip to content

Commit

Permalink
more struct definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Feb 29, 2024
1 parent c62c606 commit ae8c658
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 14 deletions.
19 changes: 19 additions & 0 deletions src/PowerSystemsInvestmentsPortfolios.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
module PowerSystemsInvestmentsPortfolios

import InfrastructureSystems
import InfrastructureSystems:
add_time_series,
to_json,
from_json,
serialize,
deserialize,
get_time_series,
has_time_series,
get_time_series_array,
get_time_series_timestamps,
get_time_series_values,
get_time_series_names,
CompressionSettings,
CompressionTypes,
MultiLogger,
LogEventTracker,
StructField


import PowerSystems

export Portfolio
Expand Down
154 changes: 146 additions & 8 deletions src/portfolio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ end
struct Portfolio <: IS.InfrastructurePortfoliosType
aggregation::Type{<:Union{PSY.ACBus, PSY.AggregationTopology}}
discount_rate::Float64
data::IS.PortfolioData
portfolio_data::IS.PortfolioData # Inputs to the model
investment_data::Dict # Investment decisions container i.e., model outputs. Container TBD
metadata::PortfolioMetadata
time_series_directory::Union{Nothing, String}
time_series_container::InfrastructurePortfolios.TimeSeriesContainer
Expand Down Expand Up @@ -54,11 +55,12 @@ get_description(val::Portfolio) = val.metadata.description
Add a technology to the portfoliotem.
Throws ArgumentError if the technology's name is already stored for its concrete type.
Throws ArgumentError if any Component-specific rule is violated.
Throws ArgumentError if any Technology-specific rule is violated.
Throws InvalidValue if any of the technology's field values are outside of defined valid
range.
# Examples
```julia
portfolio = Portfolio(...)
Expand All @@ -72,30 +74,30 @@ foreach(x -> add_technology!(portfolio, x), Iterators.flatten((buses, generators
function add_technology!(
portfolio::Portfolio,
technology::T;
skip_validation = false,
skip_validation=false,
kwargs...,
) where {T <: Technology}

IS.add_technology!(
portfolio.data,
technology;
allow_existing_time_series = deserialization_in_progress,
skip_validation = skip_validation,
allow_existing_time_series=deserialization_in_progress,
skip_validation=skip_validation,
_kwargs...,
)

return
end

"""
Add many components to the system at once.
Add many technologies to the portfoliotem at once.
Throws ArgumentError if the technology's name is already stored for its concrete type.
Throws ArgumentError if any Component-specific rule is violated.
Throws ArgumentError if any Technology-specific rule is violated.
Throws InvalidValue if any of the technology's field values are outside of defined valid
range.
# Examples
```julia
portfolio = Portfolio(100.0)
Expand All @@ -108,3 +110,139 @@ function add_technologies!(::Portfolio, technologies)
foreach(x -> add_technology!(portfolio, x), technologies)
return
end

"""
Get the technology of type T with name. Returns nothing if no technology matches. If T is an abstract
type then the names of technologies across all subtypes of T must be unique.
See [`get_technologies_by_name`](@ref) for abstract types with non-unique names across subtypes.
Throws ArgumentError if T is not a concrete type and there is more than one technology with
requested name
"""
function get_technology(
::Type{T},
portfolio::Portfolio,
name::AbstractString,
) where {T <: Technology}
return IS.get_component(T, portfolio.data, name)
end

"""
Returns an iterator of technologies. T can be concrete or abstract.
Call collect on the result if an array is desired.
# Examples
```julia
iter = Portfolio.get_technologies(ThermalStandard, portfolio)
iter = Portfolio.get_technologies(Generator, portfolio)
iter = Portfolio.get_technologies(x -> Portfolio.get_available(x), Generator, portfolio)
thermal_gens = get_technologies(ThermalStandard, portfolio) do gen
get_available(gen)
end
generators = collect(Portfolio.get_technologies(Generator, portfolio))
```
See also: [`iterate_technologies`](@ref)
"""
function get_technologies(
::Type{T},
portfolio::Portfolio;
subportfoliotem_name=nothing,
) where {T <: Technology}
return IS.get_components(T, portfolio.data; subportfoliotem_name=subportfoliotem_name)
end

function get_technologies(
filter_func::Function,
::Type{T},
portfolio::Portfolio;
subportfoliotem_name=nothing,
) where {T <: Technology}
return IS.get_components(
filter_func,
T,
portfolio.data;
subportfoliotem_name=subportfoliotem_name,
)
end

"""
Add time series data to a component.
Throws ArgumentError if the component is not stored in the system.
"""
function add_time_series!(
portfolio::Portfolio,
component::Technology,
time_series::TimeSeriesData,
)
return IS.add_time_series!(portfolio.data, component, time_series)
end

"""
Add the same time series data to multiple components.
This is significantly more efficent than calling `add_time_series!` for each component
individually with the same data because in this case, only one time series array is stored.
Throws ArgumentError if a component is not stored in the system.
"""
function add_time_series!(portfolio::Portfolio, technologies, time_series::TimeSeriesData)
return IS.add_time_series!(portfolio.data, technologies, time_series)
end

"""
Return the compression settings used for system data such as time series arrays.
"""
get_compression_settings(portfolio::Portfolio) = IS.get_compression_settings(portfolio.data)

"""
Return the resolution for all time series.
"""
get_time_series_resolution(portfolio::Portfolio) = IS.get_time_series_resolution(portfolio.data)

"""
Remove all time series data from the system.
"""
function clear_time_series!(portfolio::Portfolio)
return IS.clear_time_series!(portfolio.data)
end

"""
Remove the time series data for a component and time series type.
"""
function remove_time_series!(
portfolio::Portfolio,
::Type{T},
component::Component,
name::String,
) where {T <: TimeSeriesData}
return IS.remove_time_series!(portfolio.data, T, component, name)
end

"""
Remove all the time series data for a time series type.
"""
function remove_time_series!(portfolio::Portfolio, ::Type{T}) where {T <: TimeSeriesData}
return IS.remove_time_series!(portfolio.data, T)
end

function IS.serialize(portfolio::Portfolio)
return
end

function IS.deserialize(
::Type{Portfolio},
filename::AbstractString;
time_series_read_only = false,
time_series_directory = nothing,
kwargs...,
)
portfolio = nothing
return portfolio
end

function deserialize_components!(portfolio::Portfolio, raw)
end
12 changes: 6 additions & 6 deletions src/technologies.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Required fields for a technology Type
- name
- available
- power_systems_type
- time_series_container
- internal
- name
- available
- power_systems_type
- time_series_container
- internal
"""
abstract type Technology <: IS.Component end
abstract type Technology <: IS.InfrastructureSystemsComponent end

get_name(val::Technology) = val.name
get_available(val::Technology) = val.available
Expand Down

0 comments on commit ae8c658

Please sign in to comment.