R Under development (unstable) (2024-01-07 r85787 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # test -- propagate() > > library(spup) > library(raster) Loading required package: sp > > # create dummy rasters > set.seed(654321) > # create var1 > sdf <- data.frame(x = rep(0:2, each = 3), + y = rep(0:2, 3), + l = rnorm(9)) > coordinates(sdf) <- ~ x + y > gridded(sdf) <- TRUE > rasterDF1 <- raster(sdf) > > sdf <- data.frame(x = rep(0:2, each = 3), + y = rep(0:2, 3), + l = runif(9)) > coordinates(sdf) <- ~ x + y > gridded(sdf) <- TRUE > rasterDFsd1 <- raster(sdf) > > # create var2 > sdf <- data.frame(x = rep(0:2, each = 3), + y = rep(0:2, 3), + l = rnorm(9,100,1)) > coordinates(sdf) <- ~ x + y > gridded(sdf) <- TRUE > rasterDF2 <- raster(sdf) > # sd for the second var > sdf <- data.frame(x = rep(0:2, each = 3), + y = rep(0:2, 3), + l = rnorm(9,10,0.5)) > coordinates(sdf) <- ~ x + y > gridded(sdf) <- TRUE > rasterDFsd2 <- raster(sdf) > > # define UM and run sampling > crm1 <- makeCRM(0.8, 200, "Sph") > UM1 <- defineUM(TRUE, distribution = "norm", crm = crm1, + distr_param = c(rasterDF1, rasterDFsd2)) > UM2 <- defineUM(TRUE, "norm", c(rasterDF2, rasterDFsd2)) > var1 <- genSample(UM1, 10, "ugs") [using unconditional Gaussian simulation] > var2 <- genSample(UM2, 10, "randomSampling") There were 20 warnings (use warnings() to see them) > > # run propagation > some_model <- function(A, B) { + C <- A*B + C + } > out <- propagate(list(var1, var2), some_model, 10) > summary(out) Length Class Mode [1,] 9 RasterLayer S4 [2,] 9 RasterLayer S4 [3,] 9 RasterLayer S4 [4,] 9 RasterLayer S4 [5,] 9 RasterLayer S4 [6,] 9 RasterLayer S4 [7,] 9 RasterLayer S4 [8,] 9 RasterLayer S4 [9,] 9 RasterLayer S4 [10,] 9 RasterLayer S4 > > some_model <- function(A) A*2 > out <- propagate(var1, some_model, 10) > summary(out) Length Class Mode [1,] 9 RasterLayer S4 [2,] 9 RasterLayer S4 [3,] 9 RasterLayer S4 [4,] 9 RasterLayer S4 [5,] 9 RasterLayer S4 [6,] 9 RasterLayer S4 [7,] 9 RasterLayer S4 [8,] 9 RasterLayer S4 [9,] 9 RasterLayer S4 [10,] 9 RasterLayer S4 > > > > > proc.time() user system elapsed 9.00 0.37 9.36