GEE 的Sentinel CloudProbability 的去云算法 代码
时间: 2024-01-22 08:20:35 浏览: 170
以下是基于Google Earth Engine平台的Sentinel-2云去除代码,使用了Sentinel-2的B2、B3、B4、B8波段和cloud_mask,其中cloud_mask是通过Sentinel-2的QA60数据中的cloud_probability和cloud_shadow_probability计算得到的:
```javascript
// Load Sentinel-2 TOA reflectance data.
var sentinel = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2019-01-01', '2019-12-31')
.filterBounds(geometry)
.map(function(image) {
var cloud_mask = ee.Image(0).where(
image.select('QA60').bitwiseAnd(1<<10), 1).rename('cloud_mask');
var cloud_probability = image.select('QA60').bitwiseAnd(1024).rightShift(10).rename('cloud_probability');
var cloud_shadow_probability = image.select('QA60').bitwiseAnd(2048).rightShift(11).rename('cloud_shadow_probability');
var cloud_mask_combined = cloud_mask.or(cloud_probability.gt(20)).or(cloud_shadow_probability.gt(20));
return image.addBands(cloud_mask_combined);
})
.map(function(image) {
return image.clip(geometry);
});
// Function to mask clouds using the Sentinel-2 cloud mask.
var maskClouds = function(image) {
var cloudMask = image.select('cloud_mask').not();
return image.updateMask(cloudMask);
};
// Function to calculate the NDVI.
var calculateNDVI = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi');
return image.addBands(ndvi);
};
// Function to calculate the EVI.
var calculateEVI = function(image) {
var evi = image.expression(
'2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)',
{
'nir': image.select('B8'),
'red': image.select('B4'),
'blue': image.select('B2')
}).rename('evi');
return image.addBands(evi);
};
// Apply the cloud mask, calculate the NDVI and EVI, and combine the bands.
var sentinel_ndvi_evi = sentinel
.map(maskClouds)
.map(calculateNDVI)
.map(calculateEVI)
.select(['B2', 'B3', 'B4', 'B8', 'ndvi', 'evi']);
// Function to filter images based on the quality of the NDVI and EVI.
var filterQuality = function(image) {
var ndvi_quality = image.select('ndvi').qualityMosaic('ndvi').gte(0.6);
var evi_quality = image.select('evi').qualityMosaic('evi').gte(0.6);
return image.updateMask(ndvi_quality.and(evi_quality));
};
// Filter the images based on the quality of the NDVI and EVI.
var sentinel_filtered = sentinel_ndvi_evi.filter(filterQuality);
// Create a median composite of the filtered images and display it.
var sentinel_median = sentinel_filtered.median();
Map.addLayer(sentinel_median, {bands: ['B4', 'B3', 'B2'], min: 0, max: 0.3}, 'Sentinel-2 Median Composite');
```
其中,cloud_mask_combined是通过cloud_mask、cloud_probability和cloud_shadow_probability三个变量进行计算得到的云掩膜,用来遮盖掉云和阴影。```calculateNDVI```和```calculateEVI```分别用来计算NDVI和EVI。```filterQuality```用来过滤掉质量较差的NDVI和EVI。最后,使用```sentinel_filtered.median()```来得到过滤后的影像的中值合成图。
阅读全文