2

I have an NDSI snow layer loaded in Google Earth Engine. Since snow is present for values <0.4, I want to make values >0.4 opaque. I looked at the manual's examples, but this code is not giving me what I want. Instead I get black (<0.40) and white (>0.40).

What am I missing?

var winter = NDSI.filter(ee.Filter.calendarRange(1999,2018,'year')).filter(ee.Filter.calendarRange(6,8,'month'));
var medianWinter = winter.median();
var medianWinterMask = medianWinter.gt(0.4);
Map.addLayer(medianWinterMask);
1
  • What is it giving you?
    – Jon
    Commented Jul 20, 2018 at 16:41

2 Answers 2

3

To mask an image, use the method ee.Image.updateMask(). Masking is also covered in the Introduction to the Earth Engine JavaScript API tutorial.

There are many ways to present masked data, but here is one possibility using the variables from your example code:

Map.addLayer(medianWinter.updateMask(medianWinterMask), {min:0, max:100});
2

Very useful, Tyler, thanks! After looking at the documentation, I was able to apply a second mask to exclude water. So this shows snow pixels (NDSI < 0.4) over land as white – everything else is transparent, which is what I was going for. Looks great on top of the satellite imagery. I used the Hansen dataset to identify land pixels, based on the example in Google's tutorial.

//Select the datamask band from the Hansen data
var datamask = Hansen.select('datamask');
// Create a binary mask. For this band, 0=No Data, 1=Land, and 2=Water
var HansenMask = datamask.eq(1);

var winter = NDSI.filter(ee.Filter.calendarRange(1999,2018,'year')).filter(ee.Filter.calendarRange(6,8,'month'));
var medianWinter = winter.median();
var medianWinterMask = medianWinter.gt(0.4);

var doubleMask = medianWinterMask.updateMask(HansenMask);
Map.addLayer(doubleMask.updateMask(medianWinterMask));

This gets the job done, but there other more elegant ways of masking water, snow, and clouds – notably Fmask – here are two great tutorials with useful examples:

https://medium.com/upstream/find-water-and-remove-clouds-with-fmask-on-google-earth-engine-261c090cb62d

https://www.researchgate.net/publication/302589628_Generating_a_cloud-free_homogeneous_Landsat-8_mosaic_of_Switzerland_using_Google_Earth_Engine

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.