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

[WIP] adds more customization parameters to the NadCustomizer #960

Open
wants to merge 6 commits into
base: branch_labels
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
10 changes: 6 additions & 4 deletions cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,12 @@ std::vector<std::string> getMatrixMultiSubstationSvgAndMetadata(const JavaHandle
return svgAndMetadata.get();
}

void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& svgFile, const std::string& metadataFile, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions, dataframe* branch_labels) {
void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& svgFile, const std::string& metadataFile, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions) {
auto c_parameters = parameters.to_c_struct();
ToCharPtrPtr voltageLevelIdPtr(voltageLevelIds);
PowsyblCaller::get()->callJava(::writeNetworkAreaDiagramSvg, network, (char*) svgFile.data(), (char*) metadataFile.data(),
voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels);
voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels, three_wt_labels, bus_descriptions, vl_descriptions);
}

std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters) {
Expand All @@ -735,10 +736,11 @@ std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vecto
return toString(PowsyblCaller::get()->callJava<char*>(::getNetworkAreaDiagramSvg, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get()));
}

std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions, dataframe* branch_labels) {
std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions) {
auto c_parameters = parameters.to_c_struct();
ToCharPtrPtr voltageLevelIdPtr(voltageLevelIds);
auto svgAndMetadataArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkAreaDiagramSvgAndMetadata, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels);
auto svgAndMetadataArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkAreaDiagramSvgAndMetadata, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get(), fixed_positions, branch_labels, three_wt_labels, bus_descriptions, vl_descriptions);
ToStringVector svgAndMetadata(svgAndMetadataArrayPtr);
return svgAndMetadata.get();
}
Expand Down
6 changes: 4 additions & 2 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,13 @@ std::vector<std::string> getMatrixMultiSubstationSvgAndMetadata(const JavaHandle

std::vector<std::string> getSingleLineDiagramComponentLibraryNames();

void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& svgFile, const std::string& metadataFile, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions, dataframe* branch_labels);
void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& svgFile, const std::string& metadataFile, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions);

std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters);

std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions, dataframe* branch_labels);
std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters, dataframe* fixed_positions,
dataframe* branch_labels, dataframe* three_wt_labels, dataframe* bus_descriptions, dataframe* vl_descriptions);

std::vector<std::string> getNetworkAreaDiagramDisplayedVoltageLevels(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth);

Expand Down
4 changes: 2 additions & 2 deletions cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,14 @@ PYBIND11_MODULE(_pypowsybl, m) {
m.def("write_network_area_diagram_svg", &pypowsybl::writeNetworkAreaDiagramSvg, "Write network area diagram SVG",
py::arg("network"), py::arg("svg_file"), py::arg("metadata_file"), py::arg("voltage_level_ids"),
py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"), py::arg("fixed_positions"),
py::arg("branch_labels"));
py::arg("branch_labels"), py::arg("three_wt_labels"), py::arg("bus_descriptions"), py::arg("vl_descriptions"));

m.def("get_network_area_diagram_svg", &pypowsybl::getNetworkAreaDiagramSvg, "Get network area diagram SVG as a string",
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"));

m.def("get_network_area_diagram_svg_and_metadata", &pypowsybl::getNetworkAreaDiagramSvgAndMetadata, "Get network area diagram SVG and its metadata as a list of strings",
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"), py::arg("fixed_positions"),
py::arg("branch_labels"));
py::arg("branch_labels"), py::arg("three_wt_labels"), py::arg("bus_descriptions"), py::arg("vl_descriptions"));

m.def("get_network_area_diagram_displayed_voltage_levels", &pypowsybl::getNetworkAreaDiagramDisplayedVoltageLevels, "Get network area diagram displayed voltage level",
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"));
Expand Down
58 changes: 47 additions & 11 deletions docs/user_guide/network_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,23 @@ We can generate a network area diagram using fixed positions, defined in a dataf
])
>>> nad = network.get_network_area_diagram(fixed_positions=pos_df)

In the dataframe:
- id is the equipment id for the node
- x, y define the position for the node
- legend_shift_x, legend_shift_y define the legend box top-left position (relative to the node position)
- legend_connection_shift_x, legend_connection_shift_y define the legend box side endpoint position (relative to the node position) for the segment connecting a node and its legend box
In the dataframe:

