Making fasterRaster faster
Adam B. Smith
2024-10-24
Source:vignettes/faster_fasterRaster.Rmd
faster_fasterRaster.Rmd
There are several ways to speed up fasterRaster functions. These are listed below in order of their most likely gains, with the first few being potentially the largest.
Load rasters and vectors directly from disk: Use
fast()
to load rasters and vectrors directly from disk. Convertingterra
orsf
objects toGRaster
s andGVector
s can be slower. Why? Because if the object does not have a file to which theR
object points, Usefast()
has to save it to disk first as a GeoTIFF or GeoPackage file, then load it intoGRASS
.Save
GRaster
s andGVector
s directly to disk: ConvertingGRaster
s andGVector
s toSpatRaster
s orSpatVector
usingrast()
orvect()
, then saving them is much slower than just saving them. Why? Because these functions actually save the file to disk then uses the respective function from the respective package to connect to the file.Increase memory and the number of cores usable by GRASS: By default,
fasterRaster
use 2 cores and 2048 MB (2 GB) of memory forGRASS
modules that allow users to specify these values. You can set these to higher values usingfaster()
and thus potentially speed up some calculations. Functions in newer versions ofGRASS
have more capacity to use these options, so updatingGRASS
to the latest version can help, too.Turn off automatic removal of temporary files in the disk cache: To obviate problems with disk space filling up, by default most fasterRaster functions delete intermediate files. However, if you are not creating a lot of very big
GRaster
s orGVector
s, you can skip this time-taking step by setting theclean
option toFALSE
usingfaster(clean = FALSE)
. By default, this setting isTRUE
. This can save a few seconds of runtime for functions that create temporary files.Do operations on
GRaster
s andGVector
s in the same coordinate reference system together: Every time you switch between using aGRaster
orGVector
with a different coordinate reference system (CRS),GRASS
has to spend a few seconds changing to that CRS. You can save some time by doing as much work as possible with objects in one CRS, then switching to work on objects in another CRS.
~ FINIS ~