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.

1 Answer 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])

// 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')

// 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')

// vis parameters
var viz = {
  min: 0,
  max: 350,
  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,
         return f.set('date', img.date());
   description: 'geometry',
   scale: 1000,
   folder: "Google EE results",
   description: 'RMSP mask', 

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.