0

我正在计算 Sentinel2 上 NDVI 图像收集的统计数据。

我在定义的时间段和特定区域内获得了 S2_SR 的图像集,然后移除云。

        var S2 = ee.ImageCollection('COPERNICUS/S2_SR')
    
    //filter start and end date
    .filterDate('2019-03-01', '2020-03-31')
    
    //filter according to drawn boundary
    .filterBounds(ROI);
    
    var palettes = require('users/gena/packages:palettes');
    var palette = palettes.colorbrewer.Spectral[8];
    
    // Function to mask cloud from built-in quality band
    // information on cloud
    var computeQAbits = function(image, start, end, newName) {
        var pattern = 0;
    
        for (var i=start; i<=end; i++) {
            pattern += Math.pow(2, i);
        }
    
        return image.select([0], [newName]).bitwiseAnd(pattern).rightShift(start);
    };
    
    var sentinel2 = function(image) {
    
      var cloud_mask = image.select("QA60");
      var opaque = computeQAbits(cloud_mask, 10, 10, "opaque");
      var cirrus = computeQAbits(cloud_mask, 11, 11, "cirrus");
      var mask = opaque.or(cirrus);
    
      return image.updateMask(mask.not());
    }

Then I've calculated NDVI and NDWI for each date;

       var addNDVI = function(image) {
          var ndvi = image.normalizedDifference(['B5', 'B4']).multiply(10000).rename('NDVI');
        
          return image.addBands(ndvi);
        };
        
        var addNDWI = function(image) {
          var ndwi = image.normalizedDifference(['B3', 'B8']).multiply(10000).rename('NDWI');
          return image.addBands(ndwi);
        };
        // Add NDVI band to image collection
        var S2 = S2.map(addNDVI);
        var S2 = S2.map(addNDWI);
        var NDVI = S2.select(['NDVI']);
        var NDWI = S2.select(['NDWI']);
var S2 = S2.map(addNDVI);
var S2 = S2.map(addNDWI);
var NDVI = S2.select(['NDVI']);
var NDWI = S2.select(['NDWI']);

var P_95_NDVI = NDVI.reduce(ee.Reducer.percentile([95]));
var P_05_NDVI = NDVI.reduce(ee.Reducer.percentile([5]));

NDVI_P = NDVI.updateMask(NDVI.gt(P_05_NDVI).and(NDVI.lt(P_95_NDVI)));


var P_95_NDWI = NDWI.reduce(ee.Reducer.percentile([95]));
var P_05_NDWI = NDWI.reduce(ee.Reducer.percentile([5]));

NDWI_P = NDWI.updateMask(NDWI.gt(P_05_NDWI).and(NDWI.lt(P_95_NDWI)));
    

然后,我计算了我的统计数据,最小值、最大值、平均值、中值、标准差。因此,从我的输出中,我得到了我在一段时间内每个像素的 NDVI 和 NDWI 指数的最小值、最大值、平均值、中值、标准差。

 // Add indices bands to image collection
    
    var reducer1 = ee.Reducer.mean();
    
    var reducers = reducer1.combine({reducer2: ee.Reducer.median(), sharedInputs: true})
                           .combine({reducer2: ee.Reducer.max(), sharedInputs: true})
                           .combine({reducer2: ee.Reducer.min(), sharedInputs: true})
                           .combine({reducer2: ee.Reducer.stdDev(), sharedInputs: true});
    
    
    var results_NDVI = NDVI.reduce(reducers);
    var results_NDWI = NDWI.reduce(reducers);
    
    var results = results_NDVI.addBands(results_NDWI);
    
    var results_integer = results.int16();

但是,我注意到由于云而存在一些剩余的异常值。在计算我的统计数据之前,我想删除低于第 5 个百分位数和高于第 95 个百分位数的 NDVI 和 NDWI 的值。确保我的统计数据不会受到异常值的影响。

谢谢

4

1 回答 1

1

我建议使用减速器(即 ee.Reducer.percentile([95]))计算第 95 个和第 5 个百分位,然后屏蔽图像:

results = results.updateMask(results.gt(bottomPercentile).and(results.lt(topPercentile)));
于 2020-11-10T20:44:47.590 回答