Commit 8cb14c3d authored by Markus Mirz's avatar Markus Mirz

replace simulink and dpsim read funcs by csv func

parent ec73916a
import numpy as np
import pandas as pd
from .timeseries import *
import re
from .timeseries import *
def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
......@@ -35,72 +35,7 @@ def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
return timeseries
def read_timeseries_PLECS(filename, timeseries_names=None):
pd_df = pd.read_csv(filename)
timeseries_list = []
if timeseries_names is None:
# No trajectory names specified, thus read in all
timeseries_names = list(pd_df.columns.values)
timeseries_names.remove('Time')
for name in timeseries_names:
timeseries_list.append(TimeSeries(name, pd_df['Time'].values, pd_df[name].values))
else:
# Read in specified time series
for name in timeseries_names:
timeseries_list.append(TimeSeries(name, pd_df['Time'].values, pd_df[name].values))
print('PLECS results column names: ' + str(timeseries_names))
print('PLECS results number: ' + str(len(timeseries_list)))
return timeseries_list
def read_timeseries_simulink(filename, timeseries_names=None):
pd_df = pd.read_csv(filename)
timeseries_list = {}
cmpl_result_columns = []
real_result_columns = []
if timeseries_names is None:
# No column names specified, thus read in all and strip off spaces
pd_df.rename(columns=lambda x: x.strip(), inplace=True)
column_names = list(pd_df.columns.values)
# Remove timestamps column name and store separately
column_names.remove('time')
timestamps = pd_df.iloc[:, 0]
# Find real and complex variable names
real_string = '.real'
imaginary_string = '.imag'
for column in column_names:
if real_string in column:
tmp = column.replace(real_string, '')
cmpl_result_columns.append(tmp)
#print("Found complex variable: " + tmp)
elif not imaginary_string in column:
real_result_columns.append(column)
#print("Found real variable: " + column)
for column in real_result_columns:
timeseries_list[column] = TimeSeries(column, timestamps, pd_df[column])
for column in cmpl_result_columns:
timeseries_list[column] = TimeSeries(column, timestamps,
np.vectorize(complex)(pd_df[column + real_string],
pd_df[column + imaginary_string]))
else:
# Read in specified time series
print('cannot read specified columns yet')
print('Simulink results real column names: ' + str(real_result_columns))
print('Simulink results complex column names: ' + str(cmpl_result_columns))
print('Simulink results variable number: ' + str(len(timeseries_list)))
print('Simulink results length: ' + str(len(timestamps)))
return timeseries_list
def read_timeseries_dpsim(filename, timeseries_names=None, print_status=True):
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.
:param filename: name of the csv file that has the data
......@@ -160,13 +95,19 @@ def read_timeseries_dpsim(filename, timeseries_names=None, print_status=True):
print('cannot read specified columns yet')
if print_status :
print('DPsim results real column names: ' + str(real_result_columns))
print('DPsim results complex column names: ' + str(cmpl_result_columns))
print('DPsim results variable number: ' + str(len(timeseries_list)))
print('DPsim results length: ' + str(len(timestamps)))
print('column number: ' + str(len(timeseries_list)))
print('results length: ' + str(len(timestamps)))
print('real column names: ' + str(real_result_columns))
print('complex column names: ' + str(cmpl_result_columns))
return timeseries_list
def read_timeseries_dpsim(filename, timeseries_names=None, print_status=True):
return read_timeseries_csv(filename, timeseries_names, print_status)
def read_timeseries_simulink(filename, timeseries_names=None, print_status=True):
return read_timeseries_csv(filename, timeseries_names, print_status)
def read_dpsim_log(log_path):
log_file = open(log_path, "r")
log_lines = [line for line in log_file]
......
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