-
Notifications
You must be signed in to change notification settings - Fork 0
/
evergladesgranules.py
59 lines (51 loc) · 1.67 KB
/
evergladesgranules.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
from datetime import date
from concurrent import futures
import numpy as np
import json
from Spherical.arc import Polygon
from gedi.granuleconstraint import RegionGC
from gedi.api import L2A
import matplotlib.pyplot as plt
"""
Create an L2AAPI object to access the granules' metadata. This initialization
will fail if the credentials in BEX_USER and BEX_PWD are invalid.
"""
api = L2A()
"""
Create a granuleconstraint.GranuleConstraint functor which excludes granules outside
the polygonal national park boundary. Note that the polygon is described in a json
file with a local path.
"""
with open('/Users/fcseidl/EarthLab-local/everglades-national-park_225.geojson') as f:
gj = json.load(f)
points = np.array(gj['features'][0]['geometry']['coordinates'][0]).T
points[0], points[1] = points[1], points[0].copy()
points = np.fliplr(points)
poly = Polygon(points)
granuleconstraint = RegionGC(poly, api)
"""
Plot the outline of the park.
"""
latlon = poly(np.linspace(0, poly.length(), 500))
plt.plot(latlon[1], latlon[0])
plt.show()
"""
Obtain an iterator over every L2A file in the gedi archive with the '.xml'
extension from January 2020.
"""
urls = api.urls_in_date_range(
t_start=date(2020, 1, 1),
t_end=date(2020, 1, 31),
suffix='.xml'
)
"""
Finally, run through the iterator and print each url, along with an index and
a boolean value indicating whether the granule intersects the everglades. Note
that for the loop below to complete in under a day, map should be replaced
with, e.g. a ThreadPoolExecutor.map call to exploit parallelization.
"""
print("index, accepted, url")
n = 1
for accept, url in map(granuleconstraint, urls):
print(f"{n}, {accept}, {url}")
n += 1