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 missing element accessor and fix missing boolean attributes in dataframes #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ From a loaded network you can have a access to the following network elements (a
* buses
* bus_breaker_view_buses
* generators
* loads
* batteries
* lines
* 2_windings_transformers
Expand All @@ -53,6 +54,7 @@ From a loaded network you can have a access to the following network elements (a
* injections
* branches
* terminals
* operational_limits

```julia

Expand Down Expand Up @@ -106,4 +108,49 @@ julia> @info Powsybl.Network.get_lines(network)[:,["id", "name", "p1"]]

```

### Network extensions

Network extensions can be accessed through a call to Powsybl.Network.get_extensions

```julia

julia> using Powsybl

julia> network = Powsybl.Network.create_micro_grid_be()
Powsybl.Network.NetworkHandle(Powsybl.JavaHandleAllocated(Ptr{Nothing} @0x0000000020f43260), "urn:uuid:d400c631-75a0-4c30-8aed-832b0d282e73", "urn:uuid:d400c631-75a0-4c30-8aed-832b0d282e73", "CGMES", 0, 1.4016186e9)

julia> Powsybl.Network.get_extensions(network, "activePowerControl")
2×6 DataFrame
Row │ id droop participate participation_factor max_target_p min_target_p
│ String Float64 Bool Float64 Float64 Float64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 3a3b27be-b18b-4385-b557-6735d733… NaN true 0.0 NaN NaN
2 │ 550ebe0d-f2b2-48c1-991f-cebea43a… NaN true 0.0 NaN NaN

```

Available extensions can be listed using the following call :

```julia
julia> Powsybl.Network.get_extensions_names()
19-element Vector{String}:
"activePowerControl"
"branchObservability"
"busbarSectionPosition"
"coordinatedReactiveControl"
"detail"
"entsoeArea"
"entsoeCategory"
"generatorShortCircuit"
"hvdcAngleDroopActivePowerControl"
"hvdcOperatorActivePowerRange"
"identifiableShortCircuit"
"injectionObservability"
"linePosition"
"measurements"
"position"
"secondaryVoltageControl"
"slackTerminal"
"standbyAutomaton"
"substationPosition"
```
13 changes: 12 additions & 1 deletion cpp/powsybljl-cpp/powsybl_jl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ JLCXX_MODULE define_module_powsybl(jlcxx::Module& mod)
})
.method("as_string_array", [](series& s) {
return pypowsybl::toVector<std::string>((array *) & s.data);
})
.method("as_bool_array", [](series& s) {
return jlcxx::ArrayRef<bool,1>(static_cast<bool*>(s.data.ptr), s.data.length);
});

mod.add_type<network_metadata>("NetworkMetadata")
Expand Down Expand Up @@ -128,6 +131,14 @@ JLCXX_MODULE define_module_powsybl(jlcxx::Module& mod)

mod.method("create_network_elements_series_array", [] (pypowsybl::JavaHandle handle, element_type type, std::vector<std::string> const& attributes, filter_attributes_type filter_attributes, bool nominal_apparent_power, double per_unit) {
return pypowsybl::createNetworkElementsSeriesArray(handle, type, filter_attributes, attributes, nullptr, nominal_apparent_power, per_unit);
}, "Get a series");
}, "Create a network elements series array for a given element type");

mod.method("create_network_elements_extension_series_array", [] (pypowsybl::JavaHandle handle, std::string const& extension_name, std::string const& table_name) {
return pypowsybl::createNetworkElementsExtensionSeriesArray(handle, extension_name, table_name);
}, "Create a network elements extensions series array for a given extension name");

mod.method("get_extensions_names", [] () {
return pypowsybl::getExtensionsNames();
}, "Get all the extensions names available");

}
23 changes: 22 additions & 1 deletion src/Network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module Network
return Powsybl.get_network_metadata(network.handle)
end

function get_extensions_names()
return [String(extension_name) for extension_name in Powsybl.get_extensions_names()]
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
Expand Down Expand Up @@ -154,18 +158,35 @@ module Network
return get_elements(network, Powsybl.TERMINAL, all_attributes, attributes)
end

function get_loads(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}())
return get_elements(network, Powsybl.LOAD, all_attributes, attributes)
end

function get_operational_limits(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}())
return get_elements(network, Powsybl.OPERATIONAL_LIMITS, all_attributes, attributes)
end

function get_extensions(network::NetworkHandle, extension_name::String, table_name::String = "")
series_array = Powsybl.create_network_elements_extension_series_array(network.handle, extension_name, table_name)
return create_dataframe_from_series_array(series_array[])
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)
# To avoid getting CxxWrap StdString type in the dataframe
data = [String(cxx_str_elem) for cxx_str_elem in Powsybl.as_string_array(serie)]
elseif type == 1
data = Powsybl.as_double_array(serie)
elseif type == 2
data = Powsybl.as_int_array(serie)
elseif type == 3
# To avoid getting CxxWrap CxxBool type in the dataframe
data = [Bool(cxx_bool_elem) for cxx_bool_elem in Powsybl.as_bool_array(serie)]
else
continue
end
Expand Down
5 changes: 2 additions & 3 deletions test/print_network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ network = Powsybl.Network.create_ieee9()
@test network.case_date ≈ 1.240704e9

lines = Powsybl.Network.get_lines(network)
@test names(lines) == ["id", "name", "r", "x", "g1", "b1", "g2",
"b2", "p1", "q1", "i1", "p2", "q2", "i2", "voltage_level1_id",
"voltage_level2_id", "bus1_id", "bus2_id"]
@test names(lines) == ["id", "name", "r", "x", "g1", "b1", "g2", "b2", "p1", "q1", "i1", "p2", "q2",
"i2", "voltage_level1_id", "voltage_level2_id", "bus1_id", "bus2_id", "connected1", "connected2"]

@test lines[:, "id"] == ["L7-8-0", "L9-8-0", "L7-5-0", "L9-6-0", "L5-4-0", "L6-4-0"]
@test lines[:, "bus1_id"] == ["VL2_1", "VL3_1", "VL2_1", "VL3_1", "VL5_0", "VL6_0"]
Loading