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

5
def read_timeseries_Modelica(filename, timeseries_names=None):
6
    from modelicares import SimRes
7
    sim = SimRes(filename)
8
9
    timeseries_list = []
    if timeseries_names is None:
10
11
12
13
        # No trajectory names specified, thus read in all
        print('TBD')
    else:
        # Read in specified time series
14
15
16
17
        for name in timeseries_names:
            timeseries_list.append(TimeSeries(name, sim(name).times(), sim(name).values()))
    return timeseries_list

18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
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))
    return timeseries_list
33

34
def read_timeseries_DPsim(filename, timeseries_names=None):
35
    pd_df = pd.read_csv(filename)
36
37
38
    timeseries_list = []

    if timeseries_names is None:
39
        # No trajectory names specified, thus read in all
40
41
42
43
        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))
44
45
    else:
        # Read in specified time series
46
47
48
49
50
51
52
        print('no column names specified yet')

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

54
def read_timeseries_DPsim_node_values(filename, timeseries_names=None):
55
    pd_df = pd.read_csv(filename, header=None)
56
    timeseries_list = []
57

58
    if timeseries_names is None:
59
60
61
62
63
64
65
66
        # 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
67
                timeseries_list.append(TimeSeries('node '+ str(node_name) +' Re', pd_df.iloc[:,0], pd_df.iloc[:,column]))
68
69
            else:
                node_name = node_index - node_number
70
                timeseries_list.append(TimeSeries('node '+ str(node_name) +' Im', pd_df.iloc[:,0], pd_df.iloc[:,column]))
71
72
73
74
75

            node_index = node_index + 1
    else:
        # Read in specified time series
        print('no column names specified yet')
76
77
78
79
80
81

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