简体   繁体   English

如何使用tfrecord中的python API从谷歌地球引擎下载哨兵图像

[英]How to download a sentinel images from google earth engine using python API in tfrecord

While trying to download sentinel image for a specific location, the tif file is generated by default in drive but its not readable by openCV or PIL.Image().Below is the code for the same. 在尝试下载特定位置的标记图像时,默认情况下会在驱动器中生成tif文件,但openCV或PIL.Image()无法读取。下面是相同的代码。 If I use the file format as tfrecord. 如果我使用文件格式作为tfrecord。 There are no Images downloaded in the drive. 驱动器中没有下载图像。

starting_time = '2018-12-15' 
delta = 15  
L = -96.98  
B = 28.78  
R = -97.02  
T = 28.74

cordinates = [L,B,R,T] 
my_scale = 30 
fname = 'sinton_texas_30'


llx = cordinates[0] 
lly = cordinates[1] 
urx = cordinates[2] 
ury = cordinates[3]

geometry = [[llx,lly], [llx,ury], [urx,ury], [urx,lly]]

tstart = datetime.datetime.strptime(starting_time, '%Y-%m-%d') tend =
tstart+datetime.timedelta(days=delta)
collSent = ee.ImageCollection('COPERNICUS/S2').filterDate(str(tstart).split('')[0], str(tend).split(' ')[0]).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)).map(mask2clouds)


medianSent = ee.Image(collSent.reduce(ee.Reducer.median())) cropLand = ee.ImageCollection('USDA/NASS/CDL').filterDate('2017-01-01','2017-12-31').first() 
task_config = {
 'scale': my_scale,
 'region': geometry,
 'fileFormat':'TFRecord'
   }

f1 = medianSent.select(['B1_median','B2_median','B3_median'])


taskSent = ee.batch.Export.image(f1,fname+"_Sent",task_config)
taskSent.start()

I expect the output to be readable in python so I can covert into numpy. 我希望输出在python中可读,所以我可以转换为numpy。 In case of file format 'tfrecord', I expect the file to be downloaded in my drive. 如果文件格式为“tfrecord”,我希望将文件下载到我的驱动器中。

I think you should think about the following things: 我想你应该考虑以下事情:

File format 文件格式

If you want to open your file with PIL or OpenCV, and not with TensorFlow, you would rather use GeoTIFF. 如果要使用PIL或OpenCV打开文件,而不是使用TensorFlow,则宁愿使用GeoTIFF。 Try with this format and see if things are improved. 尝试使用此格式,看看是否有所改进。

Saving to drive 保存到驱动器

Normally saving to your Drive is the default behavior. 通常保存到您的云端硬盘是默认行为。 However, you can try to force writing to your drive: 但是,您可以尝试强制写入驱动器:

ee.batch.Export.image.toDrive(image=f1, ...)

You can further try to setup a folder, where the images should be sent to: 您可以进一步尝试设置文件夹,其中图像应发送到:

ee.batch.Export.image.toDrive(image=f1, folder='foo', ...)

In addition, the Export data help page and this tutorial are good starting points for further research. 此外, 导出数据帮助页面和本教程是进一步研究的良好起点。

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

相关问题 如何从 Google Earth Engine python api 迭代和下载图像集中的每个图像 - How to iterate over and download each image in an image collection from the Google Earth Engine python api Google Earth Engine-从ImageCollection Python API导出RGB图像 - Google Earth Engine - RGB image export from ImageCollection Python API Google Earth Engine Python API 提取错误 MODIS NDVI 值 - Google Earth Engine Python API wrong MODIS NDVI value extracted 使用 python 和 selenium 从 Google 下载图像 - Download images from Google using python with selenium 使用Python无法从Google Earth Engine脚本获得结果 - Can't get result from Google Earth Engine Script using Python 从 ee.reduceRegion 谷歌地球引擎 Python 获取图像 - Get image from ee.reduceRegion Google Earth Engine Python Google Earth Engine Python API 的解决方法,并且在 Python 3 中不支持 `ee.mapclient` - Workaround for Google Earth Engine Python API and no support for `ee.mapclient` in Python 3 如何使用 Google 的视觉 API 从单个调用中注释多个图像? Python - How to annotate MULTIPLE images from a single call using Google's vision API? Python 如何使用python从Google一次下载许多pdf文件? - how to download many pdf files from google at once using python? Python - 无法使用 Google Drive API 从 Google Drive 下载文件 - Python - Can not download file from Google Drive using Google Drive API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM