def downsample(data, n, axis=0, xvals='subsample'):
 ma = None
 if (hasattr(data, 'implements') and data.implements('MetaArray')):
  ma = data
  data = data.view(np.ndarray)
 if hasattr(axis, '__len__'):
  if (not hasattr(n, '__len__')):
   n = ([n] * len(axis))
  for i in range(len(axis)):
   data = downsample(data, n[i], axis[i])
  return data
 if (n <= 1):
  return data
 nPts = int((data.shape[axis] / n))
 s = list(data.shape)
 s[axis] = nPts
 s.insert((axis + 1), n)
 sl = ([slice(None)] * data.ndim)
 sl[axis] = slice(0, (nPts * n))
 d1 = data[tuple(sl)]
 d1.shape = tuple(s)
 d2 = d1.mean((axis + 1))
 if (ma is None):
  return d2
 else:
  info = ma.infoCopy()
  if ('values' in info[axis]):
   if (xvals == 'subsample'):
    info[axis]['values'] = info[axis]['values'][::n][:nPts]
   elif (xvals == 'downsample'):
    info[axis]['values'] = downsample(info[axis]['values'], n)
  return MetaArray(d2, info=info)

def downsample ( data , n , axis = 0 , xvals = 'subsample' ) : ma = None if ( hasattr ( data , 'implements' ) and data . implements ( 'MetaArray' ) ) : ma = data data = data . view ( np . ndarray ) if hasattr ( axis , '__len__' ) : if ( not hasattr ( n , '__len__' ) ) : n = ( [ n ] * len ( axis ) ) for i in range ( len ( axis ) ) : data = downsample ( data , n [ i ] , axis [ i ] ) return data if ( n <= 1 ) : return data nPts = int ( ( data . shape [ axis ] / n ) ) s = list ( data . shape ) s [ axis ] = nPts s . insert ( ( axis + 1 ) , n ) sl = ( [ slice ( None ) ] * data . ndim ) sl [ axis ] = slice ( 0 , ( nPts * n ) ) d1 = data [ tuple ( sl ) ] d1 . shape = tuple ( s ) d2 = d1 . mean ( ( axis + 1 ) ) if ( ma is None ) : return d2 else : info = ma . infoCopy ( ) if ( 'values' in info [ axis ] ) : if ( xvals == 'subsample' ) : info [ axis ] [ 'values' ] = info [ axis ] [ 'values' ] [ : : n ] [ : nPts ] elif ( xvals == 'downsample' ) : info [ axis ] [ 'values' ] = downsample ( info [ axis ] [ 'values' ] , n ) return MetaArray ( d2 , info = info )
downsample by averaging points together across axis .