0

As per Mosaicking a Image Collection by Date (day) in Google Earth Engine, I tried the answering code from Rodrigo E. Principe.

That code is very good. I can mosaic all the images (tiles) all my area.

But my problem is that I lost all the properties in each image list after Mosaicking.

In order to analysis with Time series, I need to have metadata('system:time_start') but I can not find this Metadata in in each image list from the new ImageCollection(mosaicking).

So, Please advise how to transfer all properties to new ImageCollection after mosaicking

The Mosaic code is modified from 'Rodrigo E. Principe' by the following code:

var ROI = 
    ee.Geometry.Polygon(
        [[[100.14445909748613, 14.689307337967634],
          [100.14445909748613, 14.04009719681829],
          [100.98491319904863, 14.04009719681829],
          [100.98491319904863, 14.689307337967634]]], null, false);

Map.centerObject(ROI, 10);

var start = ee.Date('2017-09-03');
var finish = ee.Date('2017-10-30');

var S1 = ee.ImageCollection('COPERNICUS/S1_GRD')
                     .filterDate(start, finish)
                     .filterBounds(ROI)
                     .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                     .filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
                     .filter(ee.Filter.eq('instrumentMode', 'IW'));

print('S1',S1)

/////////////////////Mosaicking a Image Collection by Date (day) ////////////////

// Difference in days between start and finish
var diff = finish.difference(start, 'day');

// Make a list of all dates
var range = ee.List.sequence(0, diff.subtract(1)).map(function(day){return start.advance(day,'day')});

// Funtion for iteraton over the range of dates
var day_mosaics = function(date, newlist) {
  // Cast
  date = ee.Date(date);
  newlist = ee.List(newlist);
  
  // Filter collection between date and the next day
  var filtered = S1.filterDate(date, date.advance(1,'day'));
  
  // Make the mosaic
  var image_m = ee.Image(filtered.mosaic());
  
  // Add the mosaic to a list only if the collection has images
  return ee.List(ee.Algorithms.If(filtered.size(), newlist.add(image_m), newlist))
}

// Iterate over the range to make a new list, and then cast the list to an imagecollection
var S1_mosaic = ee.ImageCollection(ee.List(range.iterate(day_mosaics,ee.List([]))));

print('S1_mosaic',S1_mosaic)

// Adds a time band to the image.Original from (https://developers.google.com/earth-engine/reducers_regression)
var createTimeBand = function(image) {
  return image.addBands(image.metadata('system:time_start').divide(1e18));
};


var linearFit = S1_mosaic.select(['system:time_start', 'VH'])
  .reduce(ee.Reducer.linearFit());
  
print(linearFit)

Code link : https://code.earthengine.google.com/dbd55ea2354984025b0fc10874f23ea9

1

In your case, since you're using ee.Reducer.linearFit(), you will want your time as a band, not a property. You can add a time band at the time you create your daily mosaic. Note that the docs for ee.Reducer.linearFit() that you linked to seems to be outdated (the metadata() function doesn't exist). In the updated script below, I converted system:time_start into days since Unix epoch and added it as a band t to each mosaic.

var ROI = 
    ee.Geometry.Polygon(
        [[[100.14445909748613, 14.689307337967634],
          [100.14445909748613, 14.04009719681829],
          [100.98491319904863, 14.04009719681829],
          [100.98491319904863, 14.689307337967634]]], null, false);

Map.centerObject(ROI, 10);

var start = ee.Date('2017-09-03');
var finish = ee.Date('2017-10-30');

var S1 = ee.ImageCollection('COPERNICUS/S1_GRD')
                     .filterDate(start, finish)
                     .filterBounds(ROI)
                     .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                     .filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
                     .filter(ee.Filter.eq('instrumentMode', 'IW'));

print('S1',S1)

/////////////////////Mosaicking a Image Collection by Date (day) ////////////////

// Difference in days between start and finish
var diff = finish.difference(start, 'day');

// Make a list of all dates
var range = ee.List.sequence(0, diff.subtract(1)).map(function(day){return start.advance(day,'day')});

// Funtion for iteraton over the range of dates
var day_mosaics = function(date, newlist) {
  // Cast
  date = ee.Date(date);
  newlist = ee.List(newlist);

  // Filter collection between date and the next day
  var filtered = S1.filterDate(date, date.advance(1,'day'));

  var timeBand = ee.Image(date.millis())
    .divide(1000 * 3600 * 24) // Unix epoch days
    .int()
    .rename('t')

  // Make the mosaic
  var image_m = ee.Image(filtered.mosaic())
    .addBands(timeBand)

  // Add the mosaic to a list only if the collection has images
  return ee.List(ee.Algorithms.If(filtered.size(), newlist.add(image_m), newlist))
}

// Iterate over the range to make a new list, and then cast the list to an imagecollection
var S1_mosaic = ee.ImageCollection(ee.List(range.iterate(day_mosaics,ee.List([]))));

print('S1_mosaic',S1_mosaic)

var linearFit = S1_mosaic.select(['t', 'VH'])
  .reduce(ee.Reducer.linearFit());

print(linearFit)
Map.addLayer(linearFit, {bands: 'scale', min: -0.5, max: 0.5}, 'scale')
Map.addLayer(linearFit, {bands: 'offset', min: -3000, max: 9000}, 'offset')

https://code.earthengine.google.com/39e3b9dfe4f00e7b381ce2c1bfd3d266

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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