Skip to content
Snippets Groups Projects
Commit f91e6081 authored by Bichen Li's avatar Bichen Li
Browse files

Read in node voltages and component currents

parent e2d033d0
No related branches found
No related tags found
No related merge requests found
import re import re
from dataprocessing.readtools import * from dataprocessing.readtools import *
from dataprocessing.plottools import * from dataprocessing.plottools import *
import cmath
import matplotlib.pyplot as plt 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 low = 0
high = 0 high = 0
flag = True flag = True
...@@ -11,11 +14,11 @@ def readsim(file_name,timeseries_names=None, is_regex=False): ...@@ -11,11 +14,11 @@ def readsim(file_name,timeseries_names=None, is_regex=False):
seq = [] seq = []
value = [] value = []
i = 0 i = 0
namelist = ['U','ANGLEU','P','Q','I','ANGLEI'] namelist = ['U', 'ANGLEU', 'P', 'Q', 'I', 'ANGLEI']
timeseries = [] timeseries = []
isfloat = re.compile(r'^[-+]?[0-9]+\.[0-9]+$') isfloat = re.compile(r'^[-+]?[0-9]+\.[0-9]+$')
for line in str_tmp.readlines(): for line in str_tmp.readlines():
line = line.replace(",",".") line = line.replace(",", ".")
high -= high high -= high
low -= low low -= low
del value[:] del value[:]
...@@ -30,30 +33,77 @@ def readsim(file_name,timeseries_names=None, is_regex=False): ...@@ -30,30 +33,77 @@ def readsim(file_name,timeseries_names=None, is_regex=False):
else: else:
value.append(line[low:high]) value.append(line[low:high])
else: # NONE else: # NONE
value.append(r'#') #No value, set as # value.append(r'#') # No value, set as #
low = high + 1 low = high + 1
high += 1 high += 1
if flag is False: if flag is False:
dic[i] = dict(zip(seq, value)) dic[i] = dict(zip(seq, value))
i += 1 i += 1
if value[0] is not '0': check_pass = True
nameindex = [] if timeseries_names is None and is_regex is False:
for m in range(5): if value[0] == '0':
nameindex.append(seq[1] + '.' + seq[2] + '.' + namelist[m]) for m in range(2):
if timeseries_names is None and is_regex is False: timeseries.append(TimeSeries(value[1] + '.' + namelist[m], 0, value[m + 6]))
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]))
else: else:
# Read in specified time series for check in range(len(timeseries) - 1):
for m in range(5): if timeseries[check].name == value[3] + '.' + namelist[4]:
if timeseries_names is namelist[m]: check_pass = False
timeseries.append(TimeSeries(nameindex[m], 0, value[m + 6])) 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 flag = False
str_tmp.close() str_tmp.close()
return timeseries return timeseries
...@@ -3,13 +3,46 @@ ...@@ -3,13 +3,46 @@
import read_NEPLAN import read_NEPLAN
import re 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 # Example 1: Read in all variable
print('************************ Test for read in all variable start ****************')
result = read_NEPLAN.readsim(file) result = read_NEPLAN.readsim(file)
for i in range(6): for i in range(len(result)):
print(result[i]) # result as list of TimeSeries 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 # 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_bus_voltages = readsim_Neplan.readsim(file, )
# all_comp_currents = ... # all_comp_currents = ...
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment