当前位置: 首页>>代码示例>>Python>>正文


Python FileIO.getSavedFile方法代码示例

本文整理汇总了Python中FileIO.getSavedFile方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.getSavedFile方法的具体用法?Python FileIO.getSavedFile怎么用?Python FileIO.getSavedFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileIO的用法示例。


在下文中一共展示了FileIO.getSavedFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GenerateSinusoid

# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import getSavedFile [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 getSavedFile [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.getSavedFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。