Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed Aug 29, 2023
1 parent d11db50 commit 101fc63
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 52 deletions.
22 changes: 22 additions & 0 deletions tests/testthat/test-get-aoi-extent.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
test_that("get_aoi_extent works",
{
expect_equal(get_aoi_extent(EPSG=4326, country_iso="FRA")$extent_latlon,
c(lonmin=-6, latmin=41, lonmax=10, latmax=52))
expect_equal(get_aoi_extent(EPSG=2154, country_iso="FRA")$extent_proj,
c(xmin=-58254, ymin=6014745, xmax=1290258, ymax=7247373))
expect_equal(get_aoi_extent(EPSG=2154, extent_latlon=c(-6, 41, 10, 52))$extent_proj,
c(xmin=-58254, ymin=6014745, xmax=1290258, ymax=7247373))
expect_equal(get_aoi_extent(EPSG=2154,
extent_proj=c(-58254, 6014745, 1290258, 7247373))$extent_latlon,
c(lonmin=-8, latmin=40, lonmax=12, latmax=53))
# Get France borders
URL <- paste0("https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg/gadm41_FRA.gpkg")
dir_tmp <- tempdir()
dest_file <- file.path(dir_tmp, "gadm41_FRA.gpkg")
download.file(URL, quiet=TRUE, destfile=dest_file)
expect_equal(get_aoi_extent(EPSG=4326, vector_file=dest_file)$extent_latlon,
c(lonmin=-6, latmin=41, lonmax=10, latmax=52))
}
)

# End
24 changes: 14 additions & 10 deletions tests/testthat/test-get_chelsa_current.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
library(gecevar)
name <- "Reunion"
iso <- "REU"
epsg <- 3337
all_extent <- transform_shp_country_extent(EPSG = epsg,
country_name = name)
extent <- all_extent[1]
extent_latlon <- as.numeric(all_extent[2:5])
r <- get_aoi_extent(EPSG = epsg,
country_iso = iso)
extent_latlon <- r$extent_latlon
extent_proj <- r$extent_proj

clim_path <- get_chelsa_current(extent_latlon = extent_latlon,
extent = extent,
EPSG = epsg,
destination = tempfile(),
resolution = 1000,
rm_download = TRUE)
extent_proj = extent_proj,
EPSG = epsg,
destination = tempfile(),
resolution = 1000,
rm_download = TRUE)

clim <- terra::rast(clim_path)
ext_out <- terra::ext(clim)
ext <- as.numeric(strsplit(extent[1], " ")[[1]])
Expand All @@ -32,3 +34,5 @@ test_that("get_chelsa_current works", {
})

unlink(file.path(clim_path))

# End
16 changes: 10 additions & 6 deletions tests/testthat/test-get_chelsa_future.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
library(gecevar)
name <- "Reunion"
iso <- "REU"
epsg <- 3337
all_extent <- transform_shp_country_extent(EPSG = epsg,
country_name = name)
extent <- all_extent[1]
extent_latlon <- as.numeric(all_extent[2:5])
r <- get_aoi_extent(EPSG = epsg,
country_iso = iso)
extent_latlon <- r$extent_latlon
extent_proj <- r$extent_proj

clim_path <- get_chelsa_future(extent_latlon = extent_latlon,
extent = extent,
extent_proj = extent_proj,
EPSG = epsg,
destination = tempfile(),
resolution = 1000,
Expand All @@ -16,6 +17,7 @@ clim_path <- get_chelsa_future(extent_latlon = extent_latlon,
"UKESM1-0-LL"),
SSP = 585,
rm_download = TRUE)

clim <- terra::rast(clim_path)
GCM = c("GFDL-ESM4", "IPSL-CM6A-LR",
"MPI-ESM1-2-HR", "MRI-ESM2-0",
Expand All @@ -39,3 +41,5 @@ test_that("get_chelsa_future works", {
})

unlink(file.path(clim_path))

# End
16 changes: 10 additions & 6 deletions tests/testthat/test-get_env_variables.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
library(gecevar)
name <- "Reunion"
iso <- "REU"
epsg <- 3337
all_extent <- transform_shp_country_extent(EPSG = epsg,
country_name = name)
extent <- all_extent[1]
extent_latlon <- as.numeric(all_extent[2:5])
r <- get_aoi_extent(EPSG = epsg,
country_iso = iso)
extent_latlon <- r$extent_latlon
extent_proj <- r$extent_proj

# for method="curl" in download.file
# sudo apt-get install curl
# Use downloader::download for portability ?
# for Open street Maps
# sudo apt-get install osmctools
environ_path <- get_env_variables(extent_latlon = extent_latlon,
extent = extent,
extent_proj = extent_proj,
EPSG = epsg,
country_name = "Reunion",
destination = tempfile(),
forest_year = 2010,
resolution = 1000,
rm_download = TRUE,
gisBase = NULL)

env <- terra::rast(environ_path)
ext_out <- terra::ext(env)
ext <- as.numeric(strsplit(extent[1], " ")[[1]])
Expand All @@ -37,3 +39,5 @@ test_that("get_env_variables works", {
})

unlink(file.path(environ_path))

# End
27 changes: 0 additions & 27 deletions tests/testthat/test-transform_shp_country_extent.R

This file was deleted.

3 changes: 0 additions & 3 deletions tests/testthat/test-xml.R

This file was deleted.

0 comments on commit 101fc63

Please sign in to comment.