Skip to content

Commit

Permalink
Merge branch 'main' into remove_deprecated_attributes_network_modific…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
EtienneLt authored Jun 26, 2024
2 parents f9f8ccf + c8ae80c commit 4b040a3
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 10 deletions.
1 change: 1 addition & 0 deletions cpp/powsybl-cpp/powsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ typedef struct nad_parameters_struct {
int layout_type;
int scaling_factor;
double radius_factor;
int edge_info_displayed;
} nad_parameters;

typedef enum {
Expand Down
2 changes: 2 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ NadParameters::NadParameters(nad_parameters* src) {
layout_type = static_cast<NadLayoutType>(src->layout_type);
scaling_factor = src->scaling_factor;
radius_factor = src->radius_factor;
edge_info_displayed = static_cast<EdgeInfoType>(src->edge_info_displayed);
}

void SldParameters::sld_to_c_struct(sld_parameters& res) const {
Expand All @@ -1220,6 +1221,7 @@ void NadParameters::nad_to_c_struct(nad_parameters& res) const {
res.layout_type = (int) layout_type;
res.scaling_factor = scaling_factor;
res.radius_factor = radius_factor;
res.edge_info_displayed = (int) edge_info_displayed;
}

std::shared_ptr<sld_parameters> SldParameters::to_c_struct() const {
Expand Down
7 changes: 7 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ enum class NadLayoutType {
GEOGRAPHICAL
};

enum class EdgeInfoType {
ACTIVE_POWER = 0,
REACTIVE_POWER,
CURRENT
};

class NadParameters {
public:
NadParameters(nad_parameters* src);
Expand All @@ -417,6 +423,7 @@ class NadParameters {
NadLayoutType layout_type;
int scaling_factor;
double radius_factor;
EdgeInfoType edge_info_displayed;
};

//=======short-circuit analysis==========
Expand Down
8 changes: 7 additions & 1 deletion cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ PYBIND11_MODULE(_pypowsybl, m) {
.value("FORCE_LAYOUT", pypowsybl::NadLayoutType::FORCE_LAYOUT)
.value("GEOGRAPHICAL", pypowsybl::NadLayoutType::GEOGRAPHICAL);

py::enum_<pypowsybl::EdgeInfoType>(m, "EdgeInfoType")
.value("ACTIVE_POWER", pypowsybl::EdgeInfoType::ACTIVE_POWER)
.value("REACTIVE_POWER", pypowsybl::EdgeInfoType::REACTIVE_POWER)
.value("CURRENT", pypowsybl::EdgeInfoType::CURRENT);

py::class_<pypowsybl::NadParameters>(m, "NadParameters")
.def(py::init(&pypowsybl::createNadParameters))
.def_readwrite("edge_name_displayed", &pypowsybl::NadParameters::edge_name_displayed)
Expand All @@ -565,7 +570,8 @@ PYBIND11_MODULE(_pypowsybl, m) {
.def_readwrite("substation_description_displayed", &pypowsybl::NadParameters::substation_description_displayed)
.def_readwrite("layout_type", &pypowsybl::NadParameters::layout_type)
.def_readwrite("scaling_factor", &pypowsybl::NadParameters::scaling_factor)
.def_readwrite("radius_factor", &pypowsybl::NadParameters::radius_factor);
.def_readwrite("radius_factor", &pypowsybl::NadParameters::radius_factor)
.def_readwrite("edge_info_displayed",&pypowsybl::NadParameters::edge_info_displayed);

m.def("write_single_line_diagram_svg", &pypowsybl::writeSingleLineDiagramSvg, "Write single line diagram SVG",
py::arg("network"), py::arg("container_id"), py::arg("svg_file"), py::arg("metadata_file"), py::arg("sld_parameters"));
Expand Down
3 changes: 2 additions & 1 deletion docs/user_guide/network_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Network-area diagrams can be customized through NadParameters:
>>> from pypowsybl.network import NadParameters
>>> network = pp.network.create_ieee14()
>>> nad = network.get_network_area_diagram('VL6', nad_parameters=NadParameters(edge_name_displayed=True, id_displayed=True, edge_info_along_edge=False, power_value_precision=1, angle_value_precision=0, current_value_precision=1, voltage_value_precision=0, bus_legend=False, substation_description_displayed=True))
>>> nad = network.get_network_area_diagram('VL6', nad_parameters=NadParameters(edge_name_displayed=True, id_displayed=True, edge_info_along_edge=False, power_value_precision=1, angle_value_precision=0, current_value_precision=1, voltage_value_precision=0, bus_legend=False, substation_description_displayed=True, edge_info_displayed=EdgeInfoType.REACTIVE_POWER))
- edge_name_displayed: if true, names along lines and transformer legs are displayed (default value false)
- id_displayed: if true, the equipment ids are displayed. If false, the equipment names are displayed (if a name is null, then the id is displayed) (default value false)
Expand All @@ -114,6 +114,7 @@ Network-area diagrams can be customized through NadParameters:
- voltage_value_precision: number of digits after the decimal point for voltage values(default value 1)
- bus_legend: if true, angle and voltage values associated to a voltage level are displayed in a text box. If false, only the voltage level name is displayed (default value true)
- substation_description_displayed: if true, the substation name is added to the voltage level info on the diagram (default value false)
- edge_info_displayed: type of info displayed (EdgeInfoType.ACTIVE_POWER(default),EdgeInfoType.REACTIVE_POWER or EdgeInfoType.CURRENT)
In order to get a list of the displayed voltage levels from an input voltage level (or an input list of voltage levels) and a depth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,12 @@ public interface NadParametersPointer extends PointerBase {

@CField("radius_factor")
void setRadiusFactor(double radiusFactor);

@CField("edge_info_displayed")
void setEdgeInfoDisplayed(int edgeInfoDisplayed);

@CField("edge_info_displayed")
int getEdgeInfoDisplayed();
}

@CEnum("DynamicMappingType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.powsybl.nad.layout.BasicForceLayoutFactory;
import com.powsybl.nad.layout.GeographicalLayoutFactory;
import com.powsybl.nad.layout.LayoutFactory;
import com.powsybl.nad.svg.SvgParameters;
import com.powsybl.python.commons.CTypeUtil;
import com.powsybl.python.commons.Directives;
import com.powsybl.python.commons.PyPowsyblApiHeader;
Expand Down Expand Up @@ -67,6 +68,7 @@
import java.util.*;
import java.util.zip.ZipOutputStream;

import static com.powsybl.nad.svg.SvgParameters.EdgeInfoEnum.*;
import static com.powsybl.python.commons.CTypeUtil.toStringList;
import static com.powsybl.python.commons.PyPowsyblApiHeader.*;
import static com.powsybl.python.commons.Util.*;
Expand Down Expand Up @@ -896,6 +898,12 @@ public static NadParametersPointer convertToNadParametersPointer(NadParameters p
}

public static void copyToCNadParameters(NadParameters parameters, NadParametersPointer cParameters) {
int edgeInfo = switch (parameters.getSvgParameters().getEdgeInfoDisplayed()) {
case ACTIVE_POWER -> 0;
case REACTIVE_POWER -> 1;
case CURRENT -> 2;
default -> throw new PowsyblException("Type of information not taken into account");
};
cParameters.setEdgeNameDisplayed(parameters.getSvgParameters().isEdgeNameDisplayed());
cParameters.setEdgeInfoAlongEdge(parameters.getSvgParameters().isEdgeInfoAlongEdge());
cParameters.setIdDisplayed(parameters.getSvgParameters().isIdDisplayed());
Expand All @@ -905,6 +913,7 @@ public static void copyToCNadParameters(NadParameters parameters, NadParametersP
cParameters.setVoltageValuePrecision(parameters.getSvgParameters().getVoltageValuePrecision());
cParameters.setBusLegend(parameters.getSvgParameters().isBusLegend());
cParameters.setSubstationDescriptionDisplayed(parameters.getSvgParameters().isSubstationDescriptionDisplayed());
cParameters.setEdgeInfoDisplayed(edgeInfo);
}

@CEntryPoint(name = "createNadParameters")
Expand Down Expand Up @@ -953,6 +962,12 @@ public static NadParameters convertNadParameters(NadParametersPointer nadParamet
case 1: yield new GeographicalLayoutFactory(network, nadParametersPointer.getScalingFactor(), nadParametersPointer.getRadiusFactor(), new BasicForceLayoutFactory());
default: yield new BasicForceLayoutFactory();
};
SvgParameters.EdgeInfoEnum edgeInfo = switch (nadParametersPointer.getEdgeInfoDisplayed()) {
case 0 -> ACTIVE_POWER;
case 1 -> REACTIVE_POWER;
case 2 -> CURRENT;
default -> throw new PowsyblException("Type of information not taken into account");
};
nadParameters.setLayoutFactory(layoutFactory);
nadParameters.getSvgParameters()
.setEdgeNameDisplayed(nadParametersPointer.isEdgeNameDisplayed())
Expand All @@ -963,7 +978,8 @@ public static NadParameters convertNadParameters(NadParametersPointer nadParamet
.setVoltageValuePrecision(nadParametersPointer.getVoltageValuePrecision())
.setIdDisplayed(nadParametersPointer.isIdDisplayed())
.setBusLegend(nadParametersPointer.isBusLegend())
.setSubstationDescriptionDisplayed(nadParametersPointer.isSubstationDescriptionDisplayed());
.setSubstationDescriptionDisplayed(nadParametersPointer.isSubstationDescriptionDisplayed())
.setEdgeInfoDisplayed(edgeInfo);
return nadParameters;
}

Expand Down
17 changes: 17 additions & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ class FilterAttributesType:
@property
def name(self) -> str: ...

class EdgeInfoType:
__members__: ClassVar[Dict[str, EdgeInfoType]] = ... # read-only
ACTIVE_POWER: ClassVar[EdgeInfoType] = ...
REACTIVE_POWER: ClassVar[EdgeInfoType] = ...
CURRENT: ClassVar[EdgeInfoType] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class JavaHandle:
...

Expand Down Expand Up @@ -280,6 +296,7 @@ class NadParameters:
layout_type: NadLayoutType
scaling_factor: int
radius_factor: float
edge_info_displayed: EdgeInfoType
def __init__(self) -> None: ...

class LimitType:
Expand Down
2 changes: 1 addition & 1 deletion pypowsybl/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .impl.bus_breaker_topology import BusBreakerTopology
from .impl.node_breaker_topology import NodeBreakerTopology
from .impl.sld_parameters import SldParameters
from .impl.nad_parameters import NadLayoutType
from .impl.nad_parameters import NadLayoutType, EdgeInfoType
from .impl.nad_parameters import NadParameters
from .impl.layout_parameters import LayoutParameters
from .impl.network_creation_util import (
Expand Down
13 changes: 11 additions & 2 deletions pypowsybl/network/impl/nad_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
import pypowsybl._pypowsybl as _pp
from pypowsybl._pypowsybl import (
NadLayoutType
NadLayoutType, EdgeInfoType
)

class NadParameters:
Expand All @@ -16,7 +16,8 @@ def __init__(self, edge_name_displayed: bool = False, id_displayed: bool = False
edge_info_along_edge: bool = True, power_value_precision: int = 0, angle_value_precision: int = 1,
current_value_precision: int = 0, voltage_value_precision: int = 1, bus_legend: bool = True,
substation_description_displayed: bool = False, layout_type: NadLayoutType = NadLayoutType.FORCE_LAYOUT,
scaling_factor: int = 150000, radius_factor: float = 150.0):
scaling_factor: int = 150000, radius_factor: float = 150.0,
edge_info_displayed: EdgeInfoType = EdgeInfoType.ACTIVE_POWER):
self._edge_name_displayed = edge_name_displayed
self._edge_info_along_edge = edge_info_along_edge
self._id_displayed = id_displayed
Expand All @@ -29,6 +30,7 @@ def __init__(self, edge_name_displayed: bool = False, id_displayed: bool = False
self._layout_type = layout_type
self._scaling_factor = scaling_factor
self._radius_factor = radius_factor
self._edge_info_displayed = edge_info_displayed

@property
def edge_name_displayed(self) -> bool:
Expand Down Expand Up @@ -90,6 +92,11 @@ def radius_factor(self) -> float:
"""radius_factor"""
return self._radius_factor

@property
def edge_info_displayed(self) -> EdgeInfoType:
"""edge_info_displayed"""
return self._edge_info_displayed

def _to_c_parameters(self) -> _pp.NadParameters:
c_parameters = _pp.NadParameters()
c_parameters.edge_name_displayed = self._edge_name_displayed
Expand All @@ -104,6 +111,7 @@ def _to_c_parameters(self) -> _pp.NadParameters:
c_parameters.layout_type = self._layout_type
c_parameters.scaling_factor = self._scaling_factor
c_parameters.radius_factor = self._radius_factor
c_parameters.edge_info_displayed = self._edge_info_displayed
return c_parameters

def __repr__(self) -> str:
Expand All @@ -120,4 +128,5 @@ def __repr__(self) -> str:
f", layout_type={self._layout_type}" \
f", scaling_factor={self._scaling_factor}" \
f", radius_factor={self._radius_factor}" \
f", edge_info_displayed={self._edge_info_displayed}" \
f")"
28 changes: 24 additions & 4 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pypowsybl.report as rp
import util
from pypowsybl import PyPowsyblError
from pypowsybl.network import ValidationLevel, SldParameters, NadLayoutType, NadParameters, LayoutParameters
from pypowsybl.network import ValidationLevel, SldParameters, NadLayoutType, NadParameters, LayoutParameters, EdgeInfoType

TEST_DIR = pathlib.Path(__file__).parent
DATA_DIR = TEST_DIR.parent / 'data'
Expand Down Expand Up @@ -865,7 +865,8 @@ def test_nad():
current_value_precision=1,
voltage_value_precision=0,
bus_legend=False,
substation_description_displayed=True
substation_description_displayed=True,
edge_info_displayed=EdgeInfoType.CURRENT
))
assert re.search('.*<svg.*', nad.svg)
with tempfile.TemporaryDirectory() as tmp_dir_name:
Expand All @@ -887,7 +888,9 @@ def test_nad():
current_value_precision=1,
voltage_value_precision=0,
bus_legend=False,
substation_description_displayed=True))
substation_description_displayed=True,
edge_info_displayed=EdgeInfoType.REACTIVE_POWER
))


def test_nad_displayed_voltage_levels():
Expand Down Expand Up @@ -2012,8 +2015,9 @@ def test_nad_parameters():
assert nad_parameters.layout_type == NadLayoutType.FORCE_LAYOUT
assert nad_parameters.scaling_factor == 150000
assert nad_parameters.radius_factor == 150.0
assert nad_parameters.edge_info_displayed == EdgeInfoType.ACTIVE_POWER

nad_parameters = NadParameters(True, True, False, 1, 2, 1, 2, False, True, NadLayoutType.GEOGRAPHICAL, 100000, 120.0)
nad_parameters = NadParameters(True, True, False, 1, 2, 1, 2, False, True, NadLayoutType.GEOGRAPHICAL, 100000, 120.0, EdgeInfoType.REACTIVE_POWER)
assert nad_parameters.edge_name_displayed
assert not nad_parameters.edge_info_along_edge
assert nad_parameters.id_displayed
Expand All @@ -2026,6 +2030,22 @@ def test_nad_parameters():
assert nad_parameters.layout_type == NadLayoutType.GEOGRAPHICAL
assert nad_parameters.scaling_factor == 100000
assert nad_parameters.radius_factor == 120.0
assert nad_parameters.edge_info_displayed == EdgeInfoType.REACTIVE_POWER

nad_parameters = NadParameters(True, True, False, 1, 2, 1, 2, False, True, NadLayoutType.GEOGRAPHICAL, 100000, 120.0, EdgeInfoType.CURRENT)
assert nad_parameters.edge_name_displayed
assert not nad_parameters.edge_info_along_edge
assert nad_parameters.id_displayed
assert nad_parameters.power_value_precision == 1
assert nad_parameters.angle_value_precision == 2
assert nad_parameters.current_value_precision == 1
assert nad_parameters.voltage_value_precision == 2
assert not nad_parameters.bus_legend
assert nad_parameters.substation_description_displayed
assert nad_parameters.layout_type == NadLayoutType.GEOGRAPHICAL
assert nad_parameters.scaling_factor == 100000
assert nad_parameters.radius_factor == 120.0
assert nad_parameters.edge_info_displayed == EdgeInfoType.CURRENT


if __name__ == '__main__':
Expand Down

0 comments on commit 4b040a3

Please sign in to comment.