Commit c8fad311 authored by Bichen Li's avatar Bichen Li

- First vision of Assertion function

- build an init file
parent a4e03edf
#!/usr/bin/python #!/usr/bin/python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import re import re
import os
import sys
sys.path.append(r'D:\HIWI\Git\data-processing\dataprocessing')
from dataprocessing.readtools import * from dataprocessing.readtools import *
def compare_modelica_neplan(Net_Name): def compare_modelica_neplan(Net_Name):
# Read in original nepaln result file # Read in original nepaln result file
file_Neplan = os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + ".rlf") file_Neplan = os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + ".rlf")
...@@ -11,14 +12,14 @@ def compare_modelica_neplan(Net_Name): ...@@ -11,14 +12,14 @@ def compare_modelica_neplan(Net_Name):
file_Modelica = os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + ".mat") file_Modelica = os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + ".mat")
result_neplan = read_timeseries_NEPLAN_loadflow(file_Neplan) result_neplan = read_timeseries_NEPLAN_loadflow(file_Neplan)
result_modelica = read_timeseries_Modelica(file_Modelica) result_modelica = read_timeseries_Modelica(file_Modelica)
'''
# neplan result output # neplan result output
f_neplan = open(os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + "_neplan.txt"), "w") f_neplan = open(os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + "_neplan.txt"), "w")
# modelica result output # modelica result output
f_modelica = open(os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + "_modelica.txt"), "w") f_modelica = open(os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + "_modelica.txt"), "w")
# error result output # error result output
f_error = open(os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name + f_error = open(os.path.abspath("C:/Users/admin/Desktop/" + Net_Name + "/" + Net_Name +
"_error_modelica_neplan.txt"), "w") "_error_modelica_neplan.txt"), "w")'''
list_del = [] list_del = []
for i in range(len(result_neplan)): for i in range(len(result_neplan)):
result_neplan[i].name = result_neplan[i].name.replace(' ', '') result_neplan[i].name = result_neplan[i].name.replace(' ', '')
...@@ -27,30 +28,31 @@ def compare_modelica_neplan(Net_Name): ...@@ -27,30 +28,31 @@ def compare_modelica_neplan(Net_Name):
pass pass
else: else:
result_neplan[i].values = result_neplan[i].values * 1000 # unification of the unit,which is kV/kA in neplan result_neplan[i].values = result_neplan[i].values * 1000 # unification of the unit,which is kV/kA in neplan
f_neplan.write( '''f_neplan.write(
'%s is %s \n' % (result_neplan[i].name, result_neplan[i].values[0])) # result as list of TimeSeries '%s is %s \n' % (result_neplan[i].name, result_neplan[i].values[0])) # result as list of TimeSeries'''
for i in range(len(result_modelica)): for i in range(len(result_modelica)):
result_modelica[i].name = result_modelica[i].name.upper() result_modelica[i].name = result_modelica[i].name.upper()
if 'ANGLE' in result_modelica[i].name: if 'ANGLE' in result_modelica[i].name:
result_modelica[i].values = result_modelica[i].values / cmath.pi * 180 # unification of the unit result_modelica[i].values = result_modelica[i].values / cmath.pi * 180 # unification of the unit
f_modelica.write('%s is %s \n' % (result_modelica[i].name, result_modelica[i].values[1])) #f_modelica.write('%s is %s \n' % (result_modelica[i].name, result_modelica[i].values[1]))
timeseries_names = [] # list for names
timeseries_error = [] # list for error timeseries_error = [] # list for error
len_limit = len(result_modelica) len_limit = len(result_modelica)
for i in range(len(result_neplan)): for i in range(len(result_neplan)):
flag_NOT_found = False flag_NOT_found = False
for j in range(len_limit): for j in range(len_limit):
if result_neplan[i].name == result_modelica[j].name: # Find the same variable if result_neplan[i].name == result_modelica[j].name: # Find the same variable
timeseries_error.append(TimeSeries(result_neplan[i].name, result_modelica[j].time, timeseries_names.append(result_neplan[i].name)
TimeSeries.rmse(result_modelica[j], result_neplan[i]))) timeseries_error.append(TimeSeries.rmse(result_modelica[j], result_neplan[i]))
j = len_limit + 1
flag_NOT_found = True flag_NOT_found = True
if not flag_NOT_found: if not flag_NOT_found:
timeseries_error.append(TimeSeries(result_neplan[i].name, 0, -1)) timeseries_error.append(TimeSeries(result_neplan[i].name, 0, -1))
# No such variable in Modelica model, set the error to -1 # No such variable in Modelica model, set the error to -1
'''
f_error.write('Error of %s is %f \n Base value' f_error.write('Error of %s is %f \n Base value'
' of %s is %s \n\n' % (timeseries_error[i].name, timeseries_error[i].values, ' of %s is %s \n\n' % (timeseries_error[i].name, timeseries_error[i].values,
timeseries_error[i].name, result_neplan[i].values[0])) timeseries_error[i].name, result_neplan[i].values[0]))'''
return dict(zip(timeseries_names, timeseries_error))
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