I want to control my NDVI trends with climate variables. Therefore I am using temperature, precipitation and soil moisture. But since my NDVI is in annual maximum I need to have the same format for the controlling. Therefore I try to calculate these annual max images for the climate bands. But when I then try to use these, the analysis is not working and giving me this error: Error in map(ID=1): Element.getNumber: Unable to cast value to Number.

This is the code to calculate the annual max images.

//Calc annual max for TerraClimate for Temp, soil and prec
var annual_max_temp =  ee.ImageCollection(ee.List.sequence(1981, 2015).map(function (year){
  var date_start = ee.Date.fromYMD(year, 1, 1);
  var date_end = date_start.advance(1, "year");

        .select(['tmmx','soil', 'pr'])
        .filterDate(date_start, date_end)
          .set({year: year, 'system:time_start':date_start})
          .set({year: year, 'system:time_end':date_end}));

And here is the complete code: https://code.earthengine.google.com/?scriptPath=users%2Fwelp1992%2FMaster%3ATemperature

1 Answer 1


The error does not occur in the part of the code you present here. Later, you try to retrieve the system:time_start property with getNumber(), while you have set it as an ee.Date() in line 12. Probably, setting it to the standard GEE long number format (using millis() on an ee.Date()) will help you:

      .set({year: year, 'system:time_start':date_start.millis()})
      .set({year: year, 'system:time_end':date_end.millis()}))
  • Yes it makes sense. I added the millis() now and partly the code works now. But there is still a problem with the feature collection. One of the features (number 137) is not working, but nothing appears to be different. The code works when I limit the FeatureCollection: var conflicts = ee.FeatureCollection('users/welp1992/Conflicts25_Date').limit(136)
    – Mathias
    Jul 6, 2020 at 6:32
  • Ask a new question and share your asset to allow others to reproduce the error
    – Kuik
    Jul 6, 2020 at 7:01
  • I asked a new question now and shared the FC and script there. Question
    – Mathias
    Jul 6, 2020 at 10:18

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.