Commit 32555fbb authored by Bichen Li's avatar Bichen Li

Move read in function from examples to readtools in DataProcessing

parent f91e6081
......@@ -2,6 +2,7 @@ import numpy as np
import pandas as pd
from .timeseries import *
import re
import cmath
def read_timeseries_Modelica(filename, timeseries_names=None, is_regex=False):
from modelicares import SimRes
......@@ -159,3 +160,106 @@ def read_timeseries_dpsim_cmpl_separate(filename, timeseries_names=None):
for result in timeseries_list:
print(result.name)
return timeseries_list
def read_timeseries_NEPLAN(file_name, timeseries_names = None, is_regex = False):
str_tmp = open(file_name, "r")
low = 0
high = 0
flag = True
dic = {}
seq = []
value = []
i = 0
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(",", ".")
high -= high
low -= low
del value[:]
for letter in line:
if letter == " " or letter == "\n": # different data or end
if low is not high: # not NONE
if flag: # seq
seq.append(line[low:high])
else: # value
if isfloat.match(line[low:high]):
value.append(float(line[low:high]))
else:
value.append(line[low:high])
else: # NONE
value.append(r'#') # No value, set as #
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]))
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
......@@ -106,4 +106,4 @@ def readsim(file_name, timeseries_names = None, is_regex = False):
flag = False
str_tmp.close()
return timeseries
return timeseries
\ No newline at end of file
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import read_NEPLAN
import re
from dataprocessing.readtools import *
file = r"C:\Users\admin\Desktop\Load_read\Load_flow_WCSS.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)
result = read_timeseries_NEPLAN(file)
for i in range(len(result)):
print('%s is %s' % (result[i].name,result[i].values)) # 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')
......@@ -21,14 +21,14 @@ 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')
result2 = read_timeseries_NEPLAN(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')
for i in range(len(result3)):
print('%s is %s' % (result3[i].name, result3[i].values))
print('************************ Test for read in specific variable end ****************')
print('\n')
......@@ -36,13 +36,8 @@ 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))
result4 = read_timeseries_NEPLAN(file, '^LINE89.*$', 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 ****************')
print('\n')
# all_bus_voltages = readsim_Neplan.readsim(file, )
# all_comp_currents = ...
\ No newline at end of file
print('\n')
\ No newline at end of file
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