5

I am trying to apply a mask cloud in a SAVI collection (LANDSAT) to get a chart with time variations between pixels.

var region = table3

    Map.addLayer(table3)

    var col = ee.ImageCollection('LANDSAT/LE7_SR')
        .filterDate('2004-01-01', '2011-12-31')
        .filterBounds(table3)
        .filter(ee.Filter.eq('WRS_PATH', 1))
        .filter(ee.Filter.eq('WRS_ROW', 72));

        print(col)

    // Mask clouds
    var col_noclouds = col.map(function(img) {
                       var mask = 
    img.select(['cfmask']).neq(4).neq(1).neq(2).neq(3)
                       return img.updateMask(mask)
                       })

    // Median image
    var medians = ee.Image(col_noclouds.median())

    var clipper = medians.clip(table3)


    // A function to compute Soil Adjusted Vegetation Index.
    var SAVI = function(image) {
      return clipper.expression(
          '(1 + L) * float(nir - red)/ (nir + red + L)',
          {
            'nir': image.select('B5'),
            'red': image.select('B4'),
            'L': 0.5
          }).set('system:time_start', image.get('system:time_start'));
    };

    // Shared visualization parameters.
    var vis = {
      min: 0,
      max: 1,
      palette: [
          'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
          '74A901', '66A000', '529400', '3E8601', '207401', '056201',
          '004C00', '023B01', '012E01', '011D01', '011301'
      ]
    };


    var image = ee.ImageCollection(col) 
       .map(SAVI);

    print(image)

    Map.addLayer(image,vis);


    var TS5 = Chart.image.seriesByRegion(image, region,  
    ee.Reducer.mean(),'constant', 500, 'system:time_start').setOptions({
              title: 'NDVI Long-Term Time Series',
              vAxis: {title: 'constant'},
    });
    print(TS5);

I can make the chart for "image" (collection with SAVI function) but I do not know how to insert the cloud mask.

Any recommendation?

1 Answer 1

4

The problem is in the creation of the cloud mask. Use:

var mask = image.select(['cfmask']).neq((2,4))

instead:

var mask = image.select(['cfmask']).neq(4).neq(1).neq(2).neq(3)

Value 2 and 4 are for cloud shadows and clouds in cfmask.

With a reproducible example:

var col = ee.ImageCollection('LANDSAT/LE7_SR')
    .filterDate('2004-01-01', '2011-12-31')
    .filter(ee.Filter.eq('WRS_PATH', 1))
    .filter(ee.Filter.eq('WRS_ROW', 72));

// Mask clouds
var col_noclouds = col.map(function(img) {
  var mask = img.select(['cfmask']).neq(4).neq(1).neq(2).neq(3);
      return img.updateMask(mask);
});

// A function to compute Soil Adjusted Vegetation Index.
var SAVI = function(image) {
  var img = image.expression(
      '(1 + L) * float(nir - red)/ (nir + red + L)',
      {
        'nir': image.select('B5'),
        'red': image.select('B4'),
        'L': 0.5
      }).set('system:time_start', image.get('system:time_start'));
  var mask = image.select(['cfmask']).neq((2,4));
  return img.updateMask(mask);
};

// Shared visualization parameters.
var vis = {
  min: 0,
  max: 1,
  palette: [
      'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
      '74A901', '66A000', '529400', '3E8601', '207401', '056201',
      '004C00', '023B01', '012E01', '011D01', '011301'
  ]
};


var image = ee.ImageCollection(col).map(SAVI);

Map.addLayer(ee.Image(image.first()),vis);

By the way, cfmsk is not used anymore. Change to pixel_qa_band

Your Answer

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

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