-
Notifications
You must be signed in to change notification settings - Fork 2
/
Download_Temp_GEE.py
74 lines (72 loc) · 3.27 KB
/
Download_Temp_GEE.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 13 12:53:47 2019
@author: David Helman
"""
# ============================================================================ #
# This program is called by 'run_RK4_2D.py' to download MODIS LST TIF files
# from GEE for a specific AOI and period. 'run_RK4_2D.py' then reads a single
# TIF file and calculate the population of the insect pest as a 2D matrix for
# a single day (hack for now).
#
# Author: David Helman
# Date: 13 January, 2019
# ============================================================================ #
def gee_temp(start_date,end_date):
import datetime
import ee
import os
from ee import batch
ee.Initialize()
# start_date = '2018-04-12'
# end_date = '2018-04-16'
os.chdir('/Users/davidhelman/Google Drive (davidhelman1@gmail.com)/')
ImageCollection = 'MODIS/006/MYD11A1' # Image collection GEE's name
fc = ee.Geometry.Polygon( [[35.462837219238280,32.479356572655625]\
, [35.548667907714844,32.479356572655625]\
, [35.548667907714844,32.539288337047424]\
, [35.462837219238280,32.539288337047424]])
folder_to_save_google_drive = 'ts_RS-PestDyn'
crs = 'EPSG:4326' # Projection
product = "MYD11A1_LST_DAY" # Product name
var = ['LST_Day_1km'] # Product's variable
# Get spatial resolution:
info = ee.Image(ee.ImageCollection('MODIS/006/MYD11A1').first())
Projection_info = info.projection()
resolution = Projection_info.nominalScale().getInfo()
print(resolution)
# Get image collection:
collection = ee.ImageCollection(ImageCollection)\
.filterDate(start_date,end_date).filterBounds(fc)
data_to_donwload = collection.sort('system:start_time') # arrange by date
image_id_info_data = ee.FeatureCollection(data_to_donwload)
features = image_id_info_data.getInfo()['features']#[0]['id']
IDlist = []
date_list = []
# Loop over images in collection (get name with conventional dates)"
for ID in features:
# Each image has an ID with unix date format
date = ID['properties']['system:time_start']
stringdate = str(date)
image_id = [ID][0]['id']
IDlist.append(image_id)
date_list.append(datetime.datetime\
.fromtimestamp(float(stringdate[0:10])+90000)\
.strftime('%Y-%m-%d'))
# Loop over list and import images (+given name) to Google Drive folder:
for ID, date in zip(IDlist, date_list):
clip_enddata = ee.Image(ID).select(var).clip(fc)
file_name = product+"_"+ID[18:28]
out = batch.Export.image.toDrive(clip_enddata\
,folder=folder_to_save_google_drive\
,description=file_name\
,scale=resolution\
,maxPixels=298523062\
,region = fc.bounds()\
.getInfo()['coordinates']\
,crs=crs)
process = batch.Task.start(out)
print file_name
import time
time.sleep(20)