0

I'm trying to calculate annual average MSAVI2 values to explore vegetation productivity. The way my current code is set up, I'm concerned that the mosaic function is only taking the latest available image i.e., just the 12/31/2000 image in my example below. I'd like to be able to average all values across the given date range to get annual average MSAVI2 data for a given year.

Is there any function I can replace mosaic with to get this?

current status of my code:

//compute composite for all images for 2000
var compositeLS00 = LS
  .filterDate('2000-01-01','2000-12-31')
  .mosaic()

Map.addLayer(compositeLS00, {bands: ['B4', 'B4', 'B3']}, 'compositeLS00')

// compute MSAVI2 using expression
var msavi2LS00 = compositeLS00.expression(
  '(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2', 
  {
    'NIR': compositeLS00.select('B4'), 
    'RED': compositeLS00.select('B3')
  }
);
//add the MSAVI2 layer
Map.addLayer(msavi2LS00, {min: -0.1, max: 0.5}, 'msavi2LS00')

1 Answer 1

0

I'm concerned that the mosaic function is only taking the latest available image

Yes, that is correct.

Is there any function I can replace mosaic with to get this?

No, you need to do something different. If you want an average of "MSAVI2" values then you have to compute "MSAVI2" for each image. This is done with ee.ImageCollection.map(). Once you have done that, then you can take your average.

// Just filter the collection, don't mosaic.
var LS00_collection = LS.filterDate('2000-01-01','2000-12-31');

// Map over the collection to produce the desired data as a collection.
var MSAVI2_collection = LS00_collection.map(function (image) {
  return image.expression(
    '(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2', 
    {
      'NIR': image.select('B4'), 
      'RED': image.select('B3')
    }
  );
});

// Now you can take an average.
var msavi2LS00 = MSAVI2_collection.median();
Map.addLayer(msavi2LS00, {min: -0.1, max: 0.5}, 'msavi2LS00');

Notice that the operation which is to be done for each image is inside the mapped function (function (image) { ... }).

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.