[英]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: 我想你应该考虑以下事情:
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. 尝试使用此格式,看看是否有所改进。
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.