linkagescape / linkage-mapper

ArcGIS tools to automate mapping and prioritization of wildlife habitat corridors
https://circuitscape.org/linkagemapper/
GNU General Public License v3.0
39 stars 12 forks source link

Issue with zonal statistics dropping core polygons #3

Closed aprisbrey closed 6 years ago

aprisbrey commented 6 years ago

https://github.com/linkagescape/linkage-mapper/blob/ff68cc58c820978a2ac5028f3cac0e05c04555f5/toolbox/scripts/lp_main.py#L397-L400 Encountering an error linked back to calculating zonal statistics for the OCAV. Zonal statistics output is dropping several of the polygons, so when the zonal stats table is joined back to the core layer, these stats values are null for the dropped polygons. Then when this part of the code is reached (calculating CAV normalization): https://github.com/linkagescape/linkage-mapper/blob/ff68cc58c820978a2ac5028f3cac0e05c04555f5/toolbox/scripts/lp_main.py#L214-L217 the script stops and an error is thrown: "unsupported operand type(s) for -: 'float' and 'NoneType'" since it's trying to do calculations with null values.

This also occurred (after I removed the OCAV option from the GUI) in doing the same calculation for climate envelope - two cores received null values for "clim_env" and the calculation could not be completed.

rgreenefl commented 6 years ago

Are the cores in question "small"? If so, my guess is that when they are converted to raster by zonal stats, they are so small that no cells in the resulting raster are allocated for those cores. If this theory sounds plausible, a couple of things to try include:

Even if this theory works out, we obviously need to program for this possibility and avoid the crash!

aprisbrey commented 6 years ago

John and I fixed the issue by doing two things:

1) Resampling the OCAV layer to a finer resolution. The OCAV layer was too coarse and zonal stats could not calculate values for some of the cores, hence the error. 2) Specifying the extent of the OCAV and climate layers and assigning a value (in this case, 0) to all null values within the extent so that areas around the edges weren't getting thrown off by null values.

These may be instructions we just want to put in the user guide to warn people of; that they should take these steps ahead of time - building it into the tool (to resample and assign a value to null values) may be too much?

dkav commented 6 years ago

I agree with Randal, it would be best to create logic to handle this scenario.

johngallo commented 6 years ago

OK, if @dkav or @rgreenefl or someone else with confidence programming python logic into this code, wants to draft logic for this, that would be great, otherwise, the default is for Annie to add to the User Guide somewhere , maybe in the tips section something like:

"Something like: "the OCAV and Climate inputs may need to be resampled to a finer resolution if some of the core areas are about the same size as a pixel."

and then give this a label like "to fix in a future version"

johngallo commented 6 years ago

GH: Issue with zonal statistics dropping core polygons #3

rgreenefl commented 6 years ago

Diagnostic message added in temp branch and pull request made.

aprisbrey commented 6 years ago

Commits merged and branch deleted.