I try to find a correlation between a linear trend of two NDVI time series before and after a specific day in time. And that I want to repeat (iterate/map?) for a lot of points globally distributed. I created a feature collection (asset in GEE) with all the points (coordinates), the date of a conflict (for which I want to see if there is a change in NDVI), and the NDVI value of that point. I used the GIMMS NDVI coarse resolution dataset (found in GEE) for the NDVI values.

Function to create the feature collection worked with following code.

  .map(function(f) {
    var GIMMSndvi = ee.ImageCollection('NASA/GIMMS/3GV0')
                      .filterDate('1989-01-01', '2013-12-16')
                      //.filterBounds(Conflicts_ALL) //*********** this doesn't wrok since the entire GIMMS is one image, you should use clip()
                      .map(function(img) {return img.clip(Conf25)})
      .map(function(img) {
        var d = img.reduceRegion({
                    reducer: ee.Reducer.first(), 
          geometry: f.geometry(),
          scale: 8000
        return f.set(d).set('GIMMSdate', img.date().format('yyyyMMdd')); //Do I need this operation still? Return of date?  /////************sure, otherwise how do you know the time of your value

    return GIMMSndvi; //global variable, use later in script


Now I'm stuck in the next step. I need to create a function which goes through the FC (598 rows per point), creates an NDVI trend for all values till the day of conflict and safe that slope. Then the same for the second half of the table. Then I have to find the difference between these two and safe it. And this calculation should be repeated for all the points (around 9000). And in the end, I want to have one overall trend estimate.

I have been thinking and trying a lot the past weeks, and wonder if this task is doable in GEE. Should I use plots add the trend lines and save the slopes, e.g. I could plot all time-series and average them to an overall trend (the problem is I need always two trend lines per point). Or should I do it rather with the linear trend function (ee.Reducer.linearFit())?

Could someone could give me a hint or two on how to do it?


The below example hopefully gives you some ideas on how you could attack this using linearFit():

var conflicts = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point([12.492297, 41.89024]), {conflictDate: '2010-01-01'}),
  ee.Feature(ee.Geometry.Point([12.453361, 41.902216]), {conflictDate: '1990-01-01'})

var startDate = '1989-01-01'
var endDate = '2013-12-16'

var timeSeries = ee.ImageCollection('NASA/GIMMS/3GV0')
    .filterDate(startDate, endDate)
    .map(function (image) {
      return image.addBands(
          .divide(1000*3600*24) // days

var conflictsWithSlopes = conflicts.map(addSlopes)
print('slope change stats', conflictsWithSlopes.aggregate_stats('slopeChange'))
// Other aggregate_*() functions...

function addSlopes(conflict) {
  var conflictDate = conflict.getString('conflictDate')
  var beforeSlope = getSlope(timeSeries, conflict, startDate, conflictDate)
  var afterSlope = getSlope(timeSeries, conflict, conflictDate, endDate)
  return conflict
    .set('beforeSlope', beforeSlope)
    .set('afterSlope', afterSlope)
    .set('slopeChange', afterSlope.subtract(beforeSlope))

function getSlope(timeSeries, conflict, startDate, endDate) {
  return timeSeries
    .select(['t', 'ndvi'])
    .filterDate(startDate, endDate)
      // If your conflict regions aren't points, 
      // you might want to use a mean or median reducer
      reducer: ee.Reducer.first(), 
      geometry: conflict.geometry(),
      scale: 8000


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.