Skip to content

Commit

Permalink
default for sits functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Jan 31, 2025
1 parent 965bc4a commit 5779b9c
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 166 deletions.
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ S3method(sits_accuracy,default)
S3method(sits_accuracy,derived_cube)
S3method(sits_accuracy,raster_cube)
S3method(sits_accuracy,sits)
S3method(sits_accuracy,tbl_df)
S3method(sits_apply,default)
S3method(sits_apply,derived_cube)
S3method(sits_apply,raster_cube)
Expand All @@ -386,7 +385,6 @@ S3method(sits_bands,sits_model)
S3method(sits_bbox,default)
S3method(sits_bbox,raster_cube)
S3method(sits_bbox,sits)
S3method(sits_bbox,tbl_df)
S3method(sits_classify,default)
S3method(sits_classify,derived_cube)
S3method(sits_classify,raster_cube)
Expand Down Expand Up @@ -473,7 +471,6 @@ S3method(sits_timeline,derived_cube)
S3method(sits_timeline,raster_cube)
S3method(sits_timeline,sits)
S3method(sits_timeline,sits_model)
S3method(sits_timeline,tbl_df)
S3method(sits_to_csv,default)
S3method(sits_to_csv,sits)
S3method(sits_to_csv,tbl_df)
Expand Down
18 changes: 1 addition & 17 deletions R/sits_accuracy.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,8 @@ sits_accuracy.derived_cube <- function(data, ...) {
}
#' @rdname sits_accuracy
#' @export
sits_accuracy.tbl_df <- function(data, ...) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data))) {
data <- .cube_find_class(data)
} else if (all(.conf("sits_tibble_cols") %in% colnames(data))) {
class(data) <- c("sits", class(data))
} else {
stop(.conf("messages", "sits_accuracy_tbl_df"))
}
acc <- sits_accuracy(data, ...)
return(acc)
}
#' @rdname sits_accuracy
#' @export
sits_accuracy.default <- function(data, ...) {
data <- tibble::as_tibble(data)
acc <- sits_accuracy(data, ...)
return(acc)
stop(.conf("messages", "sits_accuracy"))
}
#' @title Print accuracy summary
#' @name sits_accuracy_summary
Expand Down
12 changes: 1 addition & 11 deletions R/sits_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,5 @@ sits_apply.derived_cube <- function(data, ...) {
#' @rdname sits_apply
#' @export
sits_apply.default <- function(data, ...) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data))) {
data <- .cube_find_class(data)
} else if (all(.conf("sits_tibble_cols") %in% colnames(data))) {
class(data) <- c("sits", class(data))
} else {
stop(.conf("messages", "sits_apply_default"))
}

