Skip to content

Commit 7a6b404

Browse files
Merge pull request #1388 from M3nin0/fix/accuracy-empty-points
enhance sits_accuracy message in case of empty results
2 parents 9568ad5 + 59f2391 commit 7a6b404

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎R/api_accuracy.R‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
.check_chr_contains(colnames(validation), "label")
195195
# transform the `sf` object in a valid
196196
validation |>
197+
sf::st_transform(
198+
crs = "EPSG:4326"
199+
) |>
197200
dplyr::mutate(
198201
geom = sf::st_geometry(validation)
199202
) |>

‎R/sits_accuracy.R‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ sits_accuracy.class_cube <- function(data, ...,
212212
if (nrow(points_tile) < 1L) {
213213
return(NULL)
214214
}
215-
216215
# convert the tibble to a matrix
217216
xy <- matrix(c(points_tile[["X"]], points_tile[["Y"]]),
218217
nrow = nrow(points_tile),
@@ -243,6 +242,9 @@ sits_accuracy.class_cube <- function(data, ...,
243242
reference = reference
244243
)
245244
})
245+
if (.has_not(.dissolve(pred_ref_lst))) {
246+
stop(.conf("messages", "sits_accuracy_class_cube_no_validation_points"))
247+
}
246248
# retrieve predicted and reference vectors for all rows of the cube
247249
pred_ref <- do.call(rbind, pred_ref_lst)
248250
# is this data valid?

‎inst/extdata/config_messages.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ sits_add_base_cube: "unable to add cube - check if cube2 contains base maps"
360360
sits_accuracy: "unable to extract values to measure accuracy - check input"
361361
sits_accuracy_sits: "unable to extract predicted and reference data from samples\n have the samples been classified?"
362362
sits_accuracy_class_cube: "invalid validation data"
363+
sits_accuracy_class_cube_no_validation_points: "No validation points were extracted from the classified data cube - ensure they intersect"
363364
sits_accuracy_raster_cube: "input should be a classified cube"
364365
sits_accuracy_class_vector_cube: "attributes for predicted and reference values should be contained in the segments object"
365366
sits_accuracy_tbl_df: "input should be a classified sits tibble or a classified data cube"

‎tests/testthat/test-accuracy.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("conf_matrix -2 classes", {
1+
test_that("conf_matrix - 2 classes", {
22
data(cerrado_2classes)
33
set.seed(1234)
44
train_data <- sits_sample(cerrado_2classes, frac = 0.5)

0 commit comments

Comments
 (0)