TransWikia.com

Compute neighborhood statistics in GEE with your own function/reducer

Geographic Information Systems Asked by user179390 on May 6, 2021

I have generated an Image in GEE, which corresponds to a classification. Each pixel is assigned to 1 group (out of a certain number of groups, let’s say 100). I would like, for each pixel, to compute neighborhood statistics within a focal window of a given size, say a square window of size 10 pixels. I found the “reduceNeighborhood” function which does just that. However, there is only a handful of reducers available, and the neighborhood statistics I’m trying to compute are slightly more complex than what the available reducers allow doing. For instance, I’d like to compute a diversity index, such as the Shannon index. This is a very simple formula (see Wiki), but I cannot compute it by combining existing reducers (at least I hardly see how).

Given my limited knowledge of GEE, I foresee two approaches to compute the Shannon index:

1/ The first one is the simplest one: specify my own formula to be used as a reducer in the “reduceNeighborhood” function. I’ve looked around but never saw someone do that, so I’m guessing it’s not possible.

2/ The second one is the painful one: (1) disaggregated the classified image into 100 images (1 per group), (2) compute some neighborhood statistics on each of the 100 images (i.e. the abundance – or count – of pixels belonging to each group within focal windows), (3) reaggregate the 100 output bands into 1 using the appropriate formula (Shannon index). This strategy would require a loop and seems like a very inefficient use of computational resources.

Thus, before trying to figure out if 2/ is implementable, I’d like to make sure option n°1 is indeed not possible. My question this is : Is it possible to specify its own function / reducer in “reduceNeighborhood” ?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP