Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. If I use the file format as 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. In case of file format 'tfrecord', I expect the file to be downloaded in my drive.

like image 859
Mohit Anand Avatar asked Mar 23 '19 11:03

Mohit Anand


People also ask

How do I export an image from Google Earth Engine?

To export an image to an asset in your Earth Engine assets folder, use Export. image.

Does Google Earth Engine Support Python?

In addition to the web-based IDE Google Earth Engine also provides a Python API that can be used on your local machine without the need to utilize a browser, although the capabilities of this API are reduced compared to the Code Editor/IDE.


1 Answers

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

like image 89
anki Avatar answered Dec 10 '22 10:12

anki