Skip to content

Commit

Permalink
initial version of sits_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Apr 23, 2023
1 parent 82fd9ed commit 0dd3402
Show file tree
Hide file tree
Showing 12 changed files with 543 additions and 11 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Collate:
'sits_sf.R'
'sits_smooth.R'
'sits_som.R'
'sits_summary.R'
'sits_tae.R'
'sits_tempcnn.R'
'sits_timeline.R'
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ S3method(sits_view,probs_cube)
S3method(sits_view,raster_cube)
S3method(sits_view,sits)
S3method(sits_view,som_map)
S3method(summary,class_cube)
S3method(summary,probs_cube)
S3method(summary,raster_cube)
S3method(summary,variance_cube)
export("%>%")
export("sits_labels<-")
export(sits_accuracy)
Expand Down
15 changes: 12 additions & 3 deletions R/sits_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,18 @@ sits_cube.local_cube <- function(source,
# precondition - data directory must be provided
.check_file(x = data_dir, msg = "'data_dir' parameter must be provided.")

# precondition - check source and collection
.source_check(source = source)
.source_collection_check(source = source, collection = collection)
# precondition - check source and collection for eo_cubes only
# is this a cube with results?
if (!purrr::is_null(bands) &&
all(bands %in% .conf("sits_results_bands"))) {
results_cube <- TRUE
} else {
results_cube <- FALSE
}
if (!results_cube) {
.source_check(source = source)
.source_collection_check(source = source, collection = collection)
}

dots <- list(...)

Expand Down
18 changes: 14 additions & 4 deletions R/sits_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ plot.probs_cube <- function(
#' @param palette RColorBrewer palette
#' @param rev Reverse order of colors in palette?
#' @param type Type of plot ("map" or "hist")
#' @param sample_hist Percentage of image to be sampled to obtain histogram
#' @param tmap_options List with optional tmap parameters
#' tmap_max_cells (default: 1e+06)
#' tmap_graticules_labels_size (default: 0.7)
Expand Down Expand Up @@ -805,6 +806,7 @@ plot.variance_cube <- function(
palette = "YlGnBu",
rev = FALSE,
type = "map",
sample_hist = 0.05,
tmap_options = NULL
) {
# precondition
Expand All @@ -816,6 +818,13 @@ plot.variance_cube <- function(
can_repeat = FALSE,
msg = "tile is not included in the cube"
)
# check percentage
.check_num(
sample_hist,
min = 0.01,
max = 1,
msg = "Sample percentage for histogram should be between 0.01 and 1"
)

# filter the cube
tile <- .cube_filter_tiles(cube = x, tiles = tile)
Expand All @@ -826,7 +835,7 @@ plot.variance_cube <- function(
if (type == "map")
p <- .plot_variance_map(tile, labels, palette, rev, tmap_options)
else
p <- .plot_variance_hist(tile)
p <- .plot_variance_hist(tile, sample_hist)

return(p)
}
Expand Down Expand Up @@ -1481,11 +1490,12 @@ plot.class_cube <- function(x, y, ...,
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @keywords internal
#' @noRd
#' @param tile Variance cube to be plotted.
#' @param tile Variance cube to be plotted
#' @param sample_hist Percentage of image to be sampled to obtain histogram
#'
#' @return A plot object
#'
.plot_variance_hist <- function(tile) {
.plot_variance_hist <- function(tile, sample_hist) {

# get all labels to be plotted
labels <- sits_labels(tile)
Expand All @@ -1497,7 +1507,7 @@ plot.class_cube <- function(x, y, ...,
nrows <- .tile_nrows(tile)
ncols <- .tile_ncols(tile)
# sample the pixels
n_samples <- as.integer(nrows / 5 * ncols / 5)
n_samples <- as.integer(nrows * ncols * sample_hist)
points <- sf::st_sample(sf_cube, size = n_samples)
points <- sf::st_coordinates(points)
# get the r object
Expand Down
Loading

0 comments on commit 0dd3402

Please sign in to comment.