Commit 45aa3db8 authored by Bichen Li's avatar Bichen Li

- Fix some bugs in readtools

 - Fit the assertresults function into the new structure of the package
 - Fix some bugs in validationtools
 - Add more comments
parent 5f05189b
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from dataprocessing.timeseries import * from timeseries import *
import re import re
import cmath
def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False): def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
from modelicares import SimRes from modelicares import SimRes
...@@ -30,9 +29,6 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False): ...@@ -30,9 +29,6 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
for name in timeseries_names: for name in timeseries_names:
timeseries.append(TimeSeries(name, sim(name).times(), sim(name).values())) 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)))
return timeseries return timeseries
...@@ -265,11 +261,13 @@ def read_timeseries_NEPLAN_loadflow(file_name, timeseries_names=None, is_regex=F ...@@ -265,11 +261,13 @@ def read_timeseries_NEPLAN_loadflow(file_name, timeseries_names=None, is_regex=F
pass pass
else: else:
line_del.append(rule_check) line_del.append(rule_check)
# delete those values that are not needed. # delete those values that are not needed.
line_del = set(line_del) line_del = set(line_del)
line_del = sorted(line_del) line_del = sorted(line_del)
for num_to_del in range(len(line_del)): for num_to_del in range(len(line_del)):
del timeseries[line_del[len(line_del) - num_to_del - 1]] del timeseries[line_del[len(line_del) - num_to_del - 1]]
return timeseries return timeseries
...@@ -336,5 +334,4 @@ def read_timeseries_simulink_loadflow(file_name, timeseries_names=None, is_regex ...@@ -336,5 +334,4 @@ def read_timeseries_simulink_loadflow(file_name, timeseries_names=None, is_regex
line_del = sorted(line_del) line_del = sorted(line_del)
for num_to_del in range(len(line_del)): for num_to_del in range(len(line_del)):
del timeseries[line_del[len(line_del) - num_to_del - 1]] del timeseries[line_del[len(line_del) - num_to_del - 1]]
return timeseries return timeseries
\ No newline at end of file
#!/usr/bin/python #!/usr/bin/python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import os import os
from dataprocessing.readtools import *
from readtools import *
def convert_neplan_to_modelica_timeseries(neplan_timeseries): def convert_neplan_to_modelica_timeseries(neplan_timeseries):
...@@ -94,9 +97,13 @@ def compare_timeseries(ts1, ts2): ...@@ -94,9 +97,13 @@ def compare_timeseries(ts1, ts2):
for j in range(len_limit): for j in range(len_limit):
if ts1[i].name == ts2[j].name: # Find the same variable if ts1[i].name == ts2[j].name: # Find the same variable
timeseries_names.append(ts1[i].name) timeseries_names.append(ts1[i].name)
timeseries_error.append(TimeSeries.rmse(ts2[j], ts1[i])/ts1[i].values[1]) if ts1[i].values[0] == 0:
timeseries_error.append(TimeSeries.rmse(ts2[j], ts1[i])) # is it good to do so?
else:
timeseries_error.append(TimeSeries.rmse(ts2[j], ts1[i])/ts1[i].values[0])
print(ts1[i].name) print(ts1[i].name)
print(TimeSeries.rmse(ts2[j], ts1[i])/ts1[i].values[len(ts1[i].values) - 1]) print(timeseries_error[len(timeseries_error) - 1])
flag_not_found = True flag_not_found = True
if flag_not_found is False: if flag_not_found is False:
# No such variable in Modelica model, set the error to -1 # No such variable in Modelica model, set the error to -1
...@@ -116,7 +123,7 @@ def assert_modelia_results(net_name, error): ...@@ -116,7 +123,7 @@ def assert_modelia_results(net_name, error):
fail_list = [] # List for all the failed test fail_list = [] # List for all the failed test
# the limitations are set to 0.5 # the limitations are set to 0.5
for name in error.keys(): for name in error.keys():
if abs(error[name]) > 0.01: if abs(error[name]) > 0.5:
fail_list.append(name) fail_list.append(name)
else: else:
print("Test on %s Passed" % name) print("Test on %s Passed" % name)
......
...@@ -2,14 +2,18 @@ import re ...@@ -2,14 +2,18 @@ import re
import os import os
import sys import sys
from dataprocessing.validationtools import * sys.path.append(r"D:\HIWI\Git\data-processing\dataprocessing")
from dataprocessing.readtools import * from validationtools import *
from readtools import *
os.chdir(r"D:\HIWI\Git")
print("Test Start") print("Test Start")
# We need to extract all the result files from git now # We need to extract all the result files from git now
for files in os.listdir( for files in os.listdir(
os.path.abspath("reference-results/Neplan/BasicGrids")): os.path.abspath("reference-results/Neplan/BasicGrids")):
# Assert the result, model result path read from cmd line # Assert the result, model result path read from cmd line
assert_modelia_neplan_results(os.path.splitext(files)[0], validate_modelica_res(os.path.splitext(files)[0],
os.path.abspath("reference-results/Modelica/BasicGrids/" + os.path.abspath("reference-results/Modelica/BasicGrids/" +
os.path.splitext(files)[0] + ".mat"), os.path.splitext(files)[0] + ".mat"),
os.path.abspath("reference-results/Neplan/BasicGrids/" + os.path.abspath("reference-results/Neplan/BasicGrids/" +
......
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