Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASdataprocessing
Commits
f91e6081
Commit
f91e6081
authored
Mar 27, 2018
by
Bichen Li
Browse files
Read in node voltages and component currents
parent
e2d033d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/NEPLAN/read_NEPLAN.py
View file @
f91e6081
import
re
from
dataprocessing.readtools
import
*
from
dataprocessing.plottools
import
*
import
cmath
import
matplotlib.pyplot
as
plt
def
readsim
(
file_name
,
timeseries_names
=
None
,
is_regex
=
False
):
str_tmp
=
open
(
file_name
,
"r"
)
def
readsim
(
file_name
,
timeseries_names
=
None
,
is_regex
=
False
):
str_tmp
=
open
(
file_name
,
"r"
)
low
=
0
high
=
0
flag
=
True
...
...
@@ -11,11 +14,11 @@ def readsim(file_name,timeseries_names=None, is_regex=False):
seq
=
[]
value
=
[]
i
=
0
namelist
=
[
'U'
,
'ANGLEU'
,
'P'
,
'Q'
,
'I'
,
'ANGLEI'
]
namelist
=
[
'U'
,
'ANGLEU'
,
'P'
,
'Q'
,
'I'
,
'ANGLEI'
]
timeseries
=
[]
isfloat
=
re
.
compile
(
r
'^[-+]?[0-9]+\.[0-9]+$'
)
for
line
in
str_tmp
.
readlines
():
line
=
line
.
replace
(
","
,
"."
)
line
=
line
.
replace
(
","
,
"."
)
high
-=
high
low
-=
low
del
value
[:]
...
...
@@ -30,30 +33,77 @@ def readsim(file_name,timeseries_names=None, is_regex=False):
else
:
value
.
append
(
line
[
low
:
high
])
else
:
# NONE
value
.
append
(
r
'#'
)
#
No value, set as #
value
.
append
(
r
'#'
)
#
No value, set as #
low
=
high
+
1
high
+=
1
if
flag
is
False
:
dic
[
i
]
=
dict
(
zip
(
seq
,
value
))
i
+=
1
if
value
[
0
]
is
not
'0'
:
nameindex
=
[]
for
m
in
range
(
5
):
nameindex
.
append
(
seq
[
1
]
+
'.'
+
seq
[
2
]
+
'.'
+
namelist
[
m
])
if
timeseries_names
is
None
and
is_regex
is
False
:
for
m
in
range
(
5
):
timeseries
.
append
(
TimeSeries
(
nameindex
[
m
],
0
,
value
[
m
+
6
]))
elif
is_regex
is
True
:
# Read in variables which match with regex
p
=
re
.
compile
(
timeseries_names
)
for
m
in
range
(
5
):
if
p
.
search
(
nameindex
[
m
]):
timeseries
.
append
(
TimeSeries
(
nameindex
[
m
],
0
,
value
[
m
+
6
]))
check_pass
=
True
if
timeseries_names
is
None
and
is_regex
is
False
:
if
value
[
0
]
==
'0'
:
for
m
in
range
(
2
):
timeseries
.
append
(
TimeSeries
(
value
[
1
]
+
'.'
+
namelist
[
m
],
0
,
value
[
m
+
6
]))
else
:
# Read in specified time series
for
m
in
range
(
5
):
if
timeseries_names
is
namelist
[
m
]:
timeseries
.
append
(
TimeSeries
(
nameindex
[
m
],
0
,
value
[
m
+
6
]))
for
check
in
range
(
len
(
timeseries
)
-
1
):
if
timeseries
[
check
].
name
==
value
[
3
]
+
'.'
+
namelist
[
4
]:
check_pass
=
False
result
=
cmath
.
rect
(
timeseries
[
check
].
values
,
timeseries
[
check
+
1
].
values
/
180
*
cmath
.
pi
)
+
cmath
.
rect
(
value
[
10
],
value
[
11
]
/
180
*
cmath
.
pi
)
(
timeseries
[
check
].
value
,
timeseries
[
check
+
1
].
value
)
=
cmath
.
polar
(
result
)
timeseries
[
check
+
1
].
values
=
timeseries
[
check
+
1
].
value
/
cmath
.
pi
*
180
timeseries
[
check
-
1
].
values
+=
value
[
9
]
timeseries
[
check
-
2
].
values
+=
value
[
8
]
if
check_pass
:
for
m
in
range
(
2
,
6
):
timeseries
.
append
(
TimeSeries
(
value
[
3
]
+
'.'
+
namelist
[
m
],
0
,
value
[
m
+
6
]))
elif
is_regex
is
True
:
# Read in variables which match with regex
p
=
re
.
compile
(
timeseries_names
)
if
value
[
0
]
==
'0'
:
for
m
in
range
(
2
):
if
p
.
search
((
value
[
1
]
+
'.'
+
namelist
[
m
])):
timeseries
.
append
(
TimeSeries
(
value
[
1
]
+
'.'
+
namelist
[
m
],
0
,
value
[
m
+
6
]))
else
:
for
check
in
range
(
len
(
timeseries
)
-
1
):
if
timeseries
[
check
].
name
==
value
[
3
]
+
'.'
+
namelist
[
4
]:
check_pass
=
False
result
=
cmath
.
rect
(
timeseries
[
check
].
values
,
timeseries
[
check
+
1
].
values
/
180
*
cmath
.
pi
)
+
cmath
.
rect
(
value
[
10
],
value
[
11
]
/
180
*
cmath
.
pi
)
(
timeseries
[
check
].
values
,
timeseries
[
check
+
1
].
values
)
=
cmath
.
polar
(
result
)
timeseries
[
check
+
1
].
values
=
timeseries
[
check
+
1
].
values
/
cmath
.
pi
*
180
timeseries
[
check
-
1
].
values
+=
value
[
9
]
timeseries
[
check
-
2
].
values
+=
value
[
8
]
if
check_pass
:
for
m
in
range
(
2
,
6
):
if
p
.
search
((
value
[
3
]
+
'.'
+
namelist
[
m
])):
timeseries
.
append
(
TimeSeries
(
value
[
3
]
+
'.'
+
namelist
[
m
],
0
,
value
[
m
+
6
]))
else
:
# Read in specified time series
if
value
[
0
]
==
'0'
:
for
m
in
range
(
2
):
if
timeseries_names
==
(
value
[
1
]
+
'.'
+
namelist
[
m
]):
timeseries
.
append
(
TimeSeries
(
value
[
1
]
+
'.'
+
namelist
[
m
],
0
,
value
[
m
+
6
]))
else
:
for
check
in
range
(
len
(
timeseries
)
-
1
):
if
timeseries
[
check
].
name
==
value
[
3
]
+
'.'
+
namelist
[
4
]:
check_pass
=
False
result
=
cmath
.
rect
(
timeseries
[
check
].
values
,
timeseries
[
check
+
1
].
values
/
180
*
cmath
.
pi
)
+
cmath
.
rect
(
value
[
10
],
value
[
11
]
/
180
*
cmath
.
pi
)
(
timeseries
[
check
].
values
,
timeseries
[
check
+
1
].
values
)
=
cmath
.
polar
(
result
)
timeseries
[
check
+
1
].
values
=
timeseries
[
check
+
1
].
values
/
cmath
.
pi
*
180
timeseries
[
check
-
1
].
values
+=
value
[
9
]
timeseries
[
check
-
2
].
values
+=
value
[
8
]
if
check_pass
:
for
m
in
range
(
2
,
6
):
if
timeseries_names
==
(
value
[
3
]
+
'.'
+
namelist
[
m
]):
timeseries
.
append
(
TimeSeries
(
value
[
3
]
+
'.'
+
namelist
[
m
],
0
,
value
[
m
+
6
]))
flag
=
False
str_tmp
.
close
()
return
timeseries
examples/NEPLAN/read_NEPLAN_example.py
View file @
f91e6081
...
...
@@ -3,13 +3,46 @@
import
read_NEPLAN
import
re
file
=
r
"C:\Users\jdi-bli\Desktop\Test\Slack_Rxline_PQLoad.rlf"
file
=
r
"C:\Users\admin\Desktop\Load_read\Load_flow_WCSS.rlf"
# Example 1: Read in all variable
print
(
'************************ Test for read in all variable start ****************'
)
result
=
read_NEPLAN
.
readsim
(
file
)
for
i
in
range
(
6
):
print
(
result
[
i
])
# result as list of TimeSeries
for
i
in
range
(
len
(
result
)):
print
(
'%s is %s'
%
(
result
[
i
].
name
,
result
[
i
].
values
))
# result as list of TimeSeries
print
(
'************************ Test for read in all variable end ****************'
)
print
(
'
\n
'
)
# Example 2: Read in specific variable
print
(
'************************ Test for read in specific variable start ****************'
)
print
(
'************************ Read in specific Voltage ****************'
)
result1
=
read_NEPLAN
.
readsim
(
file
,
'FOUR.U'
)
for
i
in
range
(
len
(
result1
)):
print
(
'%s is %s'
%
(
result1
[
i
].
name
,
result1
[
i
].
values
))
print
(
'************************ Read in specific Current ****************'
)
result2
=
read_NEPLAN
.
readsim
(
file
,
'LINE89.I'
)
for
i
in
range
(
len
(
result2
)):
print
(
'%s is %s'
%
(
result2
[
i
].
name
,
result2
[
i
].
values
))
print
(
'************************ Test for read in specific variable end ****************'
)
print
(
'
\n
'
)
# Example 3: Read in using regular expression
print
(
'************************ Test for read in using Regular Expression start ****************'
)
result3
=
read_NEPLAN
.
readsim
(
file
,
'^LINE89.*$'
,
True
)
for
i
in
range
(
len
(
result3
)):
print
(
'%s is %s'
%
(
result3
[
i
].
name
,
result3
[
i
].
values
))
print
(
'************************ Test for read in using Regular Expression end ****************'
)
print
(
'
\n
'
)
# all_bus_voltages = readsim_Neplan.readsim(file, )
# all_comp_currents = ...
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment