

def aggregate_periods(self, periods):
    'Returns list of ndarrays averaged to a given number of periods.\n\n        Arguments:\n        periods -- desired number of periods as int\n        '
    try:
        fieldname = self.raster_field.name
    except TypeError:
        raise exceptions.FieldDoesNotExist('Raster field not found')
    arrays = self.arrays(fieldname)
    arr = arrays[0]
    fill = getattr(arr, 'fill_value', None)
    if (getattr(arr, 'ndim', 0) > 2):
        arrays = np.vstack(arrays)
    marr = np.ma.array(arrays, fill_value=fill, copy=False)
    try:
        means = marr.reshape((periods, (- 1))).mean(axis=1)
    except ValueError:
        means = [a.mean() for a in np.array_split(marr, periods)]
    obj = self[0]
    setattr(obj, fieldname, means)
    return [obj]

dataset/ETHPy150Open bkg/django-spillway/spillway/query.py RasterQuerySet.aggregate_periods/original