Nothing
test_that("the transfer is monotone and covers the range", {
set.seed(2)
v <- array(runif(5 * 4 * 3, 1, 400), c(5L, 4L, 3L))
f <- vol_field(v, lon = 1:3, lat = 1:4, depth = c(0, 5, 10, 15, 20))
e <- vol_encode(f)
expect_s3_class(e, "vol_encoding")
expect_true(all(e$codes >= 1L))
expect_identical(min(e$codes[e$codes > 0L]), 1L)
expect_identical(max(e$codes), 254L)
o <- order(as.numeric(v))
expect_false(is.unsorted(as.numeric(e$codes)[o]))
})
test_that("a missing cell takes the reserved code and no other cell does", {
v <- array(c(NA_real_, 1, 2, 3), c(4L, 1L, 1L))
f <- vol_field(v, lon = 1, lat = 1, depth = c(0, 1, 2, 3))
e <- vol_encode(f)
expect_identical(as.integer(e$codes[1, 1, 1]), 0L)
expect_true(all(e$codes[2:4, 1, 1] > 0L))
})
test_that("the reported error is the error", {
set.seed(3)
v <- array(runif(4 * 4 * 4, 0.5, 900), c(4L, 4L, 4L))
f <- vol_field(v, lon = 1:4, lat = 1:4, depth = c(0, 1, 2, 3))
e <- vol_encode(f)
t <- e$transfer
back <- ((e$codes[e$codes > 0L] - 1) / (t$codes - 1L) *
(sqrt(t$hi) - sqrt(t$lo)) + sqrt(t$lo)) ^ 2
expect_equal(t$max_error, max(abs(v[!is.na(v)] - back)))
expect_equal(t$rms_error, sqrt(mean((v[!is.na(v)] - back) ^ 2)))
})
test_that("the square-root transfer refuses a negative field when asked for", {
f <- vol_field(array(c(-1, 1, 2, 3), c(4L, 1L, 1L)), 1, 1, c(0, 1, 2, 3))
expect_error(vol_encode(f, transfer = "sqrt"), "non-negative")
expect_s3_class(vol_encode(f, transfer = "linear"), "vol_encoding")
expect_identical(vol_encode(f)$transfer$kind, "linear")
})
test_that("a constant field takes code 1 everywhere and decodes to the constant", {
# Regression: the codes were all NA, from a division by a zero range.
f <- vol_field(array(7, c(2L, 2L, 2L)), 1:2, 1:2, c(0, 1))
e <- vol_encode(f)
expect_false(anyNA(e$codes))
expect_true(all(e$codes == 1L))
# sqrt(7)^2 is 7 to within one unit in the last place
expect_lt(e$transfer$max_error, 8 * .Machine$double.eps * 7)
expect_lt(e$transfer$rms_error, 8 * .Machine$double.eps * 7)
expect_s3_class(summary(e), "summary.vol_encoding")
p <- vol_payload(f, tempfile("pl"), created = "x")
expect_lt(p$manifest$display$vmin, p$manifest$display$vmax)
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.