I'm working with Sentinel 2 satellite and I have sampled on the map 4 blue points indicating an irrigated areas, and other 4 red points for non-irrigated ones.

Then, I have considered 4 collections, one for each month, starting by May

collection_mag = (ee.ImageCollection('COPERNICUS/S2')
              .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10)) 
              .filterDate('2019-05-01', '2016-05-31')

collection_giu = (ee.ImageCollection('COPERNICUS/S2')
              .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10)) 
              .filterDate('2019-06-01', '2019-06-30')

collection_lul = (ee.ImageCollection('COPERNICUS/S2')
              .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10)) 
              .filterDate('2019-07-01', '2019-07-31')

collection_ago = (ee.ImageCollection('COPERNICUS/S2')
              .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10)) 
              .filterDate('2019-08-01', '2019-08-31')

For each collection, I have calculated the NDVI, then reduced the collection into one image

def NDVI(image):
    return image.expression('float(b("B8") - b("B4")) / (b("B8") + b("B4"))')

img_mag = collection_mag.map(NDVI).mean()
img_giu = collection_giu.map(NDVI).mean()
img_lul = collection_lul.map(NDVI).mean()
img_ago = collection_ago.map(NDVI).mean()

This is the result by now (printing only the last month collection) - : This is the result by now

I want to plot a chart indicating the NDVI value, month by month, of the sampled points. Can anyone help me?

1 Answer 1


Although I did this within the Javascript code editor, code should be fairly similar for the Python environment:

first, make some geometry you should have. I would recommend making a feature of each point and turn it into a feature collection.

// import a geometry with 8 points

get the image collection you like:

// import image collection             
var collection = (ee.ImageCollection('COPERNICUS/S2')
              .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 40)) // if you set this to low, you won't have images sometimes

Then make a monthly composite image using e.g. this function:

// make monthly NDVI composites
var listMonths = ee.List.sequence(1,12);
var monthlyNDVI = ee.ImageCollection.fromImages(listMonths.map(function(month){
  var start = ee.Date.fromYMD(2019, month, 1);
  var end = ee.Date.fromYMD(2019, month, 1).advance(1, 'month');
  var images = collection.filterDate(start, end);
  var NDVI =  images.map(function(image){
    return image.expression('float(b("B8") - b("B4")) / (b("B8") + b("B4"))').rename('NDVI');
  return NDVI.mean().set('system:time_start', start);

And print a chart using:

// print chart and collection
var chart = ui.Chart.image.seriesByRegion(monthlyNDVI, geometry, ee.Reducer.mean(), 'NDVI', 10);

Link code

  • Thank you so much for the response, I will try to traduce this in Pyhton! Sep 16, 2019 at 7:02

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.