Skip to content

Commit

Permalink
notes: skip tests on cran, GLC url
Browse files Browse the repository at this point in the history
  • Loading branch information
Cidree committed Nov 22, 2024
1 parent 45836d9 commit 43dae5a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 69 deletions.
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.2.0
Date: 2024-11-16 10:36:04 UTC
SHA: e828d4070443bc80d9a014b9efb4850a3745525b
Date: 2024-11-22 10:58:06 UTC
SHA: 45836d91c48e355c88af29143ffee9e2ac6efb71
2 changes: 1 addition & 1 deletion R/land-cover.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @return A \code{tibble}
#' @keywords internal
#' @references <https://lcviewer.vito.be/download>
#' @references <https://land.copernicus.eu/en/products/global-dynamic-land-cover>
get_glc_tbl <- function() {

# 1. Vector with possible longitudes
Expand Down
2 changes: 1 addition & 1 deletion man/get_glc_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 81 additions & 65 deletions tests/testthat/test-land-cover.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
## 1.1. Load data ---------------

## LC for coords
copernicus_coords <- fd_landcover_copernicus(
lon = -7,
lat = 43
)
test_that("download LCC with coords work", {
skip_on_cran()
## load data
copernicus_coords <- fd_landcover_copernicus(lon = -7,lat = 43)
## check spatraster
expect_s4_class(copernicus_coords, "SpatRaster")
## check source names
expect_equal(
copernicus_coords |> terra::sources() |> basename(),
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Forest-Type-layer_EPSG-4326.tif"
)
})

## LC coords several layers
test_that("download LCC with coords work", {
skip_on_cran()
## load data
copernicus_coords_2_layers <- fd_landcover_copernicus(
lon = -7,
lat = 43,
layer = c("crops", "tree")
)
## check spatraster
expect_s4_class(copernicus_coords_2_layers, "SpatRaster")
## check source names
expect_equal(
copernicus_coords_2_layers |> terra::sources() |> basename(),
c(
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif",
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Tree-CoverFraction-layer_EPSG-4326.tif"
)
)
})

# ## LC coords several layers
# copernicus_coords_2_layers <- fd_landcover_copernicus(
# lon = -7,
# lat = 43,
# layer = c("crops", "tree")
# )
#
# ## LC coords several layers and years
# copernicus_years <- fd_landcover_copernicus(
Expand All @@ -36,10 +59,19 @@ polygon_2tiles_sf <- sf::st_sfc(sf::st_point(c(-7, 44)), crs = 4326) |>
sf::st_as_sf()

## LC polygon one layer (merging 2 tiles)
copernicus_polygon <- fd_landcover_copernicus(
x = polygon_2tiles_sf,
layer = "builtup"
)
test_that("download for one polygon, merging 2 tiles", {
skip_on_cran()
## get data
copernicus_polygon <- fd_landcover_copernicus(
x = polygon_2tiles_sf,
layer = "builtup"
)
## check spatraster
expect_s4_class(copernicus_polygon, "SpatRaster")
## check layer names
expect_equal(copernicus_polygon |> names(), "builtup_2019")
})


## LC polygon 2 layers (merging 2 tiles)
# copernicus_polygon_2_layers <- fd_landcover_copernicus(
Expand All @@ -48,65 +80,49 @@ copernicus_polygon <- fd_landcover_copernicus(
# )

## Crop
copernicus_crop <- fd_landcover_copernicus(
x = polygon_1tile_vect,
layer = "grass",
year = 2016,
crop = TRUE
)


## 1.2. Unit tests --------------

## Check that data is properly downloaded (tiles are merged)
test_that("Data is properly downloaded", {
expect_s4_class(copernicus_coords, "SpatRaster")
# expect_s4_class(copernicus_coords_2_layers, "SpatRaster")
# expect_s4_class(copernicus_years, "SpatRaster")
expect_s4_class(copernicus_polygon, "SpatRaster")
# expect_s4_class(copernicus_polygon_2_layers, "SpatRaster")
test_that("download polygon, crop", {
skip_on_cran()
## get data
copernicus_crop <- fd_landcover_copernicus(
x = polygon_1tile_vect,
layer = "grass",
year = 2016,
crop = TRUE
)
## check spatraster
expect_s4_class(copernicus_crop, "SpatRaster")
})

## Check that layers are correctly downloaded
test_that("Layers are correctly downloaded and named", {
## check layer names
expect_equal(copernicus_crop |> names(), "grass_2016")
## check crop worked well
expect_equal(terra::ext(copernicus_crop)[1], terra::ext(polygon_1tile_vect)[1], tolerance = 1e-1)
expect_equal(terra::ext(copernicus_crop)[2], terra::ext(polygon_1tile_vect)[2], tolerance = 1e-1)
expect_equal(terra::ext(copernicus_crop)[3], terra::ext(polygon_1tile_vect)[3], tolerance = 1e-1)
expect_equal(terra::ext(copernicus_crop)[4], terra::ext(polygon_1tile_vect)[4], tolerance = 1e-1)

expect_equal(
copernicus_coords |> terra::sources() |> basename(),
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Forest-Type-layer_EPSG-4326.tif"
)
})

# expect_equal(
# copernicus_coords_2_layers |> terra::sources() |> basename(),
# c(
# "W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif",
# "W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Tree-CoverFraction-layer_EPSG-4326.tif"
# )
# )

# expect_equal(
# copernicus_years |> names(),
# c(
# paste0("crops_", 2015:2019),
# paste0("tree_", 2015:2019)
# )
# )

expect_equal(copernicus_polygon |> names(), "builtup_2019")
# expect_equal(copernicus_polygon_2_layers |> names(), c("bare_2019", "snow_2019"))
expect_equal(copernicus_crop |> names(), "grass_2016")


})
## Check that data is properly downloaded (tiles are merged)
# test_that("Data is properly downloaded", {
# # expect_s4_class(copernicus_years, "SpatRaster")
# # expect_s4_class(copernicus_polygon_2_layers, "SpatRaster")
# })
#
# ## Check that layers are correctly downloaded
# test_that("Layers are correctly downloaded and named", {
# # expect_equal(
# # copernicus_years |> names(),
# # c(
# # paste0("crops_", 2015:2019),
# # paste0("tree_", 2015:2019)
# # )
# # )
# # expect_equal(copernicus_polygon_2_layers |> names(), c("bare_2019", "snow_2019"))
# })


## Check extent when cropping
test_that("Crop works", {
expect_equal(terra::ext(copernicus_crop)[1], terra::ext(polygon_1tile_vect)[1], tolerance = 1e-1)
expect_equal(terra::ext(copernicus_crop)[2], terra::ext(polygon_1tile_vect)[2], tolerance = 1e-1)
expect_equal(terra::ext(copernicus_crop)[3], terra::ext(polygon_1tile_vect)[3], tolerance = 1e-1)
expect_equal(terra::ext(copernicus_crop)[4], terra::ext(polygon_1tile_vect)[4], tolerance = 1e-1)
})


# 2. Esri LCE -------------------------------------------------------------
Expand Down

0 comments on commit 43dae5a

Please sign in to comment.