Skip to content
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

Document comparison with SDMTools::PatchStats #44

Closed
jsta opened this issue Sep 21, 2018 · 14 comments
Closed

Document comparison with SDMTools::PatchStats #44

jsta opened this issue Sep 21, 2018 · 14 comments

Comments

@jsta
Copy link
Contributor

jsta commented Sep 21, 2018

I am considering porting some code using SDMTools::PatchStats to landscapemetrics::calculate_metrics(what = "patch") but I am having some difficulty comparing their outputs. Would some documentation comparing the two be welcome? If so, does it make sense to document in the README, vignette, or function docs?

@marcosci
Copy link
Member

If I remember correctly SDMTools does not convert the results to hectar and so on, as FRAGSTATS and we do - do you mean that with difficulties?

Otherwise: We should probably make this vignette a bit more broad:

https://r-spatialecology.github.io/landscapemetrics/articles/articles/comparing_fragstats_landscapemetrics.html

... and include SDMTools there 👍

@jsta
Copy link
Contributor Author

jsta commented Sep 21, 2018

Hmm, I hadn't considered a units mismatch.

@mhesselbarth
Copy link
Member

mhesselbarth commented Sep 22, 2018

I remeber checking (just very quickly) some results with SDMTools and think everythink looked ok, with exception of the units mismatch (which sometimes leads to a propagation). Maybe we should have a closer look if something else may be a problem (@marcosci).

@marcosci
Copy link
Member

Yup, the vignette needs an update anyway 👍

@jsta
Copy link
Contributor Author

jsta commented Oct 8, 2018

Here is my comparison attempt: https://gist.github.com/jsta/bd791f2c5e2609775bf9b322abb27c01

@marcosci
Copy link
Member

marcosci commented Oct 9, 2018

Hi @jsta,

I just included a section about SDMTools here in this vignette:

https://r-spatialecology.github.io/landscapemetrics/articles/articles/comparing_tools.html#comparison-with-sdmtools

I changed your code a bit to show how you would get the same results with SDMTools as with landscapemetrics/FRAGSTATS. The metrics you were after would rather be calculated with ClassStats in SDMTools, or? If something is missing or I am wrong, please say so and I will change it/make it clearer.

@jsta
Copy link
Contributor Author

jsta commented Oct 9, 2018

Right about ClassStats I was trying to keep the comparison as simple as possible. I plan to do some more digging and consider a PR against that vignette if that's alright.

@marcosci
Copy link
Member

marcosci commented Oct 9, 2018

Sure :) Thanks!

@jsta
Copy link
Contributor Author

jsta commented Oct 9, 2018

I updated my gist with a more direct ClassStats comparison. All the metrics look good except the core metrics (and prop.like.adjacencies/ lsm_c_pladj). Got any ideas? I don't get better results adjusting directions, consider_boundary, or edge_depth.

@marcosci
Copy link
Member

PLADJ should be fine, the result from landscapemetrics is correct (or at least the same as you get from FRAGSTATS).

There are datasets with the true values (calculated from FRAGSTATS, landscapemetrics::fragstsats_class_landscape for your example) in the package, we tested against them during the development:

fragstats_class_landscape_value <- dplyr::select(fragstats_class_landscape,
                                              TYPE, PLADJ)
names(fragstats_class_landscape_value) <- c("class", "value")
landscapemetrics_class_landscape_value <- lsm_c_pladj(landscape)
comparison <- dplyr::full_join(x = fragstats_class_landscape_value,
                            y = landscapemetrics_class_landscape_value,
                            by = "class",
                            suffix = c(".fs", ".lsm"))

You can find more here:

https://github.com/r-spatialecology/landscapemetrics/blob/master/tests/testthat/test_fragstats.R

We disabled that because FRAGSTATS has only a precision of 4 digits, so we ended up with a lot of rounding and the test itself did not make that much sense anymore.

There are slight differences between the definition of core areas in our case and FRAGSTATS, we count edge cells (and therefore always have 1, 2, 3, 4 cells as edge depth) and FRAGSTSATS looks at cell centroids for the core area and measures the distance between cell centroids. The results differ only after some digits, at least during our testing. We have that on the agenda, so that they perfectly match with fragstats:

#15

@marcosci
Copy link
Member

@jsta If you find something knew, let me know and we reopen here 👍

@jsta
Copy link
Contributor Author

jsta commented Oct 22, 2018

I settled on finding that FRAGSTATS and SDMTools core metrics do not match but I'm not sure why.

@marcosci
Copy link
Member

So, without the chance at looking at the code from FRAGSTATS, I assume the difference comes from the definition of edge.

SDMTools does the same basically the same as we do:

https://github.com/jjvanderwal/SDMTools/blob/2eee12d07557e2b22cd31a302c92ddb820eb4859/src/patchstats.c

(The landscapemetrics::show_cores functions is a good way to look at that).

We played around a little and found out that we get the same results for the core metrics if we treat the raster as points (where the cell center becomes the point). If you then specify edge depths and measure distances, you get the same result as in FRAGSTATS.

@mhesselbarth
Copy link
Member

I guess that FRAGSTATS actually somehow measures distances to the edge and therefore the area of a cell can be only partly core area. Contrastingly, we define the edge-distance rather as "rows of cells" away from the edge. Therefore, a cell can be either completely core or completely edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants