Wednesday, 8 February 2017

landsat - How to generate a collection of mosaic images by mapping over date list in Google Earth Engine


I want to generate a collection of mosaicked images from Landsat 5 over multiple years. I have checked that the individual images are not null but on returning the mosaic in the code below throws the error:




List (Error) ImageCollection.fromImages: Attempt to create an ImageCollection with non-image elements.



var p1 = ee.Geometry.Point([103.521,13.028]);
var p2 = ee.Geometry.Point([105.622,13.050]);

var Date_Start = ee.Date('2000-05-01');
var Date_End = ee.Date('2007-12-01');
var Date_window = ee.Number(30);


// Create list of dates for time series
var n_months = Date_End.difference(Date_Start,'month').round();
var dates = ee.List.sequence(0,n_months,1);
var make_datelist = function(n) {
return Date_Start.advance(n,'month');
};
dates = dates.map(make_datelist);
var fnc = function(d1) {
var start = ee.Date(d1);
var end = ee.Date(d1).advance(14,'month');

var date_range = ee.DateRange(start,end);
var S1 = ee.ImageCollection('LANDSAT/LT5_L1T_TOA')
.filterDate(date_range)
.sort('CLOUD_COVER')
.filterBounds(p1).first()

var S2 = ee.ImageCollection('LANDSAT/LT5_L1T_TOA')
.filterDate(date_range)
.sort('CLOUD_COVER')
.filterBounds(p2).first()


var mosaic = ee.ImageCollection([ee.Image(S1), ee.Image(S2)]).mosaic();

return mosaic
};

var list_of_images = dates.map(fnc);
print('list_of_images', list_of_images);
var mt = ee.ImageCollection(list_of_images);
print(mt);

Map.addLayer(mt, {}, 'mt');

ERROR:


List (Error)
ImageCollection.fromImages: Attempt to create an ImageCollection with non-image elements.

Answer



I was able to solve the issue (with the help of Google Earth Developer Group's folks). Use var mosaic = ee.Image(S1).blend(ee.Image(S2)) to mosaic instead of mosaic() and make sure the dates have non-null images.


Hope this helps to future readers.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...