0

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. This is the code @Daniel Well helped me with:

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)
    .select(['ndvi'])
    .map(function (image) {
      return image.addBands(
        ee.Image(image.getNumber('system:time_start'))
          .subtract(ee.Date(startDate).millis())
          .divide(1000*3600*24) // days
          .int()
          .rename('t')
      )
    })

var conflictsWithSlopes = conflicts.map(addSlopes)
print(conflictsWithSlopes)
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)
    .reduce(ee.Reducer.linearFit())
    .select('scale')
    .reduceRegion({
      // 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
    })
    .getNumber('scale')
}

Now I would like to use conflict points (around 9000) and their corresponding dates (like in the example) stored in a FC Link The conflict coordinates column is called "coordinate" and the date "date_start".

So far I have tried this:

var conflicts = conflicttable.select(['coordinate']);
var conflictDate = conflicttable.select(['date_start']);

and I get this error: FeatureCollection (Error) Error in map(ID=000000000000000005a2): DateRange: Parameter 'start' is required.

1 Answer 1

0

The problem (except for just picking up the conflict date with a different property name, conflictDate -> date_start) is that you have conflicts for dates where you have no imagery. You need to have some images both before and after your conflict date to calculate the two slopes. You can filter out conflicts outside of some date range like this:

var startDate = '1989-01-01'
var endDate = '2013-12-16'
var conflicts = ee.FeatureCollection('users/welp1992/Conflicts25_Date')
  .filterMetadata('date_start', 'greater_than', '1990-01-01')
  .filterMetadata('date_start', 'less_than', '2013-01-01')
  .limit(259)

https://code.earthengine.google.com/7f08b9827f13c8ccde7b0c5bc7718525

3
  • Thank you for the help! Yes I thought about that too. If one of the time spans is less than one year, the slope will be quite big (positive or negative) and the sum will not say anything. I will play around till I find a reasonable time span. Besides that apparently I can only compute around 3500 points, than this error appears: <Earth Engine capacity exceeded>. I can devide the tasks, but is there a way to overcome this problem?
    – Mathias
    Commented May 7, 2020 at 11:59
  • Earth Engine capacity exceeded is usually a temporary problem that goes away. You would typically see out of memory errors or computation timed out. If you're having problems, don't print the results in the code editor, just export them. You get more resources when processing in a background task. Commented May 7, 2020 at 12:02
  • Thanks, yes it worked after trying a few times. Also exporting as CSV file worked!
    – Mathias
    Commented May 8, 2020 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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