0

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.

My code: https://code.earthengine.google.com/dd0afc7fa1829310e3195ffaea2bc2b7

// bufferu function
function bufferPoints(radius, bounds) {
  return function(pt) {
    pt = ee.Feature(pt);
    return bounds ? pt.buffer(radius).bounds() : pt.buffer(radius);
  };
}
// cloud, shadow and snow filter: fmask (qa)
function fmask(image) {
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  var snowBitMask = (1 << 4); // snow
  var qa = image.select('QA_PIXEL');
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0))
                 .and(qa.bitwiseAnd(snowBitMask).eq(0));
  return image.updateMask(mask);
}
// calculation of indices
function addNDVI(image) {
  var ndvi = image.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI')
  return image.addBands([ndvi])
}
function addNDMI(image) {
  var ndmi = image.normalizedDifference(['SR_B5', 'SR_B6']).rename('NDMI')
  return image.addBands([ndmi])
}
function addNDSI(image) {
  var ndsi = image.normalizedDifference(['SR_B3', 'SR_B6']).rename('NDSI')
  return image.addBands([ndsi])
}
function addEVI(image) {
  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');
  return image.addBands([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)
              .map(fmask)
              .map(addNDVI)
              .map(addNDMI)
              .map(addNDSI)
              .map(addEVI);
              
// 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 enter image description here

2
  • 2
    Your question needs more details. What were you doing? What solution did you try? It would be better if you share your code.
    – Padmanabha
    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

1 Answer 1

0

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)

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.