-
Notifications
You must be signed in to change notification settings - Fork 52
Description
So I am attempting to implement a maximum filter on a CHM (Canopy Height Model) with a variable window size here, 'Tree_Heights' is a data frame containing the fitted values of a linear regression model to predict tree diameter, the window size is supposed to match the lower prediction interval for the radius of a tree at a given height.
RoundOdd <- function(x) {2*floor(x/2)+1}
fitlwr <- function(x){
RoundOdd(Tree_Heights[Tree_Heights$Tree_Height == x, "fit.lwr"]/2)
}
m <- raster::focalWeight(x = CMM, d = fitlwr(), type = "circle")
CMM <- raster::focal(x = CMM, w = m, fun = max)
This returns the following error:
Error in [.data.frame(Tree_Heights, Tree_Heights$Tree_Height == x, "fit.lwr") : argument "x" is missing, with no default
6.[.data.frame(Tree_Heights, Tree_Heights$Tree_Height == x, "fit.lwr")
5.Tree_Heights[Tree_Heights$Tree_Height == x, "fit.lwr"]
4.RoundOdd(Tree_Heights[Tree_Heights$Tree_Height == x, "fit.lwr"]/2)
3.fitlwr()
2..circular.weight(x, d[1])
1.raster::focalWeight(x = CMM, d = fitlwr(), type = "circle")
If I try instead to use the function in the argument for window size, I get this error:
Error in .local(x, ...) : is.matrix(w) is not TRUE
5. stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
4. stopifnot(is.matrix(w))
3. .local(x, ...)
2. raster::focal(x = CMM, w = fitlwr, fun = max)
- raster::focal(x = CMM, w = fitlwr, fun = max)
Is there no way to use a variable window size inherently in this function? Are there any other options for doing this in the Raster package?