Change the resolution of one datacube of a EBV netCDF based on another EBV netCDF or a given resolution.
ebv_resample(
filepath_src,
datacubepath_src = NULL,
entity_src = NULL,
timestep_src = 1,
resolution,
outputpath,
method = "bilinear",
scenario = NULL,
metric = NULL,
return_raster = FALSE,
overwrite = FALSE,
ignore_RAM = FALSE,
verbose = TRUE
)
Character. Path to the netCDF file whose resolution should be changed.
Character. Optional. Default: NULL. Path to the
datacube (use ebv_datacubepaths()
). Alternatively, you can use
the scenario and metric argument to define which cube you want to access.
Character or Integer. Default is NULL. If the structure is 3D, the entity argument is set to NULL. Else, a character string or single integer value must indicate the entity of the 4D structure of the EBV netCDFs.
Integer or character. Select one or several timestep(s). Either provide an integer value or list of values that refer(s) to the index of the timestep(s) (minimum value: 1) or provide a date or list of dates in ISO format, such as '2015-01-01'.
Character or Numeric. Either the path to an EBV netCDF file that determines the resolution (character) or the resolution defined directly (numeric). The vector defining the resolution directly must contain three elements: the x-resolution, the y-resolution and the corresponding EPSG code, e.g. c(0.25, 0.25, 4326).
Character. Set path to write data as GeoTiff on disk.
Character. Default: bilinear. Define resampling method. Choose
from: "near","bilinear","cubic", "cubicspline", "lanczos", "sum", "min",
"q1", "med", "q3", "max", "average", "mode" and "rms". For categorical
data, use 'near'. Based on terra::project()
.
Character or integer. Optional. Default: NULL. Define the
scenario you want to access. If the EBV netCDF has no scenarios, leave the
default value (NULL). You can use an integer value defining the scenario or
give the name of the scenario as a character string. To check the available
scenarios and their name or number (integer), use
ebv_datacubepaths()
.
Character or integer. Optional. Define the metric you want to
access. You can use an integer value defining the metric or give the name
of the scenario as a character string. To check the available metrics and
their name or number (integer), use ebv_datacubepaths()
.
Logical. Default: FALSE. Set to TRUE to directly get the corresponding SpatRaster object.
Logical. Default: FALSE. Set to TRUE to overwrite the output file defined by 'outputpath'.
Logical. Default: FALSE. Checks if there is enough space in your memory to read the data. Can be switched off (set to TRUE).
Logical. Default: TRUE. Turn off additional prints by setting it to FALSE.
Default: returns the output path of the GeoTiff with the new resolution. Optional: return the SpatRaster object with the new resolution.
#set path to EBV netCDF
file <- system.file(file.path("extdata","martins_comcom_subset.nc"),
package="ebvcube")
#get all datacubepaths of EBV netCDF
datacubes <- ebv_datacubepaths(file, verbose=FALSE)
#define different resolutions
res1 <- system.file(file.path("extdata",
"baisero_spepop_id5_20220405_v1_empty.nc"), package="ebvcube")
res2 <- c(0.5,0.5,4326)
#define output path
out <- file.path(system.file(package='ebvcube'),"extdata","changeRes.tif")
if (FALSE) {
#resample defining the resolution and EPSG code by hand - return SpatRaster
data_raster <- ebv_resample(filepath_src = file, datacubepath_src = datacubes[1,1],
entity_src=1, timestep_src = 1, resolution = res2,
outputpath = out, method='near', return_raster=TRUE,
overwrite=TRUE)
#resample using a netCDF file - return GeoTiff
ebv_resample(filepath_src = file, datacubepath_src = datacubes[1,1],
entity_src=1, timestep_src = 1, resolution = res1,
outputpath = out, overwrite=TRUE)
}