PhilipMostert / PointedSDMs

Wrapper function for 'inlabru' for modeling species distribution models from disparate datasets.
24 stars 6 forks source link

Faster spat cov annotation #17

Closed RRTogunov closed 3 months ago

RRTogunov commented 3 months ago

Three updates to speed up processing of environmental data:

  1. apply 'class' on just the first row of covariate data instead of converting the whole spatRaster to a data.frame for getting class of covariate.
  2. annotate all environmental data covariates for all species and datasets simultaneously, then split into nested dataset-species lists. This is repeated for annotating covariate data at mesh nodes. This replaces the nested for loops, which were responsible for the very slow data preparation.
  3. use custom nearestValue function based on FNN package to annotate covariates using nearest non-NA cell. this is significantly faster than inlabru::bru_fill_missing().

Note: I have only tested with locations as class sf and spatial covariates as class SpatRaster. Some edits may be required for legacy formats (i.e., raster & sp).

PhilipMostert commented 3 months ago

Thanks, think this looks good. Might just need to import the FNN function properly.