简体   繁体   English

GEE Python API:将图像导出到 Google Drive 失败

[英]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.在使用 App Engine(在本地主机上)运行的应用程序中使用 GEE Python API,我试图将图像导出到 Google Drive 中的文件。 The task seems to start and complete successfully but no file is created in Google Drive.该任务似乎已成功启动并完成,但未在 Google 云端硬盘中创建文件。

I have tried to execute the equivalent javascript code in GEE code editor and this works, the file is created in Google Drive.我试图在 GEE 代码编辑器中执行等效的 javascript 代码,这有效,该文件是在 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.在 python 中,我尝试了各种方法来启动任务,但它总是给我相同的结果:任务完成但没有创建文件。

My python code is as follows:我的python代码如下:

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.在打印的任务列表中,任务的状态从READY 到RUNNING 然后COMPLETED。 But after completion no file is created in Google Drive in my folder "GEEtest" (nor anywhere else).但是完成后,在我的文件夹“GEEtest”(或其他任何地方)中的 Google Drive 中不会创建任何文件。

What am I doing wrong?我究竟做错了什么?

You can't pass a dictionary of arguments directly in python.您不能直接在 python 中传递参数字典。 You need to pass it using the kwargs convention (do a web search for more info).您需要使用 kwargs 约定传递它(进行网络搜索以获取更多信息)。 Basically, you just need to preface the task_config argument with double asteriks like this:基本上,您只需要在task_config参数task_config加上双星号,如下所示:

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).然后按原样继续(我假设您在下一行中使用task.config而不是task_config是一个错字)。 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.另请注意,您可以直接查询任务(例如使用task.status() ),它可能会提供有关任务失败的时间/原因的更多信息。 This isn't well documented as far as I can tell but you can read about it in the API code .据我所知,这并没有得到很好的记录,但您可以在API 代码中阅读它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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