# Finding the best image per year of Landsat image collection in Google Earth Engine

I am trying to create a series of images with the best image per year using Landsat 7 from 2000-2017 around the legal Amazon (using RBG bands 1-3). The code I have so far pulls up over 70,000 images over the period. It seems like I should be looping through images in each year and finding the least cloudy image, but I know you're not supposed to write loops in GGE.

I'm really new to this platform so I may be missing something obvious!

The end goal is to create a timelapse that I will overlay with my own dataset. The code below is what I have so far, and I have no idea how to proceed from here:

// create polygon around legal amazon
var Amaz = ee.Geometry.Polygon([[-43.0, -18.0], [-69.0, -18.0], [-69.0,5.0], [-43.0, 5.0]]);

//dates of interest
var start = ee.Date('2000-01-01');
var end = ee.Date('2018-01-01');

// create image collection

var Amazon_images = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
.filterBounds(Amaz)
.filterDate(start, end)
.sort('CLOUD_COVER', false);

// Get number of images
var count = Amazon_images.size();
print('size of collection Amazon_images', count);


Yep, instead of for/while loops, Earth Engine prefers mapping over any type of collection or list (the "Mapping over .." chapters in the documentation are pretty helpful).

We can map over a list of years, filter to an annual Landsat collection, sort by cloud cover and then simply pick the first (least cloudy) image. At each step, the mapping returns a single image (the annual image of least cloud cover), which results in an ImageCollection. I have included the return of a rough image mosaic due to your region of interest being so large.

var roi = ee.Geometry.Polygon([[-43.0, -18.0], [-69.0, -18.0], [-69.0,5.0],
[-43.0, 5.0]]);
Map.centerObject(roi, 4)

var startyear = 2000
var endyear = 2018

var LS7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
.filterBounds(roi)
.filterDate(startyear+'-01-01', endyear+1+'-01-01')

var count = LS7.size();
print('size of collection Amazon_images', count);

// Get least cloudy annual scene / mosaic via the cc metadata property.
// years = [2000, 2001, 2002]
var years = ee.List.sequence(startyear, endyear).getInfo()

var annual_least_cc = years.map(function(year){
// Get least cloudy annual single scene.
// var annual = LS7.filterDate(year+'-01-01', (year+1)+'-01-01')
//                 .sort('CLOUD_COVER')
// var annual_img = ee.Image(annual.first())
// Map.addLayer(annual_img.divide(10000), {bands: ['B3', 'B2', 'B1'], min: 0, max: 0.3}, year)

// Or get mosaic of least cloudy annual scenes.
var annual = LS7.filterDate(year+'-01-01', (year+1)+'-01-01')
.sort('CLOUD_COVER', false) // mosaic puts last element on top.
var annual_img = ee.Image(annual.mosaic())
Map.addLayer(annual_img.divide(10000), {bands: ['B3', 'B2', 'B1'], min: 0, max: 0.3}, year)

return annual_img
})
annual_least_cc = ee.ImageCollection(annual_least_cc)
print(annual_least_cc)

• @christopherRieke thanks, that did make the a nice image collection! From what I understand, the landsat imagery is 30x30m res, but when I zoom in on the images, the resolution is really poor. Do you have any idea why that is? – Jacy Hyde Jul 2 '18 at 23:41
• Hm looks normal to me resolution-wise. There is nothing in the script that would cause anything zoom/resolution related as far as I can tell. You specifically said resolution so I guess you don't mean the horizontal stripes caused by the masked out Landsat-7 scanlines? – Christoph Rieke Jul 3 '18 at 19:13
• @ChristopherRieke no not the scanlines. I'm comparing it to some google earth imagery I have from a couple of years ago and the detail on zooming in is way worse. Though again, I've never used landsat before, so maybe my expectations were just too high? I'm trying to be able to pick out transmission lines in the area, and I can see them in the imagery but its pretty unclear in the landsat image – Jacy Hyde Jul 3 '18 at 21:58
• @JacyHyde Yeah Google Earth is mostly 30cm nowadays or even better in urban areas. Here is a nice comparison of different resolutions landscape.satsummit.io/capture/… You could look into pansharpening Landsat to 15m or using Sentinel-2 if the time series is sufficient. – Christoph Rieke Jul 3 '18 at 22:13
• @ChristopherRieke Pansharpening seems like a good option, since I think sentinel only goes back till ~2014. The landsat 7 tier 1 images that I'm using now don't have the panchromatic band, so I'm looking at Landsat 7 Collection 1 Tier 1 and Real-Time data Raw Scenes, which has an 8th panchromatic band. However, they don't have that cloud cover specifications like the other dataset, so I can't figure out how to sort them to get the best image. Do you have any ideas? Again, thanks so much for all your help! – Jacy Hyde Jul 5 '18 at 19:03