2015-04-09 00:41:22 +08:00
|
|
|
|
__author__ = 'dmy'
|
|
|
|
|
|
|
|
|
|
|
|
import numpy
|
|
|
|
|
|
|
|
|
|
|
|
class IEEEData:
|
|
|
|
|
|
def __init__(self,filePath,seperator='\t'):
|
|
|
|
|
|
self._filePath=filePath
|
|
|
|
|
|
self._seperator=seperator
|
|
|
|
|
|
self._read()
|
|
|
|
|
|
def _convertToVector(self,lineVec):#把数据文件按分隔符存成矩阵,像Matlab一样。
|
2015-04-30 22:42:21 +08:00
|
|
|
|
#先全部转换为列表
|
|
|
|
|
|
maxLen=0
|
|
|
|
|
|
for v in lineVec:
|
|
|
|
|
|
if maxLen<len(v):
|
|
|
|
|
|
maxLen=len(v)
|
|
|
|
|
|
array=numpy.zeros( (len(lineVec),maxLen),dtype=float)
|
|
|
|
|
|
for (i,c) in enumerate(lineVec):
|
|
|
|
|
|
for (j,v) in enumerate(c):
|
|
|
|
|
|
array[i,j]=v
|
|
|
|
|
|
self._array=array
|
|
|
|
|
|
return self._array
|
2015-04-09 00:41:22 +08:00
|
|
|
|
|
|
|
|
|
|
def _read(self):
|
|
|
|
|
|
lineVec=[]
|
|
|
|
|
|
with open(self._filePath,'tr') as f:
|
|
|
|
|
|
for line in f:
|
|
|
|
|
|
if len(line.strip())==0:
|
|
|
|
|
|
continue
|
|
|
|
|
|
lineVec.append([float(x) for x in line.split(self._seperator)])
|
2015-04-30 22:42:21 +08:00
|
|
|
|
array=self._convertToVector(lineVec)
|
|
|
|
|
|
self._toLine(array)
|
|
|
|
|
|
self._toTrans(array)
|
|
|
|
|
|
self._toPQbus(array)
|
|
|
|
|
|
self._toPG(array)
|
|
|
|
|
|
self._toQG(array)
|
|
|
|
|
|
self.busNum=array[0,1]
|
|
|
|
|
|
|
|
|
|
|
|
def _toTrans(self,array):
|
|
|
|
|
|
zeros=numpy.where(array[:,0]==0)[0]
|
|
|
|
|
|
self.transBlock=array[zeros[2]+1:zeros[3],:]
|
|
|
|
|
|
|
|
|
|
|
|
def _toLine(self,array):
|
|
|
|
|
|
zeros=numpy.where(array[:,0]==0)[0]
|
|
|
|
|
|
lineBlock=array[zeros[0]+1:zeros[1],:]
|
|
|
|
|
|
self.lineBlock=lineBlock
|
|
|
|
|
|
|
|
|
|
|
|
def _toPG(self,array):
|
|
|
|
|
|
zeros=numpy.where(array[:,0]==0)[0]
|
|
|
|
|
|
self.PGBlock=array[zeros[4]+1:zeros[5],:]
|
|
|
|
|
|
|
|
|
|
|
|
def _toPQbus(self,array):
|
|
|
|
|
|
zeros=numpy.where(array[:,0]==0)[0]
|
|
|
|
|
|
self.PQbus=array[zeros[3]+1:zeros[4],:]
|
|
|
|
|
|
|
|
|
|
|
|
def _toQG(self,array):
|
|
|
|
|
|
zeros=numpy.where(array[:,0]==0)[0]
|
|
|
|
|
|
self.QG=array[zeros[4]+1:zeros[5],:]
|
|
|
|
|
|
|
2015-04-09 00:41:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|