Commit 3568e0fd authored by Markus Mirz's avatar Markus Mirz
Browse files

added dpsim read and complex calc support

parent 68f82ceb
import matplotlib.pyplot as plt
import numpy as np
from .timeseries import *
def complex_abs(name, real, imag):
ts_abs = TimeSeries(name, real.time, np.sqrt(real.values ** 2 + imag.values ** 2))
return ts_abs
import numpy as np import numpy as np
from modelicares import SimRes
import pandas as pd import pandas as pd
from .timeseries import *
class TimeSeries:
def __init__(self, name, time, values, label=""):
self.time = np.array(time)
self.values = np.array(values)
self.name = name
self.label = name
def read_time_series_Modelica(filename, time_series_names=None): def read_time_series_Modelica(filename, time_series_names=None):
from modelicares import SimRes
sim = SimRes(filename) sim = SimRes(filename)
times_series = [] times_series = []
if time_series_names is None: if time_series_names is None:
...@@ -36,4 +29,28 @@ def read_time_series_PLECS(filename, time_series_names=None): ...@@ -36,4 +29,28 @@ def read_time_series_PLECS(filename, time_series_names=None):
# Read in specified time series # Read in specified time series
for name in time_series_names: for name in time_series_names:
times_series.append(TimeSeries(name, pd_df['Time'].values, pd_df[name].values)) times_series.append(TimeSeries(name, pd_df['Time'].values, pd_df[name].values))
return times_series return times_series
\ No newline at end of file
def read_time_series_DPsim(filename, time_series_names=None):
pd_df = pd.read_csv(filename, header=None)
time_series = []
if time_series_names is None:
# No trajectory names specified, thus read in all
column_names = list(pd_df.columns.values)
column_names.remove(0)
node_index = 1
node_number = int(len(column_names) / 2)
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]))
else:
node_name = node_index - node_number
time_series.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
import numpy as np
class TimeSeries:
def __init__(self, name, time, values, label=""):
self.time = np.array(time)
self.values = np.array(values)
self.name = name
self.label = name
\ No newline at end of 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