Calculates the set of entries not present in the second vector. Added for convenience since this is not supported by default in R.
a %notin% b
a %notin% b
a |
First |
b |
Second |
A vector
of logical
entries of 'a'
not present in 'b'
.
Martin Jung
# example code
# example code
ibis.iSDM
This function expects a downscaled GLOBIOM output as created in
the BIOCLIMA project. It converts the input to a stars object to be fed to
the ibis.iSDM
R-package.
conv_downscalr2ibis( fname, ignore = NULL, period = "all", template = NULL, shares_to_area = FALSE, use_gdalutils = FALSE, verbose = TRUE )
conv_downscalr2ibis( fname, ignore = NULL, period = "all", template = NULL, shares_to_area = FALSE, use_gdalutils = FALSE, verbose = TRUE )
fname |
A filename in |
ignore |
A |
period |
A |
template |
An optional |
shares_to_area |
A |
use_gdalutils |
(Deprecated) |
verbose |
|
A SpatRaster
stack with the formatted GLOBIOM predictors.
Martin Jung
## Not run: ## Does not work unless downscalr file is provided. # Expects a filename pointing to a netCDF file. covariates <- conv_downscalr2ibis(fname) ## End(Not run)
## Not run: ## Does not work unless downscalr file is provided. # Expects a filename pointing to a netCDF file. covariates <- conv_downscalr2ibis(fname) ## End(Not run)
Shows the size of the objects currently in the R environment. Helps to locate large objects cluttering the R environment and/or causing memory problems during the execution of large workflows.
misc_objectSize(n = 10)
misc_objectSize(n = 10)
n |
Number of objects to show, Default: |
A data frame with the row names indicating the object name, the field 'Type' indicating the object type, 'Size' indicating the object size, and the columns 'Length/Rows' and 'Columns' indicating the object dimensions if applicable.
Bias Benito
if(interactive()){ #creating dummy objects x <- matrix(runif(100), 10, 10) y <- matrix(runif(10000), 100, 100) #reading their in-memory size misc_objectSize() }
if(interactive()){ #creating dummy objects x <- matrix(runif(100), 10, 10) y <- matrix(runif(10000), 100, 100) #reading their in-memory size misc_objectSize() }
Prepared covariates often have special characters in their variable names which can or can not be used in formulas or cause errors for certain procedures. This function converts special characters (points, underscores or similar) of variable names into a species format.
misc_sanitizeNames(names)
misc_sanitizeNames(names)
names |
A vector
of sanitized character
.
# Correct variable names vars <- c("Climate-temperature2015", "Elevation__sealevel", "Landuse.forest..meanshare") misc_sanitizeNames(vars)
# Correct variable names vars <- c("Climate-temperature2015", "Elevation__sealevel", "Landuse.forest..meanshare") misc_sanitizeNames(vars)
This function serves as a general wrapper function to export a provided spatial gridded layer as multi-dimensional NetCDF file. It furthermore requires the specification of a list containing metadata information.
spl_exportNetCDF( obj, filename, global_meta = system.file("iiasa_meta.yaml", package = "BNRTools"), separate_meta = FALSE, ... )
spl_exportNetCDF( obj, filename, global_meta = system.file("iiasa_meta.yaml", package = "BNRTools"), separate_meta = FALSE, ... )
obj |
A |
filename |
A |
global_meta |
A global metadata descriptor by default using IIASA standard
metadata (Default: |
separate_meta |
A |
... |
Any other metadata that should be overwritten or added to |
The default metadata is contained in "inst/iiasa_meta"
. See examples.
A support for 'stars'
could be added.
Martin Jung
# Load default metadata (loaded by default by function too) meta <- yaml::read_yaml(system.file("iiasa_meta.yaml", package = "BNRTools")) # Dummy raster obj <- terra::rast(ncol = 100, nrow = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100, resolution = 5, crs = terra::crs("WGS84"), val = runif(400) ) # Export spl_exportNetCDF(obj, filename = "test.nc", global_meta = meta, title = "Super cool analysis")
# Load default metadata (loaded by default by function too) meta <- yaml::read_yaml(system.file("iiasa_meta.yaml", package = "BNRTools")) # Dummy raster obj <- terra::rast(ncol = 100, nrow = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100, resolution = 5, crs = terra::crs("WGS84"), val = runif(400) ) # Export spl_exportNetCDF(obj, filename = "test.nc", global_meta = meta, title = "Super cool analysis")
This function replaces all NA values in a spatial gridded layer with
a fixed value such as for example 0
. Accepted input layers are for SpatRaster
from
the "terra"
R-package and stars
from the "stars"
R-package.
spl_replaceGriddedNA(obj, value = 0, mask, verbose = FALSE)
spl_replaceGriddedNA(obj, value = 0, mask, verbose = FALSE)
obj |
A |
value |
A fixed numeric value of which all |
mask |
An optional |
verbose |
Be chatty about what is processed (Default: |
Required inputs are a single "obj"
gridded data object and a numeric value.
In addition an optional mask layer can be provided that to use a mask. In this case
all no-data values a replaced with the value in this mask.
A object of the same type as the input but with no-data values replaced with 'value'
.
Martin Jung
# Example s <- terra::rast(system.file("ex/logo.tif", package="terra")) s[sample(1:terra::ncell(s), 100)] <- NA sfill <- spl_replaceGriddedNA(s, value = 100) terra::plot(sfill)
# Example s <- terra::rast(system.file("ex/logo.tif", package="terra")) s[sample(1:terra::ncell(s), 100)] <- NA sfill <- spl_replaceGriddedNA(s, value = 100) terra::plot(sfill)
Resample two raster to the spatial resolution using aggregation or disaggregation.
spl_resampleRas(x, y, discrete = FALSE)
spl_resampleRas(x, y, discrete = FALSE)
x |
A |
y |
A |
discrete |
|
set.seed(42) ras_a <- terra::rast(ncol = 100, nrow = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100, resolution = 20, crs = NA) ras_b <- terra::rast(ncol = 100, nrow = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100, resolution = 5, crs = NA) terra::values(ras_a) <- runif(n = terra::ncell(ras_a)) terra::values(ras_b) <- runif(n = terra::ncell(ras_b)) spl_resampleRas(x = ras_a, y = ras_b)
set.seed(42) ras_a <- terra::rast(ncol = 100, nrow = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100, resolution = 20, crs = NA) ras_b <- terra::rast(ncol = 100, nrow = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100, resolution = 5, crs = NA) terra::values(ras_a) <- runif(n = terra::ncell(ras_a)) terra::values(ras_b) <- runif(n = terra::ncell(ras_b)) spl_resampleRas(x = ras_a, y = ras_b)