acc <- sits_apply(data, ...)
return(acc)
stop(.conf("messages", "sits_apply_default"))
}
15 changes: 2 additions & 13 deletions R/sits_bands.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,7 @@ sits_bands.sits_model <- function(x) {
#' @rdname sits_bands
#' @export
sits_bands.default <- function(x) {
x <- tibble::as_tibble(x)
if (all(.conf("sits_cube_cols") %in% colnames(x))) {
x <- .cube_find_class(x)
} else if (all(.conf("sits_tibble_cols") %in% colnames(x))) {
class(x) <- c("sits", class(x))
} else {
stop(.conf("messages", "sits_bands_default"))
}

bands <- sits_bands(x)
return(bands)
stop(.conf("messages", "sits_bands_default"))
}
#' @rdname sits_bands
#' @export
Expand Down Expand Up @@ -123,6 +113,5 @@ sits_bands.default <- function(x) {
#' @rdname sits_bands
#' @export
`sits_bands<-.default` <- function(x, value) {
.check_set_caller("sits_bands_assign_default")
.check_that(inherits(x, c("sits", "raster_cube")))
stop(.conf("messages", "sits_bands_assign_default"))
}
14 changes: 0 additions & 14 deletions R/sits_bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ sits_bbox.raster_cube <- function(data, crs = "EPSG:4326", as_crs = NULL) {
}
#' @rdname sits_bbox
#' @export
sits_bbox.tbl_df <- function(data, crs = "EPSG:4326", as_crs = NULL) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data))) {
data <- .cube_find_class(data)
} else if (all(.conf("sits_tibble_cols") %in% colnames(data))) {
class(data) <- c("sits", class(data))
} else {
stop(.conf("messages", "sits_bbox_default"))
}
bbox <- sits_bbox(data, crs, as_crs)
return(bbox)
}
#' @rdname sits_bbox
#' @export
sits_bbox.default <- function(data, crs = "EPSG:4326", as_crs = NULL) {
stop(.conf("messages", "sits_bbox_default"))
}
10 changes: 1 addition & 9 deletions R/sits_clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,5 @@ sits_clean.derived_cube <- 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)
if (all(.conf("sits_cube_cols") %in% colnames(cube))) {
cube <- .cube_find_class(cube)
} else {
stop(.conf("messages", "sits_clean"))
}
clean_cube <- sits_clean(cube, window_size, memsize, multicores,
output_dir, version, progress)
return(clean_cube)
stop(.conf("messages", "sits_clean"))
}
9 changes: 1 addition & 8 deletions R/sits_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,7 @@ sits_cluster_dendro.sits <- function(samples,
#' @rdname sits_cluster_dendro
#' @export
sits_cluster_dendro.default <- function(samples, ...) {
samples <- tibble::as_tibble(samples)
if (all(.conf("sits_tibble_cols") %in% colnames(samples))) {
class(samples) <- c("sits", class(samples))
} else {
stop(.conf("messages", "sits_cluster_dendro_default"))
}
samples <- sits_cluster_dendro(samples, ...)
return(samples)
stop(.conf("messages", "sits_cluster_dendro_default"))
}
#'
#' @title Show label frequency in each cluster produced by dendrogram analysis
Expand Down
2 changes: 1 addition & 1 deletion R/sits_detect_change.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ sits_detect_change.raster_cube <- function(data,
#' @export
#' @noRd
sits_detect_change.default <- function(data, dc_method, ...) {
stop("Input should be a sits tibble or a data cube")
stop(.conf("messages", "sits_detect_change_default"))
}
12 changes: 6 additions & 6 deletions R/sits_get_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ sits_get_probs <- function(cube, samples, window_size = NULL){
#' @rdname sits_get_probs
#'
#' @export
sits_get_probs.default <- function(cube, samples, window_size = NULL){
stop(.conf("messages", "sits_get_probs"))
}
#' @rdname sits_get_probs
#'
#' @export
sits_get_probs.csv <- function(cube, samples, window_size = NULL){
# Extract a data frame from csv
samples <- .csv_get_lat_lon(samples)
Expand Down Expand Up @@ -120,3 +114,9 @@ sits_get_probs.data.frame <- function(cube, samples, window_size = NULL){
)
return(data)
}
#' @rdname sits_get_probs
#'
#' @export
sits_get_probs.default <- function(cube, samples, window_size = NULL){
stop(.conf("messages", "sits_get_probs"))
}
8 changes: 1 addition & 7 deletions R/sits_label_classification.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,5 @@ sits_label_classification.derived_cube <- function(cube, ...) {
#' @rdname sits_label_classification
#' @export
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)
else
stop(.conf("messages", "sits_label_classification"))
class_cube <- sits_label_classification(cube, ...)
return(class_cube)
stop(.conf("messages", "sits_label_classification"))
}
22 changes: 3 additions & 19 deletions R/sits_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ sits_labels.sits_model <- function(data) {
#' @rdname sits_labels
#' @export
sits_labels.default <- function(data) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data))) {
data <- .cube_find_class(data)
} else if (all(.conf("sits_tibble_cols") %in% colnames(data))) {
class(data) <- c("sits", class(data))
} else {
stop(.conf("messages", "sits_labels_raster_cube"))
}
data <- sits_labels(data)
return(data)
stop(.conf("messages", "sits_labels_default"))
}
#' @title Change the labels of a set of time series
#' @name `sits_labels<-`
Expand Down Expand Up @@ -176,15 +167,8 @@ sits_labels.default <- function(data) {
#' @name `sits_labels<-`
#' @export
`sits_labels<-.default` <- function(data, value) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data)))
data <- .cube_find_class(data)
else if (all(.conf("sits_tibble_cols") %in% colnames(data)))
class(data) <- c("sits", class(data))
else
stop(.conf("messages", "sits_labels_raster_cube"))
sits_labels(data) <- value
return(data)
stop(.conf("messages", "sits_labels_assign_default"))

}
#' @title Inform label distribution of a set of time series
#' @name sits_labels_summary
Expand Down
4 changes: 1 addition & 3 deletions R/sits_mixture_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,5 @@ sits_mixture_model.tbl_df <- function(data, endmembers, ...) {
#' @rdname sits_mixture_model
#' @export
sits_mixture_model.default <- function(data, endmembers, ...) {
data <- tibble::as_tibble(data)
data <- sits_mixture_model(data, endmembers, ...)
return(data)
stop(.conf("messages", "sits_mixture_model_default"))
}
11 changes: 2 additions & 9 deletions R/sits_select.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ sits_select.raster_cube <- function(data, ...,
#' @rdname sits_select
#' @export
sits_select.default <- function(data, ...) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data)))
data <- .cube_find_class(data)
else if (all(.conf("sits_tibble_cols") %in% colnames(data)))
class(data) <- c("sits", class(data))
else
stop(.conf("messages", "sits_select"))
data <- sits_select(data, ...)
return(data)
stop(.conf("messages", "sits_select_default"))

}
9 changes: 1 addition & 8 deletions R/sits_smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,5 @@ sits_smooth.derived_cube <- function(cube, ...) {
#' @rdname sits_smooth
#' @export
sits_smooth.default <- function(cube,...) {
cube <- tibble::as_tibble(cube)
if (all(.conf("sits_cube_cols") %in% colnames(cube)))
cube <- .cube_find_class(cube)
else
stop(.conf("messages", "sits_smooth_default"))

cube <- sits_smooth(cube,...)
return(cube)
stop(.conf("messages", "sits_smooth_default"))
}
18 changes: 1 addition & 17 deletions R/sits_timeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,7 @@ sits_timeline.derived_cube <- function(data) {
}
#' @rdname sits_timeline
#' @export
sits_timeline.tbl_df <- function(data) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data)))
data <- .cube_find_class(data)
else if (all(.conf("sits_tibble_cols") %in% colnames(data)))
class(data) <- c("sits", class(data))
else
stop(.conf("messages", "sits_timeline_default"))
timeline <- sits_timeline(data)
return(timeline)
}
#' @rdname sits_timeline
#' @export
#'
sits_timeline.default <- function(data) {
data <- tibble::as_tibble(data)
timeline <- sits_timeline(data)
return(timeline)

stop(.conf("messages", "sits_timeline_default"))
}
9 changes: 1 addition & 8 deletions R/sits_variance.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,5 @@ sits_variance.default <- function(cube,
multicores = 2L,
output_dir,
version = "v1") {
cube <- tibble::as_tibble(cube)
if (all(.conf("sits_cube_cols") %in% colnames(cube)))
cube <- .cube_find_class(cube)
else
stop(.conf("messages", "sits_variance_raster_cube"))
variance_cube <- sits_variance(cube, window_size, neigh_fraction,
memsize, multicores, output_dir, version)
return(variance_cube)
stop(.conf("messages", "sits_variance_default"))
}
7 changes: 6 additions & 1 deletion inst/extdata/config_messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ sits_detect_change_method: "wrong input parameters - see example in documentatio
sits_detect_change_method_model: "dc_method is not a valid function"
sits_detect_change_method_timeline: "samples have different timeline lengths"
sits_detect_change_sits: "wrong input parameters - see example in documentation"
sits_detect_change_default: "Input should be a sits tibble or a data cube"
sits_dtw: "wrong input parameters - see example in documentation"
sits_filter: "input should be a valid set of training samples or a non-classified data cube"
sits_formula_linear: "invalid input data"
Expand All @@ -402,7 +403,8 @@ sits_kfold_validate: "ml_method is not a valid sits method"
sits_kfold_validate_samples: "sits_kfold_validate() requires labelled set of time series"
sits_kfold_validate_windows: "sits_kfold_validate() works only with 1 core in Windows"
sits_label_classification: "input should be a cube with probabilities\n - run sits_classify() before applying this function"
sits_labels_assign: "invalid input data - should be a valid set of samples or a classified data cube"
sits_labels_assign_default: "invalid input data - should be a valid set of samples or a classified data cube"
sits_labels_default: "invalid input data - should be a valid set of samples or a classified data cube"
sits_labels_assign_class_cube: "not enough new labels to replace current ones"
sits_labels_assign_probs_cube: "number of new labels dos not match current labels"
sits_labels_raster_cube: "input should be a set of time seriesor probs, class or variance cube"
Expand All @@ -420,6 +422,7 @@ sits_merge_sits: "input data is NULL or has different number of rows"
sits_merge_sits_bands: "duplicated band names - merge only works if bands in inputs are different"
sits_mixture_model: "wrong input parameters - see example in documentation"
sits_mixture_model_derived_cube: "input should not be a cube that has been classified"
sits_mixture_model_default: "wrong input parameters - see example in documentation"
sits_mlp: "wrong input parameters - see example in documentation"
sits_mlp_layers_dropout: "number of layers does not match number of dropout rates"
sits_mosaic: "wrong input parameters - see example in documentation"
Expand Down Expand Up @@ -448,6 +451,7 @@ sits_sampling_design_labels: "names of classes in cube do not match labels in ex
sits_sampling_design_alloc: "some selected allocation options are not feasible"
sits_sampling_design_available_labels: "some selected labels are not available in the cube"
sits_select: "input should be a valid set of training samples or a non-classified data cube"
sits_select_default: "input should be a valid set of training samples or a non-classified data cube"
sits_segment: "wrong input parameters - see example in documentation"
sits_slic: "wrong input parameters - see example in documentation"
sits_smooth: "wrong input parameters - see example in documentation"
Expand Down Expand Up @@ -480,6 +484,7 @@ sits_uncertainty_default: "invalid method for uncertainty estimation"
sits_uncertainty_sampling: "check that input cube is a valid uncertainty cube - see example in documentation"
sits_uncertainty_sampling_window: "unable to obtain desidered number of samples\n try a smaller 'sampling_window' parameter"
sits_variance: "wrong input parameters - see example in documentation"
sits_variance_default: "input should be a probability cube"
sits_variance_raster_cube: "input should be a probability cube"
sits_validate: "ml_method is not a valid sits method"
sits_view_probs_label: "wrong label parameter in sits_view for probs cube"
Expand Down
3 changes: 0 additions & 3 deletions man/sits_accuracy.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_bbox.Rd

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

Loading

0 comments on commit 5779b9c

Please sign in to comment.