0

I have created a list of dates from which I would like to get Sentinel3 images, only to find that I have multiple images per day.

How can I reduce it to 1 image per day?

I intend to do use median for the merging of the photos.

var region = ee.FeatureCollection([ee.Feature(Map.getBounds(true))])

//Dates of Interest
var start = ee.Date("2018-04-01");
var finish = ee.Date("2018-05-01");

//------------------- Data bases ---------------------//
var sen3 = ee.ImageCollection('COPERNICUS/S3/OLCI')
  .filterDate(start, finish)
  .filterBounds(region)
  .select(['Oa17_radiance', 'Oa08_radiance'])
  .map(function(image){
     return image
     .clip(region)
   })

//reference  dates
var sen2_for_dates = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterDate(start, finish)
  .filterBounds(region)
  .map(function(image){
    return image
    .clipToCollection(region)
    .updateMask(image.select('QA60').not())
    .addBands(image.normalizedDifference(['B8','B4']).rename('ndvi'))
  })
  .select('ndvi')

//------------------ Unique dates ----------------------//
var sen2_dates = sen2_for_dates.map(function(image){
  return image.set('simpleDateMillis', ee.Date(ee.Date(image.date().format('YYYY-MM-dd'))))
});
var listMillisSimple = ee.List(sen2_dates.aggregate_array('simpleDateMillis'));
var uniqueDatesSimple = listMillisSimple.distinct();
var SEN2_day0 = uniqueDatesSimple

//THIS IS THE lIST OF DATES I WOULD LIKE TO GET IT's IMAGES
var SEN3_day0 = uniqueDatesSimple.map(function(date){
  return ee.Date(date).advance(0, 'day');
});

var sen3_dates = sen3.map(function(image){
  return image.set('simpleDateMillis', ee.Date(ee.Date(image.date().format('YYYY-MM-dd'))))
});

//The ImageCollection that should be containing the images from the specific dates
var allImagesInRangeS30 = sen3_dates.filter(ee.Filter.inList("simpleDateMillis", SEN3_day0))

I get these structures: SEN3_day0 - List of 6 elements, dates (as needed). sen3_dates - ImageCollection of 409 images (to be filtered by the list of dates in SEN3_day0). allImagesInRangeS30 - ImageCollection of 75 images (needs to be 6, as the list).

2 Answers 2

1

My usual approach for this is to map over a list of day offsets, from start to finish. For each, filter the collection down to that date and make a composite. I add an empty property to be able to filter out days without imagery. It relies on median() returning a 0 band image when the collection is empty.

var region = ee.FeatureCollection([ee.Feature(Map.getBounds(true))])

var start = ee.Date('2018-04-01')
var finish = ee.Date('2018-05-01')

var days = finish.difference(start, 'days')
var dayOffsets = ee.List.sequence(0, days.subtract(1))
var allImagesInRangeS30 = ee.ImageCollection(dayOffsets
  .map(function (dayOffset) {
    var dayStart = start.advance(dayOffset, 'days')
    var dayFinish = dayStart.advance(1, 'days')
    var composite = ee.ImageCollection('COPERNICUS/S3/OLCI')
      .filterDate(dayStart, dayFinish)
      .filterBounds(region)
      .select(['Oa17_radiance', 'Oa08_radiance'])
      .median()
    return composite
      .set('empty', composite.bandNames().size().eq(0))
      .set('system:time_start', dayStart.millis())
  }))
  .filterMetadata('empty', 'equals', 0)

print(allImagesInRangeS30)

https://code.earthengine.google.com/e72a75cd645a8780b6b8deae6e06af80

0

How would I use this code to make a time series of the averaged value for each day? Right now I have:

print(ui.Chart.image.series(allImagesInRangeS30, geom, ee.Reducer.mean(), 9e9));

but I get error "Error generating chart: No properties to chart."

1
  • Please ask your question via a comment or a new question. May 17, 2020 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.