Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Adjust data type and properties to new computed indexes in sits_apply()"" #1071

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading