Following on from a previous question (Points to raster (image) in Google Earth Engine) I have created an Image of observations for a particular species, masked such that we are only considering pixels with a value of one (i.e. the species was observed in that pixel).
The extent of the image is necessarily large, because the observations were spread out, which means that the whole image contains many, many pixels but most are zeroes and should therefore be ignored in calculations.
All I want to do is count the number of pixels with a value of one. I tried the following code:
// Mask
var ebdMasked = ebdCountImg.mask(ebdCountImg.gt(0));
// Count pixels
var count = ebdMasked.reduceRegion({
reducer: ee.Reducer.count(),
geometry: roi,
maxPixels: 1e13
});
print(count);
Which produced the error:
Dictionary (Error)
Remote request too large (3355443200 > 83886080) for output: [<Object>].
I actually know in this case that the answer is 256, so in no way should this be too large for output. I assumed something was wrong with the mask meaning that all pixels were being considered, so I exported the masked Image to take a look. It seemed fine and, lo and behold, when I read the exported ebdMasked
back in, and try again, it works as expected:
// Try again with exported layer
var ebdMasked2 = ee.Image("users/rasenior/ebdImg");
// Mask
var ebdMasked2 = ebdMasked2.mask(ebdMasked2.gt(0));
// Count pixels
var count2 = ebdMasked2.reduceRegion({
reducer: ee.Reducer.count(),
geometry: roi,
maxPixels: 1e13
});
print(count2);
Produces:
Object (1 property)
first: 256
I'm sure I'm missing something very simple!
Full code is here: https://code.earthengine.google.com/6608ad2279f249324ed730a56605a025