1

I need to download ndvi values for some pixels for 2000-2001 using the Landsat 5 TM 8-Day NDVI Composite, but since there is no quality band as in mod13q1 there's no way to filter by quality. Therefore, I want to make a mask using an image collection with information about clouds or shadows so I can mask those pixels with high o low values. I have the script to download the ndvi values but I don't know how to apply the mask neither how to create the mask..

any experience with that?

Code:

var puntos = ee.FeatureCollection('ft:11qUO03jhF4MiECWgd5Rev536WFERNiqWf5qpqXwb');

var landsat = ee.ImageCollection('LANDSAT/LT5_L1T_8DAY_NDVI').select('NDVI')
                                     .filterDate('2000-01-01', '2000-02-28');


var f_extraer_puntos = function(i){return i.reduceRegions({collection: puntos, reducer: ee.Reducer.mean(), scale: 30, })};

// #Extract the values by running reduceRegions over each image in the image collection.
var valores_ = landsat.map(f_extraer_puntos);

var ext_puntos = ee.FeatureCollection(valores_.flatten());
// #Turn the result into a feature collection

Export.table.toDrive({ collection: ext_puntos, description:'LT5_NDVI_puntos', fileFormat: 'CSV' }); 
6
  • And your script is...
    – aldo_tapia
    Feb 14, 2018 at 18:26
  • It's just a simple cript to download ndvi values. I didn't try to add anything about the cloud mask yet..
    – pgalansino
    Feb 14, 2018 at 18:31
  • var puntos = ee.FeatureCollection('ft:11qUO03jhF4MiECWgd5Rev536WFERNiqWf5qpqXwb'); var landsat = ee.ImageCollection('LANDSAT/LT5_L1T_8DAY_NDVI').select('NDVI') .filterDate('2000-01-01', '2000-02-28');
    – pgalansino
    Feb 14, 2018 at 18:32
  • var f_extraer_puntos = function(i){return i.reduceRegions({collection: puntos, reducer: ee.Reducer.mean(), scale: 30, })};// #Extract the values by running reduceRegions over each image in the image collection. var valores_ = landsat.map(f_extraer_puntos); var ext_puntos = ee.FeatureCollection(valores_.flatten());// #Turn the result into a feature collection Export.table.toDrive({ collection: ext_puntos, description:'LT5_NDVI_puntos', fileFormat: 'CSV' });
    – pgalansino
    Feb 14, 2018 at 18:32
  • Check my answer in this post. In your case, I would use Landsat 5 TM TOA/BOA reflectance, apply a cloud mask and compute NDVI. For cloud mask check this post
    – aldo_tapia
    Feb 14, 2018 at 18:37

1 Answer 1

4

Your feature collection is private, so I can't apply your code. But, here you have how to mask clouds from Landsat 5 Collection 1 Tier 2 TOA Reflectance and compute NDVI:

var region = /* color: #0b4a8b */ee.Geometry.Polygon(
        [[[-71.9000244140625, -30.817346256492073],
          [-70.7080078125, -30.826780904779778],
          [-70.6640625, -30.372875188118016],
          [-71.8670654296875, -30.410781790845878]]]),
    landsat = ee.ImageCollection("LANDSAT/LT05/C01/T2_TOA");

var collection = landsat.filterBounds(region).filterDate('2000-01-01', '2000-02-28');

var getQABits = function(image, start, end, newName) {
    // Compute the bits we need to extract.
    var pattern = 0;
    for (var i = start; i <= end; i++) {
       pattern += Math.pow(2, i);
    }
    // Return a single band image of the extracted QA bits, giving the band
    // a new name.
    return image.select([0], [newName])
                  .bitwiseAnd(pattern)
                  .rightShift(start);
};

// A function to mask out cloudy pixels.
var cloud_shadows = function(image) {
  // Select the QA band.
  var QA = image.select(['BQA']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 7,8, 'Cloud_shadows');
  // Return an image masking out cloudy areas.
};

// A function to mask out cloudy pixels.
var clouds = function(image) {
  // Select the QA band.
  var QA = image.select(['BQA']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 4,4, 'Cloud').neq(1);
  // Return an image masking out cloudy areas.
};

var maskClouds = function(image) {
  var cs = cloud_shadows(image);
  var c = clouds(image);
  image = image.updateMask(cs);
  return image.updateMask(c);
};

var NDVI = function(image) {
  return image.normalizedDifference(['B5', 'B4']).rename('NDVI');
};

var ndvi = collection.map(maskClouds).map(NDVI);

Map.addLayer(collection, {bands: ['B4', 'B3', 'B2'],min: [0,0,0],max: [0.2, 0.2, 0.2]}, 'Landsat with clouds');
Map.addLayer(ndvi,{min: -1, max: 1, palette: ['blue', 'white', 'green']}, 'NDVI cloud free'); 

Link to reproducible example: https://code.earthengine.google.com/2602e7e0f67bd31e1f53379dcd326148

You need to check Landsat documentation to know how to decode BQA from this collection.

3
  • The link is to an example based on SENTINEL/COPERNICUS, not Landsat.
    – intotecho
    Nov 18, 2021 at 1:31
  • @intotecho you are right, thank you. It's fixed now
    – aldo_tapia
    Nov 18, 2021 at 11:41
  • NDVI should be ['B4, 'B3'] for Landsat 5, not ['B5', 'B4']. 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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