I would like to calculate an NDVI average for only 3 months (april, may, june) for 5 years from the S2A image collection. As a result I would like to create a chart with my 15 values and map an image with an overall ndvi mean.

I'm new to programming and couldn't yet successfully implement these properties into my script, even though there are already similar helpful posts like:

Calculating NDVI per region, month & year with Google Earth Engine,
Maximum ndvi for 3 months average in Google Earth Engine,
Google Earth Engine: calculating and plotting monthly average NDVI for a region from MODIS data

I am not even sure where a .mean() command as well as the time related command would belong to...

Code Link Google Earth Script

//NDVI script for ndvi time series in Obing, Germany

function maskS2clouds(images) {
  var qa = images.select('QA60');
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  return images.updateMask(mask).divide(10000).copyProperties(images).set('system:time_start', images.get('system:time_start'));

//Filter images
var images_filtered = sentinel_h.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 20))
  .filterDate('2017-03-28', '2021-07-28')
  .filter(ee.Filter.calendarRange(4, 6,'month'))


//calculate ndvi
var ndvi = function(image){
    var ndv = image.normalizedDifference(['B8','B4']);
    return ndv.copyProperties(image, ['system:index', 'system:time_start']);

var ndvi = images_filtered.map(ndvi);


var img_filtered_clip = images_filtered.first().clip(obing_clip);
var nd = ndvi.first().clip(obing_clip);

//Display data

var chart = ui.Chart.image.seriesByRegion({
  reducer: ee.Reducer.mean(), 


I am happy about any help :D

(This is my first post here so please let me know if you have any critique/tipps to improve it's quality/readability)

*Edit: This was the chart I was looking for (first) instead of the other one (second)

NDVI chart only 1 value/month NDVIchart several values/month

1 Answer 1


So this looks almost completely correct. This line:

var ndvi = images_filtered.map(ndvi);

Returns an image collection of ndvi bands. You may have noticed that an image collection is sort of a list of images together in one data structure, but it can be difficult to access the data directly. To do this you need to reduce them. In your case you have used:

var nd = ndvi.first().clip(obing_clip);

Which reduces the collection by just choosing the first ndvi image in the collection (which you can then clip). Luckily, we can also use the mean as a reducer, so to get the overall mean ndvi image we can use:

Var mean_ndvi = ndvi.mean().clip(obing_clip)

Which is one image of the average ndvi across all 15 images

To display a chart of the NDVI values, you are almost there. You have passed the collection into the chart function, but you need to tell it what band to look at, so change:




Here is a link to my edited version. I don't have access to the assets so had to create my own geometry:


  • Thank you for the help and the good explanation! I now have my mean NDVI image which I can export. I still have a hard time plotting the chart with only monthly means... I just exported all values to CSV and manually combined the specific values to an average per month value. So it's no need, but if you could also provide me with a tip on how to solve this monthly average problem in the data/chart, I would be even more grateful :) Commented Nov 30, 2022 at 9:39
  • Unfortunately I dod not know much about plotting charts in GEE so may not be able to help. But I can take a look at the code. Otherwise, you may want to consider opening new question that focuses on the plotting prt on its own
    – GeoMonkey
    Commented Nov 30, 2022 at 14:37
  • @average_julian I fixed it. See the edit in my answer
    – GeoMonkey
    Commented Nov 30, 2022 at 16:07
  • Thank you again for your answer! It doesn't change anything but I will futher play around with the code. If necessary I will follow your recommendation and create a new question :) Commented Nov 30, 2022 at 16:56
  • @average_julian hmmm, that's weird it worked for me. Are you getting any errors? I posted the link to my working code above
    – GeoMonkey
    Commented Nov 30, 2022 at 17:01

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.