Commit 74c60b82 authored by Philipp Reuber's avatar Philipp Reuber
Browse files

modify examples, modify documentation

parent a4917eea
Pipeline #250365 passed with stages
in 1 minute and 39 seconds
recursive-include examples *.xml
\ No newline at end of file
recursive-include examples *.xml *.py
\ No newline at end of file
from cimpy.cimexport import cim_export
from cimpy.cimimport import cim_import
import cimpy.utils
from cimpy.examples.importCIGREMV import import_example
from cimpy.examples.exportCIGREMV import export_example
from cimpy.examples import import_example
from cimpy.examples import export_example
from pathlib import Path
def import_example():
base = Path(__file__).resolve().parent.parent
example = base / 'examples' / 'quickstart' / 'importCIGREMV.py'
exec(open(example).read())
def export_example():
base = Path(__file__).resolve().parent.parent
example = base / 'examples' / 'quickstart' / 'exportCIGREMV.py'
exec(open(example).read())
\ No newline at end of file
import logging
import os
import cimpy
def convert_bus_branch_example():
logging.basicConfig(filename='Convert_to_Bus_Branch.log', level=logging.INFO, filemode='w')
xml_files = [r"..\sampledata\Sample_Grid_Switches\Node-Breaker\20191030T0924Z_XX_YYY_DL_.xml",
r"..\sampledata\Sample_Grid_Switches\Node-Breaker\20191030T0924Z_XX_YYY_GL_.xml",
r"..\sampledata\Sample_Grid_Switches\Node-Breaker\20191030T0924Z_XX_YYY_SSH_.xml",
r"..\sampledata\Sample_Grid_Switches\Node-Breaker\20191030T0924Z_XX_YYY_SV_.xml",
r"..\sampledata\Sample_Grid_Switches\Node-Breaker\20191030T0924Z_XX_YYY_TP_.xml",
r"..\sampledata\Sample_Grid_Switches\Node-Breaker\20191030T0924Z_YYY_EQ_.xml",]
xml_files_abs = []
for file in xml_files:
xml_files_abs.append(os.path.abspath(file))
# res = cimpy.cimread(xml_files)
res, namespaces = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
bus_branch = cimpy.utils.node_breaker_to_bus_branch(res)
# dicts = cimpy.get_class_attributes_dict(res)
cimpy.cim_export(bus_branch, namespaces, 'Bus_Branch_Converted', 'cgmes_v2_4_15')
\ No newline at end of file
import logging
import os
import cimpy
def export_example():
logging.basicConfig(filename='exportCIGREMV.log', level=logging.INFO, filemode='w')
cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
xml_files = [r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_DI.xml",
r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_EQ.xml",
r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_SV.xml",
r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_TP.xml", ]
xml_files_abs = []
for file in xml_files:
xml_files_abs.append(os.path.abspath(file))
# res = cimpy.cimread(xml_files)
import_result = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
activeProfileList = ['DI', 'EQ', 'SV', 'TP']
# dicts = cimpy.get_class_attributes_dict(res)
cimpy.cim_export(import_result, 'CIGREMV_reference_cgmes_v2_4_15', 'cgmes_v2_4_15', activeProfileList)
os.chdir(cwd)
import logging
import os
import cimpy
def import_example():
logging.basicConfig(filename='importCIGREMV.log', level=logging.INFO, filemode='w')
cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
xml_files = [r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_DI.xml",
r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_EQ.xml",
r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_SV.xml",
r"..\..\examples\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_TP.xml", ]
xml_files_abs = []
for file in xml_files:
xml_files_abs.append(os.path.abspath(file))
# res = cimpy.cimread(xml_files)
import_result = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
print("\n\n")
results = ["ACLineSegment", "PowerTransformer", "EnergyConsumer"]
for key, value in import_result['topology'].items():
if value.__class__.__name__ in results:
print(value.__str__())
os.chdir(cwd)
......@@ -7,7 +7,7 @@ For this export example we use the result from the import example. The whole exp
.. code-block:: python
import_result = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15")
For the function cim_export a list containing all profiles which should be used for the export is needed. For more information about the arguments of the cim_export function see `Functions <https://acs.pages.rwth-aachen.de/public/cim/cimpy/Functions.html>`_.
......
......@@ -8,9 +8,9 @@ First import the CIMpy module and set up the logger. If there is not a file set
.. code-block:: python
import cimpy
import logging
import os
import cimpy
from pathlib import Path
logging.basicConfig(filename='importCIGREMV.log', level=logging.INFO, filemode='w')
......@@ -18,19 +18,20 @@ Next we need the absolute path of the XML/RDF files.
.. code-block:: python
xml_files = [r"..\sampledata\CIGRE_MV\CIGRE_MV_Rudion_With_LoadFLow_Results\Rootnet_FULL_NE_24J13h_EQ.xml",
r"..\sampledata\CIGRE_MV\CIGRE_MV_Rudion_With_LoadFLow_Results\Rootnet_FULL_NE_24J13h_SV.xml",
r"..\sampledata\CIGRE_MV\CIGRE_MV_Rudion_With_LoadFLow_Results\Rootnet_FULL_NE_24J13h_TP.xml", ]
example = Path('.').resolve()
sample_folder = example / 'examples' / 'sampledata' / 'CIGRE_MV'
sample_files = sample_folder.glob('*.xml')
xml_files_abs = []
for file in xml_files:
xml_files_abs.append(os.path.abspath(file))
xml_files = []
for file in sample_folder.glob('*.xml'):
xml_files.append(str(file.absolute()))
In the next step the files given in xml_files_abs are imported:
.. code-block:: python
import_result = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15")
For more information about the function cim_import see `Functions <https://acs.pages.rwth-aachen.de/public/cim/cimpy/Functions.html>`_.
......
......@@ -10,6 +10,8 @@ For a quick example for the import just run
.. code-block:: python
import cimpy
cimpy.import_example()
This example imports grid data stored in XML/RDF files and prints a subset of the created objects. For deeper insights into the example check the import example documentation:
......@@ -26,6 +28,8 @@ For a quick example for the export just run
.. code-block:: python
import cimpy
cimpy.export_example()
This example uses the import result of the import example and exports them back to RDF/XML files. For deeper insights into the example check the export example documentation:
......
import logging
import os
from pathlib import Path
import cimpy
logging.basicConfig(filename='exportCIGREMV.log', level=logging.INFO, filemode='w')
xml_files = [r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_DI.xml",
r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_EQ.xml",
r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_SV.xml",
r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_TP.xml", ]
example = Path('.').resolve()
sample_folder = example / 'examples' / 'sampledata' / 'CIGRE_MV'
sample_files = sample_folder.glob('*.xml')
xml_files_abs = []
for file in xml_files:
xml_files_abs.append(os.path.abspath(file))
xml_files = []
for file in sample_folder.glob('*.xml'):
xml_files.append(str(file.absolute()))
# res = cimpy.cimread(xml_files)
import_result = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15")
activeProfileList = ['DI', 'EQ', 'SV', 'TP']
# dicts = cimpy.get_class_attributes_dict(res)
cimpy.cim_export(import_result, 'CIGREMV_reference_cgmes_v2_4_15', 'cgmes_v2_4_15', activeProfileList)
import logging
import os
import cimpy
from pathlib import Path
logging.basicConfig(filename='importCIGREMV.log', level=logging.INFO, filemode='w')
print(os.getcwd())
xml_files = [r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_DI.xml",
r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_EQ.xml",
r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_SV.xml",
r"..\sampledata\CIGRE_MV\Rootnet_FULL_NE_24J13h_TP.xml", ]
example = Path('.').resolve()
sample_folder = example / 'examples' / 'sampledata' / 'CIGRE_MV'
sample_files = sample_folder.glob('*.xml')
xml_files_abs = []
for file in xml_files:
xml_files_abs.append(os.path.abspath(file))
xml_files = []
for file in sample_folder.glob('*.xml'):
xml_files.append(str(file.absolute()))
# res = cimpy.cimread(xml_files)
import_result = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15")
print("\n\n")
results = ["ACLineSegment", "PowerTransformer", "EnergyConsumer"]
for key, value in import_result['topology'].items():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment