当在 Python 中使用 Google Earth Engine 并通过服务帐户进行身份验证时,为什么导出到云端硬盘的内容为空?
我正在使用Python的Google Earth Engine获取Sentinel-2组成,然后将其下载到我的Google Drive。在进行手动身份验证时,一切正常工作:
ee.Authenticate()
ee.Initialize()
但是,由于我想在工作流程中使用我的代码,并且不要一直使用手动身份验证,因此我使用的是一个服务帐户,例如diced 在这里。它可以正常工作,我可以使用GEE而无需手动执行任何操作:
# get service account
service_account = '[email protected]'
# get credentials
credentials = ee.ServiceAccountCredentials(service_account, gee_secret.json)
ee.Initialize(credentials)
为了将文件导出到Google驱动器,我使用以下代码:
# export options
export_config = {
'scale':10,
'region':aoi, #aoi is a polygon
'crs': 'EPSG:3031',
}
file_name = "test"
# export to drive
task = ee.Batch.Export.iamge.toDrive(image, file_name, **export_config)
task.start()
使用两个身份验证方法,此任务已成功完成(任务的状态已“完成”)。但是,只有在使用手动身份验证时,我才能在驱动器中看到我的导出图像。使用自动身份验证时,我的驱动器为空。
其他人已经问了一个类似的问题在这里。这里可能的想法是,图像文件已导出到服务帐户的Google驱动器,而不是我个人的Google Drive。但是,我不确定如何访问其他驱动器。
有人想知道如何解决此问题(=如何访问导出的文件?)。还是有另一个用于自动身份验证的解决方案,其中文件将在我的个人Google驱动器上使用?
I'm using the Google Earth Engine in Python to get a Sentinel-2 composition and download it to my google drive. When doing a manual authentication everything is working fine:
ee.Authenticate()
ee.Initialize()
However, as I want to use my code in a workflow and don't use all the time the manual authentication, I am using a service account, like described here. It works fine and I can use GEE without doing anything manually:
# get service account
service_account = '[email protected]'
# get credentials
credentials = ee.ServiceAccountCredentials(service_account, gee_secret.json)
ee.Initialize(credentials)
In order to export my File to Google Drive I'm using following code:
# export options
export_config = {
'scale':10,
'region':aoi, #aoi is a polygon
'crs': 'EPSG:3031',
}
file_name = "test"
# export to drive
task = ee.Batch.Export.iamge.toDrive(image, file_name, **export_config)
task.start()
With both authentication methods this task is successfully finished (The status of the task is 'Completed'). However, only when using the manual authentication, I can see my exported image in my Drive. When using the automatic authentication, my Drive is empty.
Someone else already asked a similar question here. A possible idea here was that the image file is exported to the Google Drive of the service account and not to my personal Google Drive. However, I am not sure how to access this other Drive.
Does anyone have an idea how to solve this (=how to access the exported file?). Or have another solution for automatic authentication in which the file will be at my personal Google Drive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢 DaImTo 和 Yancy Godoy 的提示!有了这些我就能找到解决办法。我将把它发布在这里,这样它可能对其他人也有用。
事实上,导出到 Google Drive 的效果非常好,但是它没有导出到我个人的 Google Drive,而是导出到服务帐户的 Google Drive。因此,为我的服务帐户添加对 Google Drive 的访问权限非常重要(请参阅 这里)。
您可以在下面找到完整的工作流程。对于下载,我使用 PyDrive
Many thanks to the hints of DaImTo and Yancy Godoy! With these I could find a solution. I will post it here, so that it is maybe useful for others as well.
Indeed the export to the Google Drive worked perfectly, however it was not exported to my personal Google Drive, but to the Google Drive of the service account. It was therefore important to add the access to Google Drive for my service account (see here).
In the following you can find a complete workflow. For the downloading I am using PyDrive