Exemplo n.º 1
0
    def readCoord(self, fqRange=(20,20000), norm=1):
        amp = []
        fq = []
        for i in range(self.binCount):
            f, a = self.readAvg(i)
            if f < fqRange[0] or f > fqRange[1]:
                continue
            # take log of a
            if norm:
                f = math.log(f, 10)
            amp.append(a)
            fq.append(f)
        # always add min and max to fq values, w/ zero amp
        # this is necessary before normalization
        # unit interval will then map to min and max
        for val in fqRange:
            fq.append(math.log(val, 10))
            amp.append(0)

        # normalize values
        if norm:
            amp = unit.unitNormRange(amp)
            fq = unit.unitNormRange(fq)
        
        coord = []
        # make pairs
        for i in range(len(amp)):
            coord.append((fq[i], amp[i]))
        return coord
Exemplo n.º 2
0
    def __call__(self, valArray, tArray, refDictArray):
        # vale and time should always be the same length
        assert (len(valArray) == len(tArray)
                and len(tArray) == len(refDictArray))
        # process each value
        self.currentValue = []

        # normalize all values and add to selector w/ pre-defiend
        normSeries = unit.unitNormRange(valArray)
        selector = basePmtr.Selector(normSeries, self.control)

        for i in range(len(valArray)):
            val = valArray[i]  # original value
            t = tArray[i]
            refDict = refDictArray[i]
            # get normalized val from selector, remap b/n min and max
            postVal = unit.denorm(selector(), self.minObj(t, refDict),
                                  self.maxObj(t, refDict))
            self.currentValue.append(postVal)

        # return list of values
        return self.currentValue
Exemplo n.º 3
0
    def __call__(self, valArray, tArray, refDictArray):
         # vale and time should always be the same length
        assert (len(valArray) == len(tArray) and 
                  len(tArray) == len(refDictArray))
        # process each value
        self.currentValue = []

        # normalize all values and add to selector w/ pre-defiend
        normSeries = unit.unitNormRange(valArray)
        selector = basePmtr.Selector(normSeries, self.control)

        for i in range(len(valArray)):
            val = valArray[i] # original value
            t = tArray[i]
            refDict = refDictArray[i]
            # get normalized val from selector, remap b/n min and max
            postVal = unit.denorm(selector(), 
                         self.minObj(t, refDict),   self.maxObj(t, refDict))
            self.currentValue.append(postVal)

        # return list of values
        return self.currentValue
Exemplo n.º 4
0
    def extract(self, fmt='table', norm=1, rowStart=None, rowEnd=None, 
                      centerOffset=0, width=None):
        """ tage a segmetn from the 2d table datas
        width should not be negative
        norm: turn normalizing on or off; will change into list, even if an array

        >>> a = Table([[1,2,3], [4,5,6]])
        >>> a.extract('table', 1, 0, 1, 2)
        [[1.0, 0.0, 0.5]]
        """
        fmt = fmt.lower() # lower for reading values
        if rowStart == None: rowStart = 0
        if rowEnd == None: rowEnd = len(self.data)
        if centerOffset == None: centerOffset = 0
        if width == None: width = self.colCount
        elif width <= 0: width = 1 # never less than == 0
            
        # provide modulus of start
        rowStart = rowStart % self.rowCount
        rowEnd = rowEnd % (self.rowCount+1)

        data = self.data[rowStart:rowEnd]
        
        c = self._getCenter() + centerOffset # shift index value
        lOffset, rOffset = drawer.intHalf(width)

        # note: these values may exceed index values:
        # will be wraped with the drawer util
        lSlice = (c - lOffset)
        rSlice = (c + rOffset)

        # this will force that a copy is made and og data is not altered
        dataFilter = []

        if 'pair' in fmt: fmtCellExtract = 'pair'
        elif 'indexactive' in fmt: fmtCellExtract = 'indexactive'
        elif 'indexpassive' in fmt: fmtCellExtract = 'indexpassive'
        # these must follow searches above
        elif 'index' in fmt: fmtCellExtract = 'index'
        elif 'active' in fmt: fmtCellExtract = 'valueactive'
        elif 'passive' in fmt: fmtCellExtract = 'valuepassive'          
        else: fmtCellExtract = 'value' # default
        
        for step in data:
            dataFilter.append(drawer.listSliceWrap(step, lSlice, 
                                                    rSlice, fmtCellExtract))

        # tabular output
        if fmt == 'table': # should these range be provided?
            # cannot provide values to getMinMax; will return None if both
            # min and max not set, and unit proc will find automatically
            if norm: return unit.unitNormRangeTable(dataFilter, self._getMinMax())
            else: return dataFilter
            
        # read tabel and concat into one list
        elif 'flat' in fmt: # 
            if 'column' in fmt: # must rotate to read columns
                dataFilter = self._rotate(dataFilter)
            # 'row' or default
            dataFlat = []
            for row in dataFilter: 
                if 'reflect' in fmt or 'flip' in fmt: row.reverse()
                for val in row:
                    dataFlat.append(val)
            if norm: # minMax may be None
                dataFlat = unit.unitNormRange(dataFlat, self._getMinMax(dataFlat))
            return dataFlat
        # lists of data based on row/col operations; 
        # one value per row/col; min is always 0, max may be much greater
        else:             
            if 'column' in fmt: # must rotate to read columns
                dataFilter = self._rotate(dataFilter)
            # 'row' or default
            dataFlat = []            
            if 'sum' in fmt:
                for row in dataFilter:
                    x = 0
                    for val in row: 
                        x = x + val
                    dataFlat.append(x)  
            elif 'average' in fmt: 
                rowWidth = len(dataFilter[0]) # all rows must be the same
                for row in dataFilter:
                    x = 0
                    for val in row: x = x + val
                    # only change integers, as other number types may be here, 
                    # such as floats and decimals
                    if drawer.isInt(x): x = float(x)
                    dataFlat.append(x/rowWidth)
            elif 'product' in fmt: # multiply each value
                for row in dataFilter:
                    x = 1 # init value here is 1
                    for val in row: x = x * val
                    dataFlat.append(x)
            # noramlization for all but binary
            if norm:
                dataFlat = unit.unitNormRange(dataFlat, self._getMinMax(dataFlat))
            return dataFlat
