3

Radius of gyration (in the field of ecology) is a measure of the spatial extent of a habitat patch, and is defined as the mean distance between each cell in the patch and the patch centroid (cell-center to cell-center distance).

Can anyone suggest an efficient way to calculate this metric from a raster where patches have a value 1 and the background has a value of 0?

My current model uses the following series of processes, but is clunky and requires a hefty processing time. See below:

  1. Convert raster layer to polygon to find the centroid of each patch (Raster to Polygon, Feature to Point.
  2. Convert raster layer to point to find cell centers of each cell (Raster to Point).
  3. Find the cell center that is closest to the centroid (Near).
  4. Calculate distance between the cell center closest to the centroid and every other cell center in the patch (Point Distance).
  5. Calculate mean of the resulting table of distances (Summary Statistics)

This is all very clunky and time-consuming given the multiple conversions necessary and the number of patches I need to calculate. I am guessing there is a faster and more efficient way to perform this calculation, as other programs like FragStats can do it very rapidly.

  • 1
    I would not say that was clunky, sounds very logical. One thing I would say is having read your description you could use python and the multiprocessing module to parallelized the problem and use all the cores in your processor. – Hornbydd Oct 27 '16 at 22:25
  • @Hornbydd Thanks for the input. I was not aware of the multiprocessing module but will definitely look into it, would love to find a way to make this tool run faster. Cheers. – K. Credo Oct 27 '16 at 22:52
  • What if the cell from another patch is closer to different patch center? – FelixIP Oct 28 '16 at 6:32
  • 1
    You may find this document helpful, there are also several useful blogs out there detailing how to use multiprocessing. One thing I would say when it works its great! But it sure can be flaky! – Hornbydd Oct 28 '16 at 9:20
  • @FelixIP As it stands I have an intermediate step between 2 and 3 above that iterates through each centroid/cell center combination separately. – K. Credo Oct 28 '16 at 21:56
1

The workflow below:

  • is super fast, because it is raster based
  • unlike vector approach, that you are using, it will handle the situation with biggie sitting next to a small patch, when cells of the former are closer to centre of small pacth

INPUT BINARY RASTER:

enter image description here

Note: I removed background values of 0.

WORKFLOW:

arcpy.gp.RegionGroup_sa("binary","C:/FELIX_DATA/SCRARCH/GROUPS","EIGHT","WITHIN","NO_LINK","#")
arcpy.gp.SingleOutputMapAlgebra_sa("$$XMAP","C:/FELIX_DATA/SCRARCH/X","#")
arcpy.gp.SingleOutputMapAlgebra_sa("$$YMAP","C:/FELIX_DATA/SCRARCH/Y","#")
arcpy.gp.ZonalStatistics_sa("GROUPS","VALUE","X","C:/FELIX_DATA/SCRARCH/xMean","MEAN","DATA")
arcpy.gp.ZonalStatistics_sa("GROUPS","VALUE","Y","C:/FELIX_DATA/SCRARCH/yMean","MEAN","DATA")
arcpy.gp.RasterCalculator_sa("""Power(("X" - "xMean")*("X" - "xMean")+("Y" - "yMean")*("Y" - "yMean"),0.5)""","C:/FELIX_DATA/SCRARCH/distance")
arcpy.gp.ZonalStatisticsAsTable_sa("GROUPS","VALUE","distance","C:/FELIX_DATA/SCRARCH/stats.dbf","DATA","MEAN")
arcpy.RasterToPolygon_conversion("GROUPS","C:/FELIX_DATA/SCRARCH/polygons.shp","SIMPLIFY","VALUE")
arcpy.AddField_management("POLYGONS","R_GYR","FLOAT","#","#","#","#","NULLABLE","NON_REQUIRED","#")
arcpy.AddJoin_management("POLYGONS","GRIDCODE","stats","VALUE","KEEP_ALL")
arcpy.CalculateField_management("POLYGONS","polygons.R_GYR","[stats.MEAN]","VB","#")

OUTPUT PATCHES WITH COMPUTED RADIUS:

enter image description here

Very little efforts required to bring it to Python, where by importing spatial analyst tools one can use in memory rasters, e.g. first line will look something like this:

outRegionGrp = RegionGroup(binary, "EIGHT")

If you have to repeat this process, I suggest scripting it.

  • Many thanks for the input! Don't have experience writing actual workflows in Python but this is a great chance to learn. I had a feeling there was a raster-based way of doing this. The RegionGroup is groundbreaking for me, didn't know such a command existed. – K. Credo Oct 28 '16 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.