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

Merge branch 'master' of git.rwth-aachen.de:acs/public/simulation/data-processing

parents e1f08571 93b7f93a
[*.py]
indent_style = space
indent_size = 4
......@@ -43,4 +43,4 @@ for i in range(len(ts_dpsimList)):
print('************************ convert dpsim to modelica end ****************')
res_err=validationtools.compare_timeseries(res_ref,ts_dpsimList)
validationtools.assert_modelia_results(net_name,res_err,threshold)
\ No newline at end of file
validationtools.assert_modelica_results(net_name,res_err,threshold)
\ No newline at end of file
#!/usr/bin/python
# -*- coding: UTF-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)
for i in range(len(result_ALL)):
print('%s is %s' % (result_ALL[i].name, result_ALL[i].values)) # result as list of TimeSeries
print('************************ Test for read in all variable end ****************')
print('\n')
# Example 2: Read in specific variable
print('************************ Test for read in specific variable start ****************')
print('************************ Read in specific Voltage ****************')
result_U = read_timeseries_NEPLAN_loadflow(file, 'FOUR.U')
for i in range(len(result_U)):
print('%s is %s' % (result_U[i].name, result_U[i].values))
print('************************ Read in specific Voltage Angel ****************')
result_ANGELU = read_timeseries_NEPLAN_loadflow(file, 'FOUR.ANGELU')
for i in range(len(result_ANGELU)):
print('%s is %s' % (result_ANGELU[i].name, result_ANGELU[i].values))
print('************************ Read in specific Current ****************')
result_I = read_timeseries_NEPLAN_loadflow(file, 'LINE89.I')
for i in range(len(result_I)):
print('%s is %s' % (result_I[i].name, result_I[i].values))
print('************************ Read in specific Current Angel ****************')
result_ANGELI = read_timeseries_NEPLAN_loadflow(file, 'LINE89.ANGELI')
for i in range(len(result_ANGELI)):
print('%s is %s' % (result_ANGELI[i].name, result_ANGELI[i].values))
print('************************ Test for read in specific variable end ****************')
print('\n')
# Example 3: Read in using regular expression
print('************************ Test for read in using Regular Expression start ****************')
print('************************ Read in Current using Regular Expression ****************')
result_I_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.I$', True)
for i in range(len(result_I_REG)):
print('%s is %s' % (result_I_REG[i].name, result_I_REG[i].values))
print('************************ Read in Current Angel using Regular Expression ****************')
result_ANGERLI_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.ANGELI$', True)
for i in range(len(result_ANGERLI_REG)):
print('%s is %s' % (result_ANGERLI_REG[i].name, result_ANGERLI_REG[i].values))
print('************************ Read in Voltage using Regular Expression ****************')
result_U_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.U$', True)
for i in range(len(result_U_REG)):
print('%s is %s' % (result_U_REG[i].name, result_U_REG[i].values))
print('************************ Read in Voltage Angel using Regular Expression ****************')
result_ANGELU_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.ANGELU$', True)
for i in range(len(result_ANGELU_REG)):
print('%s is %s' % (result_ANGELU_REG[i].name, result_ANGELU_REG[i].values))
print('************************ Test for read in using Regular Expression end ****************')
\ No newline at end of file
#!/usr/bin/python
# -*- coding: UTF-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)
for i in range(len(result_ALL)):
print('%s is %s' % (result_ALL[i].name, result_ALL[i].values)) # result as list of TimeSeries
print('************************ Test for read in all variable end ****************')
print('\n')
# Example 2: Read in specific variable
print('************************ Test for read in specific variable start ****************')
print('************************ Read in specific Voltage ****************')
result_U = read_timeseries_NEPLAN_loadflow(file, 'FOUR.U')
for i in range(len(result_U)):
print('%s is %s' % (result_U[i].name, result_U[i].values))
print('************************ Read in specific Voltage Angel ****************')
result_ANGELU = read_timeseries_NEPLAN_loadflow(file, 'FOUR.ANGELU')
for i in range(len(result_ANGELU)):
print('%s is %s' % (result_ANGELU[i].name, result_ANGELU[i].values))
print('************************ Read in specific Current ****************')
result_I = read_timeseries_NEPLAN_loadflow(file, 'LINE89.I')
for i in range(len(result_I)):
print('%s is %s' % (result_I[i].name, result_I[i].values))
print('************************ Read in specific Current Angel ****************')
result_ANGELI = read_timeseries_NEPLAN_loadflow(file, 'LINE89.ANGELI')
for i in range(len(result_ANGELI)):
print('%s is %s' % (result_ANGELI[i].name, result_ANGELI[i].values))
print('************************ Test for read in specific variable end ****************')
print('\n')
# Example 3: Read in using regular expression
print('************************ Test for read in using Regular Expression start ****************')
print('************************ Read in Current using Regular Expression ****************')
result_I_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.I$', True)
for i in range(len(result_I_REG)):
print('%s is %s' % (result_I_REG[i].name, result_I_REG[i].values))
print('************************ Read in Current Angel using Regular Expression ****************')
result_ANGERLI_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.ANGELI$', True)
for i in range(len(result_ANGERLI_REG)):
print('%s is %s' % (result_ANGERLI_REG[i].name, result_ANGERLI_REG[i].values))
print('************************ Read in Voltage using Regular Expression ****************')
result_U_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.U$', True)
for i in range(len(result_U_REG)):
print('%s is %s' % (result_U_REG[i].name, result_U_REG[i].values))
print('************************ Read in Voltage Angel using Regular Expression ****************')
result_ANGELU_REG = read_timeseries_NEPLAN_loadflow(file, '^.*\.ANGELU$', True)
for i in range(len(result_ANGELU_REG)):
print('%s is %s' % (result_ANGELU_REG[i].name, result_ANGELU_REG[i].values))
print('************************ Test for read in using Regular Expression end ****************')
#!/usr/bin/python
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)
plt.show()
__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
separately
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
......@@ -210,9 +209,9 @@ def read_timeseries_NEPLAN_loadflow(file_name, timeseries_names=None, is_regex=F
high += 1
"""
A typical line current in neplan has two parts from both end, but we doesn't have to calculate them
with the assumption that the topology of the gird should be correct with which we can validate the
current by comparing the voltage of the nodes connected to the ends of the line
A typical line current in neplan has two parts from both end, but we doesn't have to calculate them
with the assumption that the topology of the gird should be correct with which we can validate the
current by comparing the voltage of the nodes connected to the ends of the line
"""
if flag is not True: # flag is true when it's the first line
if value[3] is not '#':
......@@ -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
separately.
......@@ -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.
See: https://villas.fein-aachen.org/doc/node-formats.html
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] == '#':
continue
sample = Sample.parse(line)
times.append(sample.ts)
for index, field in enumerate(sample.values, start=0):
if len(fields) <= index:
fields.append([])
fields[index].append(field)
for index, field in enumerate(fields):
name = 'signal_{}'.format(index)
series = TimeSeries(name, times, field)
timeseries.append(series)
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
timeseries_names.append(ts1[i].name)
......@@ -132,15 +132,16 @@ def compare_timeseries(ts1, ts2):
print(ts1[i].name)
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
timeseries_names.append(ts1[i].name)
timeseries_error.append(-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:
fail_list.append(name)
......@@ -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.name)
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(res.name)
print(res.values)
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