Commit 48704105 authored by Bichen Li's avatar Bichen Li

-Fix Bugs when read in specific variables

-Add "_loadflow" suffix to read_in function
-Add some comments in the function
parent f3f22117
......@@ -161,12 +161,11 @@ def read_timeseries_dpsim_cmpl_separate(filename, timeseries_names=None):
print(result.name)
return timeseries_list
def read_timeseries_NEPLAN(file_name, timeseries_names = None, is_regex = False):
str_tmp = open(file_name, "r")
def read_timeseries_NEPLAN_loadflow(file_name, timeseries_names = None, is_regex = False):
str_tmp = open(file_name, "r") # Read in files
low = 0
high = 0
flag = True
dic = {}
seq = []
value = []
i = 0
......@@ -193,73 +192,46 @@ def read_timeseries_NEPLAN(file_name, timeseries_names = None, is_regex = False)
low = high + 1
high += 1
if flag is False:
dic[i] = dict(zip(seq, value))
i += 1
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:
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]))
check_pass = True # Check for current of the same component
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
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]))
for check in range(len(timeseries) - 1):
if timeseries[check].name == value[3] + '.' + namelist[4]:
check_pass = False # Find current of the same component, Calculate the current using (r,tha)
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):
timeseries.append(TimeSeries(value[3] + '.' + namelist[m], 0, value[m + 6]))
flag = False
str_tmp.close()
line_del = []
if is_regex is True:
# Read in variables which match with regex
p = re.compile(timeseries_names)
length = len(timeseries)
for rule_check in range(length):
if p.search(timeseries[rule_check].name):
pass
else:
line_del.append(rule_check);
elif timeseries_names is not None:
# Read in specified time series
length = len(timeseries)
for rule_check in range(length):
if timeseries_names == timeseries[rule_check].name:
pass
else:
line_del.append(rule_check);
for num_to_del in range(len(line_del)):
del timeseries[line_del[len(line_del) - num_to_del - 1]]
return timeseries
......@@ -9,7 +9,8 @@ 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_timeseries_NEPLAN(file)
result = read_timeseries_NEPLAN_loadflow(file)
print(result[24].values)
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 ****************')
......@@ -21,12 +22,12 @@ print('\n')
# Example 2: Read in specific variable
print('************************ Test for read in specific variable start ****************')
print('************************ Read in specific Voltage ****************')
result2 = read_timeseries_NEPLAN(file, 'FOUR.U')
result2 = read_timeseries_NEPLAN_loadflow(file, 'FOUR.U')
for i in range(len(result2)):
print('%s is %s' % (result2[i].name, result2[i].values))
print('************************ Read in specific Current ****************')
result3 = read_timeseries_NEPLAN(file, 'LINE89.I')
result3 = read_timeseries_NEPLAN_loadflow(file, 'LINE89.I')
for i in range(len(result3)):
print('%s is %s' % (result3[i].name, result3[i].values))
print('************************ Test for read in specific variable end ****************')
......@@ -36,7 +37,7 @@ print('\n')
# Example 3: Read in using regular expression
print('************************ Test for read in using Regular Expression start ****************')
result4 = read_timeseries_NEPLAN(file, '^LINE89.*$', True)
result4 = read_timeseries_NEPLAN_loadflow(file, '^.*\.I$', True)
for i in range(len(result4)):
print('%s is %s' % (result4[i].name, result4[i].values))
print('************************ Test for read in using Regular Expression end ****************')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment