Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
Data Processing
Commits
00489685
Commit
00489685
authored
Nov 15, 2017
by
Markus Mirz
Browse files
updated dpsim tools
parent
20ab9a9b
Changes
4
Hide whitespace changes
Inline
Side-by-side
dataprocessing/plotdpsim.py
View file @
00489685
...
...
@@ -3,6 +3,7 @@ from .plottools import *
from
.calc
import
*
import
matplotlib
import
matplotlib.pyplot
as
plt
from
scipy.interpolate
import
interp1d
matplotlib
.
rcParams
.
update
({
'font.size'
:
8
})
def
plot_dpsim_abs_diff
(
filename1
,
label1
,
node1
,
filename2
,
label2
,
node2
):
...
...
@@ -143,8 +144,297 @@ def plot_dpsim_abs_single(filename, node):
plt
.
grid
(
True
)
plt
.
show
()
def
main
():
plot_dpsim_single
()
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
def
plotNodeVoltageInterpDpRef
(
filenameRef
,
filenameDP
,
node
):
node
=
node
-
1
dfRef
=
pd
.
read_csv
(
filenameRef
,
header
=
None
)
dfDP
=
pd
.
read_csv
(
filenameDP
,
header
=
None
)
if
(
dfRef
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfDP
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
# Ref
timeRef
=
np
.
array
(
dfRef
.
ix
[:,
0
])
voltageRef
=
np
.
array
(
dfRef
.
ix
[:,
node
+
1
])
# DP interpolated
timeDP
=
np
.
array
(
dfDP
.
ix
[:,
0
])
voltageReDP
=
np
.
array
(
dfDP
.
ix
[:,
node
+
1
])
voltageImDP
=
np
.
array
(
dfDP
.
ix
[:,
int
((
dfDP
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
interpTime
=
np
.
arange
(
dfDP
.
ix
[
0
,
0
],
dfDP
.
ix
[
dfDP
.
shape
[
0
]
-
1
,
0
],
0.00005
)
fVoltageRe
=
interp1d
(
timeDP
,
voltageReDP
)
fVoltageIm
=
interp1d
(
timeDP
,
voltageImDP
)
interpVoltageRe
=
fVoltageRe
(
interpTime
)
interpVoltageIm
=
fVoltageIm
(
interpTime
)
voltageShiftDPInterp
=
interpVoltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
interpTime
)
-
interpVoltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
interpTime
)
voltageAbsDP
=
np
.
sqrt
(
voltageReDP
**
2
+
voltageImDP
**
2
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
timeRef
,
voltageRef
,
'm:'
,
label
=
'Ref'
)
ax1
.
plot
(
interpTime
,
voltageShiftDPInterp
,
'b--'
,
label
=
'DP interp'
)
ax1
.
plot
(
timeDP
,
voltageAbsDP
,
'r-'
,
label
=
'DP abs'
)
# Now add the legend with some customizations.
legend
=
ax1
.
legend
(
loc
=
'lower right'
,
shadow
=
True
)
# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame
=
legend
.
get_frame
()
frame
.
set_facecolor
(
'0.90'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotNodeVoltageDpEmtRef
(
filenameRef
,
filenameDP
,
filenameEMT
,
node
):
node
=
node
-
1
dfRef
=
pd
.
read_csv
(
filenameRef
,
header
=
None
)
dfEMT
=
pd
.
read_csv
(
filenameEMT
,
header
=
None
)
dfDP
=
pd
.
read_csv
(
filenameDP
,
header
=
None
)
if
(
dfRef
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfEMT
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfDP
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
# Ref
timeRef
=
np
.
array
(
dfRef
.
ix
[:,
0
])
voltageRef
=
np
.
array
(
dfRef
.
ix
[:,
node
+
1
])
# EMT
timeEMT
=
np
.
array
(
dfEMT
.
ix
[:,
0
])
voltageEMT
=
np
.
array
(
dfEMT
.
ix
[:,
node
+
1
])
# DP
timeDP
=
np
.
array
(
dfDP
.
ix
[:,
0
])
voltageReDP
=
np
.
array
(
dfDP
.
ix
[:,
node
+
1
])
voltageImDP
=
np
.
array
(
dfDP
.
ix
[:,
int
((
dfDP
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltageAbsDP
=
np
.
sqrt
(
voltageReDP
**
2
+
voltageImDP
**
2
)
voltageShiftDP
=
voltageReDP
*
np
.
cos
(
2
*
np
.
pi
*
50
*
timeDP
)
-
voltageImDP
*
np
.
sin
(
2
*
np
.
pi
*
50
*
timeDP
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
timeRef
,
voltageRef
,
'm:'
,
label
=
'Ref'
)
ax1
.
plot
(
timeEMT
,
voltageEMT
,
'g--'
,
label
=
'EMT'
)
ax1
.
plot
(
timeDP
,
voltageShiftDP
,
'b--'
,
label
=
'DP shift'
)
ax1
.
plot
(
timeDP
,
voltageAbsDP
,
'r-'
,
label
=
'DP abs'
)
# Now add the legend with some customizations.
legend
=
ax1
.
legend
(
loc
=
'lower right'
,
shadow
=
True
)
# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame
=
legend
.
get_frame
()
frame
.
set_facecolor
(
'0.90'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotNodeVoltageDpEmt
(
filenameDP
,
filenameEMT
,
node
):
node
=
node
-
1
dfEMT
=
pd
.
read_csv
(
filenameEMT
,
header
=
None
)
dfDP
=
pd
.
read_csv
(
filenameDP
,
header
=
None
)
if
(
dfEMT
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfDP
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
# EMT
timeEMT
=
np
.
array
(
dfEMT
.
ix
[:,
0
])
voltageEMT
=
np
.
array
(
dfEMT
.
ix
[:,
node
+
1
])
# DP
timeDP
=
np
.
array
(
dfDP
.
ix
[:,
0
])
voltageReDP
=
np
.
array
(
dfDP
.
ix
[:,
node
+
1
])
voltageImDP
=
np
.
array
(
dfDP
.
ix
[:,
int
((
dfDP
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltageAbsDP
=
np
.
sqrt
(
voltageReDP
**
2
+
voltageImDP
**
2
)
voltageShiftDP
=
voltageReDP
*
np
.
cos
(
2
*
np
.
pi
*
50
*
timeDP
)
-
voltageImDP
*
np
.
sin
(
2
*
np
.
pi
*
50
*
timeDP
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
timeEMT
,
voltageEMT
,
'g--'
,
label
=
'EMT'
)
ax1
.
plot
(
timeDP
,
voltageShiftDP
,
'b--'
,
label
=
'DP shift'
)
ax1
.
plot
(
timeDP
,
voltageAbsDP
,
'r-'
,
label
=
'DP abs'
)
# Now add the legend with some customizations.
legend
=
ax1
.
legend
(
loc
=
'lower right'
,
shadow
=
True
)
# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame
=
legend
.
get_frame
()
frame
.
set_facecolor
(
'0.90'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotEmtNodeResults
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltage
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
voltage
,
'b-'
)
# plt.yticks(np.arange(-10, 10, 1.0))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V] or [A]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotNodeResults
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltageRe
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
voltageIm
=
np
.
array
(
df
.
ix
[:,
int
((
df
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltage
=
np
.
sqrt
(
voltageRe
**
2
+
voltageIm
**
2
)
voltageEmt
=
voltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
time
)
-
voltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
time
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
voltageEmt
,
'b-'
,
time
,
voltage
,
'r-'
)
# plt.yticks(np.arange(-10, 10, 1.0))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V] or [A]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotInterpolatedNodeResults
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltageRe
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
voltageIm
=
np
.
array
(
df
.
ix
[:,
int
((
df
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
interpTime
=
np
.
arange
(
df
.
ix
[
0
,
0
],
df
.
ix
[
df
.
shape
[
0
]
-
1
,
0
],
0.00005
)
fVoltageRe
=
interp1d
(
time
,
voltageRe
)
fVoltageIm
=
interp1d
(
time
,
voltageIm
)
interpVoltageRe
=
fVoltageRe
(
interpTime
)
interpVoltageIm
=
fVoltageIm
(
interpTime
)
voltageMeas
=
np
.
sqrt
(
voltageRe
**
2
+
voltageIm
**
2
)
voltage
=
np
.
sqrt
(
interpVoltageRe
**
2
+
interpVoltageIm
**
2
)
voltageEmt
=
interpVoltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
interpTime
)
-
interpVoltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
interpTime
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
interpTime
,
voltageEmt
,
'b-'
)
ax1
.
plot
(
time
,
voltageMeas
,
'r-'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V] or [A]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotResultsInterfacedInductor
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Voltage not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltageRe
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
voltageIm
=
np
.
array
(
df
.
ix
[:,
int
((
df
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltage
=
np
.
sqrt
(
voltageRe
**
2
+
voltageIm
**
2
)
voltageEmt
=
voltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
time
)
-
voltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
time
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
voltageEmt
,
'b-'
,
time
,
voltage
,
'r-'
)
plt
.
yticks
(
np
.
arange
(
-
10
,
10
,
1.0
))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'voltage [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotResultsSynGenUnitTest
(
filename
,
node1
,
node2
,
node3
):
node1
=
node1
-
1
node2
=
node2
-
1
node3
=
node3
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node1
or
node1
<
0
or
\
(
df
.
shape
[
1
]
-
1
)
/
2
<
node2
or
node2
<
0
or
\
(
df
.
shape
[
1
]
-
1
)
/
2
<
node3
or
node3
<
0
:
print
(
'Voltage not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
mag1
=
np
.
array
(
df
.
ix
[:,
node1
+
1
])
mag2
=
np
.
array
(
df
.
ix
[:,
node2
+
1
])
mag3
=
np
.
array
(
df
.
ix
[:,
node3
+
1
])
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
mag1
,
'b-'
,
time
,
mag2
,
'r-'
,
time
,
mag3
,
'g-'
)
# ax1.plot(time, voltageEmt, 'b-', time, voltage, 'r-')
# plt.yticks(np.arange(-10, 10, 1.0))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'Magnitude'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotResultsSynGenUnitTestVar
(
filename
,
varNum
):
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
])
<
varNum
or
varNum
<
0
:
print
(
'Variable not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
mag
=
np
.
array
(
df
.
ix
[:,
varNum
])
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
mag
,
'b-'
)
# plt.yticks(np.arange(-10, 10, 1.0))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'Magnitude'
)
ax1
.
grid
(
True
)
plt
.
show
()
dataprocessing/plotdpsim_deprecated.py
deleted
100644 → 0
View file @
20ab9a9b
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
scipy.interpolate
import
interp1d
def
plotNodeVoltageInterpDpRef
(
filenameRef
,
filenameDP
,
node
):
node
=
node
-
1
dfRef
=
pd
.
read_csv
(
filenameRef
,
header
=
None
)
dfDP
=
pd
.
read_csv
(
filenameDP
,
header
=
None
)
if
(
dfRef
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfDP
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
# Ref
timeRef
=
np
.
array
(
dfRef
.
ix
[:,
0
])
voltageRef
=
np
.
array
(
dfRef
.
ix
[:,
node
+
1
])
#DP interpolated
timeDP
=
np
.
array
(
dfDP
.
ix
[:,
0
])
voltageReDP
=
np
.
array
(
dfDP
.
ix
[:,
node
+
1
])
voltageImDP
=
np
.
array
(
dfDP
.
ix
[:,
int
((
dfDP
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
interpTime
=
np
.
arange
(
dfDP
.
ix
[
0
,
0
],
dfDP
.
ix
[
dfDP
.
shape
[
0
]
-
1
,
0
],
0.00005
)
fVoltageRe
=
interp1d
(
timeDP
,
voltageReDP
)
fVoltageIm
=
interp1d
(
timeDP
,
voltageImDP
)
interpVoltageRe
=
fVoltageRe
(
interpTime
)
interpVoltageIm
=
fVoltageIm
(
interpTime
)
voltageShiftDPInterp
=
interpVoltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
interpTime
)
-
interpVoltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
interpTime
)
voltageAbsDP
=
np
.
sqrt
(
voltageReDP
**
2
+
voltageImDP
**
2
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
timeRef
,
voltageRef
,
'm:'
,
label
=
'Ref'
)
ax1
.
plot
(
interpTime
,
voltageShiftDPInterp
,
'b--'
,
label
=
'DP interp'
)
ax1
.
plot
(
timeDP
,
voltageAbsDP
,
'r-'
,
label
=
'DP abs'
)
# Now add the legend with some customizations.
legend
=
ax1
.
legend
(
loc
=
'lower right'
,
shadow
=
True
)
# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame
=
legend
.
get_frame
()
frame
.
set_facecolor
(
'0.90'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotNodeVoltageDpEmtRef
(
filenameRef
,
filenameDP
,
filenameEMT
,
node
):
node
=
node
-
1
dfRef
=
pd
.
read_csv
(
filenameRef
,
header
=
None
)
dfEMT
=
pd
.
read_csv
(
filenameEMT
,
header
=
None
)
dfDP
=
pd
.
read_csv
(
filenameDP
,
header
=
None
)
if
(
dfRef
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfEMT
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfDP
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
# Ref
timeRef
=
np
.
array
(
dfRef
.
ix
[:,
0
])
voltageRef
=
np
.
array
(
dfRef
.
ix
[:,
node
+
1
])
# EMT
timeEMT
=
np
.
array
(
dfEMT
.
ix
[:,
0
])
voltageEMT
=
np
.
array
(
dfEMT
.
ix
[:,
node
+
1
])
#DP
timeDP
=
np
.
array
(
dfDP
.
ix
[:,
0
])
voltageReDP
=
np
.
array
(
dfDP
.
ix
[:,
node
+
1
])
voltageImDP
=
np
.
array
(
dfDP
.
ix
[:,
int
((
dfDP
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltageAbsDP
=
np
.
sqrt
(
voltageReDP
**
2
+
voltageImDP
**
2
)
voltageShiftDP
=
voltageReDP
*
np
.
cos
(
2
*
np
.
pi
*
50
*
timeDP
)
-
voltageImDP
*
np
.
sin
(
2
*
np
.
pi
*
50
*
timeDP
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
timeRef
,
voltageRef
,
'm:'
,
label
=
'Ref'
)
ax1
.
plot
(
timeEMT
,
voltageEMT
,
'g--'
,
label
=
'EMT'
)
ax1
.
plot
(
timeDP
,
voltageShiftDP
,
'b--'
,
label
=
'DP shift'
)
ax1
.
plot
(
timeDP
,
voltageAbsDP
,
'r-'
,
label
=
'DP abs'
)
# Now add the legend with some customizations.
legend
=
ax1
.
legend
(
loc
=
'lower right'
,
shadow
=
True
)
# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame
=
legend
.
get_frame
()
frame
.
set_facecolor
(
'0.90'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotNodeVoltageDpEmt
(
filenameDP
,
filenameEMT
,
node
):
node
=
node
-
1
dfEMT
=
pd
.
read_csv
(
filenameEMT
,
header
=
None
)
dfDP
=
pd
.
read_csv
(
filenameDP
,
header
=
None
)
if
(
dfEMT
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
if
(
dfDP
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
# EMT
timeEMT
=
np
.
array
(
dfEMT
.
ix
[:,
0
])
voltageEMT
=
np
.
array
(
dfEMT
.
ix
[:,
node
+
1
])
#DP
timeDP
=
np
.
array
(
dfDP
.
ix
[:,
0
])
voltageReDP
=
np
.
array
(
dfDP
.
ix
[:,
node
+
1
])
voltageImDP
=
np
.
array
(
dfDP
.
ix
[:,
int
((
dfDP
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltageAbsDP
=
np
.
sqrt
(
voltageReDP
**
2
+
voltageImDP
**
2
)
voltageShiftDP
=
voltageReDP
*
np
.
cos
(
2
*
np
.
pi
*
50
*
timeDP
)
-
voltageImDP
*
np
.
sin
(
2
*
np
.
pi
*
50
*
timeDP
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
timeEMT
,
voltageEMT
,
'g--'
,
label
=
'EMT'
)
ax1
.
plot
(
timeDP
,
voltageShiftDP
,
'b--'
,
label
=
'DP shift'
)
ax1
.
plot
(
timeDP
,
voltageAbsDP
,
'r-'
,
label
=
'DP abs'
)
# Now add the legend with some customizations.
legend
=
ax1
.
legend
(
loc
=
'lower right'
,
shadow
=
True
)
# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame
=
legend
.
get_frame
()
frame
.
set_facecolor
(
'0.90'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotEmtNodeResults
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltage
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
voltage
,
'b-'
)
#plt.yticks(np.arange(-10, 10, 1.0))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V] or [A]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotNodeResults
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltageRe
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
voltageIm
=
np
.
array
(
df
.
ix
[:,
int
((
df
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltage
=
np
.
sqrt
(
voltageRe
**
2
+
voltageIm
**
2
)
voltageEmt
=
voltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
time
)
-
voltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
time
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
voltageEmt
,
'b-'
,
time
,
voltage
,
'r-'
)
#plt.yticks(np.arange(-10, 10, 1.0))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V] or [A]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotInterpolatedNodeResults
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Node not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltageRe
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
voltageIm
=
np
.
array
(
df
.
ix
[:,
int
((
df
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
interpTime
=
np
.
arange
(
df
.
ix
[
0
,
0
],
df
.
ix
[
df
.
shape
[
0
]
-
1
,
0
],
0.00005
)
fVoltageRe
=
interp1d
(
time
,
voltageRe
)
fVoltageIm
=
interp1d
(
time
,
voltageIm
)
interpVoltageRe
=
fVoltageRe
(
interpTime
)
interpVoltageIm
=
fVoltageIm
(
interpTime
)
voltageMeas
=
np
.
sqrt
(
voltageRe
**
2
+
voltageIm
**
2
)
voltage
=
np
.
sqrt
(
interpVoltageRe
**
2
+
interpVoltageIm
**
2
)
voltageEmt
=
interpVoltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
interpTime
)
-
interpVoltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
interpTime
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
interpTime
,
voltageEmt
,
'b-'
)
ax1
.
plot
(
time
,
voltageMeas
,
'r-'
)
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'mag [V] or [A]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotResultsInterfacedInductor
(
filename
,
node
):
node
=
node
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node
or
node
<
0
:
print
(
'Voltage not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
voltageRe
=
np
.
array
(
df
.
ix
[:,
node
+
1
])
voltageIm
=
np
.
array
(
df
.
ix
[:,
int
((
df
.
shape
[
1
]
-
1
)
/
2
+
node
+
1
)])
voltage
=
np
.
sqrt
(
voltageRe
**
2
+
voltageIm
**
2
)
voltageEmt
=
voltageRe
*
np
.
cos
(
2
*
np
.
pi
*
50
*
time
)
-
voltageIm
*
np
.
sin
(
2
*
np
.
pi
*
50
*
time
)
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
voltageEmt
,
'b-'
,
time
,
voltage
,
'r-'
)
plt
.
yticks
(
np
.
arange
(
-
10
,
10
,
1.0
))
ax1
.
set_xlabel
(
'time [s]'
)
ax1
.
set_ylabel
(
'voltage [V]'
)
ax1
.
grid
(
True
)
plt
.
show
()
def
plotResultsSynGenUnitTest
(
filename
,
node1
,
node2
,
node3
):
node1
=
node1
-
1
node2
=
node2
-
1
node3
=
node3
-
1
df
=
pd
.
read_csv
(
filename
,
header
=
None
)
print
(
df
.
shape
)
if
(
df
.
shape
[
1
]
-
1
)
/
2
<
node1
or
node1
<
0
or
\
(
df
.
shape
[
1
]
-
1
)
/
2
<
node2
or
node2
<
0
or
\
(
df
.
shape
[
1
]
-
1
)
/
2
<
node3
or
node3
<
0
:
print
(
'Voltage not available'
)
exit
()
time
=
np
.
array
(
df
.
ix
[:,
0
])
mag1
=
np
.
array
(
df
.
ix
[:,
node1
+
1
])
mag2
=
np
.
array
(
df
.
ix
[:,
node2
+
1
])
mag3
=
np
.
array
(
df
.
ix
[:,
node3
+
1
])
fig
,
ax1
=
plt
.
subplots
()
ax1
.
plot
(
time
,
mag1
,
'b-'
,
time
,
mag2
,
'r-'
,
time
,
mag3
,
'g-'
)
#ax1.plot(time, voltageEmt, 'b-', time, voltage, 'r-')
#plt.yticks(np.arange(-10, 10, 1.0))