# How to use the reducer.mean function to average multiple data points?

I am trying to figure out GDD over a period of multiple years given a period of time for each year, and the code provided below allows me to do that.

Now that I have 10 years of data points, I am stuck trying to use a reducer.mean function to average all of these variables into one final image layer.

So my basic question: how do i employ the reducer.mean function to average 10 or so variables?

``````var dataset = ee.ImageCollection('MODIS/006/MYD11A1')
.filter(ee.Filter.date('2017-04-15', '2017-05-20'));
var landSurfaceTemperature = dataset.select(['LST_Day_1km', 'LST_Night_1km']);

// Create a geometry representing an export region.
var features = ee.Geometry.Rectangle([-85.1417893413635, 45.31413490213395, -86.125065708551, 44.65070625463291]);

// According to: https://gis.stackexchange.com/questions/307548/getting-temperature-data-of-given-point-using-modis-lst-data
// map over the image collection and use server side functions
var tempToFahr = landSurfaceTemperature.map(function(image){
var props = image.toDictionary(image.propertyNames());
// Mask where one of Night or day temperature has no data
// we assume that the night temperature is the min temp, and the day temperature is the max temperature
// Calculate the GGD and make all the negative values 0 (see: https://en.wikipedia.org/wiki/Growing_degree-day)
var GDD = meanFahr.subtract(52.5).rename('GDD');
var GDDnonNeg = GDD.where(GDD.lt(0), 0).rename('GDDnonNeg');
});

// calculate the sum of GGD values
var summed = tempToFahr.select('GDDnonNeg').reduce(ee.Reducer.sum()).rename('summedGDD');

var dataset2 = ee.ImageCollection('MODIS/006/MYD11A1')
.filter(ee.Filter.date('2016-04-15', '2016-05-20'));
var landSurfaceTemperature2 = dataset.select(['LST_Day_1km', 'LST_Night_1km']);

// Create a geometry representing an export region.
var features2 = ee.Geometry.Rectangle([-85.1417893413635, 45.31413490213395, -86.125065708551, 44.65070625463291]);

// According to: https://gis.stackexchange.com/questions/307548/getting-temperature-data-of-given-point-using-modis-lst-data
// map over the image collection and use server side functions
var tempToFahr2 = landSurfaceTemperature2.map(function(image){
var props2 = image.toDictionary(image.propertyNames());
// Mask where one of Night or day temperature has no data
// we assume that the night temperature is the min temp, and the day temperature is the max temperature
// Calculate the GGD and make all the negative values 0 (see: https://en.wikipedia.org/wiki/Growing_degree-day)
var GDD2 = meanFahr2.subtract(52.5).rename('GDD2');
var GDDnonNeg2 = GDD2.where(GDD2.lt(0), 0).rename('GDDnonNeg2');
});

// calculate the sum of GGD values
var summed2 = tempToFahr2.select('GDDnonNeg2').reduce(ee.Reducer.sum()).rename('summedGDD2');

// ######### END ADDED CODE ############

Map.setCenter(-85.60371794450282,44.73590436363271, 10);

var dataset3 = ee.ImageCollection('MODIS/006/MYD11A1')
.filter(ee.Filter.date('2015-04-15', '2015-05-20'));
var landSurfaceTemperature3 = dataset.select(['LST_Day_1km', 'LST_Night_1km']);

// Create a geometry representing an export region.
var features3 = ee.Geometry.Rectangle([-85.1417893413635, 45.31413490213395, -86.125065708551, 44.65070625463291]);

// According to: https://gis.stackexchange.com/questions/307548/getting-temperature-data-of-given-point-using-modis-lst-data
// map over the image collection and use server side functions
var tempToFahr3 = landSurfaceTemperature3.map(function(image){
var props3 = image.toDictionary(image.propertyNames());
// Mask where one of Night or day temperature has no data
// we assume that the night temperature is the min temp, and the day temperature is the max temperature
// Calculate the GGD and make all the negative values 0 (see: https://en.wikipedia.org/wiki/Growing_degree-day)
var GDD3 = meanFahr3.subtract(52.5).rename('GDD3');
var GDDnonNeg3 = GDD3.where(GDD3.lt(0), 0).rename('GDDnonNeg3');
});

// calculate the sum of GGD values
var summed3 = tempToFahr3.select('GDDnonNeg3').reduce(ee.Reducer.sum()).rename('summedGDD3');

// ######### END ADDED CODE ############

var landSurfaceTemperatureVis = {
min: 0,
max: 15,
bands: ['LST_Day_1km'],
opacity: .6,
palette: [
'040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
'0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
'3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
'ff0000', 'de0101', 'c21301', 'a71001', '911003'
],
};
Map.setCenter(-85.60371794450282,44.73590436363271, 10);