简体   繁体   中英

GEE Python API: Export image to Google Drive fails

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?

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 eg 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 .

我认为该文件是在用于 Python API 的“服务帐户”的谷歌驱动器上生成并存储的,而不是在您使用网络代码编辑器时通常使用的私人帐户上。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM