有没有办法确保您在 Google 地球引擎的帮助下创建的马赛克是完整的?
Is there a way to be sure that the mosiaic you're creating with help of Googles Earth Engine is complete?
如标题中所述 - 我们正在尝试将马赛克中的数据用于项目,但数据只有在马赛克实际完成时才有意义。因此,如果我们选择的区域太大,卫星可能无法在一天的时间内飞越该地点,从而导致结果不完整。
那么有没有办法只得到100%完整马赛克的结果呢?
这是我们使用的代码:
// Difference in days between start and finish
var diff = finish.difference(start, 'day');
// Make a list of all dates
var range = ee.List.sequence(0, diff.subtract(1)).map(function(day){return start.advance(day,'day')});
// Funtion for iteraton over the range of dates
var day_mosaics = function(date, newlist) {
// Cast
date = ee.Date(date);
newlist = ee.List(newlist);
// Filter collection between date and the next day
var filtered = collection.filterDate(date, date.advance(1,'day'));
// Make the mosaic and clip to aoi
var clipped = ee.Image(filtered.mosaic().clip(aoi)).setMulti({'system:time_start': date});
var footprint = ee.Feature(clipped.get('system:footprint'));
// Add the mosaic to a list only if the collection has images
return ee.List(ee.Algorithms.If(footprint.area().eq(aoi.area()), newlist.add(clipped), newlist));
};
// Iterate over the range to make a new list, and then cast the list to an imagecollection
var mosaic = ee.ImageCollection(ee.List(range.iterate(day_mosaics, ee.List([]))));
print(mosaic);
你已经有了查看足迹的想法,但它会更准确
- 使用 mask 像素而不是足迹几何图形,以防图像中有任何孔洞,并且
- 不是计算有效区域,而是找出是否有任何个无效区域。
var missingPixels = image
.mask() // Get the mask data as an image
.reduce(ee.Reducer.min()) // Take the least coverage across all bands
.expression('1 - b(0)') // Invert the value
.rename(['missing_pixels']); // Give the result a better name
// Sum up missing pixel indications; if nonzero, some are missing. Pick a scale that is good enough for your purposes.
var noMissingPixels = missingPixels.reduceRegion({
geometry: aoi,
reducer: ee.Reducer.sum(),
scale: 100
}).getNumber('missing_pixels').eq(0);
print(noMissingPixels);
https://code.earthengine.google.com/2dff320b7ab68e27e3acbd96efa23e4b
其他建议:iterate()
收集列表结果效率低下,应尽可能避免。当你想处理一个集合并丢弃一些元素时,你可以使用 map()
并将 dropNulls
参数设置为 true
,并且 return null
用于任何元素你不想保留:
var day_mosaics = function(date) {
... regular code goes here, but no 'newlist' ...
return ee.Algorithms.If(noMissingPixels, clipped, null);
};
var mosaic = ee.ImageCollection(range.map(day_mosaics, true));
这适用于非常大的集合,而构建列表可能 运行 内存不足。
如标题中所述 - 我们正在尝试将马赛克中的数据用于项目,但数据只有在马赛克实际完成时才有意义。因此,如果我们选择的区域太大,卫星可能无法在一天的时间内飞越该地点,从而导致结果不完整。 那么有没有办法只得到100%完整马赛克的结果呢?
这是我们使用的代码:
// Difference in days between start and finish
var diff = finish.difference(start, 'day');
// Make a list of all dates
var range = ee.List.sequence(0, diff.subtract(1)).map(function(day){return start.advance(day,'day')});
// Funtion for iteraton over the range of dates
var day_mosaics = function(date, newlist) {
// Cast
date = ee.Date(date);
newlist = ee.List(newlist);
// Filter collection between date and the next day
var filtered = collection.filterDate(date, date.advance(1,'day'));
// Make the mosaic and clip to aoi
var clipped = ee.Image(filtered.mosaic().clip(aoi)).setMulti({'system:time_start': date});
var footprint = ee.Feature(clipped.get('system:footprint'));
// Add the mosaic to a list only if the collection has images
return ee.List(ee.Algorithms.If(footprint.area().eq(aoi.area()), newlist.add(clipped), newlist));
};
// Iterate over the range to make a new list, and then cast the list to an imagecollection
var mosaic = ee.ImageCollection(ee.List(range.iterate(day_mosaics, ee.List([]))));
print(mosaic);
你已经有了查看足迹的想法,但它会更准确
- 使用 mask 像素而不是足迹几何图形,以防图像中有任何孔洞,并且
- 不是计算有效区域,而是找出是否有任何个无效区域。
var missingPixels = image
.mask() // Get the mask data as an image
.reduce(ee.Reducer.min()) // Take the least coverage across all bands
.expression('1 - b(0)') // Invert the value
.rename(['missing_pixels']); // Give the result a better name
// Sum up missing pixel indications; if nonzero, some are missing. Pick a scale that is good enough for your purposes.
var noMissingPixels = missingPixels.reduceRegion({
geometry: aoi,
reducer: ee.Reducer.sum(),
scale: 100
}).getNumber('missing_pixels').eq(0);
print(noMissingPixels);
https://code.earthengine.google.com/2dff320b7ab68e27e3acbd96efa23e4b
其他建议:iterate()
收集列表结果效率低下,应尽可能避免。当你想处理一个集合并丢弃一些元素时,你可以使用 map()
并将 dropNulls
参数设置为 true
,并且 return null
用于任何元素你不想保留:
var day_mosaics = function(date) {
... regular code goes here, but no 'newlist' ...
return ee.Algorithms.If(noMissingPixels, clipped, null);
};
var mosaic = ee.ImageCollection(range.map(day_mosaics, true));
这适用于非常大的集合,而构建列表可能 运行 内存不足。