Skip to content
Snippets Groups Projects
Commit 8e077c15 authored by Markus Mirz's avatar Markus Mirz
Browse files

added new dpsim specific plot module

parent 3568e0fd
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,17 @@ import matplotlib.pyplot as plt
import numpy as np
from .timeseries import *
def diff(name, ts1, ts2):
""" Calculate difference.
Assumes the same time steps for both timeseries.
"""
ts_diff = TimeSeries(name, ts1.time, (ts1.values - ts2.values))
return ts_diff
def complex_abs(name, real, imag):
""" Calculate absolute value of complex variable.
Assumes the same time steps for both timeseries.
"""
ts_abs = TimeSeries(name, real.time, np.sqrt(real.values ** 2 + imag.values ** 2))
return ts_abs
from .readtools import *
from .plottools import *
from .calc import *
import matplotlib.pyplot as plt
def plot_dpsim_abs_diff(filename1, node1, filename2, node2):
ts_dpsim1 = read_time_series_DPsim(filename1)
ts_dpsim2 = read_time_series_DPsim(filename2)
ts_dpsim1_length = len(ts_dpsim1)
im_offset1 = int(ts_dpsim1_length / 2)
if im_offset1 <= node1 or node1 < 0:
print('Node 1 not available')
exit()
ts_dpsim2_length = len(ts_dpsim2)
im_offset2 = int(ts_dpsim2_length / 2)
if im_offset2 <= node1 or node1 < 0:
print('Node 2 not available')
exit()
# this assumes same timestep for both simulations
ts_abs1 = complex_abs('node ' + str(node1) + 'abs', ts_dpsim1[node1], ts_dpsim1[node1 + im_offset1])
ts_abs1.label = 'reference'
ts_abs2 = complex_abs('node ' + str(node2) + 'abs', ts_dpsim2[node1], ts_dpsim2[node1 + im_offset2])
ts_abs2.label = 'local co-sim'
ts_diff = diff('diff', ts_abs1, ts_abs2)
ts_diff.label = 'difference'
figure_id = 1
plt.figure(figure_id)
plot_single_ts(figure_id, ts_abs1)
plot_single_ts(figure_id, ts_abs2)
plot_single_ts(figure_id, ts_diff)
plt.xlabel('Time [s]')
plt.ylabel('Voltage [V]')
plt.grid(True)
plt.show()
def plot_dpsim_abs_single(filename, node):
ts_dpsim = read_time_series_DPsim(filename)
ts_dpsim_length = len(ts_dpsim)
print('DPsim results file length:')
print(ts_dpsim_length)
for result in ts_dpsim:
print(result.name)
im_offset = int(ts_dpsim_length / 2)
if im_offset <= node1 or node1 < 0:
print('Node 1 not available')
exit()
abs1 = complex_abs('node ' + str(node1) + 'abs', ts_dpsim[node1], ts_dpsim[node1 + im_offset])
abs1.label = 'absolute'
figure_id = 1
plt.figure(figure_id)
plot_single_ts(figure_id, abs1)
plt.xlabel('Time [s]')
plt.ylabel('Voltage [V]')
plt.grid(True)
plt.show()
def main():
plot_dpsim_single()
if __name__ == "__main__":
main()
\ No newline at end of file
import matplotlib.pyplot as plt
import numpy as np
from .timeseries import *
def plot_single_ts(figure_id, time_series, plt_linestyle='-'):
plt.figure(figure_id)
plt.plot(time_series.time, time_series.values, linestyle=plt_linestyle, label=time_series.label)
plt.gca().autoscale(axis='x', tight=True)
plt.legend()
def plot_in_subplots(figure_id, time_series, plt_linestyle='-'):
plt.figure(figure_id)
for ts in time_series:
......@@ -10,6 +17,14 @@ def plot_in_subplots(figure_id, time_series, plt_linestyle='-'):
plt.gca().autoscale(axis='x', tight=True)
plt.legend()
def plot_in_oneplot(figure_id, time_series, plt_linestyle='-'):
plt.figure(figure_id)
for ts in time_series:
plt.subplot(len(time_series), 1, time_series.index(ts) + 1)
plt.plot(ts.time, ts.values, linestyle=plt_linestyle, label=ts.label)
plt.gca().autoscale(axis='x', tight=True)
plt.legend()
def set_time_series_labels(time_series, time_series_labels):
for ts in time_series:
......
......@@ -164,38 +164,6 @@ def plotEmtNodeResults(filename, node):
ax1.grid(True)
plt.show()
def plotDpDiff(filename1, node1, filename2, node2):
node1 = node1 - 1
node2 = node2 - 1
df1 = pd.read_csv(filename1, header=None)
df2 = pd.read_csv(filename2, header=None)
if (df1.shape[1] - 1) / 2 < node1 or node1 < 0:
print('Node 1 not available')
exit()
if (df2.shape[1] - 1) / 2 < node2 or node2 < 0:
print('Node 2 not available')
exit()
# this assumes same timestep for both runs
time = np.array(df1.ix[:,0])
re1 = np.array(df1.ix[:,node1 + 1])
re2 = np.array(df2.ix[:,node2 + 1])
im1 = np.array(df1.ix[:,int((df1.shape[1] - 1) / 2 + node1 + 1)])
im2 = np.array(df2.ix[:,int((df2.shape[1] - 1) / 2 + node2 + 1)])
abs1 = np.sqrt(re1**2+im1**2)
abs2 = np.sqrt(re2**2+im2**2)
diff = np.sqrt((re1-re2)**2+(im1-im2)**2)
fig, ax = plt.subplots()
ax.plot(time, abs1, 'b-', time, abs2, 'r-', time, diff, 'g-')
ax.set_xlabel('time [s]')
ax.set_ylabel('mag [V]')
ax.grid(True)
plt.show()
def plotNodeResults(filename, node):
node = node - 1
df = pd.read_csv(filename, header=None)
......
......@@ -33,7 +33,7 @@ def read_time_series_PLECS(filename, time_series_names=None):
def read_time_series_DPsim(filename, time_series_names=None):
pd_df = pd.read_csv(filename, header=None)
time_series = []
timeseries_list = []
if time_series_names is None:
# No trajectory names specified, thus read in all
......@@ -44,13 +44,18 @@ def read_time_series_DPsim(filename, time_series_names=None):
for column in column_names:
if node_index <= node_number:
node_name = node_index
time_series.append(TimeSeries('node '+ str(node_name) +' Re', pd_df.iloc[:,0], pd_df.iloc[:,column]))
timeseries_list.append(TimeSeries('node '+ str(node_name) +' Re', pd_df.iloc[:,0], pd_df.iloc[:,column]))
else:
node_name = node_index - node_number
time_series.append(TimeSeries('node '+ str(node_name) +' Im', pd_df.iloc[:,0], pd_df.iloc[:,column]))
timeseries_list.append(TimeSeries('node '+ str(node_name) +' Im', pd_df.iloc[:,0], pd_df.iloc[:,column]))
node_index = node_index + 1
else:
# Read in specified time series
print('no column names specified yet')
return time_series
print('DPsim results file length:')
print(len(timeseries_list))
for result in timeseries_list:
print(result.name)
return timeseries_list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment