Skip to content

Commit bd57dde

Browse files
committed
improve terrascope tests
1 parent 2a88ef3 commit bd57dde

8 files changed

+100
-66
lines changed

tests/testthat/test-cube-terrascope.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test_that("Creating WORLD-COVER-2021 cubes from TERRASCOPE", {
2020
message = "TERRASCOPE is not accessible"
2121
)
2222

23-
expect_true(all(sits_bands(class_cube) %in% c("CLASS")))
23+
expect_true(all(sits_bands(class_cube) %in% c("class")))
2424
expect_equal(nrow(class_cube), 4)
2525
bbox_cube <- sits_bbox(class_cube, as_crs = "EPSG:4326")
2626
bbox_cube_1 <- sits_bbox(.tile(class_cube), as_crs = "EPSG:4326")

tests/testthat/test-data.R

+18-10
Original file line numberDiff line numberDiff line change
@@ -507,27 +507,35 @@ test_that("Reading data from Classified data from STAC", {
507507
"lat_min" = -11.80208, "lat_max" = -11.49583)
508508

509509
# load cube from stac
510-
class_cube <- sits_cube(
511-
source = "TERRASCOPE",
512-
collection = "WORLD-COVER-2021",
513-
roi = roi,
514-
progress = FALSE
510+
class_cube <- .try(
511+
{
512+
sits_cube(
513+
source = "TERRASCOPE",
514+
collection = "WORLD-COVER-2021",
515+
roi = roi,
516+
progress = FALSE
517+
)
518+
},
519+
.default = NULL
515520
)
516521

517522
testthat::skip_if(purrr::is_null(class_cube),
518523
message = "TERRASCOPE is not accessible"
519524
)
520525

521526
# adapt date to work with the sinop samples
522-
class_cube[["file_info"]][[1]][["date"]] <- "2013-10-01"
527+
class_cube[["file_info"]][[1]][["start_date"]] <- "2013-10-01"
528+
class_cube[["file_info"]][[1]][["end_date"]] <- "2013-10-01"
523529
# Using CSV
524530
csv_raster_file <- system.file("extdata/samples/samples_sinop_crop.csv",
525531
package = "sits"
526532
)
527-
points_poly <- sits_get_data(class_cube,
528-
samples = csv_raster_file,
529-
progress = TRUE,
530-
multicores = 1
533+
points_poly <- suppressWarnings(
534+
sits_get_data(class_cube,
535+
samples = csv_raster_file,
536+
progress = TRUE,
537+
multicores = 1
538+
)
531539
)
532540
expect_equal(nrow(points_poly), 5)
533541
expect_equal(

tests/testthat/test-labels.R

+20-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ test_that("Labels from a STAC class cube", {
1010
roi <- c("lon_min" = -55.80259, "lon_max" = -55.19900,
1111
"lat_min" = -11.80208, "lat_max" = -11.49583)
1212
# create world cover from stac
13-
class_cube <- sits_cube(
14-
source = "TERRASCOPE",
15-
collection = "WORLD-COVER-2021",
16-
roi = roi,
17-
progress = FALSE
13+
class_cube <- .try(
14+
{
15+
sits_cube(
16+
source = "TERRASCOPE",
17+
collection = "WORLD-COVER-2021",
18+
roi = roi,
19+
progress = FALSE
20+
)
21+
},
22+
.default = NULL
1823
)
1924

2025
testthat::skip_if(purrr::is_null(class_cube),
@@ -81,11 +86,16 @@ test_that("Relabel class cube from STAC", {
8186
roi <- c("lon_min" = -55.80259, "lon_max" = -55.19900,
8287
"lat_min" = -11.80208, "lat_max" = -11.49583)
8388
# create world cover from stac
84-
class_cube <- sits_cube(
85-
source = "TERRASCOPE",
86-
collection = "WORLD-COVER-2021",
87-
roi = roi,
88-
progress = FALSE
89+
class_cube <- .try(
90+
{
91+
sits_cube(
92+
source = "TERRASCOPE",
93+
collection = "WORLD-COVER-2021",
94+
roi = roi,
95+
progress = FALSE
96+
)
97+
},
98+
.default = NULL
8999
)
90100
testthat::skip_if(purrr::is_null(class_cube),
91101
message = "TERRASCOPE is not accessible"

tests/testthat/test-mosaic.R

+11-15
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,16 @@ test_that("One-date, mosaic with class cube from STAC", {
175175
)
176176
roi <- sf::st_transform(roi, 3857)
177177
# load class cube
178-
label_cube <- sits_cube(
179-
source = "TERRASCOPE",
180-
collection = "WORLD-COVER-2021",
181-
roi = roi,
182-
progress = FALSE
178+
label_cube <- .try(
179+
{
180+
sits_cube(
181+
source = "TERRASCOPE",
182+
collection = "WORLD-COVER-2021",
183+
roi = roi,
184+
progress = FALSE
185+
)
186+
},
187+
.default = NULL
183188
)
184189
testthat::skip_if(purrr::is_null(label_cube),
185190
message = "TERRASCOPE is not accessible"
@@ -205,17 +210,8 @@ test_that("One-date, mosaic with class cube from STAC", {
205210
expect_equal(bbox_cube[["ymin"]], bbox_roi[["ymin"]], tolerance = 0.01)
206211
expect_equal(bbox_cube[["xmax"]], bbox_roi[["xmax"]], tolerance = 0.01)
207212
expect_equal(bbox_cube[["ymax"]], bbox_roi[["ymax"]], tolerance = 0.01)
208-
# resume feature
209-
mosaic_class <- sits_mosaic(
210-
cube = label_cube,
211-
roi = roi,
212-
crs = 4326,
213-
output_dir = output_dir,
214-
version = "v1",
215-
progress = FALSE
216-
)
217-
expect_equal(mosaic_class[["tile"]], "MOSAIC")
218213

214+
# delete files
219215
unlink(label_cube$file_info[[1]]$path)
220216
unlink(mosaic_class$file_info[[1]]$path)
221217
})

tests/testthat/test-plot.R

+15-10
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,21 @@ test_that("Plot Time Series and Images", {
9898
})
9999

100100
test_that("Plot class cube from STAC", {
101-
to_class <- sits_cube(
102-
source = "TERRASCOPE",
103-
collection = "WORLD-COVER-2021",
104-
bands = "CLASS",
105-
roi = c("lon_min" = -62.7,
106-
"lon_max" = -62.5,
107-
"lat_min" = -8.83 ,
108-
"lat_max" = -8.70
109-
),
110-
progress = FALSE
101+
to_class <- .try(
102+
{
103+
sits_cube(
104+
source = "TERRASCOPE",
105+
collection = "WORLD-COVER-2021",
106+
bands = "CLASS",
107+
roi = c("lon_min" = -62.7,
108+
"lon_max" = -62.5,
109+
"lat_min" = -8.83 ,
110+
"lat_max" = -8.70
111+
),
112+
progress = FALSE
113+
)
114+
},
115+
.default = NULL
111116
)
112117
testthat::skip_if(purrr::is_null(to_class),
113118
message = "TERRASCOPE is not accessible"

tests/testthat/test-raster.R

+11-6
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,17 @@ test_that("Clean classification with class cube from STAC",{
838838
"lat_min" = -8.83 , "lat_max" = -8.70)
839839

840840
# load cube from stac
841-
to_class <- sits_cube(
842-
source = "TERRASCOPE",
843-
collection = "WORLD-COVER-2021",
844-
bands = "CLASS",
845-
roi = cube_roi,
846-
progress = FALSE
841+
to_class <- .try(
842+
{
843+
sits_cube(
844+
source = "TERRASCOPE",
845+
collection = "WORLD-COVER-2021",
846+
bands = "CLASS",
847+
roi = cube_roi,
848+
progress = FALSE
849+
)
850+
},
851+
.default = NULL
847852
)
848853
testthat::skip_if(purrr::is_null(to_class),
849854
message = "TERRASCOPE is not accessible"

tests/testthat/test-reclassify.R

+12-7
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,19 @@ test_that("One-year, reclassify class cube from STAC", {
191191
progress = FALSE
192192
)
193193
# Open classification map from STAC
194-
ro_class <- sits_cube(
195-
source = "TERRASCOPE",
196-
collection = "WORLD-COVER-2021",
197-
bands = "CLASS",
198-
roi = sits_bbox(prodes2021),
199-
progress = FALSE
194+
ro_class <- .try(
195+
{
196+
sits_cube(
197+
source = "TERRASCOPE",
198+
collection = "WORLD-COVER-2021",
199+
bands = "CLASS",
200+
roi = sits_bbox(prodes2021),
201+
progress = FALSE
202+
)
203+
},
204+
.default = NULL
200205
)
201-
testthat::skip_if(purrr::is_null(ro_cass),
206+
testthat::skip_if(purrr::is_null(ro_class),
202207
message = "TERRASCOPE is not accessible"
203208
)
204209
# Download data from STAC

tests/testthat/test-samples.R

+12-7
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ test_that("Sampling design", {
6969
})
7070
test_that("Sampling design with class cube from STAC", {
7171
# define roi
72-
roi <- c("lon_min" = -62.7, "lon_max" = -62.5,
73-
"lat_min" = -8.83 , "lat_max" = -8.70)
72+
roi <- c("lon_min" = -55.80259, "lon_max" = -55.19900,
73+
"lat_min" = -11.80208, "lat_max" = -11.49583)
7474
# load cube from stac
75-
class_cube <- sits_cube(
76-
source = "TERRASCOPE",
77-
collection = "WORLD-COVER-2021",
78-
roi = roi,
79-
progress = FALSE
75+
class_cube <- .try(
76+
{
77+
sits_cube(
78+
source = "TERRASCOPE",
79+
collection = "WORLD-COVER-2021",
80+
roi = roi,
81+
progress = FALSE
82+
)
83+
},
84+
.default = NULL
8085
)
8186
testthat::skip_if(purrr::is_null(class_cube),
8287
message = "TERRASCOPE is not accessible"

0 commit comments

Comments
 (0)