@@ -14,6 +14,11 @@ test_that("Reading a LAT/LONG from RASTER", {
14
14
expect_equal(names(point_ndvi )[1 ], " longitude" )
15
15
expect_true(ncol(.tibble_time_series(point_ndvi )) == 2 )
16
16
expect_true(length(sits_timeline(point_ndvi )) == 12 )
17
+ expect_true(
18
+ all(
19
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(point_ndvi )
20
+ )
21
+ )
17
22
18
23
samples2 <- tibble :: tibble(longitude = - 55.66738 , latitude = 11.76990 )
19
24
expect_warning(
@@ -49,6 +54,11 @@ test_that("Reading a CSV file from RASTER", {
49
54
expect_equal(length(names(points_poly )), 7 )
50
55
expect_true(ncol(.tibble_time_series(points_poly )) == 2 )
51
56
expect_true(length(sits_timeline(points_poly )) == 12 )
57
+ expect_true(
58
+ all(
59
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_poly )
60
+ )
61
+ )
52
62
53
63
Sys.setenv(" SITS_SAMPLES_CACHE_DIR" = tempdir())
54
64
@@ -63,6 +73,12 @@ test_that("Reading a CSV file from RASTER", {
63
73
expect_equal(length(names(points_df )), 7 )
64
74
expect_true(ncol(.tibble_time_series(points_df )) == 2 )
65
75
expect_true(length(sits_timeline(points_df )) == 12 )
76
+ expect_true(
77
+ all(
78
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_df )
79
+ )
80
+ )
81
+
66
82
Sys.unsetenv(" SITS_SAMPLES_CACHE_DIR" )
67
83
})
68
84
@@ -113,6 +129,11 @@ test_that("Retrieving points from BDC using POLYGON shapefiles", {
113
129
object = unique(points_shp [[" end_date" ]]),
114
130
expected = as.Date(cube_timeline [length(cube_timeline )])
115
131
)
132
+ expect_true(
133
+ all(
134
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_shp )
135
+ )
136
+ )
116
137
117
138
# test bounding box
118
139
polygons_bbox <- .bbox(sf_mt )
@@ -181,7 +202,7 @@ test_that("Retrieving points from BDC using POLYGON shapefiles", {
181
202
)
182
203
})
183
204
184
- test_that(" Retrieving points from MPC using POINT shapefiles" , {
205
+ test_that(" Retrieving points from BDC using POINT shapefiles" , {
185
206
shp_file <- system.file(
186
207
" extdata/shapefiles/cerrado/cerrado_forested.shp" ,
187
208
package = " sits"
@@ -226,6 +247,12 @@ test_that("Retrieving points from MPC using POINT shapefiles", {
226
247
object = unique(points_cf [[" end_date" ]]),
227
248
expected = as.Date(cube_timeline [length(cube_timeline )])
228
249
)
250
+ expect_true(
251
+ all(
252
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_cf )
253
+ )
254
+ )
255
+
229
256
points_bbox <- .bbox(sf_cf )
230
257
231
258
points_in_bbox <- dplyr :: filter(
@@ -237,7 +264,7 @@ test_that("Retrieving points from MPC using POINT shapefiles", {
237
264
)
238
265
})
239
266
240
- test_that(" Retrieving points from MPC using sits tibble" , {
267
+ test_that(" Retrieving points from BDC using sits tibble" , {
241
268
cube_bbox <- sits_bbox(cerrado_2classes )
242
269
# create a raster cube file based on the bbox of the sits tibble
243
270
modis_cube <- .try(
@@ -282,6 +309,11 @@ test_that("Retrieving points from MPC using sits tibble", {
282
309
object = unique(points_tb [[" end_date" ]]),
283
310
expected = as.Date(cube_timeline [length(cube_timeline )])
284
311
)
312
+ expect_true(
313
+ all(
314
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_tb )
315
+ )
316
+ )
285
317
})
286
318
287
319
test_that(" Retrieving points from BDC using sf objects" , {
@@ -329,6 +361,11 @@ test_that("Retrieving points from BDC using sf objects", {
329
361
object = unique(points_cf [[" end_date" ]]),
330
362
expected = as.Date(cube_timeline [length(cube_timeline )])
331
363
)
364
+ expect_true(
365
+ all(
366
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_cf )
367
+ )
368
+ )
332
369
333
370
points_bbox <- .bbox(sf_cf )
334
371
@@ -385,10 +422,14 @@ test_that("Retrieving points from BDC using sf objects", {
385
422
object = unique(points_poly [[" end_date" ]]),
386
423
expected = as.Date(cube_timeline [length(cube_timeline )])
387
424
)
425
+ expect_true(
426
+ all(
427
+ c(" sits" , " tbl_df" , " tbl" , " data.frame" ) %in% class(points_poly )
428
+ )
429
+ )
388
430
389
431
# test bounding box
390
432
polygons_bbox <- .bbox(sf_mt )
391
-
392
433
points_poly_in_bbox <- dplyr :: filter(
393
434
points_poly ,
394
435
.data [[" longitude" ]] > = polygons_bbox [[" xmin" ]],
@@ -400,6 +441,89 @@ test_that("Retrieving points from BDC using sf objects", {
400
441
expect_true(nrow(points_poly_in_bbox ) == nrow(points_poly ))
401
442
})
402
443
444
+ test_that(" Retrieving points from MPC Base Cube" , {
445
+ regdir <- paste0(tempdir(), " /base_cube_reg/" )
446
+ if (! dir.exists(regdir )) {
447
+ suppressWarnings(dir.create(regdir ))
448
+ }
449
+ # define roi
450
+ roi <- list (
451
+ lon_min = - 55.69004 ,
452
+ lon_max = - 55.62223 ,
453
+ lat_min = - 11.78788 ,
454
+ lat_max = - 11.73343
455
+ )
456
+ # load sentinel-2 cube
457
+ s2_cube <- sits_cube(
458
+ source = " MPC" ,
459
+ collection = " SENTINEL-2-L2A" ,
460
+ start_date = " 2019-01-01" ,
461
+ end_date = " 2019-01-20" ,
462
+ bands = c(" B05" ),
463
+ tiles = " 21LXH" ,
464
+ progress = FALSE
465
+ )
466
+ s2_cube <- suppressWarnings(sits_regularize(
467
+ cube = s2_cube ,
468
+ period = " P16D" ,
469
+ res = 320 ,
470
+ multicores = 1 ,
471
+ tiles = " 21LXH" ,
472
+ output_dir = regdir ,
473
+ progress = FALSE
474
+ ))
475
+ # load dem cube
476
+ dem_cube <- sits_cube(
477
+ source = " MPC" ,
478
+ collection = " COP-DEM-GLO-30" ,
479
+ tiles = " 21LXH"
480
+ )
481
+ dem_cube <- sits_regularize(
482
+ cube = dem_cube ,
483
+ multicores = 1 ,
484
+ res = 232 ,
485
+ tiles = " 21LXH" ,
486
+ output_dir = regdir
487
+ )
488
+ # create base cube
489
+ base_cube <- sits_add_base_cube(s2_cube , dem_cube )
490
+ # load samples
491
+ samples <- read.csv(
492
+ system.file(" extdata/samples/samples_sinop_crop.csv" , package = " sits" )
493
+ )
494
+ # edit samples to work with the cube (test purposes only)
495
+ samples [[" start_date" ]] <- " 2019-01-02"
496
+ samples [[" end_date" ]] <- " 2019-01-02"
497
+ # extract data
498
+ samples_ts <- sits_get_data(
499
+ base_cube ,
500
+ samples = samples ,
501
+ crs = 32721 ,
502
+ multicores = 1
503
+ )
504
+ # validations
505
+ cube_timeline <- sits_timeline(base_cube )
506
+ expect_equal(object = nrow(samples_ts ), expected = 18 )
507
+ expect_equal(
508
+ object = unique(samples_ts [[" start_date" ]]),
509
+ expected = as.Date(cube_timeline [1 ])
510
+ )
511
+ expect_equal(
512
+ object = unique(samples_ts [[" end_date" ]]),
513
+ expected = as.Date(cube_timeline [length(cube_timeline )])
514
+ )
515
+ expect_true(
516
+ all(
517
+ c(" sits_base" , " sits" , " tbl_df" , " tbl" , " data.frame" ) %in%
518
+ class(samples_ts )
519
+ )
520
+ )
521
+
522
+ unlink(s2_cube [[" file_info" ]][[1 ]]$ path )
523
+ unlink(dem_cube [[" file_info" ]][[1 ]]$ path )
524
+ unlink(base_cube [[" file_info" ]][[1 ]]$ path )
525
+ })
526
+
403
527
test_that(" Reading metadata from CSV file" , {
404
528
csv_file <- paste0(tempdir(), " /cerrado_2classes.csv" )
405
529
sits_to_csv(cerrado_2classes , file = csv_file )
@@ -476,7 +600,12 @@ test_that("Reading data from Classified data", {
476
600
expect_equal(
477
601
nrow(points_poly ), nrow(read.csv(csv_raster_file ))
478
602
)
479
-
603
+ expect_true(
604
+ all(
605
+ c(" predicted" , " sits" , " tbl_df" , " tbl" , " data.frame" ) %in%
606
+ class(points_poly )
607
+ )
608
+ )
480
609
expect_equal(
481
610
colnames(points_poly ), c(
482
611
" longitude" , " latitude" ,
@@ -545,4 +674,10 @@ test_that("Reading data from Classified data from STAC", {
545
674
" label" , " cube" , " predicted"
546
675
)
547
676
)
677
+ expect_true(
678
+ all(
679
+ c(" predicted" , " sits" , " tbl_df" , " tbl" , " data.frame" ) %in%
680
+ class(points_poly )
681
+ )
682
+ )
548
683
})
0 commit comments