-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dataframe based network interface (#2)
Explore network using julia dataframes and get network metadata. Signed-off-by: Bertrand Rix <[email protected]>
- Loading branch information
Showing
9 changed files
with
417 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule pypowsybl
updated
57 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
module Network | ||
using ..Powsybl | ||
using CxxWrap | ||
using DataFrames | ||
|
||
const nominal_apparent_power = 100.0 | ||
const per_unit = false | ||
|
||
mutable struct NetworkHandle | ||
handle::Powsybl.JavaHandle | ||
id::String | ||
name::String | ||
source_format::String | ||
forecast_distance::Int32 | ||
case_date::Float64 | ||
end | ||
|
||
function get_network_metadata(network::NetworkHandle) | ||
return Powsybl.get_network_metadata(network.handle) | ||
end | ||
|
||
function get_elements(network::NetworkHandle, type::Powsybl.ElementType, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
filter_attributes = Powsybl.DEFAULT_ATTRIBUTES | ||
if all_attributes | ||
filter_attributes = Powsybl.ALL_ATTRIBUTES | ||
elseif !isempty(attributes) | ||
filter_attributes = Powsybl.SELECTION_ATTRIBUTES | ||
end | ||
|
||
if all_attributes && !isempty(attributes) | ||
throw("parameters \"all_attributes\" and \"attributes\" are mutually exclusive") | ||
end | ||
series_array = Powsybl.create_network_elements_series_array(network.handle, type, StdVector{StdString}(attributes), filter_attributes, per_unit, nominal_apparent_power) | ||
return create_dataframe_from_series_array(series_array[]) | ||
end | ||
|
||
function get_buses(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.BUS, all_attributes, attributes) | ||
end | ||
|
||
function get_bus_breaker_view_buses(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.BUS_FROM_BUS_BREAKER_VIEW, all_attributes, attributes) | ||
end | ||
|
||
function get_generators(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.GENERATOR, all_attributes, attributes) | ||
end | ||
|
||
function get_batteries(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.BATTERY, all_attributes, attributes) | ||
end | ||
|
||
function get_lines(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.LINE, all_attributes, attributes) | ||
end | ||
|
||
function get_2_windings_transformers(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.TWO_WINDINGS_TRANSFORMER, all_attributes, attributes) | ||
end | ||
|
||
function get_3_windings_transformers(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.THREE_WINDINGS_TRANSFORMER, all_attributes, attributes) | ||
end | ||
|
||
function get_shunt_compensators(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.SHUNT_COMPENSATOR, all_attributes, attributes) | ||
end | ||
|
||
function get_non_linear_shunt_compensator_sections(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.NON_LINEAR_SHUNT_COMPENSATOR_SECTION, all_attributes, attributes) | ||
end | ||
|
||
function get_linear_shunt_compensator_sections(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.LINEAR_SHUNT_COMPENSATOR_SECTION, all_attributes, attributes) | ||
end | ||
|
||
function get_dangling_lines(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.DANGLING_LINE, all_attributes, attributes) | ||
end | ||
|
||
function get_tie_lines(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.TIE_LINE, all_attributes, attributes) | ||
end | ||
|
||
function get_lcc_converter_stations(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.LCC_CONVERTER_STATION, all_attributes, attributes) | ||
end | ||
|
||
function get_vsc_converter_stations(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.VSC_CONVERTER_STATION, all_attributes, attributes) | ||
end | ||
|
||
function get_static_var_compensators(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.STATIC_VAR_COMPENSATOR, all_attributes, attributes) | ||
end | ||
|
||
function get_voltage_levels(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.VOLTAGE_LEVEL, all_attributes, attributes) | ||
end | ||
|
||
function get_busbar_sections(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.BUSBAR_SECTION, all_attributes, attributes) | ||
end | ||
|
||
function get_substations(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.SUBSTATION, all_attributes, attributes) | ||
end | ||
|
||
function get_hvdc_lines(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.HVDC_LINE, all_attributes, attributes) | ||
end | ||
|
||
function get_switches(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.SWITCH, all_attributes, attributes) | ||
end | ||
|
||
function get_ratio_tap_changer_steps(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.RATIO_TAP_CHANGER_STEP, all_attributes, attributes) | ||
end | ||
|
||
function get_phase_tap_changer_steps(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.PHASE_TAP_CHANGER_STEP, all_attributes, attributes) | ||
end | ||
|
||
function get_ratio_tap_changers(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.RATIO_TAP_CHANGER, all_attributes, attributes) | ||
end | ||
|
||
function get_phase_tap_changers(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.PHASE_TAP_CHANGER, all_attributes, attributes) | ||
end | ||
|
||
function get_reactive_capability_curve_points(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.REACTIVE_CAPABILITY_CURVE_POINT, all_attributes, attributes) | ||
end | ||
|
||
function get_aliases(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.ALIAS, all_attributes, attributes) | ||
end | ||
|
||
function get_identifiables(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.IDENTIFIABLE, all_attributes, attributes) | ||
end | ||
|
||
function get_injections(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.INJECTION, all_attributes, attributes) | ||
end | ||
|
||
function get_branches(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.BRANCH, all_attributes, attributes) | ||
end | ||
|
||
function get_terminals(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) | ||
return get_elements(network, Powsybl.TERMINAL, all_attributes, attributes) | ||
end | ||
|
||
function create_dataframe_from_series_array(array::Powsybl.SeriesArray) | ||
myArray = Powsybl.as_array(array) | ||
df = DataFrame() | ||
for serie in myArray | ||
type = Powsybl.type(serie) | ||
name = Powsybl.name(serie) | ||
if type == 0 | ||
data = Powsybl.as_string_array(serie) | ||
elseif type == 1 | ||
data = Powsybl.as_double_array(serie) | ||
elseif type == 2 | ||
data = Powsybl.as_int_array(serie) | ||
else | ||
continue | ||
end | ||
df[!, name]=data | ||
end | ||
return df | ||
end | ||
|
||
function load(network_file::String)::NetworkHandle | ||
handle = Powsybl.load(network_file) | ||
return NetworkHandle(Powsybl.load(network_file), | ||
Powsybl.id(handle), | ||
Powsybl.name(handle), | ||
Powsybl.source_format(handle), | ||
Powsybl.forecast_distance(handle), | ||
Powsybl.case_date(handle)) | ||
end | ||
|
||
include("NetworkCreationUtils.jl") | ||
end |
Oops, something went wrong.