# GEE: how to make an average of values from the same day

I filter out the clouds, shadows and snow from the Landsat 8 data and calculate the NDVI. Examining the values in more detail, I found that some are for the same day twice. I suspect the problem is caused by overlapping images, with the point being between/on both. I tried to find a solution, but I couldn't find anything.

What I need: a function to create an average of the duplicated values in same days.

``````// bufferu function
function bufferPoints(radius, bounds) {
return function(pt) {
pt = ee.Feature(pt);
};
}
// cloud, shadow and snow filter: fmask (qa)
var cloudsBitMask = (1 << 5);
var snowBitMask = (1 << 4); // snow
var qa = image.select('QA_PIXEL');
}
// calculation of indices
var ndvi = image.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI')
}
var ndmi = image.normalizedDifference(['SR_B5', 'SR_B6']).rename('NDMI')
}
var ndsi = image.normalizedDifference(['SR_B3', 'SR_B6']).rename('NDSI')
}
var evi = image.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': image.select('SR_B5'),
'RED': image.select('SR_B4'),
'BLUE': image.select('SR_B2')}).rename('EVI');
}
// _____________________________

// DATA

var ptsEast = ee.FeatureCollection(ee.Geometry.MultiPoint(
[[117.94363514659328, 46.70941786484102],
[119.42678944346828, 46.807262069830664],
[119.41580311534328, 47.03986601821814],
[119.07522694346828, 47.09224973615361],
[118.85550038096828, 47.159524596123624],
[118.71267811534328, 47.159524596123624],
[118.52591053721828, 47.159524596123624],
[118.37210194346828, 47.1371090963271],
[118.11941639659328, 47.159524596123624]]));

var ptsGobi = ee.FeatureCollection(ee.Geometry.Point([96.9963300116736, 43.375274461112205]));

// merge points together
var ptsMerge = ptsEast.merge(ptsGobi)
var ptsBuff = ptsMerge.map(bufferPoints(30, true));

// Landsat 8 + filtering
var startDate = '2019-01-01'
var endDate = '2020-01-01'

var L8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filter(ee.Filter.calendarRange(6,9, 'month'))
.filterDate(startDate, endDate)
.filterBounds(ptsBuff)

// Chart maker
print(ui.Chart.image.seriesByRegion({
imageCollection: L8.select('NDVI'),
regions: ptsBuff,
reducer: ee.Reducer.mean(),
scale: 30
}).setOptions({title: 'NDVI - Landsat 8'}));

// ___
Map.addLayer(ptsMerge.draw({color: 'red', strokeWidth: 5}), {}, 'drawn');
Map.centerObject(ptsMerge);
``````

for example area 1: 24 Aug 2019

• Your question needs more details. What were you doing? What solution did you try? It would be better if you share your code. Jul 6, 2021 at 4:00
• I edited the post. sorry, I had a busy day yesterday, now all the information is listed, I hope. Jul 6, 2021 at 9:02

The simplest solution is to map over a list of distinct days, mosaicing all the images for that day:

``````var withDates = L8.map(function(img) {
return img.set('date', img.date().format('YYYY-MM-dd'))
})

var mosaicList = withDates.aggregate_array('date')
.distinct()
.map(function(date) {
var d = ee.Date(date)
return L8.filterDate(d, d.advance(1, 'day')).mosaic().set('system:index', date)
})

var mosaics = ee.ImageCollection.fromImages(mosaicList)
print(mosaics)
``````