Commit e69f6d76 authored by Bichen Li's avatar Bichen Li Committed by Bichen Li

-Correct the file name, use comparison as function

parent 00cc7059

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

Test:
script: Try.sh
#!/bin/bash
net_name="Slack_ZLoad"
python /home/cafi/Desktop/data-processing/examples/Assert_Results/Assert_Results.py $net_name
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
import os
import sys
sys.path.append(r'/home/cafi/Desktop/data-processing/dataprocessing')
from readtools import *
def compare_modelica_neplan(Net_Name): # compare the result file from NEPLAN and Modelica
# Read in original nepaln result file
file_Neplan = os.path.abspath("/home/cafi/Desktop/" + Net_Name + "/" + Net_Name + ".rlf")
# Read in original Modelica result file
file_Modelica = os.path.abspath("/home/cafi/Desktop/" + Net_Name + "/" + Net_Name + ".mat")
result_neplan = read_timeseries_NEPLAN_loadflow(file_Neplan)
result_modelica = read_timeseries_Modelica(file_Modelica)
list_del = []
for i in range(len(result_neplan)):
result_neplan[i].name = result_neplan[i].name.replace(' ', '')
result_neplan[i].name = result_neplan[i].name.upper()
if 'ANGLE' in result_neplan[i].name:
pass
else:
result_neplan[i].values = result_neplan[i].values * 1000 # unification of the unit,which is kV/kA in neplan
for i in range(len(result_modelica)):
result_modelica[i].name = result_modelica[i].name.upper()
if 'ANGLE' in result_modelica[i].name:
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]))
timeseries_names = [] # list for names
timeseries_error = [] # list for error
len_limit = len(result_modelica)
for i in range(len(result_neplan)):
flag_NOT_found = False
for j in range(len_limit):
if result_neplan[i].name == result_modelica[j].name: # Find the same variable
timeseries_names.append(result_neplan[i].name)
timeseries_error.append(TimeSeries.rmse(result_modelica[j], result_neplan[i]))
flag_NOT_found = True
if not flag_NOT_found:
timeseries_error.append(TimeSeries(result_neplan[i].name, 0, -1))
# No such variable in Modelica model, set the error to -1
return dict(zip(timeseries_names, timeseries_error))
def assert_modelia_neplan_results(net_name): # Assert the model using the function above
fail_list = []
error = compare_modelica_neplan(net_name)
for name in error.keys():
if abs(error[name]) > 0.5:
fail_list.append(name)
else:
print("Test on %s Passed" % name)
if len(fail_list) is 0:
print("\033[1;36;40mModel Passed\033[0m")
else:
for name in fail_list:
print("\033[1;31;40mTest on %s Failed\033[0m" % name)
import numpy as np
import pandas as pd
from .timeseries import *
from timeseries import *
import re
import cmath
......@@ -30,8 +30,8 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
for name in timeseries_names:
timeseries.append(TimeSeries(name, sim(name).times(), sim(name).values()))
print('Modelica results column names: ' + str(timeseries_names))
print('Modelica results number: ' + str(len(timeseries_names)))
#print('Modelica results column names: ' + str(timeseries_names))
#print('Modelica results number: ' + str(len(timeseries_names)))
return timeseries
......
import re
import os
import sys
sys.path.append(r'/home/cafi/Desktop/data-processing/dataprocessing')
from Validationtools import *
from readtools import *
print("Test Start")
assert_modelia_neplan_results(sys.argv[1]) # Assert the result, model result path read from cmd line
print("Test End")
\ No newline at end of file
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
from dataprocessing.readtools import *
from readin import read_timeseries_NEPLAN_loadflow1
# Read in original nepaln result file
file_Neplan = r"C:\Users\admin\Desktop\Slack_RxLine_PVNode\Slack_RxLine_PVNode.rlf"
# Read in original Modeliac result file
file_Modelica = r"C:\Users\admin\Desktop\Slack_RxLine_PVNode\Slack_RxLine_PVNode.mat"
result_neplan = read_timeseries_NEPLAN_loadflow1(file_Neplan)
result_modelica = read_timeseries_Modelica(file_Modelica)
# neplan result output
f_neplan = open(r"C:\Users\admin\Desktop\Slack_RxLine_PVNode\Slack_RxLine_PVNode_neplan.txt", "w")
# modelica result output
f_modelica = open(r"C:\Users\admin\Desktop\Slack_RxLine_PVNode\Slack_RxLine_PVNode_modelica.txt", "w")
# error result output
f_error = open(r"C:\Users\admin\Desktop\Slack_RxLine_PVNode\output_error_modelica-neplan.txt", "w")
list_del = []
for i in range(len(result_neplan)):
result_neplan[i].name = result_neplan[i].name.replace(' ', '')
result_neplan[i].name = result_neplan[i].name.upper()
if 'ANGLE' in result_neplan[i].name:
pass
else:
result_neplan[i].values = result_neplan[i].values * 1000 # unification of the unit,which is kV/kA in neplan
f_neplan.write('%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)):
result_modelica[i].name = result_modelica[i].name.upper()
if 'ANGLE' in result_modelica[i].name:
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]))
timeseries_error = [] # list for error
len_limit = len(result_modelica)
for i in range(len(result_neplan)):
flag_NOT_found = False
for j in range(len_limit):
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.rmse(result_modelica[j], result_neplan[i])))
j = len_limit + 1
flag_NOT_found = True
if not flag_NOT_found:
timeseries_error.append(TimeSeries(result_neplan[i].name, 0, -1))
# No such variable in Modelica model, set the error to -1