Skip to content

Commit

Permalink
Merge pull request #3 from invenia/bes/accessors
Browse files Browse the repository at this point in the history
Define accessor functions
  • Loading branch information
BSnelling authored May 10, 2022
2 parents 3769271 + 520e848 commit d5ae93a
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 122 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FullNetworkSystems"
uuid = "877b7152-b508-43dc-81fb-72341a693988"
authors = ["Invenia Technical Computing Corporation"]
version = "1.0.0-DEV"
version = "1.0.0"

[deps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
Expand Down
59 changes: 35 additions & 24 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.1"
julia_version = "1.7.2"
manifest_format = "2.0"

[[deps.ANSIColoredPrinters]]
Expand All @@ -25,9 +25,9 @@ uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[deps.ArrayInterface]]
deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "c933ce606f6535a7c7b98e1d86d5d1014f730596"
git-tree-sha1 = "81f0cb60dc994ca17f68d9fb7c942a5ae70d9ee4"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "5.0.7"
version = "5.0.8"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand All @@ -49,9 +49,9 @@ version = "1.14.0"

[[deps.ChangesOfVariables]]
deps = ["ChainRulesCore", "LinearAlgebra", "Test"]
git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1"
git-tree-sha1 = "1e315e3f4b0b7ce40feded39c73049692126cf53"
uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
version = "0.1.2"
version = "0.1.3"

