Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix empiracally etablished tolerance (unit tests)
  • Loading branch information
Jean-Romain committed Aug 21, 2018
1 parent 74df418 commit 2a79ccb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Expand Up @@ -2,8 +2,8 @@ Package: lidR
Type: Package
Title: Airborne LiDAR Data Manipulation and Visualization for Forestry
Applications
Version: 1.6.0
Date: 2018-07-25
Version: 1.6.1
Date: 2018-08-21
Authors@R: c(
person("Jean-Romain", "Roussel", email = "jean-romain.roussel.1@ulaval.ca", role = c("aut", "cre", "cph")),
person("David", "Auty", email = "", role = c("aut", "ctb"), comment = "Reviews the documentation"),
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
@@ -1,9 +1,10 @@
## lidR v1.6.1
## lidR v1.6.1 (2018-08-21)

#### BUG FIXES

* [[#161](https://github.com/Jean-Romain/lidR/pull/161)] Fix tree ID matching.
* Fix undefined variable in cluster_apply on max and linux if multicore processing is used.
* Fix undefined variable in cluster_apply on mac and linux if multicore processing is used.
* Fix rare case of unit test failure due to the random nature of the test dataset using seeds.


## lidR v1.6.0 (2018-07-20)
Expand Down
21 changes: 12 additions & 9 deletions R/utils_misc.r
Expand Up @@ -69,17 +69,20 @@ verbose = function(...)
cat(..., "\n")
}

dummy_las = function(n)
dummy_las = function(n, seeds = c)
{
dt = data.table::data.table(
X = stats::runif(n, 0, 100),
Y = stats::runif(n, 0, 100),
Z = c(stats::runif(0.8*n, 0, 25), rep(0, 0.2*n)),
Classification = as.integer(c(rep(1, 0.8*n), rep(2, 0.2*n))),
Intensity = sample(10:50, n, TRUE),
ReturnNumber = as.integer(rep(c(1,1,1,2,3,1,2,1,2,1), n/10)),
NumberOfReturns = as.integer(rep(c(1,1,3,3,3,2,2,2,2,1), n/10 )))
set.seed(1)
X = stats::runif(n, 0, 100)
set.seed(2)
Y = stats::runif(n, 0, 100)
set.seed(3)
Z = c(stats::runif(0.8*n, 0, 25), rep(0, 0.2*n))
Classification = as.integer(c(rep(1, 0.8*n), rep(2, 0.2*n)))
Intensity = sample(10:50, n, TRUE)
ReturnNumber = as.integer(rep(c(1,1,1,2,3,1,2,1,2,1), n/10))
NumberOfReturns = as.integer(rep(c(1,1,3,3,3,2,2,2,2,1), n/10 ))

dt = data.table::data.table(X, Y, Z, Classification, Intensity, ReturnNumber, NumberOfReturns)
las = suppressWarnings(LAS(dt))

return(las)
Expand Down
6 changes: 6 additions & 0 deletions cran-comments.md
@@ -1,3 +1,9 @@
This release comes after prof Bryan Ripley's request: "We see occasional check failures, e.g. with clang
and sanitizers". Indeed some test datasets were randomly generated and a tolerance on the output was added
to deal with the variability of the output. Variability can be greater than expected in rare cases.
I added fixed and hard coded seeds, thus the tests are not subject to variability. I remove empirically
etablished tolerances. This issue will not happen anymore.

## Test environments
* Linux Mint 19 (Ubuntu 16.04), R 3.4.4
* win-builder (release and devel)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-grid_catalog.R
Expand Up @@ -66,7 +66,7 @@ test_that("grid_terrain returns the same both with catalog and las", {
tr2 = raster::crop(tr2, tr1)

diff = abs(raster::values(tr1-tr2))
expect_lt(mean(diff, na.rm = TRUE), 0.01)
expect_lt(mean(diff, na.rm = TRUE), 0.0001)
})


Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-grid_terrain.R
Expand Up @@ -13,20 +13,20 @@ test_that("terrain works with knnidw", {
data.table::setkey(dtm, X, Y)
diff = truedtm[dtm]
diffZ = abs(diff$Z - diff$i.Z)
expect_lt(mean(diffZ, na.rm = TRUE), 0.21)
expect_equal(mean(diffZ, na.rm = TRUE), 0.1574152)
})

test_that("terrain works with delaunay", {
dtm = suppressWarnings(grid_terrain(las, 1, method = "delaunay"))
data.table::setkey(dtm, X, Y)
diff = truedtm[dtm][!is.na(i.Z)][, Z := Z - i.Z]
expect_lt(mean(abs(diff$Z), na.rm = TRUE), 0.095)
expect_equal(mean(abs(diff$Z), na.rm = TRUE), 0.07895608)
})

test_that("terrain works with kriging", {
dtm = grid_terrain(las, 1, method = "kriging", k = 10L)
data.table::setkey(dtm, X, Y)
diff = truedtm[dtm]
diffZ = abs(diff$Z - diff$i.Z)
expect_lt(mean(diffZ, na.rm = T), 0.071)
expect_equal(mean(diffZ, na.rm = T), 0.06199064)
})
6 changes: 4 additions & 2 deletions tests/testthat/test-metrics.R
@@ -1,18 +1,21 @@
context("metrics")

test_that("gap fraction returns proper values", {
set.seed(1)
Z = runif(50000, 0, 5)
gf = 1-gap_fraction_profile(Z, 1, 0)$gf

expect_equal(gf, c(1, 0.5, 0.333, 0.25, 0.2), tolerance = 0.015)
expect_equal(gf, c(1, 0.5, 0.333, 0.25, 0.2), tolerance = 0.01)
})

test_that("entropy returns proper values", {
set.seed(1)
Z = runif(20000, 0, 5)
S = entropy(Z)

expect_equal(S, 1, tolerance = 0.001)

set.seed(42)
Z = runif(20000, 0, 1)
Z = c(Z, 5)
S = entropy(Z)
Expand All @@ -22,7 +25,6 @@ test_that("entropy returns proper values", {

test_that("VCI returns the same as entropy values", {
Z = runif(100, 0, 5)

S = entropy(Z, zmax = 6)
V = VCI(Z, 6)

Expand Down

0 comments on commit 2a79ccb

Please sign in to comment.