speed improvement to resample_grid()