lsm_p_circle does not match my calculation by hand
Closed this issue · 3 comments
I'm just tinkering with rcpp_get_circle. I noticed that I either don't understand the calculation or something is broken.
I created a raster with a single 3x1 patch and calculated the circle metrics by hand and with lsm_p_circle. By hand, I get a value of 0.6980247 and witch lsm_p_circle 0.6180281.
Here are my calculations (as in https://r-spatialecology.github.io/landscapemetrics/reference/lsm_p_circle.html):
mat <- matrix(data = c(NA,NA,NA,
NA,5,NA,
NA,5,NA,
NA,5,NA,
NA,NA,NA), nrow = 3, ncol = 5)
raster <- raster::raster(mat)
raster::extent(raster) <- raster::extent(0, 5, 0, 3)
landscapemetrics::lsm_p_circle(raster, 8)$value
# [1] 0.6180281
# Manual calculation : value = 1 - (area / area_c)
area <- 3
area_c <- pi * 1.5^2 # circle diameter from (1, 1.5) to (4, 1.5)
value <- 1- (area/area_c)
# [1] 0.5755868
area_c <- pi * sqrt(3^2 + 1) # circle diameter from (1, 1) to (4, 2)
value <- 1- (area/area_c)
# [1] 0.6980247
If that's a bug, I'm halfway to fixing it. But I just need a short confirmation that I'm not making some silly mistake in thinking somewhere.
Could it be due to:
"In addition, to ensure that the minimum value is always zero, the diameter of the circumscribing circle is computed as the maximum distance between periphery cells based on outer edge-to-outer edge distance, as opposed to cell center-to-cell center distance used in all nearest neighbor calculations."
FRAGSTATS manual
Could it be due to:
"In addition, to ensure that the minimum value is always zero, the diameter of the circumscribing circle is computed as the maximum distance between periphery cells based on outer edge-to-outer edge distance, as opposed to cell center-to-cell center distance used in all nearest neighbor calculations."
FRAGSTATS manual
I think that's what I do. The cell centers are (1.5, 1.5) and (3.5, 1.5). If I'm not mistaken, the way FRAGSTATS does not calculate this metrics would be:
area_c <- pi * 2^2 # circle diameter from (1.5, 1.5) to (3.5, 1.5)
value <- 1- (area/area_c)
# 0.7612676
Wait...isnt' your calculation of the circle area wrong? The distance is the diameter of the circle, so the A = pi * (diameter/2) ^ 2
I think this can be closed then.