-
Notifications
You must be signed in to change notification settings - Fork 2
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
MPG(...)$lcpPerimWeight contains mystery links when input patch raster has NA regions #28
Comments
This is a byproduct of how the |
@ecologics I spoke to Sam about this and he should have it fixed by next week. |
Awesome! I am excited about this work. Let's try to get a manuscript out early in the new year. Paul |
It seems the problem is caused by the voronoi being able to spread through NA regions but links aren't permitted, so they stop short at To me, the easiest fix (and a good default i.e., conservative behaviour) is to disallow the voronoi spreading and linking through If the user wants to do something more sophisticated with the Thoughts? |
I agree on all these points. The old version of grainscape did not handle |
Sam pushed a fix for this yesterday (137fe47). I'll take a look later today to do some tests. |
@samdoctolero I get an error running your updated code: library(igraph)
library(raster)
## simplest case
x <- 100
y <- 100
m <- matrix(2L, ncol = y, nrow = y)
m[1:95, 46:55] <- NA_integer_
m[16:35, 24:35] <- 3L
m[16:35, 76:90] <- 3L
r <- raster(m)
c <- reclassify(r, rcl = cbind(c(1, 2, 3), c(10, 5, 1)))
p <- (c == 1)
mpg <- MPG(cost = c, patch = p) The above fails with:
@ecologics @cxfauvelle please hold off updating until this is resolved |
When ignoring ## Get additional patch information
uniquePatches <- voronoi[] %>% unique() %>% sort()
uniquePatches <- uniquePatches[uniquePatches > 0] ## added this I understand that the unique sets of patches had to be extracted and sorted at the same time. Since we ignored the @achubaty feel free to change that line. Basically, I'm just removing the first element of the vector which will always be zero. |
@samdoctolero with the change in 203cff5, this is working. I have tweaked the The phantom links are now gone from the test raster posted by @ecologics and @cxfauvelle: f <- 'naErrorExample.asc'
r <- raster(f)
c <- r
p <- (r == 1)
mpg <- MPG(cost = c, patch = p)
plot(is.na(r), col = c("white", "red")) ## red areas are NA
plot(mpg, add = TRUE) ## superimpose the mpg plot However, note that not all patches are linked. Is this another bug? See new issue #32. |
@samdoctolero the test passes, which suggests the spatial graph is being correctly built, but the raster is incorrect or being plotted incorrectly.
The following clip from @cxfauvelle input raster can be used to demonstrate this problem.
naErrorExample.zip
As below where red areas are NA and green areas are real patches (==1).
The text was updated successfully, but these errors were encountered: