Skip to content

Commit 43dae5a

Browse files
committed
notes: skip tests on cran, GLC url
1 parent 45836d9 commit 43dae5a

File tree

4 files changed

+85
-69
lines changed

4 files changed

+85
-69
lines changed

CRAN-SUBMISSION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Version: 0.2.0
2-
Date: 2024-11-16 10:36:04 UTC
3-
SHA: e828d4070443bc80d9a014b9efb4850a3745525b
2+
Date: 2024-11-22 10:58:06 UTC
3+
SHA: 45836d91c48e355c88af29143ffee9e2ac6efb71

R/land-cover.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#'
1010
#' @return A \code{tibble}
1111
#' @keywords internal
12-
#' @references <https://lcviewer.vito.be/download>
12+
#' @references <https://land.copernicus.eu/en/products/global-dynamic-land-cover>
1313
get_glc_tbl <- function() {
1414

1515
# 1. Vector with possible longitudes

man/get_glc_tbl.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-land-cover.R

+81-65
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,40 @@
44
## 1.1. Load data ---------------
55

66
## LC for coords
7-
copernicus_coords <- fd_landcover_copernicus(
8-
lon = -7,
9-
lat = 43
10-
)
7+
test_that("download LCC with coords work", {
8+
skip_on_cran()
9+
## load data
10+
copernicus_coords <- fd_landcover_copernicus(lon = -7,lat = 43)
11+
## check spatraster
12+
expect_s4_class(copernicus_coords, "SpatRaster")
13+
## check source names
14+
expect_equal(
15+
copernicus_coords |> terra::sources() |> basename(),
16+
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Forest-Type-layer_EPSG-4326.tif"
17+
)
18+
})
19+
20+
## LC coords several layers
21+
test_that("download LCC with coords work", {
22+
skip_on_cran()
23+
## load data
24+
copernicus_coords_2_layers <- fd_landcover_copernicus(
25+
lon = -7,
26+
lat = 43,
27+
layer = c("crops", "tree")
28+
)
29+
## check spatraster
30+
expect_s4_class(copernicus_coords_2_layers, "SpatRaster")
31+
## check source names
32+
expect_equal(
33+
copernicus_coords_2_layers |> terra::sources() |> basename(),
34+
c(
35+
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif",
36+
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Tree-CoverFraction-layer_EPSG-4326.tif"
37+
)
38+
)
39+
})
1140

12-
# ## LC coords several layers
13-
# copernicus_coords_2_layers <- fd_landcover_copernicus(
14-
# lon = -7,
15-
# lat = 43,
16-
# layer = c("crops", "tree")
17-
# )
1841
#
1942
# ## LC coords several layers and years
2043
# copernicus_years <- fd_landcover_copernicus(
@@ -36,10 +59,19 @@ polygon_2tiles_sf <- sf::st_sfc(sf::st_point(c(-7, 44)), crs = 4326) |>
3659
sf::st_as_sf()
3760

3861
## LC polygon one layer (merging 2 tiles)
39-
copernicus_polygon <- fd_landcover_copernicus(
40-
x = polygon_2tiles_sf,
41-
layer = "builtup"
42-
)
62+
test_that("download for one polygon, merging 2 tiles", {
63+
skip_on_cran()
64+
## get data
65+
copernicus_polygon <- fd_landcover_copernicus(
66+
x = polygon_2tiles_sf,
67+
layer = "builtup"
68+
)
69+
## check spatraster
70+
expect_s4_class(copernicus_polygon, "SpatRaster")
71+
## check layer names
72+
expect_equal(copernicus_polygon |> names(), "builtup_2019")
73+
})
74+
4375

4476
## LC polygon 2 layers (merging 2 tiles)
4577
# copernicus_polygon_2_layers <- fd_landcover_copernicus(
@@ -48,65 +80,49 @@ copernicus_polygon <- fd_landcover_copernicus(
4880
# )
4981

5082
## Crop
51-
copernicus_crop <- fd_landcover_copernicus(
52-
x = polygon_1tile_vect,
53-
layer = "grass",
54-
year = 2016,
55-
crop = TRUE
56-
)
57-
58-
59-
## 1.2. Unit tests --------------
60-
61-
## Check that data is properly downloaded (tiles are merged)
62-
test_that("Data is properly downloaded", {
63-
expect_s4_class(copernicus_coords, "SpatRaster")
64-
# expect_s4_class(copernicus_coords_2_layers, "SpatRaster")
65-
# expect_s4_class(copernicus_years, "SpatRaster")
66-
expect_s4_class(copernicus_polygon, "SpatRaster")
67-
# expect_s4_class(copernicus_polygon_2_layers, "SpatRaster")
83+
test_that("download polygon, crop", {
84+
skip_on_cran()
85+
## get data
86+
copernicus_crop <- fd_landcover_copernicus(
87+
x = polygon_1tile_vect,
88+
layer = "grass",
89+
year = 2016,
90+
crop = TRUE
91+
)
92+
## check spatraster
6893
expect_s4_class(copernicus_crop, "SpatRaster")
69-
})
70-
71-
## Check that layers are correctly downloaded
72-
test_that("Layers are correctly downloaded and named", {
94+
## check layer names
95+
expect_equal(copernicus_crop |> names(), "grass_2016")
96+
## check crop worked well
97+
expect_equal(terra::ext(copernicus_crop)[1], terra::ext(polygon_1tile_vect)[1], tolerance = 1e-1)
98+
expect_equal(terra::ext(copernicus_crop)[2], terra::ext(polygon_1tile_vect)[2], tolerance = 1e-1)
99+
expect_equal(terra::ext(copernicus_crop)[3], terra::ext(polygon_1tile_vect)[3], tolerance = 1e-1)
100+
expect_equal(terra::ext(copernicus_crop)[4], terra::ext(polygon_1tile_vect)[4], tolerance = 1e-1)
73101

74-
expect_equal(
75-
copernicus_coords |> terra::sources() |> basename(),
76-
"W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Forest-Type-layer_EPSG-4326.tif"
77-
)
102+
})
78103

79-
# expect_equal(
80-
# copernicus_coords_2_layers |> terra::sources() |> basename(),
81-
# c(
82-
# "W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif",
83-
# "W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Tree-CoverFraction-layer_EPSG-4326.tif"
84-
# )
85-
# )
86-
87-
# expect_equal(
88-
# copernicus_years |> names(),
89-
# c(
90-
# paste0("crops_", 2015:2019),
91-
# paste0("tree_", 2015:2019)
92-
# )
93-
# )
94104

95-
expect_equal(copernicus_polygon |> names(), "builtup_2019")
96-
# expect_equal(copernicus_polygon_2_layers |> names(), c("bare_2019", "snow_2019"))
97-
expect_equal(copernicus_crop |> names(), "grass_2016")
98105

99106

100-
})
107+
## Check that data is properly downloaded (tiles are merged)
108+
# test_that("Data is properly downloaded", {
109+
# # expect_s4_class(copernicus_years, "SpatRaster")
110+
# # expect_s4_class(copernicus_polygon_2_layers, "SpatRaster")
111+
# })
112+
#
113+
# ## Check that layers are correctly downloaded
114+
# test_that("Layers are correctly downloaded and named", {
115+
# # expect_equal(
116+
# # copernicus_years |> names(),
117+
# # c(
118+
# # paste0("crops_", 2015:2019),
119+
# # paste0("tree_", 2015:2019)
120+
# # )
121+
# # )
122+
# # expect_equal(copernicus_polygon_2_layers |> names(), c("bare_2019", "snow_2019"))
123+
# })
101124

102125

103-
## Check extent when cropping
104-
test_that("Crop works", {
105-
expect_equal(terra::ext(copernicus_crop)[1], terra::ext(polygon_1tile_vect)[1], tolerance = 1e-1)
106-
expect_equal(terra::ext(copernicus_crop)[2], terra::ext(polygon_1tile_vect)[2], tolerance = 1e-1)
107-
expect_equal(terra::ext(copernicus_crop)[3], terra::ext(polygon_1tile_vect)[3], tolerance = 1e-1)
108-
expect_equal(terra::ext(copernicus_crop)[4], terra::ext(polygon_1tile_vect)[4], tolerance = 1e-1)
109-
})
110126

111127

112128
# 2. Esri LCE -------------------------------------------------------------

0 commit comments

Comments
 (0)