Map.centerObject(table);
var stary = 2001, endy = 2023;
var NDVICL = ee.ImageCollection(ee.List.sequence(stary, endy).map(function(year) {var startd = ee.Date.fromYMD(year, 1, 1);var endd = ee.Date.fromYMD(year, 12, 31);return ee.ImageCollection('MODIS/006/MOD13A1').filterDate(startd, endd).select('NDVI').max().addBands(ee.Image.constant(year).toFloat().rename('year'));
}));
print(NDVICL)
var senSlope = NDVICL.select(['NDVI', 'year']).reduce(ee.Reducer.sensSlope()).clip(table);
var vis = {bands: ['slope'], min: -0.5, max: 0.5, palette: ['red', 'white', 'green']};
Map.addLayer(senSlope.select('slope'), vis, "Sen斜率 ");
var ones = ee.Image(1);
var zeros = ee.Image(0);
var eps = 0.01;
var listofimg = NDVICL.toList(NDVICL.size());
var mkm = ee.ImageCollection(ee.List.sequence(0, listofimg.size().subtract(2)).map(function (xi) {return ee.ImageCollection.fromImages(ee.List.sequence(ee.Number(xi).add(1), listofimg.size().subtract(1)).map(function (xj) {var diff_ij = ee.Image(listofimg.get(xj)).select('NDVI').subtract(ee.Image(listofimg.get(xi)).select('NDVI'));var diff = diff_ij.where(diff_ij.abs().lt(eps), zeros);return diff.where(diff.gt(0), ones).where(diff.lt(0), ones.multiply(-1)).rename('ES');})).sum();})).sum();
var n = ee.ImageCollection(NDVICL).reduce('count').select('NDVI_count').rename('count');
var varS = n.multiply(n.subtract(1).multiply(n.multiply(2).add(5))).divide(18).rename('varS');
var mkz = mkm.where(mkm.abs().lt(eps), 0);
var zcore = mkz.where(mkz.gt(eps), mkz.subtract(1).divide(varS.sqrt())).where(mkz.lt(-eps), mkz.add(1).divide(varS.sqrt())).rename('zcore').clip(table);
var signif = senSlope.select(0).lt(0).and(zcore.abs().gte(1.960)).rename('signif');
var siginc = senSlope.select(0).gt(0).and(zcore.abs().gte(1.960)).rename('increase');signif.updateMask(signif);
siginc.updateMask(siginc);signif = signif.multiply(-1).add(siginc).clip(table);
Map.addLayer(zcore, {min: -3, max: 3, palette: ['blue', 'white', 'red']}, 'Z值 ');
Map.addLayer(signif, {min: -1, max: 1, palette: ['#FFA07A', 'white', '#3CB371']}, '显著趋势 ');