def test_export_with_exported_files(sample_cimdata, tmpdir): activeProfileList = ['DL', 'EQ', 'SV', 'TP'] cimpy.cim_export(sample_cimdata, tmpdir + '/EXPORTED_Test', 'cgmes_v2_4_15', activeProfileList) test_dict = read_ref_xml() export_dict = read_exported_xml(tmpdir) for profile, current_test_dict in test_dict.items(): check.is_in(profile, export_dict.keys()) if profile in export_dict.keys(): current_export_dict = export_dict[profile] for class_key in current_test_dict: if 'cim:' not in class_key: continue check.is_in(class_key, current_export_dict.keys()) if class_key in current_export_dict.keys(): current_export_class = current_export_dict[class_key] current_test_class = current_test_dict[class_key] if isinstance(current_test_class, list): for item in current_test_class: check.is_in(item, current_export_class) else: check.equal(current_test_class, current_export_class)
def test_export_with_imported_files(sample_cimdata, tmpdir): activeProfileList = ['DL', 'EQ', 'SSH', 'SV', 'TP'] cimpy.cim_export(sample_cimdata, tmpdir + '/EXPORTED_Test', 'cgmes_v2_4_15', activeProfileList) test_dict = read_ref_xml() export_dict = read_exported_xml(tmpdir) for profile, current_test_dict in test_dict.items(): check.is_in(profile, export_dict.keys()) if profile in export_dict.keys(): current_export_dict = export_dict[profile] for class_key in current_test_dict: if 'cim:' not in class_key or class_key in ['cim:NameType', 'cim:Name']: continue check.is_in(class_key, current_export_dict.keys()) if class_key in current_export_dict.keys(): current_export_class = current_export_dict[class_key] current_test_class = current_test_dict[class_key] test_mRIDs = [] test_class_dict = {} if isinstance(current_test_class, list): for obj in current_test_class: try: test_mRIDs.append(obj['$rdf:ID']) test_class_dict[obj['$rdf:ID']] = obj except KeyError: try: test_mRIDs.append(obj['$rdf:about']) test_class_dict[obj['$rdf:about']] = obj except KeyError: check.is_in('$rdf:about', obj.keys()) check.is_in('$rdf:ID', obj.keys()) else: try: test_mRIDs.append(current_test_class['$rdf:ID']) test_class_dict[current_test_class['$rdf:ID'] ] = current_test_class except KeyError: try: test_mRIDs.append( current_test_class['$rdf:about']) test_class_dict[current_test_class['$rdf:about']] = obj except KeyError: check.is_in( '$rdf:about', current_test_class.keys()) check.is_in( '$rdf:ID', current_test_class.keys()) export_mRIDs = [] export_class_dict = {} if isinstance(current_export_class, list): for obj in current_export_class: try: export_mRIDs.append(obj['$rdf:ID']) export_class_dict[obj['$rdf:ID']] = obj except KeyError: try: export_mRIDs.append(obj['$rdf:about']) export_class_dict[obj['$rdf:about']] = obj except KeyError: check.is_in('$rdf:about', obj.keys()) check.is_in('$rdf:ID', obj.keys()) else: try: export_mRIDs.append( current_export_class['$rdf:ID']) export_class_dict[current_export_class['$rdf:ID'] ] = current_export_class except KeyError: try: export_mRIDs.append( current_export_class['$rdf:about']) export_class_dict[current_export_class['$rdf:about']] = obj except KeyError: check.is_in( '$rdf:about', current_export_class.keys()) check.is_in( '$rdf:ID', current_export_class.keys()) for mRID in test_mRIDs: check.is_in(mRID, export_mRIDs) if mRID in export_mRIDs: test_attr = test_class_dict[mRID].items() export_attr = export_class_dict[mRID].items() for item in test_attr: if item[0] in ['cim:NameType', 'cim:ExternalNetworkInjection.referencePriority', 'cim:Terminal.connected']: continue elif item[0] == 'cim:Terminal.sequenceNumber': test_item = 'cim:ACDCTerminal.sequenceNumber' else: test_item = item[0] if item[1] in ['0', '0e+000', '0.0', '', 'false', 'None', 'list', {'$rdf:resource': '#_32d6d32e-c3f0-43d4-8103-079a15594fc6'}]: continue if isinstance(item[1], dict) or isinstance(item[1], list): test_item = item elif len(item[1].split('.')) > 1: try: test_item = ( item[0], str(float(item[1]))) except ValueError: continue except TypeError: pass elif item[1] == 'true': test_item = (test_item, 'True') else: test_item = (test_item, item[1]) check.is_in(test_item, export_attr)
import logging from pathlib import Path import cimpy logging.basicConfig(filename='exportCIGREMV.log', level=logging.INFO, filemode='w') example = Path(__file__).resolve().parent # called as cimpy.examples.import_example() or file run from quickstart directory? if 'cimexamples.py' in str(__file__): sample_folder = example / 'examples' / 'sampledata' / 'CIGRE_MV' else: sample_folder = example / 'sampledata' / 'CIGRE_MV' sample_files = sample_folder.glob('*.xml') xml_files = [] for file in sample_folder.glob('*.xml'): xml_files.append(str(file.absolute())) import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15") activeProfileList = ['DL', 'EQ', 'SV', 'TP'] cimpy.cim_export(import_result, 'CIGREMV_reference_cgmes_v2_4_15', 'cgmes_v2_4_15', activeProfileList)
import logging import cimpy from pathlib import Path logging.basicConfig(filename='Convert_to_Bus_Branch.log', level=logging.INFO, filemode='w') example = Path(__file__).resolve().parent # called as cimpy.examples.convertBusBranch() or file run from quickstart directory? if 'cimexamples.py' in str(__file__): sample_folder = example / 'examples' / 'sampledata' / 'Sample_Grid_Switches' / 'Node-Breaker' else: sample_folder = example / 'sampledata' / 'Sample_Grid_Switches' / 'Node-Breaker' sample_files = sample_folder.glob('*.xml') xml_files = [] for file in sample_folder.glob('*.xml'): xml_files.append(str(file.absolute())) import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15") import_result = cimpy.utils.node_breaker_to_bus_branch(import_result) activeProfileList = ['DL', 'EQ', 'TP'] cimpy.cim_export(import_result, 'Bus_Branch_Converted', 'cgmes_v2_4_15', activeProfileList)
import cimpy from pathlib import Path logging.basicConfig(filename='importCIGREMV.log', level=logging.INFO, filemode='w') example = Path(__file__).resolve().parent # called as cimpy.examples.addExternalNetworkInjection() or file run from quickstart directory? if 'cimexamples.py' in str(__file__): sample_folder = example / 'examples' / 'sampledata' / 'CIGRE_MV' else: sample_folder = example / 'sampledata' / 'CIGRE_MV' sample_files = sample_folder.glob('*.xml') xml_files = [] for file in sample_folder.glob('*.xml'): xml_files.append(str(file.absolute())) import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15") import_result = cimpy.utils.add_external_network_injection( import_result, "cgmes_v2_4_15", "N1", 20.0) activeProfileList = ['DL', 'EQ', 'SV', 'TP'] cimpy.cim_export(import_result, 'ExternalInjection', 'cgmes_v2_4_15', activeProfileList)