Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Mar 9, 2024
1 parent 768e812 commit 2d6fb94
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 84 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ S3method(sits_bands,patterns)
S3method(sits_bands,raster_cube)
S3method(sits_bands,sits)
S3method(sits_bands,sits_model)
S3method(sits_bands,tbl_df)
S3method(sits_bbox,default)
S3method(sits_bbox,raster_cube)
S3method(sits_bbox,sits)
Expand All @@ -296,7 +295,6 @@ S3method(sits_clean,class_cube)
S3method(sits_clean,default)
S3method(sits_clean,derived_cube)
S3method(sits_clean,raster_cube)
S3method(sits_clean,tbl_df)
S3method(sits_cluster_dendro,default)
S3method(sits_cluster_dendro,sits)
S3method(sits_cluster_dendro,tbl_df)
Expand All @@ -319,7 +317,6 @@ S3method(sits_label_classification,derived_cube)
S3method(sits_label_classification,probs_cube)
S3method(sits_label_classification,probs_vector_cube)
S3method(sits_label_classification,raster_cube)
S3method(sits_label_classification,tbl_df)
S3method(sits_labels,default)
S3method(sits_labels,derived_cube)
S3method(sits_labels,derived_vector_cube)
Expand All @@ -346,7 +343,6 @@ S3method(sits_regularize,"mpc_cube_sentinel-1-grd")
S3method(sits_regularize,default)
S3method(sits_regularize,derived_cube)
S3method(sits_regularize,raster_cube)
S3method(sits_regularize,tbl_df)
S3method(sits_select,default)
S3method(sits_select,patterns)
S3method(sits_select,raster_cube)
Expand Down
2 changes: 0 additions & 2 deletions R/api_clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
# Returned block files for each fraction
block_files
})
# Remove raster without clean
unlink(.tile_path(tile))
# Merge blocks into a new class_cube tile
band_tile <- .tile_derived_merge_blocks(
file = out_file,
Expand Down
8 changes: 1 addition & 7 deletions R/sits_bands.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ sits_bands.sits_model <- function(x) {
}
#' @rdname sits_bands
#' @export
sits_bands.tbl_df <- function(x) {
sits_bands.default <- function(x) {
x <- tibble::as_tibble(x)
if (all(.conf("sits_cube_cols") %in% colnames(x))) {
x <- .cube_find_class(x)
Expand All @@ -86,12 +86,6 @@ sits_bands.tbl_df <- function(x) {
bands <- sits_bands(x)
return(bands)
}
#' @rdname sits_bands
#' @export
sits_bands.default <- function(x) {
stop("Input should be an object of class sits, raster_cube, or ml_model")
}

#' @rdname sits_bands
#' @export
`sits_bands<-` <- function(x, value) {
Expand Down
9 changes: 1 addition & 8 deletions R/sits_clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ sits_clean.derived_cube <- function(cube, window_size = 5L, memsize = 4L,
}
#' @rdname sits_clean
#' @export
sits_clean.tbl_df <- function(cube, window_size = 5L, memsize = 4L,
sits_clean.default <- function(cube, window_size = 5L, memsize = 4L,
multicores = 2L, output_dir,
version = "v1-clean", progress = TRUE) {
cube <- tibble::as_tibble(cube)
Expand All @@ -156,10 +156,3 @@ sits_clean.tbl_df <- function(cube, window_size = 5L, memsize = 4L,
output_dir, version, progress)
return(clean_cube)
}
#' @rdname sits_clean
#' @export
sits_clean.default <- function(cube, window_size = 5L, memsize = 4L,
multicores = 2L, output_dir,
version = "v1-clean", progress = TRUE) {
stop("Input should be a classified cube")
}
8 changes: 1 addition & 7 deletions R/sits_label_classification.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ sits_label_classification.derived_cube <- function(cube, ...) {

#' @rdname sits_label_classification
#' @export
sits_label_classification.tbl_df <- function(cube, ...){
sits_label_classification.default <- function(cube, ...){
cube <- tibble::as_tibble(cube)
if (all(.conf("sits_cube_cols") %in% colnames(cube))) {
cube <- .cube_find_class(cube)
Expand All @@ -171,9 +171,3 @@ sits_label_classification.tbl_df <- function(cube, ...){
class_cube <- sits_label_classification(cube, ...)
return(class_cube)
}

#' @rdname sits_label_classification
#' @export
sits_label_classification.default <- function(cube, ...) {
stop("Input should be a classified cube")
}
19 changes: 0 additions & 19 deletions R/sits_regularize.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,6 @@ sits_regularize.derived_cube <- function(cube,
}
#' @rdname sits_regularize
#' @export
sits_regularize.tbl_df <- function(
cube,
period,
res,
output_dir,
roi = NULL,
multicores = 2,
progress = TRUE) {
cube <- tibble::as_tibble(cube)
if (all(.conf("sits_cube_cols") %in% colnames(cube))) {
cube <- .cube_find_class(cube)
} else
stop("Input should be a data cube")
cube <- sits_regularize(cube, period, res, output_dir, roi,
multicores, progress)
return(cube)
}
#' @rdname sits_regularize
#' @export
sits_regularize.default <- function(cube,
period,
res,
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/cran/sits_codecov.R
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
withr::with_envvar(new = c("SITS_RUN_TESTS" = "YES"), covr::codecov(token = "53fbd031-6dab-40a4-98a5-84885b45531e"))

3 changes: 0 additions & 3 deletions man/sits_bands.Rd

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

11 changes: 0 additions & 11 deletions man/sits_clean.Rd

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

3 changes: 0 additions & 3 deletions man/sits_label_classification.Rd

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

11 changes: 0 additions & 11 deletions man/sits_regularize.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-bands.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ test_that("band rename", {
sinop <- .band_rename(sinop, "NDVI2")
new_band <- sits_bands(sinop)
expect_equal(new_band, "NDVI2")

sp <- sinop
class(sinop) <- "data.frame"
bands_cube <- sits_bands(sinop)
expect_equal(bands_cube, "NDVI2")
})
7 changes: 7 additions & 0 deletions tests/testthat/test-cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,19 @@ test_that("Creating cubes from BDC - based on ROI with shapefile", {
class(modis_cube2) <- "data.frame"
in2 <- .cube_intersects(modis_cube2, sf_mt)
expect_true(all(in2))
expect_true(.tile_intersects(modis_cube2[1,], sf_mt))

expect_false(.tile_within(modis_cube2[1,], sf_mt))
expect_false(.tile_within(modis_cube2[6,], sf_mt))

modis_cube3 <- .cube_filter_spatial(modis_cube2, sf_mt)
expect_equal(nrow(modis_cube2), nrow(modis_cube3))

modis_cube4 <- .cube_filter_bands(modis_cube2, "EVI")
expect_true(.cube_bands(modis_cube4) %in% .cube_bands(modis_cube2))
tile <- modis_cube2[1,]
modis_evi <- .tile_filter_bands(tile, "EVI")
expect_equal("EVI", sits_bands(modis_evi))

modis_tiles <- .cube_tiles(modis_cube2)
expect_true(all(c("011009", "012010") %in% .cube_tiles(modis_cube)))
Expand Down
Loading

0 comments on commit 2d6fb94

Please sign in to comment.