Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings and make them available in documenter.jl build #24

Merged
merged 7 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pages = OrderedDict(
)

makedocs(
modules=[PRASInterface],
modules=[PRASInterface, PRAS],
format=Documenter.HTML(prettyurls=haskey(ENV, "GITHUB_ACTIONS")),
sitename="PRASInterface.jl",
authors="Surya Dhulipala, Joseph McKinsey, José Daniel Lara",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/internal.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Internal API

```@autodocs
Modules = [PRASInterface]
Modules = [PRASInterface, PRAS]
Public = false
```
34 changes: 31 additions & 3 deletions docs/src/api/public.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
# Public API Reference

```@autodocs
Modules = [PRASInterface]
Public = true
```@docs
PRASInterface
generate_pras_system
PRAS
SystemModel
assess
SequentialMonteCarlo
Shortfall
Surplus
Flow
Utilization
StorageEnergy
GeneratorStorageEnergy
LOLE
EUE
val
stderror
generate_outage_profile
generate_csv_outage_profile
add_csv_time_series!
add_csv_time_series_single_stage!
make_generator_outage_draws!
ShortfallSamples
SurplusSamples
FlowSamples
UtilizationSamples
StorageEnergySamples
GeneratorStorageEnergySamples
GeneratorAvailability
GeneratorStorageAvailability
LineAvailability
```
4 changes: 2 additions & 2 deletions src/PRAS2PSY.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
generate_outage_profile(pras_system,num_runs,psy_sys,num_scenarios,location)
generate_outage_profile(pras_system,num_runs,psy_sys,num_scenarios,location)

Process the assess results to get timeseries of generator status and include
this timeseries data to the corresponding component in PSY System and exported
Expand Down Expand Up @@ -126,7 +126,7 @@ function generate_outage_profile(
end

"""
generate_outage_profile(pras_system,num_runs,psy_sys,num_scenarios,location)
generate_outage_profile(pras_system,num_runs,psy_sys,num_scenarios,location)

Process the assess results to get timeseries of generator status and include
this timeseries data to the corresponding component in PSY System and exported
Expand Down
13 changes: 13 additions & 0 deletions src/PRASBase/SystemModel.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
"""
SystemModel

SystemModel is the primary data structure for Probabilistic Resource Adequacy Studies (PRAS).

You can also load a `SystemModel` from an appropriately-formatted HDF5 file on disk.

# Examples

```julia
pras = SystemModel("path/to/pras.pras")
```
"""
struct SystemModel{N, L, T <: Period, P <: PowerUnit, E <: EnergyUnit}
regions::Regions{N, P}
interfaces::Interfaces{N, P}
Expand Down
5 changes: 0 additions & 5 deletions src/PRASBase/read.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
"""
SystemModel(filename::String)

Load a `SystemModel` from an appropriately-formatted HDF5 file on disk.
"""
function SystemModel(inputfile::String)
system = h5open(inputfile, "r") do f::File
version, versionstring = readversion(f)
Expand Down
81 changes: 80 additions & 1 deletion src/PRASInterface.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
"""
PowerSystems Interface for Probabilistic Resource Adequacy Studies (PRAS)

# Key Functions

- [`generate_pras_system`](@ref): convert PSY to PRAS model
- [`assess`](@ref): assess PRAS model

# Key PRAS Types

- [`SystemModel`](@ref): PRAS data structure
- [`SequentialMonteCarlo`](@ref): method for PRAS analysis
- [`Shortfall`](@ref): PRAS metric for missing generation
- [`LOLE`](@ref): PRAS metric for loss of load expectation
- [`EUE`](@ref): PRAS metric for energy unserved expectation
"""
module PRASInterface
#################################################################################
# Exports
#################################################################################
export generate_pras_system
export PRAS
export SystemModel
export assess
export SequentialMonteCarlo
# ResultSpecs
export Shortfall
export ShortfallSamples
export Surplus
export SurplusSamples
export Flow
export FlowSamples
export Utilization
export UtilizationSamples
export StorageEnergy
export StorageEnergySamples
export GeneratorStorageEnergy
export GeneratorStorageEnergySamples
export GeneratorAvailability
export StorageAvailability
export GeneratorStorageAvailability
export LineAvailability

export LOLE
export EUE
export val
export stderror
export generate_outage_profile
export generate_csv_outage_profile
export add_csv_time_series!
export add_csv_time_series_single_stage!
export make_generator_outage_draws!
export PRAS

#################################################################################
# Imports
#################################################################################
Expand All @@ -28,6 +70,17 @@ const PSY = PowerSystems
# Includes
#################################################################################

"""
PRAS

Module for Probabilistic Resource Adequacy Studies (PRAS).

Re-exported in PRASInterface

# Source

https://github.com/NREL/PRAS.jl
"""
module PRAS
using Reexport
const PRAS_VERSION = "v0.6.0"
Expand All @@ -37,6 +90,32 @@ include("ResourceAdequacy/ResourceAdequacy.jl")
include("CapacityCredit/CapacityCredit.jl")
end

import .PRAS.assess
import .PRAS.LOLE
import .PRAS.EUE
import .PRAS.val
import .PRAS.stderror
import .PRAS.SequentialMonteCarlo

import .PRAS.Shortfall
josephmckinsey marked this conversation as resolved.
Show resolved Hide resolved
import .PRAS.ShortfallSamples
import .PRAS.Surplus
import .PRAS.SurplusSamples
import .PRAS.Flow
import .PRAS.FlowSamples
import .PRAS.Utilization
import .PRAS.UtilizationSamples
import .PRAS.StorageEnergy
import .PRAS.StorageEnergySamples
import .PRAS.GeneratorStorageEnergy
import .PRAS.GeneratorStorageEnergySamples
import .PRAS.GeneratorAvailability
import .PRAS.StorageAvailability
import .PRAS.GeneratorStorageAvailability
import .PRAS.LineAvailability

import .PRAS.SystemModel

include("util/definitions.jl")
include("util/runchecks.jl")

Expand Down
19 changes: 18 additions & 1 deletion src/PSY2PRAS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Sienna/Data PowerSystems.jl System is the input and an object of PRAS SystemMode
# Examples

```julia-repl
julia> make_pras_system(psy_sys)
julia> generate_pras_system(psy_sys)
PRAS SystemModel
```
"""
Expand Down Expand Up @@ -879,6 +879,23 @@ function generate_pras_system(
end
end

"""
generate_pras_system(sys_location::String, aggregation; kwargs...)

Generate a PRAS SystemModel from a Sienna/Data PowerSystems System JSON file.

# Arguments

- `sys_location::String`: Location of the Sienna/Data PowerSystems System JSON file
- `aggregation::Type{AT}`: Aggregation topology type
- `availability::Bool`: Availability of components in the System
- `lump_region_renewable_gens::Bool`: Lumping of region renewable generators
- `export_location::Union{Nothing, String}`: Export location of the .pras file

# Returns

- `PRAS.SystemModel`: PRAS SystemModel
"""
function generate_pras_system(
sys_location::String,
aggregation::Type{AT};
Expand Down
10 changes: 8 additions & 2 deletions src/ResourceAdequacy/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ end
Base.isapprox(x::ReliabilityMetric, y::ReliabilityMetric) =
isapprox(val(x), val(y)) && isapprox(stderror(x), stderror(y))

# Loss-of-Load Expectation
"""
LOLE

Loss of load expectation metric. Contains a mean and standard error estimate.
"""
struct LOLE{N, L, T <: Period} <: ReliabilityMetric
lole::MeanEstimate

Expand Down Expand Up @@ -83,8 +86,11 @@ function Base.show(io::IO, x::LOLE{N, L, T}) where {N, L, T}
)
end

# Expected Unserved Energy
"""
EUE

Expected unserved energy expectation metric. Contains a mean and standard error estimate.
"""
struct EUE{N, L, T <: Period, E <: EnergyUnit} <: ReliabilityMetric
eue::MeanEstimate

Expand Down
32 changes: 28 additions & 4 deletions src/ResourceAdequacy/results/availability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ getindex(x::AbstractAvailabilityResult, name::String, ::Colon) =
getindex(x::AbstractAvailabilityResult, ::Colon, ::Colon) =
getindex.(x, names(x), permutedims(x.timestamps))

# Full Generator availability data
"""
GeneratorAvailability

Generator availability represents the availability of generators at timestamps
in a GeneratorAvailabilityResult with a (generators, timestamps, samples) matrix API.

No averaging occurs.
"""
struct GeneratorAvailability <: ResultSpec end

struct GeneratorAvailabilityResult{N, L, T <: Period} <: AbstractAvailabilityResult{N, L, T}
Expand All @@ -30,8 +36,14 @@ function getindex(x::GeneratorAvailabilityResult, g::AbstractString, t::ZonedDat
return vec(x.available[i_g, i_t, :])
end

# Full Storage availability data
"""
StorageAvailability

Storage availability represents the availability of storage resources at timestamps
in a StorageAvailabilityResult with a (storages, timestamps, samples) matrix API.

No averaging occurs.
"""
struct StorageAvailability <: ResultSpec end

struct StorageAvailabilityResult{N, L, T <: Period} <: AbstractAvailabilityResult{N, L, T}
Expand All @@ -49,8 +61,14 @@ function getindex(x::StorageAvailabilityResult, s::AbstractString, t::ZonedDateT
return vec(x.available[i_s, i_t, :])
end

# Full GeneratorStorage availability data
"""
GeneratorStorageAvailability

Generator storage availability represents the availability of generatorstorage resources at timestamps
in a GeneratorStorageAvailabilityResult with a (generatorstorages, timestamps, samples) matrix API.

No averaging occurs
"""
struct GeneratorStorageAvailability <: ResultSpec end

struct GeneratorStorageAvailabilityResult{N, L, T <: Period} <:
Expand All @@ -73,8 +91,14 @@ function getindex(
return vec(x.available[i_gs, i_t, :])
end

# Full Line availability data
"""
LineAvailability

Line availability represents the availability of lines at timestamps
in a LineAvailabilityResult with a (lines, timestamps, samples) matrix API.

No averaging occurs.
"""
struct LineAvailability <: ResultSpec end

struct LineAvailabilityResult{N, L, T <: Period} <: AbstractAvailabilityResult{N, L, T}
Expand Down
Loading
Loading