WSL/SLF GitLab Repository

Commit 5da683bf authored by Adrien Michel's avatar Adrien Michel
Browse files

Removed R implementation

parent 78783282
compute.spatial.pools.internal.static <- function(data, pixel, target, spatial.pool,
elevation.pool, azi.pool)
{
indices <- c(seq_along(data$x.indices))
if(spatial.pool > 0) {
dist <- as.matrix(sqrt((data$x.coords[data$x.indices[pixel]]-
data$x.coords[data$x.indices])^2+
(data$y.coords[data$y.indices[pixel]]-
data$y.coords[data$y.indices])^2))/1000
indices <- indices[which(dist<=spatial.pool)]
}
if(elevation.pool > 0) {
indices <- indices[(data$dem[indices] <= data$dem[pixel] + elevation.pool) &
(data$dem[indices] >= data$dem[pixel] - elevation.pool)]
}
if(azi.pool > 0) {
indices <-indices[((data$azi[indices] - data$azi[pixel] + 180)%%360 - 180 >= -azi.pool) &
((data$azi[indices] - data$azi[pixel] + 180)%%360 - 180 <= azi.pool) ]
}
if(spatial.pool + elevation.pool + azi.pool == 0)
{
indices=c(pixel)
}
return(list(pool = indices, spatial.pool = spatial.pool,
elevation.pool = elevation.pool, azi.pool = azi.pool))
}
compute.spatial.pools.internal.dynamic <- function(data, pixel, target, spatial.steps,
elevation.steps,
azi.steps,
spatial.pool,
elevation.pool,
azi.pool,
origin = "main")
{
out <- compute.spatial.pools.internal.static(data = data, pixel = pixel,
target = target,
spatial.pool = spatial.pool,
elevation.pool = elevation.pool,
azi.pool = azi.pool)
max_spatial <- 50
max_elev <- 300
max_azi <- 120
if(length(out$pool) < target){
continue <- FALSE
if(!spatial.pool == 0 & spatial.pool < max_spatial) {
spatial.pool <- spatial.pool + spatial.steps
continue <- TRUE
}
if(!elevation.pool == 0 & elevation.pool < max_elev){
elevation.pool <- elevation.pool + elevation.steps
continue <- TRUE
}
if(!azi.pool == 0 & azi.pool < max_azi) {
azi.pool <- azi.pool + azi.steps
continue <- TRUE
}
if(continue) {
out <- compute.spatial.pools.internal.dynamic(data = data, pixel = pixel,
target = target,
spatial.steps = spatial.steps,
elevation.steps = elevation.steps,
azi.steps = azi.steps,
spatial.pool = spatial.pool,
elevation.pool = elevation.pool,
azi.pool = azi.pool,
origin = "plus")
}
}
else if(length(out$pool) > target){
if(origin != "plus") {
# out$pool=out$pool[-((target+1):length(out$pool))]
# } else {
continue <- FALSE
if(spatial.pool > spatial.steps) {
spatial.pool <- spatial.pool - spatial.steps
continue <- TRUE
}
if(elevation.pool > elevation.steps){
elevation.pool <- elevation.pool - elevation.steps
continue <- TRUE
}
if(azi.pool > azi.steps) {
azi.pool <- azi.pool - azi.steps
continue <- TRUE
}
if(continue) {
out <- compute.spatial.pools.internal.dynamic(data = data, pixel = pixel,
target = target,
spatial.steps = spatial.steps,
elevation.steps = elevation.steps,
azi.steps = azi.steps,
spatial.pool = spatial.pool,
elevation.pool = elevation.pool,
azi.pool = azi.pool,
origin = "minus")
}
}
}
return(out)
}
#' Title
#'
#' @param x A
......@@ -126,61 +18,18 @@ compute.spatial.pools <- function(data, params.qm, ncores = 1,
}
}
if(type=="R") {
pixels <- c(1:length(data$dem))
if(ncores>1) {
`%dopar%` <- foreach::`%dopar%`
doParallel::registerDoParallel(ncores)
spatial.pools <- foreach::foreach(p=pixels) %dopar% {
if(params.qm$target > 0) {
compute.spatial.pools.internal.dynamic(data = data, pixel = p, target = params.qm$target,
spatial.steps = params.qm$spatial.pool,
elevation.steps = params.qm$elevation.pool,
azi.steps = params.qm$azi.pool,
spatial.pool = 0.5,
elevation.pool = 0.5,
azi.pool = 0.5)
} else if (params.qm$target == 0) {
compute.spatial.pools.internal.static(data = data, pixel = p, target = params.qm$target,
spatial.pool = params.qm$spatial.pool,
elevation.pool = params.qm$elevation.pool,
azi.pool = params.qm$azi.pool)
}
}
doParallel::stopImplicitCluster()
} else {
`%do%` <- foreach::`%do%`
spatial.pools <- foreach::foreach(p=pixels) %do% {
if(params.qm$target > 0) {
compute.spatial.pools.internal.dynamic(data = data, pixel = p, target = params.qm$target,
spatial.steps = params.qm$spatial.pool,
elevation.steps = params.qm$elevation.pool,
azi.steps = params.qm$azi.pool,
spatial.pool = 0.5,
elevation.pool = 0.5,
azi.pool = 0.5)
} else if (params.qm$target == 0) {
compute.spatial.pools.internal.static(data = data, pixel = p, target = params.qm$target,
spatial.pool = params.qm$spatial.pool,
elevation.pool = params.qm$elevation.pool,
azi.pool = params.qm$azi.pool)
}
}
}
} else{
spatial.pools <- computeSpatialPoolsCpp(elevation = c(data$dem),
azi = c(data$azi),
x_coordinates = data$x.coords[data$x.indices],
y_coordinates = data$y.coords[data$y.indices],
target = params.qm$target,
spatial_steps = params.qm$spatial.pool,
elevation_steps = params.qm$elevation.pool,
azi_steps = params.qm$azi.pool,
spatial_pool = 0.5,
elevation_pool = 0.5,
azi_pool = 0.5,
ncores = ncores)
spatial.pools <- computeSpatialPoolsCpp(elevation = c(data$dem),
azi = c(data$azi),
x_coordinates = data$x.coords[data$x.indices],
y_coordinates = data$y.coords[data$y.indices],
target = params.qm$target,
spatial_steps = params.qm$spatial.pool,
elevation_steps = params.qm$elevation.pool,
azi_steps = params.qm$azi.pool,
spatial_pool = 0.5,
elevation_pool = 0.5,
azi_pool = 0.5,
ncores = ncores)
}
if(!is.null(output.file)) {
saveRDS(spatial.pools, paste0(output.file))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment