Mann-Kendall 趋势定义为所有正的符号之和。如果后一天的积雪大于前一天的积雪,则符号为 1,如果相反,则符号为 -1,否则为零。通过迭代集合中的每个图像。
var modis = ee.ImageCollection("MODIS/006/MOD10A1")
.filterDate('2020-1-1', '2020-1-25')
.filterBounds(roi)
.select('NDSI_Snow_Cover')
.map(function(image){
var imgsub = image;
return image.clip(roi)
});
print(modis);
function setSnowCover(image) {
var snowCover = image.select('NDSI_Snow_Cover');
var snowDays = snowCover.neq(0).rename('Snow_Days');
return image.addBands(snowDays);
}
var snowDays = modis.map(setSnowCover);
print(snowDays);
// var snowDaysSum = snowDays.select('Snow_Days').sum().clip(region);
var snowDaysSum = snowDays.select('Snow_Days').sum().clip(roi).toInt();
print(snowDaysSum);
// Map.addLayer(snowDaysSum, {min: 0, max: 30, palette: ['00FF00', 'FF0000']}, 'Snow Days Sum');
Map.centerObject(roi, 6);
var afterFilter = ee.Filter.lessThan({
leftField: 'system:time_start',
rightField: 'system:time_start'
});
var joined = ee.ImageCollection(ee.Join.saveAll('after').apply({
primary: modis,
secondary: modis,
condition: afterFilter
})).aside(print);
var sign = function(i, j) { // i and j are images
return ee.Image(j).neq(i) // Zero case
.multiply(ee.Image(j).subtract(i).clamp(-1, 1)).int();
};
var kendall = ee.ImageCollection(joined.map(function(current) {
var afterCollection = ee.ImageCollection.fromImages(current.get('after'));
return afterCollection.map(function(image) {
// The unmask is to prevent accumulation of masked pixels that
// result from the undefined case of when either current or image
// is masked. It won't affect the sum, since it's unmasked to zero.
return ee.Image(sign(current, image));
});
// Set parallelScale to avoid User memory limit exceeded.
}).flatten()).sum();
print(kendall);
var palette = ['red', 'yellow', 'green'];
// 归一化Kendall系数到-1到1的范围
var normalizedKendall = kendall.divide(100);
Map.addLayer(normalizedKendall, {min: -1, max: 1, palette: palette}, 'Normalized Kendall Trend');
Export.image.toDrive({
image: kendall,
folder: 'MK_export',
scale: 500,
region: roi,
maxPixels: 1e13
});