0

I'm trying to get yearly NDSI using MODIS and within range of 0-1. higher NDSI values indicate snow presence. While my code is showing 0 values in glacier and snow areas, and snows as 1 for areas without snow also there is just 0 and 1 pixel values, that says to me that this was not properly obtained. I don't know why only 2 pixel values are showing. Here is the code:

Map.centerObject(studyArea)
var dataCollection = ee.ImageCollection('MODIS/006/MOD10A1')
    .select(['NDSI_Snow_Cover']).map(function(img) {
  return img.multiply(0.0001).copyProperties(img,['system:time_start','system:time_end']); 
});

var month_mean = ee.List.sequence(2001, 2001).map(
    function (year) {
        // map the time series into monthly means (for season calculation, change months here according to season)
        return ee.ImageCollection(
            ee.List.sequence(1,12).map(
                function (month) {
                    var date = ee.Date.fromYMD(year, month, 1);
                    // mean chlor_a (log-normal)
                    var monthMeanImage = dataCollection.filterDate(date, date.advance(1, 'month')).sum().rename('NDSI_Snow_Cover');

                    // add time band
                    date = ee.Image(date
                        .difference('2001-01-01', "year"))
                        .double()
                        .rename("time");
                    return date.addBands(monthMeanImage);
                })).sum().set('system:time_start', ee.Date.fromYMD(year, 1, 1)); });

var collection = ee.ImageCollection(month_mean).select('NDSI_Snow_Cover');
var Mean_2001 = collection.reduce(ee.Reducer.mean()).clip(studyArea)
print(Mean_2001)
var masking = Mean_2001.gte(0.1).and(Mean_2001.lte(1))
print(masking)
Map.addLayer(masking)

1 Answer 1

0

If you want to mask out all pixels outside of your range 0.1 <= Mean_2001 <= 1, simply use updateMask(), passing an image where pixels outside your range are 0 pixels within are 1:

var mask = Mean_2001.gte(0.1).and(Mean_2001.lte(1))
var masked = Mean_2001.updateMask(mask)
Map.addLayer(masked)
6
  • So how can I get all values image between greater then 0.1 and less then 1? Sep 15, 2022 at 7:10
  • Because I want to get values between greater then 0.1 and less then 1 Sep 15, 2022 at 7:16
  • Can you explain what you're trying to do more in detail? Do you want to display the actual NDSI values for pixels with values between 0.1 and 1, and mask out the rest? Sep 15, 2022 at 8:03
  • Actually first I got monthly NDSI and now I want to mask out that values that lies in 0.1 to 1. So that other values should be removed and my final result of NDSI be in 0.1 to 1. Sep 15, 2022 at 17:31
  • I updated the answer Sep 16, 2022 at 6:43

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.