1

I have been working with GEE to get retrievals AOD values from MCD19A2.006: Terra & Aqua MAIAC. I've seen in some code that I can give it a scale, or the best pixel quality to download data. But so far, I couldn't understand the meaning of scale and how to give a code to get the best quality.

Also in the user's guide presents a table with two columns (valid range and scale). So, that's why I am confused, because when I'm using scale, I don't know if it's refers to the valid range or scale.

> var  maiac_aod_prj = function(image) {   var im = image.select(0);  
> return image.reproject({
>     crs: maiac_aod_cal2016.first().projection(),
>     scale: 1000})}; //--> I am refering to this scale, if I change the value, data change too.
2

1 Answer 1

1

Here is the solution

// import data
var AOD = ee.ImageCollection("MODIS/006/MCD19A2_GRANULES");

// Define dates
var iniDate = ee.Date.fromYMD(2019,11,1);
var endDate = ee.Date.fromYMD(2019,12,31);

// bands
var modisBands = ['Optical_Depth_055'];


// helper function to extract the QA bits
function getQABits(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.
function maskQuality(image) {
  // Select the QA band.
  var QA = image.select('AOD_QA');
  // Get the internal_cloud_algorithm_flag bit.
  var internalQuality = getQABits(QA,8, 11, 'internal_quality_flag');
  // Return an image masking out cloudy areas.
  return image.updateMask(internalQuality.eq(0));
}

// create cloud free composite
var AODmaskQ = AOD.filter(ee.Filter.or(
  ee.Filter.date('2019-01-01', '2019-02-01'),
  ee.Filter.date('2019-11-01', '2020-01-01')
  ))
                             .map(maskQuality)
                             .select(modisBands)
                             .filterBounds(geometry);

// create composite with quality assurance (without clouds) 
var AODwithoutmask = AOD.filter(ee.Filter.or(
  ee.Filter.date('2019-01-01', '2019-02-01'),
  ee.Filter.date('2019-11-01', '2020-01-01')
  ))
                             .select(modisBands)
                             .filterBounds(geometry);


// vis parameters
var viz = {
  min: 0,
  max: 350,
  bands:['Optical_Depth_055'],
  palette: ['black', 'blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};
var composite1 = AODmaskQ.mean().clip(geometry)
var composite2 = AODwithoutmask.mean().clip(geometry)

// add the cloud free composite
Map.addLayer(composite1,viz,'Quality mask');
Map.setCenter(-46.63203, -23.55221, 9);
// add the cloud composite
Map.addLayer(composite2,viz,'Without mask');
Map.setCenter(-46.63203, -23.55221, 9);
var AOD_mean = AODmaskQ.map(function(img) {
   return img.reduceRegions({
       collection: geometry, 
       reducer: ee.Reducer.mean(),
        scale: 1000,
     }).map(function(f){
         return f.set('date', img.date());
     });
 }).flatten();
 
 Export.image.toDrive({
   image:AODmaskQ.mean(), 
   description: 'geometry',
   scale: 1000,
   region:geometry 
      });
 
 Export.table.toDrive({ 
   collection:AOD_mean.filter(ee.Filter.notNull(["mean"])),
   folder: "Google EE results",
   description: 'RMSP mask', 
   selectors:([          
     "date",          
     "mean"
     ]),
   });

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.