0

In an earlier post at How to select features in a feature collection simultaneously row by row in Google Earth Engine?, I got help for creating a code to compare conflicts and bimonthly GIMMS imagery.

Now I received a different dataset, GIMMS annual maximum NDVI data, to use tor the time 1981-2015. The filtering from previously date ('system:time_start') which was added before, doesn't work now.

Also the NDVI (now called 'b1') band is now between -99999 to +9999.

//Dates for filtering the GIMMS Image Collection // With annual data no filtering nexessary, 1981-2015 used
var startDate = 1982 //adjust with time for the 35
var endDate = 2015
print(startDate);

//Loading and filtering (by date) the UCDP conflict data (CSV) 1989-2015
var conflicts = ee.FeatureCollection('users/welp1992/Conflicts_Deaths_Greater25')
  .filterMetadata('year', 'greater_than', 1989)//min 6 years, but as long as possible
  .filterMetadata('year', 'less_than', 2010) //including 2010, to 2015 = 6 years
print(conflicts.limit(1000),'conflicts');


//filter image GIMMS by date and band and add time 't' as a band  
var timeSeries = ee.ImageCollection('users/welp1992/NDVI_Annual_Max_81_2015')
    .select(['b1'])
    .map(function (image) {
      return image.addBands(
        ee.Image(image.getNumber('system:time_start')) //'year'?
          .subtract(ee.Date(startDate).millis())
          .divide(1000*3600) // days (*365 = year)
          .int() //casts the input value to a signed 32-bit integer
          .rename('t')
      )
    })

print(timeSeries,'time');

This is the Error message I get:

ImageCollection (Error) Error in map(ID=Max_05): Image.constant: Parameter 'value' is required.

Unfortunately I cannot share the annual max NDVI data (which I have uploaded to GEE). The script is basically the same as the earlier version in the link I shared above.

Do you have any advice?

4
  • Please make the conflicts and timeseries collections publicly readable. To share an asset, click on it, click share, and check the box "anyone can read". If you really can't share that asset for whatever reason, it is really difficult to help you without being able to reproduce your error. On first looks, the error seems to be related to casting error inside the function that maps on timeseries.
    – kkrao
    Jun 20, 2020 at 18:54
  • Ok, I shared the assets now. Asset Annual Max NDVI Asset Conflicts
    – Mathias
    Jun 21, 2020 at 14:59
  • Thanks for sharing the asset. The error is caused by the line image.getNumber('system:time_start') because there is no property called 'system:time_start'. The only properties available for each image within timeSeries are system:asset_size, system:footprint. system:index. I found this out using print(timesSeries.first()).
    – kkrao
    Jun 21, 2020 at 20:22
  • Ok I see. In the previous version I used the GIMMS data. where a time band was added. So I somehow have to add a timeband as years to each image. var Maxyears = ee.List.sequence(1981, 2015); var NDVIMax35 = ee.ImageCollection.addBands( ee.List.sequence(0, Stacked_Images_35.bandNames().length().subtract(1)) .map(function(i) { return Stacked_Images_35.select(ee.Number(i)) .rename('Max35') .set('year', Maxyears.get(i)); }) ); Something like this?
    – Mathias
    Jun 22, 2020 at 13:41

1 Answer 1

1

The error is caused by the line image.getNumber('system:time_start') because there is no property called 'system:time_start'. The only properties available for each image within timeSeries are system:asset_size, system:footprint, system:index. I found this out using print(timesSeries.first()).

According to your comment, you would like to add a property called "year" to each image within timeSeries so that you don't encounter this error. To do so, use the fact that the images within timeSeries are named sequentially such as "Max_01" etc. until "Max_35" corresponding to the years 1981 to 2015. To add "year" as a property, use:

function addYear(image){ // function to add "year" property
  var year = ee.Number.parse( //convert string to number
            ee.String( // cast to number
                image.get('system:index')) // get name of image
                .replace('Max_','')) //remove leading "Max_" string
              .add(1980); // add 1980 as 1 corresponds to 1981? 
  var image = image.set('year',year)
  
  return image
}

With the above function, now you can add a band to each image like so:

var timeSeries = timeSeries.map(addYear)

var timeSeries = timeSeries
    .select(['b1'])
    .map(function (image) {
      return image.addBands(
        ee.Image(image.getNumber('year')) //'year'?
          // .subtract(ee.Date(startDate).millis()) // not needed anymore since "year" is already in years
          // .divide(1000*3600) // days (*365 = year)  // not needed anymore since "year" is already in years
          .int() //casts the input value to a signed 32-bit integer
          .rename('t')
      )
    })

Link to complete working code

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.