Reclass and sum image collection MODIS Google Earth Engine

Viewed 285

I'm trying to generate an image in Google Earth Engine but I couldn't write it the right way. The idea is to select all the MODIS - SNOW images of a full year, iterate over each image and reclassify it in two categories (1 if it is above the threshold of 50 and zero if under the threshold) and then add up all the images of the year, obtaining a final image. In this image, a value of 365 would mean that it was every day with values above 50; the same way that a value of zero would mean that at no time of the year had values above 50.

The code that I wrote iterated by the dates (1 year - 2018), selected the band (NDSI_Snow_Cover), reclassified var th1 = snow.gte(threshold).rename('thres1') and tried to add up those of the whole year.


var palettes = require('users/gena/packages:palettes');
var palette = palettes.colorbrewer.RdYlGn[9];

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

var threshold = 50;

var snow = ee.ImageCollection('MODIS/006/MOD10A1');

var start = '2018-01-01'; var end = '2019-01-01'; 

    var mergedCollection = snow.filterBounds(geometry).filterDate(start, end).map(function(image) {
    return image.select(['NDSI_Snow_Cover'])
    })

   var mergedAllFunction = function(image) {
   var ndvi = image;

   var th1 = snow.gte(threshold).rename('thres1')

  
  var areaThres1 = ee.Number(th1.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: geometry, 
    scale: 500,   
    maxPixels: 1e9
  }).values().get(0));
  
   return image.addBands(snow).addBands(th1).set('area_sqm_th1', areaThres1);
   }

var useFunction = mergedCollection.map(mergedAllFunction);

print(useFunction)
Map.addLayer(useFunction,'','Test');


0 Answers
Related