plotdpsim.py 3.63 KB
Newer Older
1
2
3
from .readtools import *
from .plottools import *
from .calc import *
Markus Mirz's avatar
update    
Markus Mirz committed
4
import matplotlib
5
import matplotlib.pyplot as plt
Markus Mirz's avatar
update    
Markus Mirz committed
6
matplotlib.rcParams.update({'font.size': 8})
7

Markus Mirz's avatar
update    
Markus Mirz committed
8
def plot_dpsim_abs_diff(filename1, label1, node1, filename2, label2, node2):
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    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])
Markus Mirz's avatar
update    
Markus Mirz committed
26
    ts_abs1 = scale_ts(ts_abs1.name, ts_abs1, 0.001)
Markus Mirz's avatar
update    
Markus Mirz committed
27
    ts_abs1.label = label1
28
    ts_abs2 = complex_abs('node ' + str(node2) + 'abs', ts_dpsim2[node1], ts_dpsim2[node1 + im_offset2])
Markus Mirz's avatar
update    
Markus Mirz committed
29
    ts_abs2 = scale_ts(ts_abs2.name, ts_abs2, 0.001)
Markus Mirz's avatar
update    
Markus Mirz committed
30
    ts_abs2.label = label2
31
32
33
34
    ts_diff = diff('diff', ts_abs1, ts_abs2)
    ts_diff.label = 'difference'

    figure_id = 1
Markus Mirz's avatar
update    
Markus Mirz committed
35
36
    #plt.figure(figure_id)
    plt.figure(figure_id, figsize=(12 / 2.54, 6 / 2.54), facecolor='w', edgecolor='k')
Markus Mirz's avatar
Markus Mirz committed
37
38
    #plot_single_ts(figure_id, ts_abs1)
    #plot_single_ts(figure_id, ts_abs2)
39
40
    plot_single_ts(figure_id, ts_diff)
    plt.xlabel('Time [s]')
Markus Mirz's avatar
update    
Markus Mirz committed
41
    plt.ylabel('Voltage [kV]')
42
    plt.grid(True)
Markus Mirz's avatar
update    
Markus Mirz committed
43
    plt.tight_layout()
44
45
    plt.show()

Markus Mirz's avatar
Markus Mirz committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def plot_dpsim_abs(filename1, label1, node1, filename2, label2, 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 = scale_ts(ts_abs1.name, ts_abs1, 0.001)
        ts_abs1.label = label1
        ts_abs2 = complex_abs('node ' + str(node2) + 'abs', ts_dpsim2[node1], ts_dpsim2[node1 + im_offset2])
        ts_abs2 = scale_ts(ts_abs2.name, ts_abs2, 0.001)
        ts_abs2.label = label2

        figure_id = 1
        # plt.figure(figure_id)
        plt.figure(figure_id, figsize=(12 / 2.54, 6 / 2.54), facecolor='w', edgecolor='k')
        plot_single_ts(figure_id, ts_abs1)
        plot_single_ts(figure_id, ts_abs2)
        plt.xlabel('Time [s]')
        plt.ylabel('Voltage [kV]')
        plt.grid(True)
        plt.tight_layout()
        plt.show()

Markus Mirz's avatar
update    
Markus Mirz committed
81

82
83
84
85
86
87
88
89
90
91
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)
Bettina Schäfer's avatar
Bettina Schäfer committed
92
    if im_offset <= node or node < 0:
93
94
95
        print('Node 1 not available')
        exit()

Bettina Schäfer's avatar
Bettina Schäfer committed
96
    abs1 = complex_abs('node ' + str(node) + 'abs', ts_dpsim[node], ts_dpsim[node + im_offset])
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    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()