TransWikia.com

About Mann-Kendall test in Google Earth Engine

Geographic Information Systems Asked by Siqing Zhao on June 10, 2021

I would like to perform the Mann-Kendall test to attain the spatial change of my yearly growing season composite (named ‘growthdata), the’system:index’ below in the code is the corresponding year list, i.e., 2000,2001,2002,2003…, this is for differentiating the before and after images. I followed the official guidance from: https://developers.google.com/earth-engine/tutorials/community/nonparametric-trends this code works but I only get the image with all white color( with all 0 value). Can anyone tell me what’s the problem with my code?

    enter code here
    ////////////////////////////test mendall code////////////////////////////
var coll= growthdata.select('mean')
var afterFilter = ee.Filter.lessThan({
  leftField: 'system:index',
  rightField: 'system:index'
});
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 joined = ee.ImageCollection(ee.Join.saveAll('after').apply({
  primary: coll,
  secondary: coll,
  condition: afterFilter
}));
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)).unmask(0)
  })
  // Set parallelScale to avoid User memory limit exceeded.
}).flatten()).reduce('sum', 2)

var palette = ['red', 'white', 'green']
// Stretch this as necessary.
Map.addLayer(kendall, {min: -800, max: 200, palette: palette}, 'kendall')
print(joined)

One Answer

The problem is that your differences all have a magnitude less than one, so the int() in the sign function is setting all values to 0.

If you're really just getting the sign of the difference, then you can use something like:

function sign(a, b) {
    return a.expression("diff < 0 ? -1 : (diff > 0 ? 1 : 0)", {
        diff: a.subtract(b)
    }
}

    

Answered by Noel Gorelick on June 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP