Skip to main content
1 of 3

Using ee.Reducer on monthly time series with missing data

Apologies, I am still a novice GEE user and despite best efforts of searching stack exchange for solutions I am still stuck on this.

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") .select('LST_Day_1km') .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")) .mean(); return monthly .set("year", y) .set("month", m) .set("system:time_start", ee.Date.fromYMD(y, m, 1));}); }) .flatten()); print (monthlyTemp, 'monthly Temp')// 228 images

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

// 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("") .reduce(ee.Reducer.max()) .rename("max_Temp"); return maxTemp .set("month", m);}) .flatten()); 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)) .reduce(ee.Reducer.min()) .rename("min_Temp"); return minTemp .set("month", m);}) .flatten()); print (MonthlyMIN, 'MonthlyMIN'); // 12 elements

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

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

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