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

5

6
def read_timeseries_Modelica(filename, timeseries_names=None):
7
    from modelicares import SimRes
8
    sim = SimRes(filename)
9
    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 18 19 20
        if not isinstance(timeseries_names, list):
            timeseries = TimeSeries(timeseries_names, sim(timeseries_names).times(), sim(timeseries_names).values())
        else:
            for name in timeseries_names:
                timeseries = []
                timeseries.append(TimeSeries(name, sim(name).times(), sim(name).values()))
    return timeseries
21

22

23 24 25 26 27 28 29 30 31 32 33 34 35 36
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
37

38
def read_timeseries_DPsim(filename, timeseries_names=None):
39
    pd_df = pd.read_csv(filename)
40 41 42
    timeseries_list = []

    if timeseries_names is None:
43
        # No trajectory names specified, thus read in all
44 45 46 47
        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))
48 49
    else:
        # Read in specified time series
50 51 52 53 54 55 56
        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
57

58
def read_timeseries_DPsim_node_values(filename, timeseries_names=None):
59
    pd_df = pd.read_csv(filename, header=None)
60
    timeseries_list = []
61

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

            node_index = node_index + 1
    else:
        # Read in specified time series
        print('no column names specified yet')
80 81 82 83 84 85

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