Skip to content

Commit

Permalink
Merge pull request #1071 from e-sensing/revert-1070-revert-1066-feat/…
Browse files Browse the repository at this point in the history
…appy_prop

Revert "Revert "Adjust data type and properties to new computed indexes in `sits_apply()`""
  • Loading branch information
gilbertocamara authored Feb 14, 2024
2 parents 6ac57f9 + ec47e06 commit fc825d1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
3 changes: 3 additions & 0 deletions R/api_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
values <- .apply_data_read(
tile = feature, block = block, in_bands = in_bands
)
if (all(is.na(values))) {
return(NULL)
}
# Evaluate expression here
# Band and kernel evaluation
values <- eval(
Expand Down
33 changes: 8 additions & 25 deletions R/api_conf.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@
#' @keywords internal
#' @noRd
#' @return names associated to the chosen access key
.conf_names <- function(key) {
.conf_names <- function(...) {
key <- c(...)
res <- tryCatch(
{
names(sits_env$config[[key]])
Expand Down Expand Up @@ -928,41 +929,23 @@ NULL
#' @param source Data source.
#' @param collection Collection in the data source.
#' @param band Band name
#' @param tile Tile
#' @details
#' If the band is not found, a default value will be returned from config.
#' If neither source nor collection entries are found in configuration file,
#' an error is thrown.
#' @returns A value in config.
.conf_eo_band <- function(source, collection, band, tile = NULL) {
.conf_eo_band <- function(source, collection, band) {
# Format band name
band <- .band_eo(band)
# Return a default value if band does not exists in config
if (!.conf_eo_band_exists(source, collection, band)) {
data_type <- "INT2S"
# does the file exist?
if (!purrr::is_null(tile)) {
band_path <- .tile_path(tile, band)
if (!purrr::is_null(band_path)) {
rast <- terra::rast(band_path)
data_type <- terra::datatype(rast)
conf_band <- .conf("default_vales", data_type)
} else {
# file does not exist
if (!.has(.conf("default_vales", band)))
conf_band <- .conf("default_vales", band)
else
conf_band <- .conf("default_vales", "INT4S")
}
if (band %in% .conf_names("default_values", "eo_cube")) {
return(.conf("default_values", "eo_cube", band))
}
return(.conf("default_values", "eo_cube", "default"))
}
else {
# Get band config value and return it
conf_band <- .conf("sources", source,
"collections", collection,
"bands", band)
}
return(conf_band)
# Get band config value and return it
.conf("sources", source, "collections", collection, "bands", band)
}
#' @title Config functions for derived_cube
#' @noRd
Expand Down
6 changes: 6 additions & 0 deletions R/api_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,12 @@ NULL
}

.cube_split_chunks_samples <- function(cube, samples_sf) {
# Hold s2 status
s2_status <- sf::sf_use_s2()
suppressMessages(sf::sf_use_s2(FALSE))
# Back to original status on exit
on.exit(suppressMessages(sf::sf_use_s2(s2_status)))
# Get block size of raster file
block <- .raster_file_blocksize(.raster_open_rast(.tile_path(cube)))
cube_chunks <- slider::slide(cube, function(tile) {
chunks <- .tile_chunks_create(
Expand Down
2 changes: 1 addition & 1 deletion R/api_source.R
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ NULL
# check source
.source_check(source = source)
# get collections from source
collections <- .conf_names(c("sources", source, "collections"))
collections <- .conf_names("sources", source, "collections")
return(collections)
}

Expand Down
4 changes: 2 additions & 2 deletions R/api_space_time_operations.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
.intersects <- function(x, y) {
as_crs <- sf::st_crs(x)
y <- sf::st_transform(y, crs = as_crs)
apply(sf::st_intersects(x, y, sparse = FALSE), 1, any)
apply(suppressMessages(sf::st_intersects(x, y, sparse = FALSE)), 1, any)
}
#' @title Spatial within
#' @noRd
Expand Down Expand Up @@ -100,7 +100,7 @@
.within <- function(x, y) {
as_crs <- sf::st_crs(x)
y <- sf::st_transform(y, crs = as_crs)
apply(sf::st_within(x, y, sparse = FALSE), 1, any)
apply(suppressMessages(sf::st_within(x, y, sparse = FALSE)), 1, any)
}
#' @title Spatial contains
#' @noRd
Expand Down
3 changes: 1 addition & 2 deletions R/api_tile.R
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ NULL
.tile_band_conf.eo_cube <- function(tile, band) {
.conf_eo_band(
source = .tile_source(tile), collection = .tile_collection(tile),
band = band[[1]],
tile = tile
band = band[[1]]
)
}
#' @export
Expand Down

0 comments on commit fc825d1

Please sign in to comment.