Google Earth Engine – Export Median Yearly Landsat 8 Bands and Indices to Google Drive

exportgoogle-earth-enginelandsat 8median

I am trying to export yearly median Landsat 8 bands and indices to Google Drive. I can do that for monthly images but I'd like to do that for yearly images. In the example below, I downloaded monthly images for January, 2015:

var landsat = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
//Create mask function
function maskL8sr(image) {
  // Bits 2, 3 and 5 are water, cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  var waterBitMask = (1 << 2);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0))
                 .and(qa.bitwiseAnd(waterBitMask).eq(0));
  return image.updateMask(mask);
}
//Create Image Collection for Landsat 8 BOA, filtering data from April 2013 to December 2013
//filtering the tiles which intersect India, selecting the predefined bands (VIS, NIR and SWIR)
//Display results
var landsat = landsat.filter(ee.Filter.calendarRange(1,1,'month'))
                      .filter(ee.Filter.calendarRange(2015,2015,'year'))
                      .filterBounds(table)
.map(maskL8sr);
var landsat = landsat.select('B2','B3','B4','B5','B6','B10')
print (landsat)

//Calculate the median for each band (B2 to B7), multiply by scale factor
//(0.0001), and clip to country polygon
var median1 = landsat.select('B2','B3','B4','B5','B6').reduce(ee.Reducer.median()).multiply(0.0001).clip(table);

//Calculate the median for B10, multiply by scale factor
//(0.1), and clip to country polygon
var median2 = landsat.select('B10').reduce(ee.Reducer.median()).multiply(0.1).clip(table);
Map.addLayer(median1)
Map.addLayer(median2)

//Create variable for each band
var B2 = median1.select('B2_median')
var B3 = median1.select('B3_median')
var B4 = median1.select('B4_median')
var B5 = median1.select('B5_median')
var B6 = median1.select('B6_median')
var B10 = median2.select('B10_median')

var B10 = B10.subtract(273.15)
 
var ndvi = B5.subtract(B4).divide(B5.add(B4)).rename('ndvi');
var ndbi = B6.subtract(B5).divide(B6.add(B5)).rename('ndbi');
var evi = median1.expression('2.5*((NIR-RED)/(NIR+6*RED-7.5*BLUE+1))',
{
'NIR':median1.select('B5_median'),
'RED':median1.select('B4_median'),
'BLUE':median1.select('B2_median')
});
var ebbi = median1.expression('(SWIR - NIR)/ 10 * sqrt(SWIR + TIRS)',
{
'NIR':median1.select('B5_median'),
'SWIR':median1.select('B6_median'),
'TIRS' : median2.select('B10_median')
});

Export.image.toDrive({
image: B3,
description: 'green',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: B2,
description: 'blue',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: B4,
description: 'red',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: B5,
description: 'nir',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: B6,
description: 'swir',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: B10,
description: 'tirs',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: evi,
description: 'evi',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: ebbi,
description: 'ebbi',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: ndbi,
description: 'ndbi',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

Export.image.toDrive({
image: ndvi,
description: 'ndvi',
scale: 100, //100 for Band10
maxPixels: 1000000000000,
region: table,
crs: 'EPSG: 7760'
});

How can I export these bands (as separate images, not as a layer stack) and indices but as (median) yearly products?

Best Answer

The answer was to change var landsat = landsat.filter(ee.Filter.calendarRange(1,1,'month')) to var landsat = landsat.filter(ee.Filter.calendarRange(1,12,'month'))