I'm pulling GEE images for large areas, for a short time period and with a fairly strict cloud condition. This can leave some parts of the GEE image with gaps where the collection has no images. That's ok given my needs. But I would like to export a simple boolean or binary mask showing where the gaps in the image collection are (eg 1 for data and 0 for no data).

I'm interested in the water so would like to avoid the assumption that no data patches are black (ie avoid the use of relationals like .eq(0) ).

Is there a simple method to output some sort of raster or vector with image validity and/or no data values? I'm doing this in Python/Colab.


I've tried .unmask as follows:

#get collection and cloud mask

S2B8=s2_sr_masked.select('B8').reduce(ee.Reducer.median()) #reduce 1 band
S2nodata=ee.Image(S2B8).unmask(-99).eq(-99) #unmask
NoDataUTM=S2nodata.reproject(thisCRS, scale=100) #reproject

#add a task to export

The output has to correct location, projection and resolution. But it's uniform 1s and by looking at an actual image pulled with similar code, there is definitly both image and data gaps. So there should be both 1s and 0s. Is there a code error in the conversion from collection to image?

Extreme example below. Here there is only a tiny spot of data in the SE corner of the image. But if you look at the NoData... layer on the left, it goes from 1 to 1. I checked and both minimum and maximum are indeed both 1.

enter image description here

  • can you please include enough code to make a minimum working example of the issue (the sourcing and filtering of the collection and the cloud masking, etc)? (Or a link to a Colab Notebook if it will make the question here too messy)
    – Matt
    Commented Jan 19, 2022 at 12:11

1 Answer 1


You can use the ee.Image.unmask() method

noDataMask = (myImage
                   .unmask(-99)    # give no data pixels an abitrary value outside the range of your data 
                   .eq(-99))       # make a boolean raster using the assigned value

Here white is value 1, where the .eq(-99) evaluates to true (where clouds are masked, leaving patches of no data), and black is 0 where it is false.

enter image description here

To invert the mask, use .neq(-99) in place of .eq(-99).

  • that returned all 1s I'm affraid. I've edited the post to add some code snipets... Commented Jan 19, 2022 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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