The optional parameter fixed_positions can also be set in the write_network_area_diagram function.
Note that positions for elements not included in the dataframe are computed using the current layout algorithm.
- id is the equipment id for the node
- x, y define the position for the node
- legend_shift_x, legend_shift_y define the legend box top-left position (relative to the node position)
- legend_connection_shift_x, legend_connection_shift_y define the legend box side endpoint position (relative to the node position) for the segment connecting a node and its legend box

The optional parameter fixed_positions can also be set in the write_network_area_diagram function.
Note that positions for elements not included in the dataframe are computed using the current layout algorithm.

We can further customize the NAD diagram using the NadCustomizer. For example, to set the labels of the NAD branches and the arrows direction, using a dataframe:

We can further customize the NAD diagram using the NadCustomizer. For example, to set
- the labels of the NAD branches and the arrows direction
- the labels of the VL labels
- the BUS labels

by using dataframes:

.. code-block:: python

Expand All @@ -328,17 +334,47 @@ We can further customize the NAD diagram using the NadCustomizer. For example, t
('LINE_S3S4', 'L2_1', 'L2', 'L2_2', 'OUT', 'IN'),
('TWT', 'TWT1_1', 'TWT1', 'TWT1_2', None, 'OUT')
])
>>> diagram_customizer=pp.network.NadCustomizer(branch_labels=labels_df)
>>> vl_descriptions_df=pd.DataFrame.from_records(index='id',
data=[
{'id': 'S1VL1', 'type': 'HEADER', 'description': 'VL A'},
{'id': 'S1VL1', 'type': 'FOOTER', 'description': 'VL A footer'},
{'id': 'S1VL2', 'type': 'HEADER', 'description': 'VL B'},
{'id': 'S2VL1', 'type': 'HEADER', 'description': 'VL C'},
{'id': 'S3VL1', 'type': 'HEADER', 'description': 'VL D'},
{'id': 'S3VL1', 'type': 'FOOTER', 'description': 'VL D footer'}
])
>>> bus_descriptions_df=pd.DataFrame.from_records(index='id',
data=[
{'id': 'S1VL1_0', 'description': 'BUS A'},
{'id': 'S1VL2_0', 'description': 'BUS B'},
{'id': 'S2VL1_0', 'description': 'BUS C'},
{'id': 'S3VL1_0', 'description': 'BUS D'}
])
>>> diagram_customizer=pp.network.NadCustomizer(branch_labels=labels_df, vl_descriptions=vl_descriptions_df, bus_descriptions=bus_descriptions_df)
>>> pars=pp.network.NadParameters(edge_name_displayed=True)
>>> network.get_network_area_diagram(voltage_level_ids='S1VL1', depth=2, nad_parameters=pars, nad_customizer=diagram_customizer)

In the dataframe:
In the branch_labels dataframe parameter:
- id is the branch id
- side1 and side2 define the labels along the two branch's edges
- middle defines the branch's label
- arrow1 and arrow2 define the direction of the arrows at the ends of the branch: 'IN' or 'OUT'. None (or an empty string) does not display the arrow.

The optional parameter nad_customizer can also be set in the write_network_area_diagram function.
In the vl_descriptions dataframe parameter:
- id is the VL id
- type: 'HEADER' or 'FOOTER' determines if the descrtiption appears above or below the bus description, in the VL info box
- description define a label for the VL. Entries with the same VL id are displayed sequentially as multiple rows

In the bus_descriptions dataframe parameter:
- id is the BUS id
- description define a label for the BUS

An additional three_wt_labels dataframe parameter can be used to set the labels and the arrows direction for three winding transformers:
- id is the three winding transformer id
- side1, side2, and side3 define the labels along the three winding transformer legs
- arrow1, arrow2, and arrow3 define the direction of the arrows at the ends of the three winding transformer legs: 'IN' or 'OUT'. None (or an empty string) does not display the arrow.

The optional parameter nad_customizer can also be set in the write_network_area_diagram function.

Network area diagram using geographical data
--------------------------------------------
Expand Down
Loading
Loading