def downSample(data, ndim):
    """ downSample(data, ndim)
    
    Downsample the data. Peforming a simple form of smoothing to prevent
    aliasing.
    
    """
    if ndim == 1:
        data2 = data[::2] * 0.4
        tmp = data[1::2] * 0.3
        data2[:tmp.shape[0]] += tmp
        data2[1:] += tmp[:data2.shape[0] - 1]
    elif ndim == 2:
        data2 = data[::2, ::2] * 0.4
        tmp = data[1::2, ::2] * 0.15
        data2[:tmp.shape[0], :] += tmp
        data2[1:, :] += tmp[:data2.shape[0] - 1, :]
        tmp = data[::2, 1::2] * 0.15
        data2[:, :tmp.shape[1]] += tmp
        data2[:, 1:] += tmp[:, :data2.shape[1] - 1]
    elif ndim == 3:
        data2 = data[::2, ::2, ::2] * 0.4
        tmp = data[1::2, ::2, ::2] * 0.1
        data2[:tmp.shape[0], :, :] += tmp
        data2[1:, :, :] += tmp[:data2.shape[0] - 1, :, :]
        tmp = data[::2, 1::2, ::2] * 0.1
        data2[:, :tmp.shape[1], :] += tmp
        data2[:, 1:, :] += tmp[:, :data2.shape[1] - 1, :]
        tmp = data[::2, ::2, 1::2] * 0.1
        data2[:, :, :tmp.shape[2]] += tmp
        data2[:, :, 1:] += tmp[:, :, :data2.shape[2] - 1]
    else:
        raise ValueError('Cannot downsample data of this dimension.')
    return data2
