def aggregate_periods(self, periods):
        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 to reshape using equal sizes first and fall back to unequal
        # splits.
        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]
Returns list of ndarrays averaged to a given number of periods.
dataset/ETHPy150Open bkg/django-spillway/spillway/query.py/RasterQuerySet.aggregate_periods