Exemplo n.º 5
0
    def extract(self, fmt='table', norm=1, rowStart=None, rowEnd=None, 
                      centerOffset=0, width=None):
        """ tage a segmetn from the 2d table datas
        width should not be negative
        norm: turn normalizing on or off; will change into list, even if an array

        >>> a = Table([[1,2,3], [4,5,6]])
        >>> a.extract('table', 1, 0, 1, 2)
        [[1.0, 0.0, 0.5]]
        """
        fmt = fmt.lower() # lower for reading values
        if rowStart == None: rowStart = 0
        if rowEnd == None: rowEnd = len(self.data)
        if centerOffset == None: centerOffset = 0
        if width == None: width = self.colCount
        elif width <= 0: width = 1 # never less than == 0
            
        # provide modulus of start
        rowStart = rowStart % self.rowCount
        rowEnd = rowEnd % (self.rowCount+1)

        data = self.data[rowStart:rowEnd]
        
        c = self._getCenter() + centerOffset # shift index value
        lOffset, rOffset = drawer.intHalf(width)

        # note: these values may exceed index values:
        # will be wraped with the drawer util
        lSlice = (c - lOffset)
        rSlice = (c + rOffset)

        # this will force that a copy is made and og data is not altered
        dataFilter = []

        if 'pair' in fmt: fmtCellExtract = 'pair'
        elif 'indexactive' in fmt: fmtCellExtract = 'indexactive'
        elif 'indexpassive' in fmt: fmtCellExtract = 'indexpassive'
        # these must follow searches above
        elif 'index' in fmt: fmtCellExtract = 'index'
        elif 'active' in fmt: fmtCellExtract = 'valueactive'
        elif 'passive' in fmt: fmtCellExtract = 'valuepassive'          
        else: fmtCellExtract = 'value' # default
        
        for step in data:
            dataFilter.append(drawer.listSliceWrap(step, lSlice, 
                                                    rSlice, fmtCellExtract))

        # tabular output
        if fmt == 'table': # should these range be provided?
            # cannot provide values to getMinMax; will return None if both
            # min and max not set, and unit proc will find automatically
            if norm: return unit.unitNormRangeTable(dataFilter, self._getMinMax())
            else: return dataFilter
            
        # read tabel and concat into one list
        elif 'flat' in fmt: # 
            if 'column' in fmt: # must rotate to read columns
                dataFilter = self._rotate(dataFilter)
            # 'row' or default
            dataFlat = []
            for row in dataFilter: 
                if 'reflect' in fmt or 'flip' in fmt: row.reverse()
                for val in row:
                    dataFlat.append(val)
            if norm: # minMax may be None
                dataFlat = unit.unitNormRange(dataFlat, self._getMinMax(dataFlat))
            return dataFlat
        # lists of data based on row/col operations; 
        # one value per row/col; min is always 0, max may be much greater
        else:             
            if 'column' in fmt: # must rotate to read columns
                dataFilter = self._rotate(dataFilter)
            # 'row' or default
            dataFlat = []            
            if 'sum' in fmt:
                for row in dataFilter:
                    x = 0
                    for val in row: 
                        x = x + val
                    dataFlat.append(x)  
            elif 'average' in fmt: 
                rowWidth = len(dataFilter[0]) # all rows must be the same
                for row in dataFilter:
                    x = 0
                    for val in row: x = x + val
                    # only change integers, as other number types may be here, 
                    # such as floats and decimals
                    if drawer.isInt(x): x = float(x)
                    dataFlat.append(x/rowWidth)
            elif 'product' in fmt: # multiply each value
                for row in dataFilter:
                    x = 1 # init value here is 1
                    for val in row: x = x * val
                    dataFlat.append(x)
            # noramlization for all but binary
            if norm:
                dataFlat = unit.unitNormRange(dataFlat, self._getMinMax(dataFlat))
            return dataFlat