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

terraize dismo functions, e.g. mess #60

Open
geryan opened this issue Aug 15, 2024 · 0 comments
Open

terraize dismo functions, e.g. mess #60

geryan opened this issue Aug 15, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@geryan
Copy link
Collaborator

geryan commented Aug 15, 2024

Those using raster inputs so don't have to go through the endless drudgery of conversion to raster and back again. The horror. The horror.

library(dismo)
#> Loading required package: raster
#> Loading required package: sp
mess
#> function (x, v, full = FALSE, filename = "", ...) 
#> {
#>     stopifnot(NCOL(v) == nlayers(x))
#>     out <- raster(x)
#>     nl <- nlayers(x)
#>     filename <- trim(filename)
#>     nms <- paste(names(x), "_mess", sep = "")
#>     if (canProcessInMemory(x)) {
#>         x <- getValues(x)
#>         if (nl == 1) {
#>             rmess <- .messi3(x, v)
#>             names(out) <- "mess"
#>             out <- setValues(out, rmess)
#>         }
#>         else {
#>             x <- sapply(1:ncol(x), function(i) .messi3(x[, i], 
#>                 v[, i]))
#>             rmess <- apply(x, 1, min, na.rm = TRUE)
#>             if (full) {
#>                 out <- brick(out, nl = nl + 1)
#>                 names(out) <- c(nms, "mess")
#>                 out <- setValues(out, cbind(x, rmess))
#>             }
#>             else {
#>                 names(out) <- "mess"
#>                 out <- setValues(out, rmess)
#>             }
#>         }
#>         if (filename != "") {
#>             out <- writeRaster(out, filename, ...)
#>         }
#>         return(out)
#>     }
#>     else {
#>         if (nl == 1) {
#>             names(out) <- "mess"
#>             tr <- blockSize(out)
#>             pb <- pbCreate(tr$n, ...)
#>             out <- writeStart(out, filename, ...)
#>             for (i in 1:tr$n) {
#>                 vv <- getValues(x, row = tr$row[i], nrows = tr$nrows[i])
#>                 vv <- .messi3(vv, v)
#>                 out <- writeValues(out, vv, tr$row[i])
#>                 pbStep(pb)
#>             }
#>         }
#>         else {
#>             if (full) {
#>                 out <- brick(out, nl = nl + 1)
#>                 names(out) <- c(nms, "mess")
#>                 tr <- blockSize(out)
#>                 pb <- pbCreate(tr$n, ...)
#>                 out <- writeStart(out, filename, ...)
#>                 for (i in 1:tr$n) {
#>                   vv <- getValues(x, row = tr$row[i], nrows = tr$nrows[i])
#>                   vv <- sapply(1:ncol(v), function(i) .messi3(vv[, 
#>                     i], v[, i]))
#>                   m <- apply(vv, 1, min, na.rm = TRUE)
#>                   out <- writeValues(out, cbind(vv, m), tr$row[i])
#>                   pbStep(pb)
#>                 }
#>             }
#>             else {
#>                 names(out) <- "mess"
#>                 tr <- blockSize(out)
#>                 pb <- pbCreate(tr$n, ...)
#>                 out <- writeStart(out, filename, ...)
#>                 for (i in 1:tr$n) {
#>                   vv <- getValues(x, row = tr$row[i], nrows = tr$nrows[i])
#>                   vv <- sapply(1:ncol(v), function(i) .messi3(vv[, 
#>                     i], v[, i]))
#>                   m <- apply(vv, 1, min, na.rm = TRUE)
#>                   out <- writeValues(out, m, tr$row[i])
#>                   pbStep(pb)
#>                 }
#>             }
#>         }
#>         out <- writeStop(out)
#>         pbClose(pb)
#>     }
#>     out
#> }
#> <bytecode: 0x14bb10c20>
#> <environment: namespace:dismo>

Created on 2024-08-16 with reprex v2.1.0

@geryan geryan added the enhancement New feature or request label Aug 15, 2024
@geryan geryan self-assigned this Aug 15, 2024
@geryan geryan added this to the mordialloc_rd_duplicator milestone Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant