def downsample_ds(normlogSAR, downsample_factor=5):
    """Spatially downsample an xarray DataArray or Dataset.
    """
    downsampled = normlogSAR.groupby_bins('x',len(normlogSAR.x)/downsample_factor).mean(dim='x').groupby_bins('y',len(normlogSAR.y)/downsample_factor).mean(dim='y')
    downsampled = downsampled.rename({'x_bins':'x','y_bins':'y'})
    return downsampled