pypso/reader.py

64 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

__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一样。
#先全部转换为列表
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
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)])
array=self._convertToVector(lineVec)
self._toLine(array)
self._toTrans(array)
self._toPQbus(array)
self._toPG(array)
self._toQG(array)
self.busNum=array[0,1]
self.balance=array[2,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],:]