1

I am trying to download yearly median Landsat 5. Specifically, I am interested in the thermal band (Band 6) and the spectral index called EBBI (formula in the code below).

My initial try, so far is (link to the code I am using) by downloading each month of the year and then calculate the yearly image outside of Google Earth Engine (GEE), in a GIS software. But this takes a huge amount of time and the end shows an error that there are no bands.

How can I export yearly median Landsat 5 images (Thermal and EBBI) in a more efficient way? By efficient I mean something similar to the code I am using to download Landsat 8. As you can see in the code for Landsat 8, all I have to change in order to compute a median monthly image or a median yearly image is to change the range in var landsat = landsat.filter(ee.Filter.calendarRange(1,1,'month')) to var landsat = landsat.filter(ee.Filter.calendarRange(1,12,'month')). And the year of course.

I would like create a similar code for Landsat 5. I have tried to do it but I am getting errors, depending to what parameters I am changing in the Landsat 5 code.

1 Answer 1

0

A complete code to download median monthly (or yearly, check the comments) Landsat 5 (surface reflectance, collection 1):

// PARAMETERS
// dates
var YEAR_START = 2011;
var YEAR_END = YEAR_START;
var MONTH_START = 9;
var MONTH_END = MONTH_START;
// export
var CRS = 'EPSG: 7760';
var MAXPIXELS = 1000000000000; // can be replaced with 10e11
var REGION = table;
// 

var landsat = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR");

//Create mask function
function mask_ls_sr_c1(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);
}


var landsat = landsat.filter(ee.Filter.calendarRange(YEAR_START, YEAR_END,'year'))
                    .filter(ee.Filter.calendarRange(MONTH_START, MONTH_END, 'month'))
                    // Note 2: when I want to do a yearly composite, I can comment out filtering by month completely
                    .filterBounds(table)
                    .map(mask_ls_sr_c1);


//Calculate the median for each band, multiply by scale factor
//(0.0001), and clip to country polygon
var median1 = landsat.reduce(ee.Reducer.median())
                     .multiply(0.0001)
                     .clip(table);

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

//Create variable for each band
var B1 = median1.select('B1_median')
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 B7 = median1.select('B7_median')
var B6 = median2.select('B6_median')

var ebbi = median1.expression('(SWIR - NIR)/ 10 * sqrt(SWIR + TIRS)',
{
  'NIR':B4,
  'SWIR':B5,
  'TIRS' : B6
});

Export.image.toDrive({
  image: B6,
  description: 'tirs',
  scale: 100, //100 for Band10
  maxPixels: MAXPIXELS,
  region: REGION,
  crs: CRS
});

Export.image.toDrive({
  image: ebbi,
  description: 'ebbi',
  scale: 100, //100 for Band10
  maxPixels: MAXPIXELS,
  region: REGION,
  crs: CRS
});

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.