I have a list of 3800 coordinates which corresponds to the air pollution monitoring stations. I am using python API to extract "MODIS/006/MCD19A2_GRANULES" for those points and export the list to my local drive to be used within another application. I know that using getInfo() is not an efficient way of unwrapping featureclass and printing values on screen or using .to_csv() command to write the list to a csv file. So, I have used featureClass.getDownloadURL() to download the file, however it is still extremely slow. And the case is became worse when I tried to repeat it for 15 years! Here is my code.
Can anyone show me a more efficient way?
AOD = ee.ImageCollection('MODIS/006/MCD19A2_GRANULES')
allnaps = pd.read_csv('all_naps_cmaq_population_lcover_elev_met.csv')
allyear=[]
for index, row in allnaps.iterrows():
year=str(row['year'])[0:4]
allyear.append(int(year))
allyears=np.unique(allyear)
url=[]
for yr in allyears:
feats=[]
allnaps = pd.read_csv('all_naps_cmaq_population_lcover_elev_met.csv')
for index, row in allnaps.iterrows():
year=str(row['year'])[0:4]
yr=str(yr)
if year!=yr:
continue
NAPSID = int(row['NAPSID'])
location_latitude=row['Latitude']
location_longitude=row['Longitude']
coord=[location_longitude, location_latitude]
point = ee.Geometry.Point(coord)
feats.append(ee.Feature(point, {'NAPSID': NAPSID, 'year':year}))
fc = ee.FeatureCollection(feats)
AODimg=AOD.filterBounds(fc).filterDate(yr+'-01-01', yr+'-12-31').mean()
reducer = ee.Reducer.mean()
data = AODimg.reduceRegions(fc, reducer.setOutputs(['Optical_Depth_047']), 1000)
print('downloading year:', yr)
url.append(data.getDownloadURL('csv', ['Optical_Depth_047','NAPSID','year'], 'AOD'+str(yr)))