Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
pred_masks: cluster begin/end moved inside mapply (cluster error on
large datasets, not sure this is a full fix yet). n_things: informative
error message. eval_pgap: fix doc examples
  • Loading branch information
obrl_soil committed Aug 29, 2017
1 parent c4a2f80 commit a611dfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions R/dsmartr_evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#' cpus = max(1, (parallel::detectCores() - 1)))
#'
#' # or supply unstacked maps (slightly faster)
#' pgap2 <- dsmartr_eval_pgap(dsmartr_probs = most_likely[['most_likely_ps']][1:2],
#' cpus = max(1, (parallel::detectCores() - 1)))
#' pgap2 <- dsmartr_eval_pgap(dsmartr_probs = most_likely[c('most_likely_prob_1', 'most_likely_prob_2')],
#' #' cpus = max(1, (parallel::detectCores() - 1)))
#'
#' # or read from file
#' mpp_1 <- raster(file.path(getwd(), 'most_probable_maps', 'mostlikely_1.tif'))
#' mpp_2 <- raster(file.path(getwd(), 'most_probable_maps', 'mostlikely_2.tif'))
#' mpp_1 <- raster(file.path(getwd(), 'most_likely_maps', 'most_likely_1.tif'))
#' mpp_2 <- raster(file.path(getwd(), 'most_likely_maps', 'most_likely_2.tif'))
#' pgap3 <- dsmartr_eval_pgap(dsmartr_probs = list(mpp_1, mpp_2),
#' cpus = max(1, (parallel::detectCores() - 1)))
#' }
Expand Down
12 changes: 8 additions & 4 deletions R/dsmartr_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#' @importFrom stats na.omit
n_things <- function(input = NULL, selector = NULL) {
input <- as.data.frame(input, stringsAsFactors = FALSE)
if(length(grep(selector, names(input))) == 0) {
stop("Error: Selector not found within input's column names")
} else {
output <- as.vector(na.omit(unlist(input[, c(grep(selector, names(input)))])))
if(length(output) == 0) { NA } else { output }
if(length(output) == 0) { NA } else { output }}
}


Expand Down Expand Up @@ -123,12 +126,12 @@ dsmartr_pred_masks <- function(samples = NULL, covariates = NULL, tolerance = 0L

message(paste0(Sys.time(), ': dsmartr prediction mask creation in progress...'))
pb <- txtProgressBar(min = 0, max = length(samples), style = 3)
beginCluster(n = cpus)

all_masks <- mapply(FUN = function(m, n) {
sx <- st_set_geometry(m, NULL)
rangex <- apply(sx[, c(3:ncol(sx))], MARGIN = 2,
FUN = function(x) range(x, na.rm = TRUE))

beginCluster(n = cpus)
pred_mask <- clusterR(x = covariates,
fun = calc,
args = list(function(cell) {
Expand All @@ -143,11 +146,12 @@ dsmartr_pred_masks <- function(samples = NULL, covariates = NULL, tolerance = 0L
datatype = 'INT2S',
overwrite = TRUE)
setTxtProgressBar(pb, n)
endCluster()
pred_mask
},
m = samples,
n = seq_along(samples))
endCluster()

close(pb)

message(paste0(Sys.time(), ': ...complete. dsmartr outputs can be located at ',
Expand Down

0 comments on commit a611dfc

Please sign in to comment.