1

In a previous question of mine, I exported all images from PROBA-V satellite for a particular month without removing the bad quality pixels. Now I want to remove the bad quality pixels before exporting the images but I don't know how to write the code.

Below, I created a var called mask_vnpa2_img in order to set the bits according to the bit mask (called SM) (here is the PROBA-V product) but I can't figure out how to incorporate it into the code:

Map.centerObject(table);

// Here I'm trying to set the Bits according to table 'Bitmask for QF_Cloud_Mask'
var mask_vnpa2_img = function(image) {
  var qa = image.select('SM');
  var CloudIceShadowFlag = bitwiseExtract(qa, 0, 2)
  var LandSea = bitwiseExtract(qa, 3)

  var mask = ee.Image(1)
    .and(CloudIceShadowFlag.eq(0)) // Clear sky conditions
    .and(LandSea.eq(1)) // Land pixels
    
      return image.updateMask(mask);
};

//Map.addLayer(table);
Map.centerObject(table);

// Project the image to Mollweide.
var wkt = ' \
  PROJCS["World_Mollweide", \
    GEOGCS["GCS_WGS_1984", \
      DATUM["WGS_1984", \
        SPHEROID["WGS_1984",6378137,298.257223563]], \
      PRIMEM["Greenwich",0], \
      UNIT["Degree",0.017453292519943295]], \
    PROJECTION["Mollweide"], \
    PARAMETER["False_Easting",0], \
    PARAMETER["False_Northing",0], \
    PARAMETER["Central_Meridian",0], \
    UNIT["Meter",1], \
    AUTHORITY["EPSG","54009"]]';

var proj_mollweide = ee.Projection(wkt);

var era5_2mt = ee.ImageCollection('VITO/PROBAV/C1/S1_TOC_100M')
                   .select('NDVI')
                   .filterDate('2018-02-01', '2018-03-01')
                   // clip to your study area
                   .map(function(image) {return image.clip(table)});

var study_area = era5_2mt.map(function(img){

  var s_ts = img.get("system:time_start");    // get the 'system:time start' property from the image

  img = ee.Image(img)
                .subtract(20)
                .divide(250)
                .set("system:time_start", s_ts)
                .set('fileName', ee.String('image_').cat(ee.Date(s_ts).format().slice(0,10)));

  return(img);
  
});

print(study_area);

// Function to export an image to Google Drive
var exportImage = function(image, fileName) {
  Export.image.toDrive({
    image: image,
    description: fileName,
    folder: 'GEE_exports',
    scale: 100,
    region: table,
    fileFormat: 'GeoTIFF'
  });
};

//print(monthlyLAI.aggregate_array('fileName'))

study_area.aggregate_array('fileName').evaluate(function (fileNames) {
  fileNames.forEach(function(fileName) {
    var image = study_area
      .filter(ee.Filter.eq('fileName', fileName))
      .first();
    Map.addLayer(image, {}, fileName, false);
    exportImage(image, fileName);
  });
});

Here is the shapefile I'm using and the code.

1 Answer 1

1

You need to map the mask_vnpa2_img() function to the image collection and select the NDVI band after mapping. The bitwiseExtract() function was missing in your code, I added it.

var bitwiseExtract = function(input, fromBit, toBit) {
   if (toBit === undefined) toBit = fromBit
  var maskSize = ee.Number(1).add(toBit).subtract(fromBit)
  var mask = ee.Number(1).leftShift(maskSize).subtract(1)
  return input.rightShift(fromBit).bitwiseAnd(mask)
}
var mask_vnpa2_img = function(image) {
  var qa = image.select('SM');
  var CloudIceShadowFlag = bitwiseExtract(qa, 0, 2)
  var LandSea = bitwiseExtract(qa, 3)

  var mask = ee.Image(1)
    .and(CloudIceShadowFlag.eq(0)) // Clear sky conditions
    .and(LandSea.eq(1)) // Land pixels
      return image.updateMask(mask);
};


var era5_2mt = ee.ImageCollection('VITO/PROBAV/C1/S1_TOC_100M')
                   .filterDate('2018-02-01', '2018-03-01')
                    // CHANGE HERE 
                   .map(function(image) {return mask_vnpa2_img(image).select('NDVI').clip(table)});
2

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.