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

Get import supported extensions #889

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -370,6 +370,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 @@ -94,6 +94,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 @@ -785,6 +785,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():
extenssions = pp.network.get_import_supported_extensions()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a 's' to remove here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

assert ['RAW', 'RAWX', 'UCT', 'biidm', 'bin', 'dgs', 'iidm', 'jiidm', 'json', 'mat', 'raw', 'rawx', 'txt', 'uct', 'xiidm', 'xml'] == extenssions


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