I am trying to generate a value of mean MODIS LST for each month in a time series for a feature collection, as well as an overall timeseries minimum and maximum LST for each month of the year. When I try to create a composite image of minimum and maximum LST for each of the 12 months, January is excluded from the image due to missing data from the first year in the series. How can I still generate the min and max composites, despite the missing data?

Here is my code, the 'outputMIN' and 'outputMAX' result in 11 bands each, and should be 12 bands (one for each month of the year):

//Define first & last years of time series
var startyear = 2000;
var endyear = 2018;
var startmonth = 1;
var endmonth = 12;

// Compute beginning & end of study period + sequence of months & years
var startdate = ee.Date.fromYMD(startyear, startmonth, 1);
var enddate = ee.Date.fromYMD(endyear , endmonth, 30);
var years = ee.List.sequence(startyear, endyear);
var months = ee.List.sequence(startmonth,endmonth);

var TempCollection = ee.ImageCollection("MODIS/061/MOD11A2")
.filterDate("startdate, enddate");

// Create LST composite for every month
var monthlyTemp =  ee.ImageCollection.fromImages(
  years.map(function (y) { 
    return months.map(function(m) {
      var monthly = TempCollection
        .filter(ee.Filter.calendarRange(y, y, "year"))
        .filter(ee.Filter.calendarRange(m, m, "month"))
      return monthly
        .set("year", y) 
        .set("month", m) 
        .set("system:time_start", ee.Date.fromYMD(y, m, 1));}); })
print (monthlyTemp, 'monthly Temp')// 228 images 

var output_Monthly = monthlyTemp.filter(ee.Filter.listContains('system:band_names', 'constant').not())

// MAX Value Composition
// Calculate mean values for each month over all years
var MonthlyMAX =  ee.ImageCollection.fromImages(months
  .map(function (m) {
    var maxTemp = monthlyTemp
      .filter(ee.Filter.eq("month", m))
//      .select("")
  return maxTemp
    .set("month", m);})
print (MonthlyMAX, 'MonthlyMAX'); //12 elements

// MIN Value Compisition
var MonthlyMIN =  ee.ImageCollection.fromImages(months
  .map(function (m) {
    var minTemp = monthlyTemp
      .filter(ee.Filter.eq("month", m))
  return minTemp
    .set("month", m);})
print (MonthlyMIN, 'MonthlyMIN'); // 12 elements

var outputMIN = MonthlyMIN.filter(ee.Filter.listContains('system:band_names', 'constant').not())
print(outputMIN,'min'); //11 bands

var outputMAX = MonthlyMAX.filter(ee.Filter.listContains('system:band_names', 'constant').not())
print(outputMAX, 'max'); //11 bands

Link to reproducible example: https://code.earthengine.google.com/58104a235cd0772e866b46759dc1692c

1 Answer 1


You can use collection.cast() to force each image to contain all the same bands. It will add an empty band for the ones that are missing.

MonthlyMIN = MonthlyMIN.cast({min_Temp: "double"}, ["min_Temp"])
  • Thank you @NoelGorelick for your helpful addition to the script. I am still confused as to why ee.Reducer.max() or ee.Reducer.min() will result in a null value for January when just the first January of the time series is missing. Is it possible to ignore missing values when using the ee.Reducers, to get maximum and minimum values for all the available months in the time series?
    – Hydro_data
    Feb 27, 2023 at 1:27

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.