Skip to content

Commit 78415ad

Browse files
fix additional problems in testing segmentation
1 parent 491516f commit 78415ad

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

R/sits_classify.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,6 @@ sits_classify.segs_cube <- function(data,
398398
}
399399
#' @rdname sits_classify
400400
#' @export
401-
sits_classify.derived_cube <- function(data, ml_model, ...) {
402-
stop("Input data cube has already been classified")
403-
}
404-
#' @rdname sits_classify
405-
#' @export
406401
sits_classify.default <- function(data, ml_model, ...) {
407402
data <- tibble::as_tibble(data)
408403
if (all(.conf("sits_cube_cols") %in% colnames(data))) {

tests/testthat/test-raster.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,3 @@ test_that("Raster terra interface", {
953953
expect_equal(nrow(r_clone), nrow(r_prodes))
954954
expect_equal(ncol(r_clone), ncol(r_prodes))
955955
})
956-
test_that("Segmentation of large files",{
957-
958-
})

tests/testthat/test-segmentation.R

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,6 @@ test_that("Segmentation", {
131131
regexp = "Recovery: "
132132
)
133133
})
134-
# Expect error when trying to classify derived cube
135-
expect_error({
136-
sits_classify(
137-
data = probs_segs,
138-
ml_model = rfor_model,
139-
output_dir = output_dir,
140-
n_sam_pol = 20,
141-
multicores = 6,
142-
memsize = 24,
143-
version = "vt2"
144-
)
145-
})
146134
# Create a classified vector cube
147135
class_segs <- sits_label_classification(
148136
cube = probs_segs,
@@ -195,13 +183,12 @@ test_that("Segmentation", {
195183
expect_true(all(sits_labels(rfor_model) %in% colnames(sf_uncert)))
196184
})
197185
test_that("Segmentation of large files",{
198-
199186
modis_cube <- .try(
200187
{
201188
sits_cube(
202189
source = "BDC",
203190
collection = "MOD13Q1-6",
204-
bands = c("NDVI", "CLOUD"),
191+
bands = c("NDVI", "EVI", "CLOUD"),
205192
tiles = "012010",
206193
start_date = "2018-09-14",
207194
end_date = "2019-08-29",
@@ -217,13 +204,17 @@ test_that("Segmentation of large files",{
217204
if (!dir.exists(output_dir)) {
218205
dir.create(output_dir)
219206
}
220-
modis_cube_local <- sits_regularize(
221-
cube = modis_cube,
222-
period = "P1M",
223-
res = 1000,
224-
multicores = 6,
225-
output_dir = output_dir
207+
expect_warning(
208+
modis_cube_local <- sits_regularize(
209+
cube = modis_cube,
210+
period = "P1M",
211+
res = 1000,
212+
multicores = 6,
213+
output_dir = output_dir
214+
)
226215
)
216+
expect_true(.cube_is_regular(modis_cube_local))
217+
expect_true(all(sits_bands(modis_cube_local) %in% c("EVI", "NDVI")))
227218
segments <- sits_segment(
228219
cube = modis_cube_local,
229220
seg_fn = sits_slic(
@@ -235,8 +226,11 @@ test_that("Segmentation of large files",{
235226
multicores = 4,
236227
memsize = 16,
237228
progress = TRUE,
238-
version = "res1000-step50-iter10-minarea100-m4"
229+
version = "v2bands"
239230
)
231+
expect_s3_class(object = segments, class = "vector_cube")
232+
expect_true("vector_info" %in% colnames(segments))
233+
240234
# Train a rf model
241235
rfor_model <- sits_train(samples_modis_ndvi, ml_method = sits_rfor)
242236
probs_segs <- sits_classify(
@@ -246,7 +240,15 @@ test_that("Segmentation of large files",{
246240
n_sam_pol = 10,
247241
multicores = 6,
248242
memsize = 24,
249-
version = "res1000"
243+
version = "v2bands"
244+
)
245+
expect_s3_class(probs_segs, class = "probs_vector_cube")
246+
expect_true(
247+
"vector_info" %in% colnames(probs_segs)
248+
)
249+
# Read segments of a probability cube
250+
vector_probs <- .segments_read_vec(probs_segs)
251+
expect_true(
252+
all(sits_labels(probs_segs) %in% colnames(vector_probs))
250253
)
251-
252254
})

0 commit comments

Comments
 (0)