尝试按云量百分比过滤前哨 2 图像

Trying to filter sentinel 2 images by percent cloud cover

我正在尝试按云量百分比(比如 20%)过滤 Sentinel 2 图像,然后对输出执行一些图像算法。

我正在尝试实施找到的 here:gis.stackexchange 线程 (https://gis.stackexchange.com/questions/303344/filter-landsat-images-cloud-cover)。不幸的是,函数 ee.Algorithms.Landsat... 不适用于 Sentinel 2 图像,这是我正在做的事情所必需的。

到目前为止我的代码如下。

var myCollection = ee.ImageCollection('COPERNICUS/S2');

var dataset2 = ee.ImageCollection(
  myCollection.filterBounds(point) //use only one image that contains the POI
  .filterDate('2015-06-23', '2019-04-25') //filter by date range
);


var ds2_cloudiness = dataset2.map(function(image){
  var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
  var cloudiness = cloud.reduceRegion({
    reducer: 'median'
  });
  return image.set(cloudiness);
});

var filteredCollection = ds2_cloudiness.filter(ee.Filter.lt('cloud', 20));

Map.addLayer(filteredCollection, {min: -.2, max:.2}, 'test')

这会输出一个错误:Landsat.simpleCloudScore: Image is not a Landsat scene or is missing SENSOR_ID metadata.任何向正确方向的微调将不胜感激。

如果您只想使用云量百分比进行过滤,我认为有一种更简单的方法。您可以根据图像元数据进行过滤。

var myCollection = ee.ImageCollection('COPERNICUS/S2');
print(myCollection.first())

如果您检查 Sentinel-2 imageCollection 中的第一张图像,您实际上可以看到它的元数据(仅针对该图像)。由于您正在处理同质且维护良好的图像集合,因此您可以期望其他图像具有相似的特性。在这里,您可以执行以下操作

myCollection = myCollection.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE',20));
print(myCollection.first());

此特定代码将过滤图像集合以查找云量小于或等于 20 的图像。您可以通过再次检查第一张图像或检查应该缩小的集合大小来验证这一点。

但是,如果您正在寻找一种单独的算法来计算图像上的云,您可能必须为 Sentinel 编写一个算法(目前)。