This repository has been archived by the owner on Dec 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from sogno-platform/feature/api
working powerflow calculation on pydantic loaded cim data
- Loading branch information
Showing
7 changed files
with
102 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import glob | ||
import os | ||
from pathlib import Path | ||
from typing import Dict, Any | ||
import requests | ||
import cimpy | ||
from power_grid_model import PowerGridModel | ||
|
||
from pgm_service.power_grid.models import Grid | ||
from pgm_service.power_grid.cgmes_pgm_converter import System as CGMESToPGMConverter | ||
|
||
|
||
def download_data(url): | ||
def download_grid_data(name, url): | ||
with open(name, 'wb') as out_file: | ||
content = requests.get(url, stream=True).content | ||
out_file.write(content) | ||
|
||
url = 'https://raw.githubusercontent.com/dpsim-simulator/cim-grid-data/master/BasicGrids/NEPLAN/Slack_Load_Line_Sample/' | ||
filename = 'Rootnet_FULL_NE_19J18h' | ||
|
||
download_grid_data(filename+'_EQ.xml', url + filename + '_EQ.xml') | ||
download_grid_data(filename+'_TP.xml', url + filename + '_TP.xml') | ||
download_grid_data(filename+'_SV.xml', url + filename + '_SV.xml') | ||
|
||
files = glob.glob(filename+'_*.xml') | ||
|
||
print('CGMES files downloaded:') | ||
print(files) | ||
|
||
this_file_folder = Path(__file__).parents[3] | ||
p = str(this_file_folder) | ||
xml_path = Path(p) | ||
xml_files = [os.path.join(xml_path, filename+'_EQ.xml'), | ||
os.path.join(xml_path, filename+'_TP.xml'), | ||
os.path.join(xml_path, filename+'_SV.xml')] | ||
|
||
print(xml_files) | ||
return xml_files | ||
|
||
|
||
def create_model(grid: Grid): # TODO make async | ||
xml_files = download_data(url=grid.input_data) | ||
cgmes_data = cimpy.cim_import(xml_files, "cgmes_v2_4_15") | ||
converter = CGMESToPGMConverter() | ||
converter.load_cim_data(cgmes_data) | ||
pgm_data = converter.create_pgm_input() | ||
return PowerGridModel(input_data=pgm_data, system_frequency=grid.system_frequency) | ||
|
||
|
||
def produce_output(grid: Grid, calculation_result: Any): | ||
print(calculation_result) | ||
|
||
|
||
async def calculate_powerflow(grid: Grid, pf_kwargs: Dict[str, Any]): | ||
model = create_model(grid=grid) | ||
calculation_result = model.calculate_power_flow(**pf_kwargs) | ||
produce_output(grid, calculation_result) |
This file was deleted.
Oops, something went wrong.