Ignore:
Timestamp:
08/11/07 18:17:40 (12 years ago)
Author:
astephen
Message:

Consolidation of titania version under DX with proper source in trunk of SVN.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/localRules/aircraftData.py

    r368 r3005  
    5151                    samplingRate, flagsToUse) 
    5252        elif samplingMethod=="selection": 
    53             self.subSampledVarself._subSampleBySelection(var, timeVar, flagVar, 
     53            self.subSampledVar=self._subSampleBySelection(var, timeVar, flagVar, 
    5454                    samplingRate, flagsToUse) 
    5555 
    5656 
     57    def _subSampleBySelection(self, var, timeVar, flagVar, samplingRate, flagsToUse): 
     58        """ 
     59        Returns a new variable which is 'var' sub-sampled by selecting the value 
     60        at the given samplingRate with data selected according to flagVar 
     61        including the flag values  specified in flagsToUse (defaults are 0 and 1). 
     62        """ 
     63        if samplingRate!=1: 
     64            raise "Sampling rates of values other than 1Hz are not yet supported." 
     65        maskedArray=self._getMaskedArray(var[:,0](squeeze=1), flagVar[:,0](squeeze=1), flagsToUse) 
     66        # Now re-construct variable axes etc 
     67        newTimeAxis=self._flatten2DTimeAxis(timeVar, samplingRate) 
     68        newVar=self._recreateVariable(var, maskedArray, newTimeAxis, flagVar, max(flagsToUse), missingValue=maskedArray.fill_value(), sampleBy="selection") 
     69        return newVar 
     70 
     71         
    5772    def _subSampleByAveraging(self, var, timeVar, flagVar, samplingRate, flagsToUse): 
    5873        """ 
     
    86101        # Now re-construct variable axes etc 
    87102        newTimeAxis=self._flatten2DTimeAxis(timeVar, samplingRate) 
    88         newVar=self._recreateVariable(var, newArray, newTimeAxis, flagVar, max(flagsToUse), missingValue=maskedArray.fill_value())  
     103        newVar=self._recreateVariable(var, newArray, newTimeAxis, flagVar, max(flagsToUse), missingValue=maskedArray.fill_value(), sampleBy="averaging")  
    89104        return newVar 
    90105 
     
    114129 
    115130 
    116     def _recreateVariable(self, var, newArray, timeAxis, flagVar, flagMax, missingValue): 
     131    def _recreateVariable(self, var, newArray, timeAxis, flagVar, flagMax, missingValue, sampleBy="averaging"): 
    117132        """ 
    118133        Rebuilds a variable using new array and new time axis. 
     
    133148        newvar=cdms.createVariable(data, id=var.id, fill_value=missing, axes=[timeAxis], attributes=newAtts) 
    134149        newvar.frequency=1 
    135         newvar.comment="Data re-sampled to 1Hz frequency by averaging. " 
    136         if flagVar: 
    137             newvar.comment=newvar.comment+"Values were included where the flag variable were less than %s and where both the flag value and actual data value were present (i.e. not missing values)." % (flagMax+1) 
    138         else: 
    139             newvar.comment=newvar.comment+"The flag variable was not used in creating this variable." 
    140         newvar.comment=newvar.comment+" Average data values were set to missing where more than half the values in any one second period were already missing." 
     150        if sampleBy=="averaging": 
     151            newvar.comment="Data averaged to give a pseudo sampling frequency of 1 Hz. " 
     152            if flagVar: 
     153                newvar.comment=newvar.comment+"Values were included where the flag variable was less than %s and where both the flag value and actual data value were present (i.e. not missing values)." % (flagMax+1) 
     154                newvar.comment=newvar.comment+" Average data values were set to missing where more than half the values in any one second period were already missing. Missing value was also used where more than half the flags were either missing value or values of 2 or greater." 
     155            else: 
     156                newvar.comment=newvar.comment+"The flag variable was not used in creating this variable." 
     157                newvar.comment=newvar.comment+" Average data values were set to missing where more than half the values in any one second period were already missing." 
     158        elif sampleBy=="selection": 
     159            newvar.comment="Data sub-sampled to give a pseudo sampling frequency of 1 Hz by selecting only the per-second frequency values. " 
     160            if flagVar: 
     161                newvar.comment=newvar.comment+" Values were included where the flag variable was less than 2 and where both the flag value and actual data value were present (i.e. not missing values)." 
     162            else: 
     163                newvar.comment=newvar.comment+" The flag variable was not used in creating this variable."  
    141164        return newvar 
    142165   
Note: See TracChangeset for help on using the changeset viewer.