[[deps.Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
Expand All @@ -70,15 +70,15 @@ uuid = "587fd27a-f159-11e8-2dae-1979310e6154"
version = "0.2.7"

[[deps.DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
git-tree-sha1 = "fb5f5316dd3fd4c5e7c30a24d50643b73e37cd40"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.9.0"
version = "1.10.0"

[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d"
git-tree-sha1 = "cc1a8e22627f33c789ab60b36a9132ac050bbf75"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.11"
version = "0.18.12"

[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
Expand All @@ -93,6 +93,12 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[deps.Dictionaries]]
deps = ["Indexing", "Random"]
git-tree-sha1 = "0340cee29e3456a7de968736ceeb705d591875a2"
uuid = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
version = "0.3.20"

[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand All @@ -105,9 +111,9 @@ version = "0.8.6"

[[deps.Documenter]]
deps = ["ANSIColoredPrinters", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "6edbf28671b4df4f692e54ae72f1e35851cfbf38"
git-tree-sha1 = "122d031e8dcb2d3e767ed434bc4d1ae1788b5a7f"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.27.16"
version = "0.27.17"

[[deps.Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
Expand All @@ -120,7 +126,7 @@ uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
version = "1.5.0"

[[deps.FullNetworkSystems]]
deps = ["AxisKeys", "Dates", "DocStringExtensions", "InlineStrings"]
deps = ["AxisKeys", "Dates", "Dictionaries", "DocStringExtensions", "InlineStrings"]
path = ".."
uuid = "877b7152-b508-43dc-81fb-72341a693988"
version = "1.0.0"
Expand All @@ -136,6 +142,11 @@ git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1"
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
version = "0.1.1"

[[deps.Indexing]]
git-tree-sha1 = "ce1566720fd6b19ff3411404d4b977acd4814f9f"
uuid = "313cdc1a-70c2-5d6a-ae34-0150d3930a38"
version = "1.1.1"

[[deps.InlineStrings]]
deps = ["Parsers"]
git-tree-sha1 = "61feba885fac3a407465726d0c330b3055df897f"
Expand All @@ -154,9 +165,9 @@ version = "0.5.4"

[[deps.InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "91b5dcf362c5add98049e6c29ee756910b03051d"
git-tree-sha1 = "336cc738f03e069ef2cac55a104eb823455dca75"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.3"
version = "0.1.4"

[[deps.InvertedIndices]]
git-tree-sha1 = "bee5f1ef5bf65df56bdd2e40447590b272a5471f"
Expand Down Expand Up @@ -210,9 +221,9 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[deps.LogExpFunctions]]
deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "a970d55c2ad8084ca317a4658ba6ce99b7523571"
git-tree-sha1 = "76c987446e8d555677f064aaac1145c4c17662f8"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.12"
version = "0.3.14"

[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down Expand Up @@ -254,9 +265,9 @@ uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[deps.OffsetArrays]]
deps = ["Adapt"]
git-tree-sha1 = "043017e0bdeff61cfbb7afeb558ab29536bbb5ed"
git-tree-sha1 = "aee446d0b3d5764e35289762f6a18e8ea041a592"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.10.8"
version = "1.11.0"

[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
Expand All @@ -269,9 +280,9 @@ version = "1.4.1"

[[deps.Parsers]]
deps = ["Dates"]
git-tree-sha1 = "621f4f3b4977325b9128d5fae7a8b4829a0c2222"
git-tree-sha1 = "1285416549ccfcdf0c50d4997a94331e88d68413"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.2.4"
version = "2.3.1"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
Expand Down Expand Up @@ -320,19 +331,19 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[deps.Static]]
deps = ["IfElse"]
git-tree-sha1 = "87e9954dfa33fd145694e42337bdd3d5b07021a6"
git-tree-sha1 = "5309da1cdef03e95b73cd3251ac3a39f887da53e"
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
version = "0.6.0"
version = "0.6.4"

[[deps.Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[deps.StatsAPI]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "8d7530a38dbd2c397be7ddd01a424e4f411dcc41"
git-tree-sha1 = "c82aaa13b44ea00134f8c9c89819477bd3986ecd"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.2.2"
version = "1.3.0"

[[deps.StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
Expand Down
10 changes: 10 additions & 0 deletions src/FullNetworkSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ export System, SystemDA, SystemRT
export Zone, Generator, Bus, Branch
export GeneratorTimeSeries, GeneratorStatus, GeneratorStatusDA, GeneratorStatusRT
export gens_per_zone, branches_by_breakpoints, get_datetimes
export get_zones, get_buses, get_generators, get_branches
export get_regulation_requirements, get_operating_reserve_requirements, get_good_utility_requirements
export get_gens_per_bus, get_loads_per_bus, get_incs_per_bus, get_decs_per_bus, get_psds_per_bus
export get_ptdf, get_lodf
export get_initial_commitment, get_bids, get_availability, get_must_run
export get_initial_generation, get_load, get_offer_curve
export get_pmin, get_pmax, get_regmin, get_regmax
export get_regulation, get_spinning, get_supplemental_on, get_supplemental_off
export get_commitment, get_regulation_commitment

include("system.jl")
include("accessors.jl")

end
144 changes: 144 additions & 0 deletions src/accessors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"""
get_datetimes(system)
Extract datetimes from a `System`.
"""
function get_datetimes(system::System)
# use offer_curve axiskeys because all subtypes of System have offer_curve
return axiskeys(system.generator_time_series.offer_curve, 2)
end

get_zones(system::System) = system.zones

"Returns a `Dictionary` with zonal regulation requirements indexed by zone number."
function get_regulation_requirements(system::System)
return map(system.zones) do zone
zone.regulation
end
end

"Returns a `Dictionary` with zonal operating reserve requirements indexed by zone number."
function get_operating_reserve_requirements(system::System)
return map(system.zones) do zone
zone.operating_reserve
end
end

"Returns a `Dictionary` with zonal good utility practice requirements indexed by zone number."
function get_good_utility_requirements(system::System)
return map(system.zones) do zone
zone.good_utility
end
end

"Returns a `Dictionary` of `Bus` objects in the `System` indexed by bus name."
get_buses(system::System) = system.buses
"Returns a `Dictionary` of `Generator` objects in the `System` indexed by unit code."
get_generators(system::System) = system.generators
"Returns a `Dictionary` of `Branch` objects in the `System` indexed by branch name."
get_branches(system::System) = system.branches

"Returns a `Dictionary` of unit codes at each bus."
get_gens_per_bus(system::System) = system.gens_per_bus
"Returns a `Dictionary` of load names at each bus."
get_loads_per_bus(system::System) = system.loads_per_bus

"Returns the power transfer distribution factor of the system."
get_ptdf(system::System) = system.ptdf
"Returns the line outage distribution factor matrix of the system for a set of contingencies."
get_lodf(system::System) = system.lodf

"Returns the generation of the generator at the start of the time period (MW)"
get_initial_generation(system::System) = system.generator_time_series.initial_generation
"Returns time series data of the load in the system"
get_load(system::System) = system.loads
"Returns time series data of the generator offer curves"
get_offer_curve(system::System) = system.generator_time_series.offer_curve
"Returns time series data of minimum generator output (MW)"
get_pmin(system::System) = system.generator_time_series.pmin
"Returns time series data of maximum generator output (MW)"
get_pmax(system::System) = system.generator_time_series.pmax
"Returns time series data of minimum generator output in the ancillary services market (MW)"
get_regmin(system::System) = system.generator_time_series.regulation_min
"Returns time series data of maximum generator output in the ancillary services market (MW)"
get_regmax(system::System) = system.generator_time_series.regulation_max

"Returns time series data of offer prices for ancillary servives regulation (\$ /MW)"
get_regulation(system::System) = system.generator_time_series.asm_regulation
"Returns time series data of offer prices for ancillary servives spinning (\$ /MW)"
get_spinning(system::System) = system.generator_time_series.asm_spin
"Returns time series data of offer prices for ancillary servives supplemental on (\$ /MW)"
get_supplemental_on(system::System) = system.generator_time_series.asm_sup_on
"Returns time series data of offer prices for ancillary servives supplemental off (\$ /MW)"
get_supplemental_off(system::System) = system.generator_time_series.asm_sup_off

"Returns a flag indicating whether each generator was on at the start of the day."
function get_initial_commitment(system::SystemDA)
return map(system.generator_time_series.initial_generation) do i
i == 0.0 ? false : true
end
end

"Returns a `Dictionary` of increment bids at each bus."
get_incs_per_bus(system::SystemDA) = system.incs_per_bus
"Returns a `Dictionary` of decrement bids at each bus."
get_decs_per_bus(system::SystemDA) = system.decs_per_bus
"Returns a `Dictionary` of price sensitive demand bids at each bus."
get_psds_per_bus(system::SystemDA) = system.psds_per_bus

"""
Returns time series data of bids for the bid type indicated. Bid type must be one of
`:increment`, `:decrement` or `:price_sensitive_demand`.
"""
function get_bids(system::SystemDA, type_of_bid::Symbol)
return getproperty(system, type_of_bid)
end

"Returns time series data of flags indicating if the generator is available to be committed in each hour"
get_availability(system::SystemDA) = system.generator_status.availability
"Returns time series data of flags indicating if the generator must be committed in each hour"
get_must_run(system::SystemDA) = system.generator_status.must_run

"Returns time series data of generator status in each hour"
get_commitment(system::SystemRT) = system.generator_status.status
"Returns time series data of generator regulation status in each hour"
get_regulation_commitment(system::SystemRT) = system.generator_status.status_regulation

"""
gens_per_zone(system::System)
Returns a `Dict` with keys of `Zone` numbers and values of generator names in that zone.
"""
function gens_per_zone(system::System)
gens_per_zone = Dict{Int, Vector{Int}}()
for gen in system.generators
if haskey(gens_per_zone, gen.zone)
push!(gens_per_zone[gen.zone], gen.unit_code)
else
gens_per_zone[gen.zone] = [gen.unit_code]
end
end
gens_per_zone[MARKET_WIDE_ZONE] = collect(keys(system.generators))
return gens_per_zone
end

"""
branches_by_breakpoints(system::System)
Returns three vectors containing of the names of branches which have 0, 1, and 2 breakpoints.
"""
function branches_by_breakpoints(system::System)
zero_bp, one_bp, two_bp = String[], String[], String[]
for branch in system.branches
if branch.is_monitored
if all(branch.break_points .== 0.0)
push!(zero_bp, branch.name)
elseif last(branch.break_points) == 0.0
push!(one_bp, branch.name)
else
push!(two_bp, branch.name)
end
end
end
return zero_bp, one_bp, two_bp
end
Loading

2 comments on commit d5ae93a

@BSnelling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/59998

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" d5ae93a401de7caab7caa541f3cd7c05ce027523
git push origin v1.0.0

Please sign in to comment.