diff --git a/tests/tinytest/test_print.R b/tests/tinytest/test_print.R new file mode 100644 index 0000000..b4e7581 --- /dev/null +++ b/tests/tinytest/test_print.R @@ -0,0 +1,23 @@ +source("setup.R") + +# Reading geotiff tags +expected_out <- + c( + "+-----------------------------------------------+ ", + "| WhiteboxRaster |", + "| dem.tif |", + "|...............................................| ", + "| bands : 1 |", + "| dimensions : 726, 800 (nrow, ncol) |", + "| resolution : 5.002392, 5.000243 (x, y) |", + "| EPSG : 2193 (Linear_Meter) |", + "| extent : 1925449 1929446 5582091 5585717 |", + "| min value : 63.698193 |", + "| max value : 361.020721 |", + "+-----------------------------------------------+ " + ) + +expect_equal( + paste(utils::capture.output(print(x)), collapse = "\n"), + paste(expected_out, collapse = "\n") +) diff --git a/vignettes/articles/benchmarks.Rmd b/vignettes/articles/benchmarks.Rmd index 256250e..99d9a89 100644 --- a/vignettes/articles/benchmarks.Rmd +++ b/vignettes/articles/benchmarks.Rmd @@ -276,6 +276,51 @@ bench::mark( ``` +# Image Processing + +Below is application of a simple minimum filter, which assigns each cell in the output grid the minimum value in a 3×3 moving window centred on each grid cell in the input raster. + +```{r bench_filters, message = FALSE, warning = FALSE} + +# Load file +f <- system.file("extdata/dem.tif", package = "wbw") +r <- terra::rast(f) +x <- wbw_read_raster(f) + +# Create a tempfile for {whitebox} +tmp <- tempfile(fileext = ".tif") + +bench_filters <- + bench::mark( + wbw = wbw_minimum_filter(x, 3, 3), + whitebox = { + whitebox::wbt_minimum_filter( + f, + output = tmp, + filterx = 3L, + filtery = 3L, + compress_rasters = FALSE + ) + }, + terra = focal(r, w = 3, fun = "min", na.rm = T), + check = FALSE, + time_unit = "ms", + iterations = 21L + ) + +bench_filters + +``` + +Make sure that there's no difference between `{wbw}` and `{terra}`: + +```{r filter_comparison} +waldo::compare( + wbw_minimum_filter(x, 3, 3) |> as_matrix(), + focal(r, w = 3, fun = "min", na.rm = T) |> as.matrix(wide = TRUE) +) +``` + ```{r cleanup, include = FALSE} unlink(tmp_wbw) unlink(tmp_terra)