1 ## Search/Download - sandbox
2 from cmr
import CollectionQuery
, GranuleQuery
12 #MOD14: bounding box = Colorado (gps coord sorted lat,lon; counterclockwise)
13 MOD14granules
= api
.parameters(
17 polygon
=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)],
18 temporal
=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end
20 print "MOD14 gets %s hits in this range" % MOD14granules
.hits()
21 MOD14granules
= api
.get(10)
23 #MOD03: geoloc data for MOD14
24 MOD03granules
= api
.parameters(
28 polygon
=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)],
29 temporal
=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end
31 print "MOD03 gets %s hits in this range" % MOD03granules
.hits()
32 MOD03granules
= api
.get(10)
34 #VNP14: fire data, res 750m
35 VNP14granules
= fire
.parameters(
38 polygon
=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)],
39 temporal
=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end
41 print "VNP14 gets %s hits in this range" % VNP14granules
.hits()
42 VNP14granules
= fire
.get(10)
44 #VNP14IMGTDL_NRT: granules with resolution 375m
45 VNP14hiresgranules
= fire
.parameters(
46 short_name
="VNP14IMGTDL_NRT",
48 polygon
=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)],
49 temporal
=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end
51 print "VNP14(hi-res) gets %s hits in this range" % VNP14hiresgranules
.hits()
52 VNP14hiresgranules
= fire
.get(10)
54 #VNP03MODLL: geoloc data for VNP14
55 VNP03granules
= fire
.parameters(
56 short_name
="VNP03MODLL",
58 polygon
=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)],
59 temporal
=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end
61 print "VNP03 gets %s hits in this range" % VNP03granules
.hits()
62 VNP03granules
= fire
.get(10)
65 def download(granules
):
66 for granule
in granules
:
67 url
= granule
['links'][0]['href']
68 filename
=os
.path
.basename(urlparse
.urlsplit(url
).path
)
70 # to store as object in memory (maybe not completely downloaded until accessed?)
71 # with requests.Session() as s:
72 # data.append(s.get(url))
74 # download - a minimal code without various error checking and corrective actions
75 # see wrfxpy/src/ingest/downloader.py
77 chunk_size
= 1024*1024
79 r
= requests
.get(url
, stream
=True)
80 if r
.status_code
== 200:
81 content_size
= int(r
.headers
['Content-Length'])
82 print 'downloading %s as %s size %sB' % (url
, filename
, content_size
)
83 with
open(filename
, 'wb') as f
:
84 for chunk
in r
.iter_content(chunk_size
):
87 print('downloaded %sB of %sB' % (s
, content_size
))
89 print 'cannot connect to %s' % url
90 print 'web request status code %s' % r
.status_code
91 print 'Make sure you have file ~/.netrc permission 600 with the content'
92 print 'machine urs.earthdata.nasa.gov\nlogin yourusername\npassword yourpassword'
94 except Exception as e
:
95 print 'download failed with error %s' % e
98 BE CAREFUL!! - the script below triggers automatic download of VERY
102 #MOD14 = download(MOD14granules)
103 MOD03
= download(MOD03granules
)
104 VNP14
= download(VNP14granules
)
105 VNP14hires
= download(VNP14hiresgranules
)
106 VNP03
= download(VNP03granules
)