martibosch / pylandstats

Computing landscape metrics in the Python ecosystem
https://doi.org/10.1371/journal.pone.0225734
GNU General Public License v3.0
82 stars 16 forks source link

4 cell neighborhood rule #13

Closed jennykri closed 3 years ago

jennykri commented 3 years ago

4 cell neighborhood rule

You did really great work on the pylandstats toolbox. Thank you for sharing it!

I have noticed that e.g. the number_of_patches function uses a 8 cell neighborhood rule, and probably the other functions do so too. In Fragstats you can chose between 4- and 8- cell rule. Did you implement the 4 cell neighborhood aswell?

Best regards

martibosch commented 3 years ago

Hello @jennykri,

thank you for your suggestion and sorry for the delay in my repsonse. I have added such a functionality in fe4005a and it will be included in the next release, hopefully next week.

Given the way in which pylandstats works, the neighborhood rule is passed to the initialization of Landscape, e.g.:

ls = pls.Landscape('path/to/raster.tif', neighborhood_rule='8')   # default
# or
ls = pls.Landscape('path/to/raster.tif', neighborhood_rule='4')

and then all the metrics computed for this landscape instance (i.e., ls) will be based on such a neighborhood rule. Therefore, if you want to compute some metrics based on the 8-cell neighborhood rule and others based on 4-cell you will need to create two different Landscape instances.

I hope that this addresses the issue, I will let you know when the feature is released. In the meantime, you can install the development version of pylandstats following this instructions - just note that you will net to run git checkout develop before pip install -e . so that you install pylandstats from the source of the develop branch.

martibosch commented 3 years ago

I have just released v2.3.0 which includes the neighborhood_rule argument when instantiating Landscape, as well as when instantiating SpatiotemporalAnalysis, ZonalAnalysis, BufferAnalysis, ZonalGridAnalysis and SpatiotemporalBufferAnalysis. I hope that this works for you.

I am closing this but feel free to reopen if needed. Thank you again for your suggestion. Best, Martí