def add_model(): """Add a new network model """ # parse the json request new_model = Model.from_dict(connexion.request.form) try: # parse the attached xml files req_files = connexion.request.files.getlist("files") files = [] for f in req_files: # Validate xml input filestr = f.stream.read() ElementTree.fromstring(filestr) f.stream.seek(0) files.append(f.stream) except ElementTree.ParseError: return Error(code=422, message="Invalid XML files"), 422 # create cimpy objects try: cimpy_data = cimpy.cim_import(files, new_model.version) except Exception: return Error(code=422, message="Invalid CIM files"), 422 new_id = model_db.put_model(new_model, cimpy_data, files) # Return the model as `ModelReply` return ModelReply.from_model(new_model, new_id)
def sample_cimdata(): """ Import the sampledata using cimpy """ example_dir = Path(os.path.join(os.path.dirname( __file__), '../cimpy/examples/sampledata/CIGRE_MV')).resolve() import_files = [] for file in example_dir.glob('*.xml'): import_files.append(str(file.absolute())) return cimpy.cim_import(import_files, 'cgmes_v2_4_15')
def create_pickle(): test_files = [] for file in example_path.glob('*.xml'): print("file: ", file) test_files.append(str(file.absolute())) imported_result = cimpy.cim_import(test_files, 'cgmes_v2_4_15') CGMES_object = cimpy.cimexport._get_class_attributes_with_references(imported_result, 'cgmes_v2_4_15') pickle.dump( CGMES_object, open( 'CIGREMV_import_reference_cgmes_v2_4_15.p1', "wb" ) )
def test_import(): """ This function tests the import functionality by importing files and comparing them to previously imported and pickled files. """ global example_dir test_files = [] for file in example_dir.glob('*.xml'): test_files.append(str(file.absolute())) imported_result = cimpy.cim_import(test_files, 'cgmes_v2_4_15') import_resolved = cimpy.cimexport._get_class_attributes_with_references( imported_result, 'cgmes_v2_4_15') ref_dict_path = Path(os.path.join(os.path.dirname( __file__), 'CIGREMV_import_reference_cgmes_v2_4_15.p')) check_dict_pickle = pickle.load(open(ref_dict_path, 'rb')) for elem in import_resolved: check.is_in(elem, check_dict_pickle)
logging.basicConfig(filename='test_switch_nv_state_estimator.log', level=logging.INFO, filemode='w') this_file_folder = os.path.dirname(os.path.realpath(__file__)) xml_path = os.path.realpath( os.path.join(this_file_folder, "..", "sample_data", "CIGRE-MV-NoTap-WithBreaker")) xml_files = [ os.path.join(xml_path, "20191126T1535Z_YYY_EQ_.xml"), os.path.join(xml_path, "20191126T1535Z_XX_YYY_SV_.xml"), os.path.join(xml_path, "20191126T1535Z_XX_YYY_TP_.xml") ] # Read cim files and create new network.System object res = cimpy.cim_import(xml_files, "cgmes_v2_4_15") system = network.System() base_apparent_power = 25 # MW system.load_cim_data(res['topology'], base_apparent_power) # Open breaker system.breakers[-1].open_breaker() system.Ymatrix_calc() # Execute power flow analysis results_pf, num_iter = nv_powerflow.solve(system) # --- State Estimation --- """ Write here the percent uncertainties of the measurements""" V_unc = 0 I_unc = 0