Commit 959526a3 authored by Markus Mirz's avatar Markus Mirz

Merge branch 'master' of

parents e1f08571 93b7f93a
indent_style = space
indent_size = 4
......@@ -43,4 +43,4 @@ for i in range(len(ts_dpsimList)):
print('************************ convert dpsim to modelica end ****************')
\ No newline at end of file
\ No newline at end of file
......@@ -3,10 +3,8 @@
import re
from dataprocessing.readtools import *
file = r"C:\Users\admin\Desktop\Load_read\Load_flow_WCSS.rlf"
# Example 1: Read in all variable
print('************************ Test for read in all variable start ****************')
result_ALL = read_timeseries_NEPLAN_loadflow(file)
import sys
import villas.dataprocessing.readtools as rt
import villas.dataprocessing.plottools as pt
import matplotlib.pyplot as plt
filename = sys.argv[1]
timeseries = rt.read_timeseries_villas(filename)
pt.plot_timeseries(1, timeseries)
__all__ = ["readtools", "plottools", "timeseries"]
\ No newline at end of file
__all__ = ["readtools", "plottools", "timeseries", "validationtools"]
\ No newline at end of file
......@@ -38,7 +38,6 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
return timeseries
def read_timeseries_csv(filename, timeseries_names=None, print_status=True):
"""Reads complex time series data from DPsim log file. Real and
imaginary part are stored in one complex variable.
......@@ -160,19 +159,19 @@ def read_timeseries_PLECS(filename, timeseries_names=None):
return timeseries_list
def read_timeseries_NEPLAN_loadflow(file_name, timeseries_names=None, is_regex=False):
def read_timeseries_NEPLAN_loadflow(filename, timeseries_names=None, is_regex=False):
Read in NEPLAN loadflow result from result file, the result is in angle notation, amplitude and angle are stored
To keep consistent with the names of voltage in most cases, the name of voltage variables are changed into '.V*'
instead of '.U*' as in the result file
:param file_name: name of the mat file for the loadflow result from neplan
:param filename: name of the mat file for the loadflow result from neplan
:param timeseries_names: column name to be read
:param is_regex: flag for using regular expression
:return: list of Timeseries objects
str_tmp = open(file_name, "r") # Read in files
str_tmp = open(filename, "r") # Read in files
low = 0 # flag for the start of a new data in str_cmp
high = 0 # flag for the end of this new data in str_cmp
flag = True # To judge if this is the first line of the file, which will be the names for the data type
......@@ -254,7 +253,7 @@ def read_timeseries_NEPLAN_loadflow(file_name, timeseries_names=None, is_regex=F
return timeseries
def read_timeseries_simulink_loadflow(file_name, timeseries_names=None, is_regex=False):
def read_timeseries_simulink_loadflow(filename, timeseries_names=None, is_regex=False):
Read in simulink load-flow result from result file(.rep), the result is in angle notation, amplitude and angle are stored
......@@ -262,12 +261,12 @@ def read_timeseries_simulink_loadflow(file_name, timeseries_names=None, is_regex
.Arms/.IDegree for current/current angle,
.Vrms/.VDegree for voltage/voltage angle.
:param file_name:path of the .rep file for the loadflow result from simulink
:param filename:path of the .rep file for the loadflow result from simulink
:param timeseries_names: specific values to be read
:param is_regex: flag for using regular expression
:return: list of Timeseries objects
str_tmp = open(file_name, 'r', encoding='latin-1') # Read in files, using latin-1 to decode /xb0
str_tmp = open(filename, 'r', encoding='latin-1') # Read in files, using latin-1 to decode /xb0
# Read in data from result file of neplan
name = [] # list for data type names
......@@ -318,3 +317,44 @@ def read_timeseries_simulink_loadflow(file_name, timeseries_names=None, is_regex
del timeseries[line_del[len(line_del) - num_to_del - 1]]
return timeseries
def read_timeseries_villas(filename):
Read data in "villas.human" format.
Format: seconds.nanoseconds+offset(sequenceno) value0 value1 ... valueN
Example: 1438959964.162102394(6) 3.489760 -1.882725 0.860070
:param filename: name of the file that contains the data
from villas.node.sample import Sample
with open(filename, 'r') as fp:
timeseries = [ ]
times = [ ]
fields = [ ]
for line in fp.readlines():
if line[0] == '#':
sample = Sample.parse(line)
for index, field in enumerate(sample.values, start=0):
if len(fields) <= index:
for index, field in enumerate(fields):
name = 'signal_{}'.format(index)
series = TimeSeries(name, times, field)
return timeseries
......@@ -121,7 +121,7 @@ def compare_timeseries(ts1, ts2):
# Match the components in result files, and compare them
for i in range(len_ts1):
flag_not_found = False
flag_found = False
for j in range(len_limit):
if ts1[i].name == ts2[j].name: # Find the same variable
......@@ -132,15 +132,16 @@ def compare_timeseries(ts1, ts2):
print(timeseries_error[len(timeseries_error) - 1])
flag_not_found = True
if flag_not_found is False:
flag_found = True
if flag_found is False:
# No such variable in Modelica model, set the error to -1
print("Warning: no matching variable found for " + ts1[i].name + "! Skipping error calculation and assertion for this variable...")
# timeseries_names.append(ts1[i].name)
# timeseries_error.append(-1)
return dict(zip(timeseries_names, timeseries_error))
def assert_modelia_results(net_name, error, threshold):
def assert_modelica_results(net_name, error, threshold):
assert the result data of a net.
:param net_name: name of the network
......@@ -149,7 +150,6 @@ def assert_modelia_results(net_name, error, threshold):
:return: outputs to command line which are the results of the assert
fail_list = [] # List for all the failed test
# the limitations are set to 0.5
for name in error.keys():
if abs(error[name]) > threshold:
......@@ -173,11 +173,24 @@ def validate_modelica_res(net_name, modelica_res_path, reference_res_path, thres
:param threshold: the threshold of the assertion, a default value of 0.5 is introduced.
:return: outputs to command line which are the results of the validation.
print('\n************************ Modelica Results ****************')
res_mod = read_timeseries_Modelica (modelica_res_path)
for res in res_mod:
print(res.values[0]) # only show first value of time series
print('\n************************ Reference Results ****************')
if os.path.splitext(reference_res_path)[1] == '.rep':
res_ref = convert_simulink_to_modelica_timeseries(read_timeseries_simulink_loadflow(reference_res_path))
elif os.path.splitext(reference_res_path)[1] == '.rlf':
res_ref = convert_neplan_to_modelica_timeseries(read_timeseries_NEPLAN_loadflow(reference_res_path))
for res in res_ref:
print('\n************************ Comparison ****************')
res_err = compare_timeseries(res_ref, res_mod)
assert_modelia_results(net_name, res_err, threshold)
print('\n************************ Assertion ****************')
assert_modelica_results(net_name, res_err, threshold)
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