1

I am writing a code in Google Earth Engine, in which I want to export the image composite of mean monthly MODIS AOD for 5 years. I am writing the following code, but whenever I try to run it the webpage got hang and says Aw Snap.

var createaodcomposite = function () {
  var yearstart = 2005;
  var yearend = 2009;
  var listaod = ee.Image([]);
  for (var loopYear = yearstart; loopYear <= yearend; loopYear = +1) {
    var start = ee.Date.fromYMD(loopYear, 6, 01);
    var end = ee.Date.fromYMD(loopYear, 12, 25);

    var aod = ee.ImageCollection("MODIS/006/MCD19A2_GRANULES")
      .select('Optical_Depth_047')
      .filterBounds(geometry)
      .filterDate(start, end)
    var finalop = aod.reduce(ee.Reducer.median()).clip(study).rename(loopYear.toString());
    var filename = ("Optical_Depth_047_").concat(loopYear.toString());

    listaod = listaod.addBands(finalop.rename(filename));
  }
  print(listaod, 'List AOD')
  Export.image.toDrive({
    image: listfin,
    description: 'yearly_AOD_ts',
    //Image resolution is 1000m
    scale: 1000,
    region: study,
    crs: 'epsg:4326',
  })
}
var comp = createaodcomposite();
print(comp)
1

1 Answer 1

0

In this case, you're good with client-side loop. That is, if you hadn't turned it into an infinite loop.

for (var loopYear = yearstart; loopYear <= yearend; loopYear = +1)

You want this to be:

for (var loopYear = yearstart; loopYear <= yearend; loopYear += 1)

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.