date - 在不同的日期使用不同的算法取消屏蔽像素(谷歌地球引擎)
问题描述
一般来说,我想获得像素,这些像素可以指示水稻幼苗移栽到田间之前稻田的淹水和移栽阶段。为此,我有我感兴趣的区域,即一个点周围的缓冲区,我想在该处取消屏蔽可能的大米像素。
可通过以下标准检测泛滥和移栽阶段: LSWI - NDVI > 0 || LSWI - EVI > 0
一旦此标准对日期 x 的像素有效,则以下标准必须对日期 x + 50 到 60 天的同一像素有效:LSWI - NDVI < 0 || LSWI - EVI < 0
我使用我命名为“l8”的 Landsat 表面反射收集。
// Create a new point geometry with the centre coordinates
var point = ee.Geometry.Point([120.92557043089494,15.71666782285468])
// Create a buffer arount the point
var buff = point.buffer(5000)
//////////////////////////// Cloud mask /////////////////////////////////////////
// This example demonstrates the use of the pixel QA band to mask
// clouds in surface reflectance (SR) data. It is suitable
// for use with any of the Landsat SR datasets.
// Function to cloud mask from the pixel_qa band of Landsat 8 SR data.
function maskL8sr(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = 1 << 3;
var cloudsBitMask = 1 << 5;
// Get the pixel QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask1 = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
var mask2 = image.select('B.*').gt(0).reduce('min');
// Mask out water using the pixel qa band
// Problem: Also rice paddy pixels were masked out!!
//var mask3 = image.select('pixel_qa').bitwiseAnd(2).neq(0);
// Return the masked image, scaled to TOA reflectance, without the QA bands.
return image.updateMask(mask1.and(mask2)).divide(10000) // in the first brackets: .and(mask3))
.select("B[0-9]*")
.copyProperties(image, ["system:time_start"]);
}
// Function to mask further clouds using B2, blue band, threshold
var maskclouds = function(image) {
var B2 = image.select(['B2']);
var bin = B2.gt(0.2);
return image.updateMask(bin.lt(1));
};
//////////////////////////// Filter the time frame /////////////////////////////////////////
// Prepare the date range filter for the dry season
var dS18_19Filter = ee.Filter.date('2018-12-01','2019-11-30');
var dS19_20Filter = ee.Filter.date('2019-12-01','2020-11-30');
var dSallFilter = ee.Filter.or(dS18_19Filter, dS19_20Filter)
//////////////////////////// Calculate indices ////////////////////////////////////
// Calculate NDVI
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
// Calculate LSWI
var addLSWI = function(image) {
var lswi = image.normalizedDifference(['B5', 'B6']).rename('LSWI');
return image.addBands(lswi);
};
// Compute EVI using an expression
var addEVI = function(image) {
var evi = image.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))',
{
'NIR': image.select('B5'),
'RED': image.select('B4'),
'BLUE': image.select('B2')
}).rename('EVI').float();
return image.addBands(evi);
};
////////////////////////////// Image Collection //////////////////////////////////
// Load Landsat 8 image collection and filter study area bounds and date
// cloud mask, select all bands
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(buff)
.filter(dSallFilter)
// apply the cloud mask for the whole image collection
.map(maskL8sr)
.map(maskclouds)
.select('B[2-7]','B10','B11')
.map(addNDVI)
.map(addLSWI)
.map(addEVI)
.sort('system:index');
// Print filtered image collection to verify if the filtering has worked
print('Landsat8', l8);
//////////////////////////////////// Paddy Rice ///////////////////////////////////////
// LSWI - NDVI/EVI > 0
var image = l8.first()
// Paddy rice by expression
var paddyRice = function(image) {
var paddy = image.expression(
'LSWI - NDVI > 0 || LSWI - EVI > 0',
{
'LSWI': image.select('LSWI'),
'NDVI': image.select('NDVI'),
'EVI': image.select('EVI')
}).rename('flTr');
return image.addBands(paddy);
};
var paddyMask = function(image) {
var pMask = image.expression(
'LSWI - NDVI > 0 || LSWI - EVI > 0',
{
'LSWI': image.select('LSWI'),
'NDVI': image.select('NDVI'),
'EVI': image.select('EVI')
});
return image.updateMask(pMask);
};
// Mask out pixels where
// algorithm at date x applies
// AND another alogrithm applies at date x + 50 - 60 days (image between time period)
// for the same pixel
var l8 = l8.map(paddyRice).map(paddyMask)
// Clarify if rice grows for pixels identified as rice
var rice = function(image){
var rice2 = image.expression(
'LSWI - NDVI < 0 || LSWI - EVI < 0', // after 50 to 60 days
{
'LSWI': image.select('LSWI'),
'NDVI': image.select('NDVI'),
'EVI': image.select('EVI')
});
return image.updateMask(rice2)
};
对于最后一个函数,我错过了这个简短算法在不同时间针对相同像素的那个。关于帮助和提示,我将不胜感激。
解决方案
推荐阅读
- reactjs - 有没有办法在 create-react-app 中显示开发构建文件?
- python - 如何从已安装的 Drive 文件夹中永久删除?
- vue.js - Nuxt 在拆分 .vue 文件时会生成不需要的路由。如何只获得我想要的路线?
- javascript - React hooks useEffect 在添加空依赖数组后不会停止获取
- java - KafkaListenerEndpointContainer 无法使用 Spring Kafka 创建 Kafka 事务
- asp.net - IIS Web 应用程序无法在同一网络上访问,但 Apache 应用程序可以
- sas - 如何突出显示直到某一点的所有内容
- javascript - 使用 JQuery 不允许在字段中输入字母时出错
- stm32 - 未提供输入时 GPIO 中断触发
- r - 为什么从使用不同字符 (å > a) 编码的数据帧中提取值?