Skip to content
Snippets Groups Projects
Commit 87de6181 authored by Julian Stürmer's avatar Julian Stürmer
Browse files

Add get_bustypes

parent 0c8d4e94
No related branches found
No related tags found
No related merge requests found
...@@ -45,11 +45,11 @@ function getlocs(network_data::Dict{String,<:Any}; getlims=false) ...@@ -45,11 +45,11 @@ function getlocs(network_data::Dict{String,<:Any}; getlims=false)
lats = [ lats = [
network_data["bus"]["$i"]["bus_lat"] network_data["bus"]["$i"]["bus_lat"]
for i in keys(network_data["bus"]) for i in keys(network_data["bus"])
] ] # latitudes
lons = [ lons = [
network_data["bus"]["$i"]["bus_lon"] network_data["bus"]["$i"]["bus_lon"]
for i in keys(network_data["bus"]) for i in keys(network_data["bus"])
] ] # longitudes
xlims = (minimum(lons), maximum(lons)) xlims = (minimum(lons), maximum(lons))
ylims = (minimum(lats), maximum(lats)) ylims = (minimum(lats), maximum(lats))
return pos, xlims, ylims return pos, xlims, ylims
...@@ -57,3 +57,47 @@ function getlocs(network_data::Dict{String,<:Any}; getlims=false) ...@@ -57,3 +57,47 @@ function getlocs(network_data::Dict{String,<:Any}; getlims=false)
return pos return pos
end end
end end
#*------------------------------------------------------------------------------
#=
Returns the bus types of all buses in the NDD in form a dictionary. The different bus types are "load", "gen" (generator), "load_and_gen" and "empty".
=#
function get_bustypes(network_data::Dict{String,<:Any})
### Active loads
loads = unique(
[load["load_bus"] for (i, load) in network_data["load"]
if load["status"] == 1]
)
### Active generators
gens = unique(
[gen["gen_bus"] for (i, gen) in network_data["gen"]
if gen["gen_status"] == 1]
)
### Buses with both load and generation
load_and_gen = [i for i in loads if i in gens]
### Remove buses with load and generation from pure loads and generators
filter!(i -> i load_and_gen, loads)
filter!(i -> i load_and_gen, gens)
### Empty buses with neither load nor generation
empty = unique(
[bus["index"] for (i, bus) in network_data["bus"]
if bus["index"] vcat(loads, gens, load_and_gen)]
)
### Check whether the right number of bus types was obtained
sum = (length(loads) + length(gens) + length(load_and_gen) + length(empty))
N::Int64 = length(network_data["bus"]) # number of buses
@assert sum == N "$sum bus types were obtained instead of $N"
return Dict(
"loads" => loads,
"gens" => gens,
"load_and_gen" => load_and_gen,
"empty" => empty
)
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment