//影像去云等预处理
/**
* 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());*/
GEE之S-G滤波
最新推荐文章于 2023-10-11 22:16:36 发布