當前位置: 首頁>>代碼示例>>Python>>正文


Python FileIO.saveFile方法代碼示例

本文整理匯總了Python中FileIO.saveFile方法的典型用法代碼示例。如果您正苦於以下問題:Python FileIO.saveFile方法的具體用法?Python FileIO.saveFile怎麽用?Python FileIO.saveFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在FileIO的用法示例。


在下文中一共展示了FileIO.saveFile方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GenerateSinusoid

# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import saveFile [as 別名]
class GenerateSinusoid(object):
    '''
    b111001100000,1,1,1,0,0,1,1,0,0,0,0,0
    '''
    def __init__(self, busName, fileBufferSize, bitResolution, upLimit=None, loLimit=None, p2pShrink=None):
        self.busName = busName
        self.fileBufferSize = fileBufferSize
        self.bitResolution = bitResolution
        self.upLimit = upLimit
        self.loLimit = loLimit
        self.p2pShrink = p2pShrink
        self.fileIO = FileIO()

    def run(self):
        self.genFileHeader()
        self.genSinusoid()
        self.genWaveformFile()

    def genFileHeader(self):
        header = '{},'
        for j in range(self.bitResolution-1, -1, -1):
            if j == self.bitResolution-1:
                header = header + '[{}] MSB,'.format(j)
            elif j == 0:
                header = header + '[{}] LSB'.format(j)
            else:
                header = header + '[{}],'.format(j)
        self.fileHeader = header.format(self.busName)

    def genSinusoid(self):
        sizeByte_2 = (2**self.bitResolution - 1)/2
        sinStepSize = (2*m.pi) / self.fileBufferSize
        self.byteValues = []

        if (self.upLimit == None and self.loLimit == None):
            if self.p2pShrink == None:
                for j in range(self.fileBufferSize):
                    b = format((round(sizeByte_2+(sizeByte_2*m.sin(j*sinStepSize)))),'0{}b'.format(self.bitResolution))
                    b = 'b'+ b
                    self.byteValues.append(b)
            else:
                sineP2P = sizeByte_2 - self.p2pShrink/2
                for j in range(self.fileBufferSize):
                    b = format((round(sizeByte_2+(sineP2P*m.sin(j*sinStepSize)))),'0{}b'.format(self.bitResolution))
                    b = 'b'+ b
                    self.byteValues.append(b)
        else:
            sineUpLimFactor = self.upLimit/2
            sineLoLimFactor = sizeByte_2 - self.loLimit
            for j in range(self.fileBufferSize):
                sineVal = m.sin(j*sinStepSize)
                if sineVal >= 0:
                    b = format((round(sizeByte_2+(sineUpLimFactor*sineVal))),'0{}b'.format(self.bitResolution))
                    b = 'b'+ b
                    self.byteValues.append(b)
                else:
                    b = format((round(sizeByte_2+(sineLoLimFactor*sineVal))),'0{}b'.format(self.bitResolution))
                    b = 'b'+ b
                    self.byteValues.append(b)

    def genCSVbyte(self, byteString):
        b = byteString.replace('b','')
        j = ''
        for i in b:
            j = j + i + ','
        j = ',' + j.strip(',')
        return j

    def genWaveformFile(self):
        self.fileIO.saveFile(exten='.csv',ftypes=[('comma separated value', '.csv'),('all files', '.*')],
                        ifilen='myfile.csv')
        waveFile = self.fileIO.getSavedFile()
        waveFile.write(self.fileHeader + '\n')
        for i in self.byteValues:
            waveFile.write(i + self.genCSVbyte(i) + '\n')
        waveFile.close()
開發者ID:Maxfooo,項目名稱:WaveformBitVectorGen,代碼行數:78,代碼來源:GenerateSinusoid.py

示例2: GenerateRamp

# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import saveFile [as 別名]
class GenerateRamp(object):
    
    
    def __init__(self, busName, fileBufferSize, bitResolution, cycles, upLimit=None, loLimit=None, p2pShrink=None):
        self.busName = busName
        self.fileBufferSize = fileBufferSize
        self.bitResolution = bitResolution
        self.cycles = cycles
        self.upLimit = upLimit
        self.loLimit = loLimit
        self.p2pShrink = p2pShrink
        self.fileIO = FileIO()
        
    def run(self):
        self.genFileHeader()
        self.genRamp()
        self.genWaveformFile()

    def genFileHeader(self):
        header = '{},'
        for j in range(self.bitResolution-1, -1, -1):
            if j == self.bitResolution-1:
                header = header + '[{}] MSB,'.format(j)
            elif j == 0:
                header = header + '[{}] LSB'.format(j)
            else:
                header = header + '[{}],'.format(j)
        self.fileHeader = header.format(self.busName)
        
        
    def genRamp(self):
        maxVal = (2**self.bitResolution - 1)
        #stepLength = self.fileBufferSize / self.cycles / maxVal
        stepSize = self.cycles
        self.byteValues = []
        
        if (self.upLimit == None and self.loLimit == None):
            if self.p2pShrink == None:
                for i in range(self.cycles):
                    for j in range(m.floor(self.fileBufferSize/self.cycles)):
                        s = j*stepSize
                        if s > maxVal:
                            s = maxVal
                        b = format((round(s)),'0{}b'.format(self.bitResolution))
                        b = 'b'+ b
                        self.byteValues.append(b)
        
            else:
                topVal = maxVal - self.p2pShrink
                botVal = self.p2pShrink
                for i in range(self.cycles):
                    for j in range(m.floor(self.fileBufferSize/self.cycles) - self.p2pShrink*2):
                        s = j*stepSize + botVal
                        if s > topVal:
                            s = topVal
                        b = format((round(s)),'0{}b'.format(self.bitResolution))
                        b = 'b'+ b
                        self.byteValues.append(b)
        
        else:
            for i in range(self.cycles):
                for j in range(m.floor(self.fileBufferSize/self.cycles) - ((maxVal - self.upLimit) + self.loLimit)):
                    s = j*stepSize + self.loLimit
                    if s > self.upLimit:
                        s = self.upLimit
                    b = format((round(s)),'0{}b'.format(self.bitResolution))
                    b = 'b'+ b
                    self.byteValues.append(b)
        
    
    def genCSVbyte(self, byteString):
        b = byteString.replace('b','')
        j = ''
        for i in b:
            j = j + i + ','
        j = ',' + j.strip(',')
        return j

    def genWaveformFile(self):
        self.fileIO.saveFile(exten='.csv',ftypes=[('comma separated value', '.csv'),('all files', '.*')],
                        ifilen='myfile.csv')
        waveFile = self.fileIO.getSavedFile()
        waveFile.write(self.fileHeader + '\n')
        for i in self.byteValues:
            waveFile.write(i + self.genCSVbyte(i) + '\n')
        waveFile.close()
開發者ID:Maxfooo,項目名稱:WaveformBitVectorGen,代碼行數:88,代碼來源:GenerateRamp.py


注:本文中的FileIO.saveFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。