Moving-window (focal) operations are central to spatial statistics and image processing but become computationally prohibitive for large rasters or wide neighborhoods. fastfocal is an open-source R package that accelerates additive focal calculations (i.e., sum and mean) using the Fast Fourier Transform (FFT). The software preserves computational accuracy while substantially reducing runtime and energy use for large rasters and wide neighborhoods. Because FFT-based convolution is most advantageous for large kernels, fastfocal includes an adaptive “smart switch” that automatically selects between direct spatial-domain computation and FFT-based convolution depending on raster and kernel size, ensuring comparable performance for small neighborhoods and substantial gains for larger ones. Benchmark results indicate that performance gains begin to emerge for kernel radii of approximately 400–500 m (i.e., 13 to 17 cells in radius at 30 m resolution), with increasingly larger gains for wider neighborhoods and larger rasters. For large rasters and wide kernels, fastfocal reduced computation time by roughly 75% and energy consumption by ∼75% compared with widely used reference implementations. By enabling rapid, large-scale focal operations in standard R workflows, fastfocal makes multi-scale spatial analysis more practical and energy efficient.
Ho Yi Wan (Fri,) studied this question.