readtools.py 2.23 KB
Newer Older
1
2
import numpy as np
import pandas as pd
3
from .timeseries import *
4
5

def read_time_series_Modelica(filename, time_series_names=None):
6
    from modelicares import SimRes
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    sim = SimRes(filename)
    times_series = []
    if time_series_names is None:
        # No trajectory names specified, thus read in all
        print('TBD')
    else:
        # Read in specified time series
        for name in time_series_names:
            times_series.append(TimeSeries(name, sim(name).times(), sim(name).values()))
    return times_series


def read_time_series_PLECS(filename, time_series_names=None):
    pd_df = pd.read_csv(filename)
    times_series = []
    if time_series_names is None:
        # No trajectory names specified, thus read in all
        time_series_names = list(pd_df.columns.values)
        time_series_names.remove('Time')
        for name in time_series_names:
            times_series.append(TimeSeries(name, pd_df['Time'].values, pd_df[name].values))
    else:
        # Read in specified time series
        for name in time_series_names:
            times_series.append(TimeSeries(name, pd_df['Time'].values, pd_df[name].values))
32
33
34
35
    return times_series

def read_time_series_DPsim(filename, time_series_names=None):
    pd_df = pd.read_csv(filename, header=None)
36
    timeseries_list = []
37
38
39
40
41
42
43
44
45
46

    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
47
                timeseries_list.append(TimeSeries('node '+ str(node_name) +' Re', pd_df.iloc[:,0], pd_df.iloc[:,column]))
48
49
            else:
                node_name = node_index - node_number
50
                timeseries_list.append(TimeSeries('node '+ str(node_name) +' Im', pd_df.iloc[:,0], pd_df.iloc[:,column]))
51
52
53
54
55

            node_index = node_index + 1
    else:
        # Read in specified time series
        print('no column names specified yet')
56
57
58
59
60
61

    print('DPsim results file length:')
    print(len(timeseries_list))
    for result in timeseries_list:
        print(result.name)
    return timeseries_list