# \donttest{
if (require(geodata, quietly = TRUE)) {
library(terra)
library(geodata)
# Download example data (requires geodata package)
elev <- elevation_30s(country="SWZ", path=tempdir())
slp <- terrain(elev, v="slope")
tmax <- worldclim_country(country="SWZ", var="tmax", path=tempdir())
tmax <- crop(tmax[[1]], ext(elev))
# Downscale temperature
x=c(elev,slp)
names(x) <- c("elev","slope")
y=tmax
names(y) <- c("tmax")
tmax.ds <- raster.downscale(x, y, scatter=TRUE, residuals = TRUE,
uncertainty = "prediction", se = TRUE)
# plot prediction and parameters
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
plot(tmax, main="Temp max")
plot(x[[1]], main="elevation")
plot(x[[2]], main="slope")
plot(tmax.ds$downscale, main="Downscaled Temp max")
par(opar)
# Plot residual error and raw prediction +/- intervals
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
plot(tmax.ds$std.error, main="Standard Error")
plot(tmax.ds$residuals, main="residuals")
plot(tmax.ds$uncertainty[[1]],
main="lower prediction interval")
plot(tmax.ds$uncertainty[[2]],
main="upper prediction interval")
par(opar)
# plot prediction uncertainty
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,1))
plot(tmax.ds$downscale - tmax.ds$uncertainty[[1]],
main="lower prediction interval")
plot(tmax.ds$downscale - tmax.ds$uncertainty[[2]],
main="upper prediction interval")
par(opar)
} else {
cat("Please install geodata package to run example", "\n")
}
# }
Run the code above in your browser using DataLab