Beispiel #1
0
    def mean(self, axis=None):
        '''
        Compute tha arithmetic mean along the specified axis.

        :param axis: (*int*) Axis along which the standard deviation is computed. 
            The default is to compute the standard deviation of the flattened array.
        
        returns: (*array_like*) Mean result
        '''
        if axis is None:
            return ArrayMath.mean(self.array)
        else:
            return MIArray(ArrayMath.mean(self.array, axis))
Beispiel #2
0
    def mean(self, axis=None):
        '''
        Compute tha arithmetic mean along the specified axis.

        :param axis: (*int*) Axis along which the standard deviation is computed. 
            The default is to compute the standard deviation of the flattened array.
        
        returns: (*array_like*) Mean result
        '''
        if axis is None:
            return ArrayMath.mean(self.array)
        else:
            return MIArray(ArrayMath.mean(self.array, axis))
Beispiel #3
0
 def month_to_season(self, season):
     '''
     Computes a user-specified three-month seasonal mean
     (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ).
     The first average (DJF=JF) and the last average (NDJ=ND) are actually 
     two-month averages.
     
     The time (leftmost) dimension must be divisible by 12. The data are assumed 
     to be monthly mean data and the first record is assumed to be January.
     
     :param season: (*string*) A string representing the season to 
         calculate: e.g., "JFM", "JJA".
         
     :returns: Season averaged data array.
     '''
     nmonth = self.dimlen(0)
     nyear = nmonth / 12
     seasons = ['DJF','JFM','FMA','MAM','AMJ','MJJ','JJA','JAS','ASO','SON','OND','NDJ']
     season = season.upper()
     if not season in seasons:
         print 'Season string is not valid: "' + season + '"!'
         raise KeyError()
     idx = seasons.index(season) - 1
     keys = []
     keys.append(slice(0,nyear,1))
     for i in range(1, self.ndim):
         keys.append(slice(None,None,None))
     r = self.__getitem__(tuple(keys))
     si = idx
     for i in range(nyear):
         ei = si + 3
         if si < 0:
             si = 0
         if ei > nmonth:
             ei = nmonth
         keys[0] = slice(si,ei,1)
         sdata = self.__getitem__(tuple(keys))
         sdata = ArrayMath.mean(sdata.asarray(), 0)
         keys[0] = i
         r.__setitem__(tuple(keys), sdata)
         si += 12
     
     return r