0

Following on from Mosaicking Image Collection by Date (day) in Google Earth Engine

I wish to mosaic images for the same day of year, but across multiple years. For example, if I have a collection of Sentinel 2 images from 2015-2020, I would like to merge ALL images in this collection that were acquired on Jan 01, Jan 02, etc., regardless of year.

I cannot seem to figure out a way of doing so.

1 Answer 1

0

To obtain the desired output you need to add an additional property to your images that indicates the day of acquisition regardless of the year. Then, you can use that property to filter your image collection and reduce them with a particular function. In the following code I added two possible options to do this. Although you want to mosaic all the images of the same day, it might be difficult to obtain several images for a particular date; thus, I also added an option to make mosaics using a time window.

var collection = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterDate(start, finish)
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filterMetadata('resolution_meters', 'equals', 10)
.filterBounds(poly)
// Add number of day as property
.map(function(image){
  // Get number of day from start of year
  var day = ee.Number.parse(ee.Date(image.get('system:time_start')).format('D'));
  // Set as additional property
  return image.set('day', day);
});

// Option A: for the exact same day
var days = collection.aggregate_array('day').distinct().sort();
print('days',days);

var dayMosaic = ee.ImageCollection.fromImages(days.map(function(day){
  var resul = collection.filter(ee.Filter.eq('day', day))
                        // Use a reducer to define how to calculate areas
                        // that overlap. Here I used mean
                        .mean()
                        .set('day', day);
  return resul;
}));

Map.centerObject(poly, 9);
// Add first image to the map
Map.addLayer(dayMosaic.first(), 
   {bands: ['VH','VV','VH'],min:-35, max: -1}, 
  'dayMosaic first');

// Option B: ror a range of dates. Here I use a window of 30 days before each date
var dayStep = 30;
var days2 = ee.List.sequence(dayStep,366,dayStep);
print('days2',days2);

var dayMosaicRange = ee.ImageCollection.fromImages(days2.map(function(day){
  var resul = collection.filter(ee.Filter.and(
                                  ee.Filter.gte('day',ee.Number(day).subtract(ee.Number(dayStep))),
                                  ee.Filter.lt('day',ee.Number(day))))
                        // Use a reducer to define how to calculate areas
                        // that overlap. Here I used mean
                        .mean()
                        .set('day', day);
  return resul;
}));

// Add first image to the map
Map.addLayer(dayMosaicRange.first(), 
  {bands: ['VH','VV','VH'],min:-35, max: -1}, 
  'dayMosaic range first');
1
  • Hi Jonathan, thank you - this worked great!
    – Jack
    Commented May 31 at 8:51

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.