0

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)))
3
  • For code review there is the Code Review Stack Exchange.
    – PolyGeo
    Oct 19, 2022 at 20:45
  • See this post: gorelick.medium.com/fast-er-downloads-a2abd512aa26 Oct 20, 2022 at 11:18
  • Thanks Noel, I have tried the method that is introduced in your referenced article. the code was for exporting image, however there was also a link to another code for exporting time series ( gist.github.com/gorelick-google/…). when I tried to run either of those codes following error occured: \Users\saeed\anaconda3\envs\MyPrograms\lib\multiprocessing\queues.py", line 368, in get return _ForkingPickler.loads(res) AttributeError: Can't get attribute 'getResult' on <module 'main' (built-in)>
    – Saeed Nadi
    Oct 20, 2022 at 17:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.