"no applicable method" for focal() function in raster
Hello, Unfortunately your email client formatted your message in HTML so the content has been scrambled. Best results experienced when the client is configured to send plain text. I think that issues is that lsm_l_condent() is expecting a raster (or similar input). See https://cran.r-project.org/web/packages/landscapemetrics/landscapemetrics.pdf Raster's focal() function slides along the raster pulling out cell values (coincident with your focal window) and passes them to the function you specify. So as the docs for raster::focal descriibe, that function must be configured to "take multiple numbers, and return a single number." landscapremetrics::lsm_l_condent is not configured that way. Perhaps you need to create your own version of the function that just operates on an input of numbers rather than an input of raster-like objects? Cheers, Ben On Mon, Sep 14, 2020 at 4:42 PM Jaime Burbano Gir?n <jaimebg27 at gmail.com> wrote:
Hi everyone,
I want to apply a moving window (3x3) to estimate conditional entropy
(Nowosad & Stepinsky, 2019) over a heterogeneous landscape:
*entropy=function(r){*
* entropy=lsm_l_condent(r, neighbourhood = 4, ordered = TRUE, base =
"log2") return(entropy$value)}w=matrix(1,3,3)result=focal(r, w,
fun=entropy)*
However, I get this error:
*Error in .focal_fun(values(x), w, as.integer(dim(out)), runfun, NAonly) :
*
*Evaluation error: no applicable method for 'lsm_l_condent' applied to an
object of class "c('double', 'numeric')".*
But, when I run entropy function in the entire landscape it works:
*> entropy(r)[1] 2.178874*
*r* is a INT4U raster object:
*class : RasterLayer dimensions : 886, 999, 885114 (nrow, ncol,
ncell)resolution : 300, 300 (x, y)extent : 934805.7, 1234506, 1006566,
1272366 (xmin, xmax, ymin, ymax)crs : +proj=tmerc
+lat_0=4.59620041666667 +lon_0=-74.0775079166667 +k=1 +x_0=1000000
+y_0=1000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs values
: 99, 321113 (min, max)*
There is any idea to solve the "no applicable method" error? Or any idea to
estimate conditional entropy applying a moving window?
Thanks in advance for the help.
Best,
Jaime
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Ben Tupper Bigelow Laboratory for Ocean Science East Boothbay, Maine http://www.bigelow.org/ https://eco.bigelow.org [[alternative HTML version deleted]]