GEE之S-G滤波


//影像去云等预处理
/**
 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
 */


//ROI
var pt=ee.Geometry.Point([119.85872739185788,33.06337427687241]);
var fc=ee.FeatureCollection(table);

//to remove cloud
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000)
                               .copyProperties(image)
                               .copyProperties(image, ["system:time_start",'system:time_end','system:footprint']);
}

var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterDate('2016-10-01', '2021-05-30')
                  .filterBounds(fc)
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
                  .map(maskS2clouds);
print(dataset);
/*var visualization = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};
*/


//Map.addLayer(dataset.mean(), visualization, 'RGB');

//calculate NDVI
var addNDVI=function(input){
  return input.select().addBands(input.normalizedDifference(['B8','B4']).select([0],['NDVI']))
}

var ndvi=dataset.map(addNDVI);
print('ndvi',ndvi);
//Map.addLayer(table);
Map.addLayer(ndvi);





//s-g滤波
//to import library
var oeel=require('users/OEEL/lib:loadAll');
var SG=oeel.ImageCollection.SavatskyGolayFilter(ndvi,
        ee.Filter.maxDifference(1000*3600*24*30, 'system:time_start', null, 'system:time_start'),
        function(infromedImage,estimationImage){
          return ee.Image.constant(ee.Number(infromedImage.get('system:time_start'))
            .subtract(ee.Number(estimationImage.get('system:time_start'))));},
        4,["NDVI"]);
print(SG);
Map.addLayer(SG.select('d_0_NDVI'));
print('Smoothed data',ui.Chart.image.series(SG.select('d_0_NDVI'), pt, ee.Reducer.mean(), 1000));

print('Smoothed derivate',ui.Chart.image.series(SG.select('d_1_NDVI'), pt, ee.Reducer.mean(), 1000));

//print('list of functions used',oeel.refs());*/

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值