Skip to content

Commit

Permalink
don't check online for non-available gsw resource, set tolerance for …
Browse files Browse the repository at this point in the history
…gsw unit tests to 1e-4
  • Loading branch information
karpfen committed Jan 15, 2024
1 parent 96e0796 commit 808989e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
9 changes: 9 additions & 0 deletions R/get_gsw.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
.get_gsw <- function(x, statistic = "occurrence", vers_gsw = "v1_4_2021",
rundir = tempdir(), verbose = TRUE) {
available_gsw_statistics <- c(
"change",
"occurrence",
"recurrence",
"seasonality",
"transitions"
)
stopifnot(statistic %in% available_gsw_statistics)

# make the gsw grid and construct urls for intersecting tiles
baseurl <- sprintf(
"https://storage.googleapis.com/global-surface-water/downloads2021/%s/%s",
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-calc_gsw_change.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test_that("gsw change works", {

expect_equal(
chg$global_surface_water_change_mean,
100
100,
tolerance = 1e-4
)
})
3 changes: 2 additions & 1 deletion tests/testthat/test-calc_gsw_occurrence.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test_that("gsw occurrence works", {

expect_equal(
occ$global_surface_water_occurrence_mean,
19.41088415664687
19.41088415664687,
tolerance = 1e-4
)
})
3 changes: 2 additions & 1 deletion tests/testthat/test-calc_gsw_recurrence.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ test_that("gsw recurrence works", {

expect_equal(
rec$global_surface_water_recurrence_mean,
22.49229803467092
22.49229803467092,
tolerance = 1e-4
)
})

3 changes: 2 additions & 1 deletion tests/testthat/test-calc_gsw_seasonality.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test_that("gsw seasonality works", {

expect_equal(
season$global_surface_water_seasonality_mean,
2.289487662369018
2.289487662369018,
tolerance = 1e-4
)
})
5 changes: 3 additions & 2 deletions tests/testthat/test-calc_gsw_transitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ test_that("gsw transitions works", {
)

expect_equal(
transitions,
transitions_expected
transitions$area,
transitions_expected$area,
tolerance = 1e-4
)
})
11 changes: 0 additions & 11 deletions tests/testthat/test-get_gsw.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ test_that(".get_gsw works", {
# Add testing attribute in order to skip downloads
attributes(portfolio)$testing <- TRUE

gsw_statistics <- c(
"change",
"occurrence",
"recurrence",
"seasonality",
"transitions"
)
for (gsw_statistic in gsw_statistics) {
resource_name <- paste0("global_surface_water_", gsw_statistic)
}

expect_error(
.get_gsw(portfolio, statistic = "not-available")
)
Expand Down

0 comments on commit 808989e

Please sign in to comment.