How would I go about making my analysis values per month rather than per year

 Create date filter and vector of years for analysis
       var date_filter = ee.Filter.date('2010-06-22', '2022-06-22');
       var year = ee.List.sequence(2010,2022);

3 Answers 3


You're not describing what type of monthly analysis you want to do. The below generates an image collection with monthly means for a date range. Maybe it at least can give you an idea on how to go about.

var aoi = Map.getBounds(true)
var startDate = ee.Date('2020-01-01')
var endDate = ee.Date('2022-07-01')

var ndviCollection = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterDate(startDate, endDate)
  .map(function (image) {
    return image
      .normalizedDifference(['B8', 'B4'])
      .copyProperties(image, image.propertyNames())

var numberOfMonths = endDate.difference(startDate, 'months')
var monthOffsets = ee.List.sequence(0, numberOfMonths.subtract(1))
var monthlyNdviCollection = ee.ImageCollection(
  monthOffsets.map(function (monthOffset) {
    var dateRange = startDate
      .advance(ee.Number(monthOffset), 'months')
    return ndviCollection
      .set('system:time_start', dateRange.start().millis())
      .set('system:time_end', dateRange.end().millis())




Here an example to compute and download different spectral indices (including NDVI) using Sentinel-2 images. The script allows to obtain monthly composites using the forEach loop:

// Processing steps:
// 0) Define input parameters.
// 1) Search and filtering imagery by date, in the study area, and clouds <75%.
// 2) Mask images to create 'crear sky' composites using the SCL product.
// 3) Compute some vegetation indices: NDVI, EVI, SAVI, OSAVI, NDMI, NDWI, MSI, MSI2.
// 4) Feature extraction (central position features) - compute monthly composites of 'mean' from the time serie.
// 5) Download data - Google Drive.

// Define extension of the study area.
//var extent = ... your feature collection...

// Define time intervals (periods) to compute statistics.
var periods = [['2018-09-01', '2018-09-30'],
               ['2018-10-01', '2018-10-31'],
               ['2018-11-01', '2018-11-30'],
               ['2018-12-01', '2018-12-31'],
               ['2019-01-01', '2019-01-31'],
               ['2019-02-01', '2019-02-28'],
               ['2019-03-01', '2019-03-31'],
               ['2019-04-01', '2019-04-30'],
               ['2019-05-01', '2019-05-31'],
               ['2019-06-01', '2019-06-30'],
               ['2019-07-01', '2019-07-31'],
               ['2019-08-01', '2019-08-31']];

var extent = ee.FeatureCollection('feature_collection');

// Run process for all periods.

function exportPeriod(period) {
  // Import and filter Sentinel-2 data.
  var s2RawData = ee.ImageCollection("COPERNICUS/S2_SR")
    .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 75)
    .filterDate(period[0], period[1])
  // Generate 'clear_sky' Sentinel-2 images using SCL.
  var s2ClearSky = function(image) {
    var scl = image.select('SCL');
    var clearSkyPixels = scl.eq(4).or(scl.eq(5)).or(scl.eq(6)).or(scl.eq(11));
    return image.updateMask(clearSkyPixels);
  var s2Data = s2RawData.map(s2ClearSky);
  // Compute spectral indices.
  var addSpectralIndices = function(image){
  // Sentinel-2 bands
  var s2Bands = 
  {'BLUE': image.select('B2').divide(10000),
   'GREEN': image.select('B3').divide(10000),
   'RED': image.select('B4').divide(10000),
   'NIR': image.select('B8').divide(10000),
   'SWIR1': image.select('B11').divide(10000),
   'SWIR2': image.select('B12').divide(10000)};
  // Vegetation indices
  var ndvi = image.expression('((NIR-RED)/(NIR+RED))', s2Bands).rename('NDVI');
  var evi = image.expression('2.5*((NIR-RED)/(1+NIR+6*RED-7.5*BLUE))', s2Bands).rename('EVI');
  var savi = image.expression('(NIR-RED)/(NIR+RED+0.5)*(1+0.5)', s2Bands).rename('SAVI');
  var osavi = image.expression('(NIR-RED)/(NIR+RED+0.16)*(1+0.16)', s2Bands).rename('OSAVI');
  // Water and moisture indices
  var ndmi = image.expression('((NIR-SWIR1)/(NIR+SWIR1))', s2Bands).rename('NDMI');
  var ndwi = image.expression('((NIR-SWIR2)/(NIR+SWIR2))', s2Bands).rename('NDWI');
  var msi = image.expression('(SWIR1/NIR)', s2Bands).rename('MSI');
  var msi2 = image.expression('SWIR2/NIR', s2Bands).rename('MSI2');
  // Add spectral indices
  var newBands = ee.Image([ndvi, evi, savi, osavi, ndmi, ndwi, msi, msi2]);
  return image.addBands(newBands);
  var s2DataSi = s2Data.map(addSpectralIndices);

  // Extract period features from the spectral indices time series.
  var ndvi = s2DataSi.select('NDVI').reduce(ee.Reducer.mean())
           .set("system:id", "NDVI");
  var evi = s2DataSi.select('EVI').reduce(ee.Reducer.mean())
           .set("system:id", "EVI");
  var savi = s2DataSi.select('SAVI').reduce(ee.Reducer.mean())
           .set("system:id", "SAVI");
  var osavi = s2DataSi.select('OSAVI').reduce(ee.Reducer.mean())
           .set("system:id", "OSAVI");
  var ndmi = s2DataSi.select('NDMI').reduce(ee.Reducer.mean())
           .set("system:id", "NDMI");
  var ndwi = s2DataSi.select('NDWI').reduce(ee.Reducer.mean())
           .set("system:id", "NDWI");
  var msi = s2DataSi.select('MSI').reduce(ee.Reducer.mean())
           .set("system:id", "MSI");
  var msi2 = s2DataSi.select('MSI2').reduce(ee.Reducer.mean())
           .set("system:id", "MSI2");

  // Merge extracted features into a ee.FeatureCollection
  var s2ExtFeatures = ee.ImageCollection([ndvi, evi, savi, osavi, ndmi, ndwi, msi, msi2]);
  // Export extracted features.
  var folder = period[0] + '_' + period[1];
  var batch = require('users/fitoprincipe/geetools:batch');
  batch.Download.ImageCollection.toDrive(s2ExtFeatures, folder, 
                {name: '{system:id}' + '_name_' + folder,
                 scale: 10, 
                 region: extent, 
                 type: 'float'});

Have you tried this:

var image  =  ee.ImageCollection("COLLECTION")
var_filtered_image  =  image.filter(ee.Filter.ed('cadance', 'monthly')) // I think this line should handle the monthly part
  .filterDate('2010-06-22', '2022-06-22').toList(); // This handles the year

I have adopted this from the code on this video: https://www.youtube.com/watch?v=b7lCNNJOfZY&ab_channel=OpenSourceRemoteSensing%26GIS

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.