Skip to content

Commit

Permalink
Get import supported extensions (#889)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Nov 19, 2024
1 parent 9a73dba commit e1080db
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ std::vector<std::string> getNetworkImportPostProcessors() {
return postProcessors.get();
}

std::vector<std::string> getNetworkImportSupportedExtensions() {
auto supportedExtensionsArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkImportSupportedExtensions);
ToStringVector supportedExtensions(supportedExtensionsArrayPtr);
return supportedExtensions.get();
}

std::vector<std::string> getLoadFlowProviderNames() {
auto formatsArrayPtr = PowsyblCaller::get()->callJava<array*>(::getLoadFlowProviderNames);
ToStringVector formats(formatsArrayPtr);
Expand Down
2 changes: 2 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ std::vector<std::string> getNetworkElementsIds(const JavaHandle& network, elemen

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

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

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

std::vector<std::string> getNetworkImportPostProcessors();
Expand Down
1 change: 1 addition & 0 deletions cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ PYBIND11_MODULE(_pypowsybl, m) {
py::arg("not_connected_to_same_bus_at_both_sides"));

m.def("get_network_import_formats", &pypowsybl::getNetworkImportFormats, "Get supported import formats");
m.def("get_network_import_supported_extensions", &pypowsybl::getNetworkImportSupportedExtensions, "Get supported import extensions");
m.def("get_network_export_formats", &pypowsybl::getNetworkExportFormats, "Get supported export formats");
m.def("get_network_import_post_processors", &pypowsybl::getNetworkImportPostProcessors, "Get supported import post processors");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public static ArrayPointer<CCharPointerPointer> getNetworkImportFormats(IsolateT
return doCatch(exceptionHandlerPtr, () -> createCharPtrArray(Importer.getFormats().stream().sorted().toList()));
}

@CEntryPoint(name = "getNetworkImportSupportedExtensions")
public static ArrayPointer<CCharPointerPointer> getNetworkImportSupportedExtensions(IsolateThread thread, ExceptionHandlerPointer exceptionHandlerPtr) {
return doCatch(exceptionHandlerPtr, () -> createCharPtrArray(Importer.list().stream().flatMap(l -> l.getSupportedExtensions().stream()).distinct().sorted().toList()));
}

@CEntryPoint(name = "getNetworkExportFormats")
public static ArrayPointer<CCharPointerPointer> getNetworkExportFormats(IsolateThread thread, ExceptionHandlerPointer exceptionHandlerPtr) {
return doCatch(exceptionHandlerPtr, () -> createCharPtrArray(Exporter.getFormats().stream().sorted().toList()));
Expand Down
1 change: 1 addition & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ def get_network_area_diagram_displayed_voltage_levels(network: JavaHandle, volta
def get_network_elements_ids(network: JavaHandle, element_type: ElementType, nominal_voltages: List[float], countries: List[str], main_connected_component: bool, main_synchronous_component: bool, not_connected_to_same_bus_at_both_sides: bool) -> List[str]: ...
def get_network_export_formats() -> List[str]: ...
def get_network_import_formats() -> List[str]: ...
def get_network_import_supported_extensions() -> List[str]: ...
def get_network_import_post_processors() -> List[str]: ...
def get_loadflow_provider_names() -> List[str]: ...
def get_security_analysis_provider_names() -> List[str]: ...
Expand Down
1 change: 1 addition & 0 deletions pypowsybl/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
get_extensions_names,
get_single_line_diagram_component_library_names,
get_import_formats,
get_import_supported_extensions,
get_export_formats,
get_import_post_processors,
get_import_parameters,
Expand Down
10 changes: 10 additions & 0 deletions pypowsybl/network/impl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def get_import_formats() -> List[str]:
return _pp.get_network_import_formats()


def get_import_supported_extensions() -> List[str]:
"""
Get list of supported import extensions
Returns:
the list of supported import extensions
"""
return _pp.get_network_import_supported_extensions()


def get_export_formats() -> List[str]:
"""
Get list of supported export formats
Expand Down
5 changes: 5 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ def test_get_import_format():
assert ['BIIDM', 'CGMES', 'IEEE-CDF', 'JIIDM', 'MATPOWER', 'POWER-FACTORY', 'PSS/E', 'UCTE', 'XIIDM'] == formats


def test_get_import_supported_extensions():
extensions = pp.network.get_import_supported_extensions()
assert ['RAW', 'RAWX', 'UCT', 'biidm', 'bin', 'dgs', 'iidm', 'jiidm', 'json', 'mat', 'raw', 'rawx', 'txt', 'uct', 'xiidm', 'xml'] == extensions


def test_get_import_parameters():
parameters = pp.network.get_import_parameters('PSS/E')
assert 1 == len(parameters)
Expand Down

0 comments on commit e1080db

Please sign in to comment.