Skip to content

Commit

Permalink
remove data.frame tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Jan 31, 2025
1 parent 5779b9c commit 108e5aa
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 303 deletions.
1 change: 0 additions & 1 deletion sits.Rproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Version: 1.0
ProjectId: 285a470e-fd26-4cdb-ae88-2e3d6112030d

RestoreWorkspace: Default
SaveWorkspace: Ask
Expand Down
12 changes: 0 additions & 12 deletions tests/testthat/test-apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,6 @@ test_that("Testing normalized index generation", {
start_date <- timeline[1]
end_date <- timeline[length(timeline)]

# test with data frame
#
gc_cube2 <- gc_cube
class(gc_cube2) <- "data.frame"

gc_cube2 <- sits_apply(gc_cube2,
NDRE = (B8A - B05) / (B8A + B05),
multicores = 1,
output_dir = dir_images
)
expect_true("NDRE" %in% sits_bands(gc_cube2))

csv_tb <- purrr::map2_dfr(lats, longs, function(lat, long) {
tibble::tibble(
longitude = long,
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-bands.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ test_that("band rename", {
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")
})
10 changes: 0 additions & 10 deletions tests/testthat/test-clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,4 @@ test_that("Creating a dendrogram and clustering the results", {
expect_true(sits_cluster_frequency(clusters_new)[3, 1] >
sits_cluster_frequency(clean)[3, 1])

# test default
samples_df <- cerrado_2classes
class(samples_df) <- "data.frame"
clusters_df <- suppressMessages(
sits_cluster_dendro(
samples_df,
bands = c("NDVI", "EVI")
)
)
expect_equal(nrow(clusters_df), 746)
})
21 changes: 0 additions & 21 deletions tests/testthat/test-cube-bdc.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,8 @@ test_that("Creating cubes from BDC - MOD13Q1-6.1 based on ROI using sf object",
intersects <- .cube_intersects(modis_cube, sf_mt)
expect_true(all(intersects))

modis_cube2 <- modis_cube
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)))

tile_011009 <- .cube_filter_tiles(modis_cube, "011009")
expect_equal(nrow(tile_011009), 1)

})
test_that("Creating cubes from BDC - MOD13Q1-6.1 invalid roi", {
Expand Down
24 changes: 0 additions & 24 deletions tests/testthat/test-cube-mpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,30 +254,6 @@ test_that("Creating cubes from MPC - MOD13Q1-6.1 based on ROI using sf object",
intersects <- .cube_intersects(modis_cube, sf_mt)
expect_true(all(intersects))

modis_cube2 <- modis_cube
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("h13v10", "h13v9") %in% .cube_tiles(modis_cube)))

tile_h13v10 <- .cube_filter_tiles(modis_cube, "h13v10")
expect_equal(nrow(tile_h13v10), 1)

})
test_that("Creating cubes from MPC - MOD09A1-6.1 based on ROI using sf object", {
shp_file <- system.file(
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-mixture_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ test_that("Mixture model tests", {
csv_file <- paste0(tempdir(), "/mmodel.csv")

reg_cube3 <- reg_cube
class(reg_cube3) <- "data.frame"
mm_rmse_csv <- sits_mixture_model(
data = reg_cube3,
endmembers = csv_file,
Expand Down
179 changes: 0 additions & 179 deletions tests/testthat/test-raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ test_that("Classification with rfor (single core)", {

# defaults and errors
expect_error(sits_classify(probs_cube, rf_model))
sinop_df <- sinop
class(sinop_df) <- "data.frame"
expect_error(sits_classify(sinop_df, rfor_model, output_dir = tempdir()))
expect_true(all(file.remove(unlist(sinop_probs$file_info[[1]]$path))))
})
test_that("Classification with SVM", {
Expand Down Expand Up @@ -446,94 +443,6 @@ test_that("Classification with post-processing", {
dir.create(output_dir)
}

sinop2c <- sits:::.cube_find_class(sinop)
expect_true("raster_cube" %in% class(sinop2c))
expect_true("eo_cube" %in% class(sinop2c))

sinop2 <- sinop
class(sinop2) <- "data.frame"
new_cube <- sits:::.cube_find_class(sinop2)
expect_true("raster_cube" %in% class(new_cube))
expect_true("eo_cube" %in% class(new_cube))

bands <- .cube_bands(sinop2)
expect_equal(bands, "NDVI")

path1 <- .tile_path(sinop2, date = "2013-09-14",
band = "NDVI")
expect_true(grepl("jp2", path1))

expect_equal(.tile_source(sinop2), "BDC")
expect_equal(.tile_collection(sinop2), "MOD13Q1-6.1")
expect_equal(.tile_satellite(sinop2), "TERRA")
expect_equal(.tile_sensor(sinop2), "MODIS")
expect_equal(.tile_bands(sinop2), "NDVI")
expect_equal(.tile_ncols(sinop2), 255)
expect_equal(.tile_nrows(sinop2), 147)
expect_equal(.tile_size(sinop2)$ncols, 255)
expect_equal(.tile_size(sinop2)$nrows, 147)
expect_gt(.tile_xres(sinop2), 231)
expect_gt(.tile_yres(sinop2), 231)
expect_equal(as.Date(.tile_start_date(sinop2)), as.Date("2013-09-14"))
expect_equal(as.Date(.tile_end_date(sinop2)), as.Date("2014-08-29"))
expect_equal(.tile_fid(sinop), .tile_fid(sinop2))
expect_equal(.tile_crs(sinop), .tile_crs(sinop2))
expect_error(.tile_area_freq(sinop))
expect_equal(.tile_timeline(sinop), .tile_timeline(sinop2))
expect_true(.tile_is_complete(sinop2))
band_conf <- .tile_band_conf(sinop2, band = "NDVI")
expect_equal(band_conf$band_name, "NDVI")

expect_error(.cube_find_class(samples_modis_ndvi))

is_complete <- .cube_is_complete(sinop2)
expect_true(is_complete)

time_tb <- .cube_timeline_acquisition(sinop2, period = "P2M", origin = NULL)
expect_equal(nrow(time_tb), 6)
expect_equal(time_tb[[1,1]], as.Date("2013-09-14"))

bbox <- .cube_bbox(sinop2)
expect_equal(bbox[["xmin"]], -6073798)
bbox2 <- .tile_bbox(sinop2)
expect_equal(bbox2[["xmin"]], -6073798)

sf_obj <- .cube_as_sf(sinop2)
bbox3 <- sf::st_bbox(sf_obj)
expect_equal(bbox[["xmin"]], bbox3[["xmin"]])

sf_obj2 <- .tile_as_sf(sinop2)
bbox4 <- sf::st_bbox(sf_obj2)
expect_equal(bbox[["xmin"]], bbox4[["xmin"]])

expect_true(.cube_during(sinop2, "2014-01-01", "2014-04-01"))
expect_true(.tile_during(sinop2, "2014-01-01", "2014-04-01"))

t <- .cube_filter_interval(sinop2, "2014-01-01", "2014-04-01")
expect_equal(length(sits_timeline(t)), 3)

t1 <- .tile_filter_interval(sinop2, "2014-01-01", "2014-04-01")
expect_equal(length(sits_timeline(t1)), 3)

timeline <- sits_timeline(sinop2)
dates <- as.Date(c(timeline[1], timeline[3], timeline[5]))
t2 <- .cube_filter_dates(sinop2, dates)
expect_equal(.tile_timeline(t2), dates)

paths <- .cube_paths(sinop2)[[1]]
expect_equal(length(paths), 12)
expect_true(grepl("jp2", paths[12]))

expect_true(.cube_is_local(sinop2))

cube <- .cube_split_features(sinop2)
expect_equal(nrow(cube), 12)

cube <- .cube_split_assets(sinop2)
expect_equal(nrow(cube), 12)

expect_false(.cube_contains_cloud(sinop2))

sinop_probs <- sits_classify(
data = sinop,
ml_model = rfor_model,
Expand Down Expand Up @@ -574,73 +483,13 @@ test_that("Classification with post-processing", {
expect_true(max_lab == 4)
expect_true(min_lab == 1)

# test access for data.frame objects
#
sinop4 <- sinop_class
class(sinop4) <- "data.frame"
new_cube4 <- .cube_find_class(sinop4)
expect_true("raster_cube" %in% class(new_cube4))
expect_true("derived_cube" %in% class(new_cube4))
expect_true("class_cube" %in% class(new_cube4))

labels <- .cube_labels(sinop4)
expect_true(all(c("Cerrado", "Forest", "Pasture","Soy_Corn") %in% labels))
labels <- .tile_labels(sinop4)
expect_true(all(c("Cerrado", "Forest", "Pasture","Soy_Corn") %in% labels))

labels <- sits_labels(sinop4)
expect_true(all(c("Cerrado", "Forest", "Pasture","Soy_Corn") %in% labels))

sits_labels(sinop4) <- c("Cerrado", "Floresta", "Pastagem","Soja_Milho")
labels <- sits_labels(sinop4)
expect_true("Cerrado" %in% labels)

expect_equal(.tile_area_freq(sinop_class)[1,3],.tile_area_freq(sinop4)[1,3])

expect_error(.tile_update_label(
sinop_probs,
c("Cerrado", "Floresta", "Pastagem","Soja_Milho")
))

class(sinop4) <- "data.frame"
col <- .cube_collection(sinop4)
expect_equal(col, "MOD13Q1-6.1")

col <- .tile_collection(sinop4)
expect_equal(col, "MOD13Q1-6.1")

crs <- .cube_crs(sinop4)
expect_true(grepl("Sinusoidal", crs))
expect_true(grepl("Sinusoidal", .tile_crs(sinop4)))

class <- .cube_s3class(sinop4)
expect_true("raster_cube" %in% class)
expect_true("derived_cube" %in% class)
expect_true("class_cube" %in% class)

expect_equal(.cube_ncols(sinop4), 255)
expect_equal(.tile_ncols(sinop4), 255)
expect_equal(.cube_nrows(sinop4), 147)
expect_equal(.tile_nrows(sinop4), 147)
expect_equal(.cube_source(sinop4), "BDC")
expect_equal(.tile_source(sinop4), "BDC")
expect_equal(.cube_collection(sinop4), "MOD13Q1-6.1")
expect_equal(.tile_collection(sinop4), "MOD13Q1-6.1")

sd <- .cube_start_date(sinop4)
expect_equal(sd, as.Date("2013-09-14"))

ed <- .cube_end_date(sinop4)
expect_equal(ed, as.Date("2014-08-29"))

timeline <- .cube_timeline(sinop4)[[1]]
expect_equal(timeline[1], sd)
expect_equal(timeline[2], ed)

size <- .tile_size(sinop4)
expect_equal(size$nrows, 147)
expect_true(.tile_is_complete(sinop4))

# Save QML file
qml_file <- paste0(tempdir(),"/myfile.qml")
sits_colors_qgis(sinop_class, qml_file)
Expand Down Expand Up @@ -711,13 +560,6 @@ test_that("Classification with post-processing", {
max_unc <- max(.raster_get_values(r_unc))
expect_true(max_unc <= 10000)

sinop5 <- sinop_uncert
class(sinop5) <- "data.frame"
new_cube5 <- .cube_find_class(sinop5)
expect_true("raster_cube" %in% class(new_cube5))
expect_true("derived_cube" %in% class(new_cube5))
expect_true("uncert_cube" %in% class(new_cube5))


timeline_orig <- sits_timeline(sinop)
timeline_probs <- sits_timeline(sinop_probs)
Expand All @@ -734,12 +576,6 @@ test_that("Classification with post-processing", {
expect_equal(timeline_orig[length(timeline_orig)], timeline_class[2])


sinop6 <- sinop_probs
class(sinop6) <- "data.frame"

sinop_bayes_3 <- sits_smooth(sinop6, output_dir = tempdir())
expect_equal(sits_bands(sinop_bayes_3), "bayes")

expect_error(sits_smooth(sinop, output_dir = tempdir()))
expect_error(sits_smooth(sinop_class, output_dir = tempdir()))
expect_error(sits_smooth(sinop_uncert, output_dir = tempdir()))
Expand Down Expand Up @@ -817,21 +653,6 @@ test_that("Clean classification",{
sits_clean(cube = sinop_probs,
output_dir = output_dir)
)
sp <- sinop_class
class(sp) <- "data.frame"

clean_cube2 <- sits_clean(
cube = sp,
output_dir = output_dir,
version = "v2",
progress = FALSE
)
sum_clean2 <- summary(clean_cube2)

expect_equal(nrow(sum_orig), nrow(sum_clean2))
expect_equal(sum(sum_orig$count), sum(sum_clean2$count))
expect_lt(sum_orig[2,4], sum_clean2[2,4])

})
test_that("Clean classification with class cube from STAC",{
cube_roi <- c("lon_min" = -62.7, "lon_max" = -62.5,
Expand Down
18 changes: 0 additions & 18 deletions tests/testthat/test-regularize.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,13 @@ test_that("Regularizing cubes from AWS, and extracting samples from them", {
expect_equal(.tile_ncols(rg_cube), 458)
expect_equal(tile_bbox$xmax, 309780, tolerance = 1e-1)
expect_equal(tile_bbox$xmin, 199980, tolerance = 1e-1)

tile_fileinfo <- .fi(rg_cube)

expect_equal(nrow(tile_fileinfo), 2)

# Checking input class
s2_cube <- s2_cube_open
class(s2_cube) <- "data.frame"
expect_error(
sits_regularize(
cube = s2_cube,
output_dir = dir_images,
res = 240,
period = "P16D",
multicores = 2,
progress = FALSE
)
)

# Retrieving data

csv_file <- system.file("extdata/samples/samples_amazonia.csv",
package = "sits"
)

# read sample information from CSV file and put it in a tibble
samples <- tibble::as_tibble(utils::read.csv(csv_file))

Expand Down
6 changes: 0 additions & 6 deletions tests/testthat/test-tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ test_that("Apply", {
tolerance = 0.1
)
})
test_that("Data frame",{
point_df <- point_mt_6bands
class(point_df) <- "data.frame"
point_df_ndvi <- sits_select(point_df, bands = "NDVI")
expect_equal(sits_bands(point_df_ndvi), "NDVI")
})
test_that("Bands", {
bands <- sits_bands(samples_modis_ndvi)

Expand Down
Loading

0 comments on commit 108e5aa

Please sign in to comment.