GEE Python API: Export image to Google Drive fails

一个人想着一个人 提交于 2019-12-13 04:08:25

问题


Using GEE Python API in an application running with App Engine (on localhost), I am trying to export an image to a file in Google Drive. The task seems to start and complete successfully but no file is created in Google Drive.

I have tried to execute the equivalent javascript code in GEE code editor and this works, the file is created in Google Drive. In python, I have tried various ways to start the task, but it always gives me the same result: the task completes but no file is created.

My python code is as follows:

landsat = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_123032_20140515').select(['B4', 'B3', 'B2'])

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])

task_config = {
    'description': 'TEST_todrive_desc',
    'scale': 30,  
    'region': geometry,
    'folder':'GEEtest'
}

task = ee.batch.Export.image.toDrive(landsat, 'TEST_todrive', task_config)
ee.batch.data.startProcessing(task.id, task.config)
# Note: I also tried task.start() instead of this last line but the problem is the same, task completed, no file created. 

# Printing the task list successively 
for i in range(10): 
    tasks = ee.batch.Task.list()
    print(tasks)
    time.sleep(5)

In the printed task list, the status of the task goes from READY to RUNNING and then COMPLETED. But after completion no file is created in Google Drive in my folder "GEEtest" (nor anywhere else).

What am I doing wrong?


回答1:


You can't pass a dictionary of arguments directly in python. You need to pass it using the kwargs convention (do a web search for more info). Basically, you just need to preface the task_config argument with double asteriks like this:

task = ee.batch.Export.image.toDrive(landsat, 'TEST_todrive', **task_config)

Then proceed as you have (I assume your use of task.config rather than task_config in the following line is a typo). Also note that you can query the task directly (using e.g. task.status()) and it may give more information about when / why the task failed. This isn't well documented as far as I can tell but you can read about it in the API code.



来源:https://stackoverflow.com/questions/55882991/gee-python-api-export-image-to-google-drive-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!