|
20 | 20 | import geopandas as gpd |
21 | 21 | import matplotlib.pyplot as plt |
22 | 22 | from sliderule import icesat2 |
23 | | -from utils import parse_command_line |
24 | | - |
25 | | -############################################################################### |
26 | | -# LOCAL FUNCTIONS |
27 | | -############################################################################### |
28 | | - |
29 | | -def process_atl06_algorithm(parms, asset): |
30 | | - |
31 | | - # Latch Start Time |
32 | | - perf_start = time.perf_counter() |
33 | | - |
34 | | - # Request ATL06 Data |
35 | | - gdf = icesat2.atl06p(parms, asset) |
36 | | - |
37 | | - # Latch Stop Time |
38 | | - perf_stop = time.perf_counter() |
39 | | - |
40 | | - # Build DataFrame of SlideRule Responses |
41 | | - num_elevations = len(gdf) |
42 | | - |
43 | | - # Display Statistics |
44 | | - perf_duration = perf_stop - perf_start |
45 | | - print("Completed in {:.3f} seconds of wall-clock time".format(perf_duration)) |
46 | | - if num_elevations > 0: |
47 | | - print("Reference Ground Tracks: {}".format(gdf["rgt"].unique())) |
48 | | - print("Cycles: {}".format(gdf["cycle"].unique())) |
49 | | - print("Received {} elevations".format(num_elevations)) |
50 | | - else: |
51 | | - print("No elevations were returned") |
52 | | - |
53 | | - # Return DataFrame |
54 | | - return gdf |
| 23 | +from utils import initialize_client |
55 | 24 |
|
56 | 25 | ############################################################################### |
57 | 26 | # MAIN |
58 | 27 | ############################################################################### |
59 | 28 |
|
60 | 29 | if __name__ == '__main__': |
61 | 30 |
|
62 | | - # Set Script Defaults |
63 | | - cfg = { |
64 | | - "url": 'localhost', |
65 | | - "organization": None, |
66 | | - "asset": 'atlas-local', |
67 | | - "region": 'examples/grandmesa.geojson', |
68 | | - "verbose": True |
69 | | - } |
70 | | - |
71 | | - # Parse Configuration Parameters |
72 | | - parse_command_line(sys.argv, cfg) |
73 | | - |
74 | 31 | # Configure Logging |
75 | 32 | logging.basicConfig(level=logging.INFO) |
76 | 33 |
|
77 | | - # Region of Interest # |
78 | | - region = icesat2.toregion(cfg["region"]) |
79 | | - |
80 | | - # Configure SlideRule # |
81 | | - icesat2.init(cfg["url"], cfg["verbose"], organization=cfg["organization"]) |
82 | | - |
83 | | - # Build ATL06 Request # |
84 | | - parms = { |
85 | | - "poly": region["poly"], |
86 | | - "raster": region["raster"], |
87 | | - "srt": icesat2.SRT_LAND, |
88 | | - "cnf": icesat2.CNF_SURFACE_HIGH, |
89 | | - "atl08_class": ["atl08_ground"], |
90 | | - "ats": 10.0, |
91 | | - "cnt": 10, |
92 | | - "len": 40.0, |
93 | | - "res": 20.0, |
94 | | - "maxi": 1 |
95 | | - } |
96 | | - |
97 | | - # Parse Algorithm Parameters |
98 | | - parse_command_line(sys.argv, parms) |
| 34 | + # Initialize Client # |
| 35 | + parms, cfg = initialize_client(sys.argv) |
99 | 36 |
|
100 | 37 | # Get ATL06 Elevations |
101 | | - atl06 = process_atl06_algorithm(parms, cfg["asset"]) |
| 38 | + tstart = time.perf_counter() |
| 39 | + atl06 = icesat2.atl06p(parms, cfg["asset"]) |
| 40 | + perf_duration = time.perf_counter() - tstart |
102 | 41 |
|
103 | | - # Check Results Present |
104 | | - if len(atl06) == 0: |
105 | | - print("No ATL06 data available") |
| 42 | + # Display Statistics |
| 43 | + print("Completed in {:.3f} seconds of wall-clock time".format(perf_duration)) |
| 44 | + if len(atl06) > 0: |
| 45 | + print("Reference Ground Tracks: {}".format(atl06["rgt"].unique())) |
| 46 | + print("Cycles: {}".format(atl06["cycle"].unique())) |
| 47 | + print("Received {} elevations".format(len(atl06))) |
| 48 | + else: |
| 49 | + print("No elevations were returned") |
106 | 50 | sys.exit() |
107 | 51 |
|
| 52 | + # Display Profile |
| 53 | + print("\nTiming Profiles") |
| 54 | + for key in icesat2.profiles: |
| 55 | + print("{:16}: {:.6f} secs".format(key, icesat2.profiles[key])) |
| 56 | + |
108 | 57 | # Calculate Extent |
109 | | - lons = [p["lon"] for p in region["poly"]] |
110 | | - lats = [p["lat"] for p in region["poly"]] |
| 58 | + lons = [p["lon"] for p in parms["poly"]] |
| 59 | + lats = [p["lat"] for p in parms["poly"]] |
111 | 60 | lon_margin = (max(lons) - min(lons)) * 0.1 |
112 | 61 | lat_margin = (max(lats) - min(lats)) * 0.1 |
113 | 62 | extent = (min(lons) - lon_margin, max(lons) + lon_margin, min(lats) - lat_margin, max(lats) + lat_margin) |
|
0 commit comments