nappy/contrib/aircraft/aircraftData.py
def _subSampleByAveraging(self, var, timeVar, flagVar, samplingRate, flagsToUse):
        """
        Returns a new variable which is 'var' sub-sampled by averaging
        at the given samplingRate with data selected according to flagVar
        including the flag values specified in flagsToUse (defaults are 0 and 1).
        """
        maskedArray=self._getMaskedArray(var, flagVar, flagsToUse)
        shape=var.shape
        if shape[1]==1:
            newNumArray=MV.ravel(maskedArray)
            newArrayMask=MV.ravel(maskedArray.mask())
            newArray=MA.masked_array(newNumArray, mask=newArrayMask, fill_value=maskedArray.fill_value())
        else:
            newArray=Numeric.zeros(shape[0], 'f')
            for t0 in range(shape[0]):
                # Set as missing if less than half are valid                 
                t1Array=maskedArray[t0]

                if samplingRate==1:
                    # If half or more are good values then calculate the mean
                    if t1Array.count()>=(shape[1]/2.):
                        newArray[t0]=MA.average(t1Array)
                    # otherwise set as missing value
                    else:
                        newArray[t0]=maskedArray.fill_value()
        
                else:
                    raise "Averaging for non 1Hz sampling rates not yet supported!"

        # Now re-construct variable axes etc
        newTimeAxis=self._flatten2DTimeAxis(timeVar, samplingRate)
        newVar=self._recreateVariable(var, newArray, newTimeAxis, flagVar, max(flagsToUse), missingValue=maskedArray.fill_value(), sampleBy="averaging") 
        return newVar

        Returns a new variable which is 'var' sub-sampled by averaging
        at the given samplingRate with data selected according to flagVar
        including the flag values specified in flagsToUse (defaults are 0 and 1).
        
Returns a new variable which is 'var' sub-sampled by averaging
at the given samplingRate with data selected according to flagVar
including the flag values specified in flagsToUse (defaults are 0 and 1).
Returns a new variable which is ' var ' sub - sampled by averaging at the given samplingRate with data selected according to flagVar including the flag values specified in flagsToUse ( defaults are 0 and 1 ) .
def _subSampleByAveraging(self, var, timeVar, flagVar, samplingRate, flagsToUse):
        maskedArray=self._getMaskedArray(var, flagVar, flagsToUse)
        shape=var.shape
        if shape[1]==1:
            newNumArray=MV.ravel(maskedArray)
            newArrayMask=MV.ravel(maskedArray.mask())
            newArray=MA.masked_array(newNumArray, mask=newArrayMask, fill_value=maskedArray.fill_value())
        else:
            newArray=Numeric.zeros(shape[0], 'f')
            for t0 in range(shape[0]):
                t1Array=maskedArray[t0]
                if samplingRate==1:
                    if t1Array.count()>=(shape[1]/2.):
                        newArray[t0]=MA.average(t1Array)
                    else:
                        newArray[t0]=maskedArray.fill_value()
                else:
                    raise "Averaging for non 1Hz sampling rates not yet supported!"
        newTimeAxis=self._flatten2DTimeAxis(timeVar, samplingRate)
        newVar=self._recreateVariable(var, newArray, newTimeAxis, flagVar, max(flagsToUse), missingValue=maskedArray.fill_value(), sampleBy="averaging") 
        return newVar
def _subSampleByAveraging ( self , var , timeVar , flagVar , samplingRate , flagsToUse ) : maskedArray = self . _getMaskedArray ( var , flagVar , flagsToUse ) shape = var . shape if shape [ 1 ] == 1 : newNumArray = MV . ravel ( maskedArray ) newArrayMask = MV . ravel ( maskedArray . mask ( ) ) newArray = MA . masked_array ( newNumArray , mask = newArrayMask , fill_value = maskedArray . fill_value ( ) ) else : newArray = Numeric . zeros ( shape [ 0 ] , 'f' ) for t0 in range ( shape [ 0 ] ) : t1Array = maskedArray [ t0 ] if samplingRate == 1 : if t1Array . count ( ) >= ( shape [ 1 ] / 2. ) : newArray [ t0 ] = MA . average ( t1Array ) else : newArray [ t0 ] = maskedArray . fill_value ( ) else : raise "Averaging for non 1Hz sampling rates not yet supported!" newTimeAxis = self . _flatten2DTimeAxis ( timeVar , samplingRate ) newVar = self . _recreateVariable ( var , newArray , newTimeAxis , flagVar , max ( flagsToUse ) , missingValue = maskedArray . fill_value ( ) , sampleBy = "averaging" ) return newVar
Returns a new variable which is 'var' sub-sampled by averaging
at the given samplingRate with data selected according to flagVar
including the flag values specified in flagsToUse (defaults are 0 and 1).
Returns a new variable which is ' var ' sub - sampled by averaging at the given samplingRate with data selected according to flagVar including the flag values specified in flagsToUse ( defaults are 0 and 1 ) .
"""
        Returns a new variable which is 'var' sub-sampled by averaging
        at the given samplingRate with data selected according to flagVar
        including the flag values specified in flagsToUse (defaults are 0 and 1).
        """ # Set as missing if less than half are valid                  # If half or more are good values then calculate the mean # otherwise set as missing value # Now re-construct variable axes etc
self
var
timeVar
flagVar
samplingRate
flagsToUse