2

I am trying to get daily estimates for AOD per Census tract in CA from the year 2000-2015. When I run the loop to filter to the daily level. I get the Error: Image.reduceRegions: Unable to find a crs. I know this is because some of the images do not have bands. (I'm assuming this is from missing data of AOD measurements for that particular day). I'm not sure how to filter out these images within the loop in order to get it to run. Here is a link to my GEE code: https://code.earthengine.google.com/98a73c8ea6e71633c3e14258b39e759d:

var CACensus= ee.FeatureCollection('users/s1mcelroy1287/tl_2010_06_tract10');
var filtAOD01= AOD.filterDate('2001-01-01','2001-12-31');
var filtAOD00=AOD.filterDate('2000-03-01','2000-12-31');



 //Creating function to get mean AOD per Census
 var calcmeanAOD=function(image){
 var AODpercensus=image.reduceRegions(
{   

  collection:CACensus,
  reducer:ee.Reducer.mean(),
  scale:1000,

})

return AODpercensus;
};

//Writing loop for daily AOD measurement per Census tract across the CA for 2001

var myList=ee.List([]);
   for (var day=1; day<366; day++){
   var data=filtAOD01.filter(ee.Filter.calendarRange(day,day,'day_of_year'));
   var AOD01 = data.select('Optical_Depth_047').mean();
   var AOD01Census=calcmeanAOD(AOD01);
   AOD01Census=AOD01Census.set('day_of_year',day);
   myList=myList.add(AOD01Census);
   var myListFlat=myList.flatten();
   var myList01=ee.FeatureCollection(myListFlat);
  }

 Export.table.toDrive(myList01,'AOD_Zcta_00');

1 Answer 1

1

I think you best restructure your approach: first make the image collection of available images, then apply reduceRegions() on that filtered image collection:

// first make an image collection for the available days
var imgColPerday = ee.ImageCollection.fromImages(
                      ee.List.sequence(1,366).map(function(day){
  var image = filtAOD01.filter(ee.Filter.calendarRange(day,day,'day_of_year'))
            .select('Optical_Depth_047').mean();
  return image.set('day_of_year', day) // set the day
  // filter out empty images
})).filter(ee.Filter.listContains('system:band_names', 'Optical_Depth_047'));

// then apply reduceRegions
var data =  ee.FeatureCollection(imgColPerday.map(function(image){

  // calculate data
  var AOD01Census = image.reduceRegions({   
      collection: CACensus,
      reducer: 'mean',
      scale: 1000,
  }).map(function(feat){
    return feat.set('day_of_year',image.get('day_of_year'));
  });  

  return AOD01Census;
})).flatten()
  // probably you want to filter out null values
  .filter(ee.Filter.notNull([ 'mean']));

print('data', data)

link code

1
  • Thank you! This worked great!
    – Sara
    Commented Apr 3, 2020 at 20:39

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.