3

I want to reclassify the MCD43A4_006_NDVI collection and change all negative values into NAs. I have the following code but I am not sure how to do this.

Any ideas?

 var geometry = /* color: #d63000 */ee.Geometry.Polygon(
            [[[107.4876749263151, 43.53145035042672],
              [107.2899210200651, 40.74603425026213],
              [114.4530069575651, 40.56266845308453],
              [118.6717569575651, 42.72968876300252]]]);

        var modisNDVI = ee.ImageCollection("MODIS/MCD43A4_006_NDVI")
        .filterBounds(geometry)
        .map(function(image){return image.clip(geometry)}) 
        .filter(ee.Filter.calendarRange(7,7,'month'));


 // Here I have no idea how to continue and set the "values less than 0"         
            var reclassified = modisNDVI.map(function(img){
          return img.gt(-1) // or gt()
        })

        var check = ee.Image(modisNDVI.first());
    Map.centerObject(check);    
    Map.addLayer (check, {min:0.0,max:1,palette:['FFFFFF','CC9966','CC9900','996600','33CC00','009900','006600','000000']},'NDVI');

    print(modisNDVI)


    var batch = require('users/fitoprincipe/geetools:batch') 
    batch.Download.ImageCollection.toDrive(modisNDVI, "Folder", {scale:500,region: geometry});

1 Answer 1

1

You can do it with masking.

// Masking pixels with values less than 0.  This will take a while.     
    var reclassified = modisNDVI.map(function(img){
      return img.updateMask(img.gt(0))// only pixels with values greater than 0
    })

var check = ee.Image(modisNDVI.first());
Map.centerObject(check);    
Map.addLayer (check, {min:0.0,max:1,palette:['FFFFFF','CC9966','CC9900','996600','33CC00','009900','006600','000000']},'NDVI');

Once masked, the pixels will no longer be used in any further calculation that you do.

2
  • Thank you @Sean Roulet. Quick question, will this mask remove zero values too? I ask because I want to keep zero values.
    – geo_dd
    Commented Feb 11, 2019 at 6:39
  • I think I have figured it out. Based on your suggestion, I changed the img.gt() to img.gte() in order to preserve zero values. Thanks!
    – geo_dd
    Commented Feb 11, 2019 at 12:18

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.