0

https://code.earthengine.google.com/18914d58d2f193bf206e108774902ce5

var months = ee.List.sequence(1, 12)

...

var monthlyRainfall = months.map(function(month) {
    var filtered = monthlyCol.filter(ee.Filter.eq('month', month))
    var monthlyMean = filtered.mean()
    return monthlyMean.set('month', month)
})

...

var deviation = months.map(function(month) {
  var longTermMean = ee.Image(monthlyRainfall
    .filter(ee.Filter.eq('month', month)).first())
  var monthlyObserved = ee.Image(observedRainfall
    .filter(ee.Filter.eq('month', month)).first())
  var deviation = (monthlyObserved.subtract(longTermMean)
    .divide(longTermMean)).multiply(100)
    .set('month', month)
  return deviation
})

I am getting an error or line no. 88 in the link that I have mentioned above.

Line 88: monthlyRainfall.filter(...).first is not a function

the solution which i found for this problem is to use ee.Image. But even after using it, I am facing the same error. Please help me how to get through it.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
meenu
  • 29
  • 5

1 Answers1

0

monthlyRainfall is an ee.List, not an ee.ImageCollection. They're similar in some ways, but ee.List doesn't have a .first() operation (instead you would write .get(0)).

Filters also work differently on lists and collections. In this case, in order to make it work the way you want, you should convert your List to an ImageCollection. Change

var monthlyRainfall = months.map(function(month) {
    var filtered = monthlyCol.filter(ee.Filter.eq('month', month))
    var monthlyMean = filtered.mean()
    return monthlyMean.set('month', month)
})

to apply ee.ImageCollection(...), which will convert the List of Images into an ImageCollection:

var monthlyRainfall = ee.ImageCollection(months.map(function(month) {
    var filtered = monthlyCol.filter(ee.Filter.eq('month', month));
    var monthlyMean = filtered.mean();
    return monthlyMean.set('month', month);
}));
Kevin Reid
  • 37,492
  • 13
  • 80
  • 108