Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/tinytest/test_print.R
Original file line number Diff line number Diff line change
@@ -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")
)
45 changes: 45 additions & 0 deletions vignettes/articles/benchmarks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading