2

I am currently trying to calculate the rain use efficiency index for the years 2000-2015 with a Landsat dataset (NDVI) and a CHIRPS (precipitation) dataset.

I already have two image collections with the property year and each has one band. One with NDVI nd the other has precipitation. The Landsat ImageCollection is already prepared and was also smoothed.

var years = ee.List.sequence(2000,2015);

var byYear = ee.ImageCollection.fromImages(
  years.map(function (y) {
  var start = ee.Date.fromYMD(y, 07, 1);
  var stop = start.advance(1, 'year');
  var sumVeg = smoothed.filterDate(start, stop).select('nd').median();
return sumVeg.set('year', y);
}));


var dataset = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
                  .filter(ee.Filter.date('2000-01-01', '2015-12-31'));
var precipitation = dataset.select('precipitation');
var years = ee.List.sequence(2000,2015);
var yearCHIRPS = ee.ImageCollection.fromImages(
  years.map(function (y) {
  var start = ee.Date.fromYMD(y, 07, 1);
  var stop = start.advance(1, 'year');
  var sumprec = precipitation.filterDate(start, stop).select('precipitation').sum();
return sumprec.set('year', y);
}));

mergedCollection = byYear.merge(yearCHIRPS);

The result is an image collection with 32 images, but I rather want to have 16 images with each two band (NDVI and precipitation) and then to calculate the RUE by dividing the NDVI through the annual precipitation with the map function.

The code is here https://code.earthengine.google.com/382aac21f969e829fd609903184d7395

1 Answer 1

1

Why not making the image collection in one go by mapping over the list of years. THen you can also immediately calculate the RUE as you have both images for a year.

var byYear = ee.ImageCollection.fromImages(
  years.map(function (y) {
  var start = ee.Date.fromYMD(y, 07, 1);
  var stop = start.advance(1, 'year');
  var sumVeg = smoothed.filterDate(start, stop).select('nd').median(); //what to use here?
  var sumprec = precipitation.filterDate(start, stop).select('precipitation').sum(); //sum of the whole year!
  /////////// Calculate RUE by dividing the NDVI/Precipitatio
  var RUE = sumVeg.divide(sumprec).rename('RUE');
return ee.Image.cat(sumVeg, sumprec, RUE).set('year', y);
}));  

print(byYear)

NOTE: this is just to make it programmatically work, I am not sure if the RUE values are actually correct.

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.