Skip to content

Commit 5e7d7ad

Browse files
committed
improvements to algorithm test
1 parent 66aeee1 commit 5e7d7ad

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

tests/algorithm.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,7 @@ def expread(resource, asset):
8282
#
8383
# ATL03 Photon Cloud Request
8484
#
85-
def phread(resource, asset):
86-
87-
# Build Region Poly
88-
region = [
89-
{ "lat": -80.75, "lon": -70.00 },
90-
{ "lat": -81.00, "lon": -70.00 },
91-
{ "lat": -81.00, "lon": -65.00 },
92-
{ "lat": -80.75, "lon": -65.00 },
93-
{ "lat": -80.75, "lon": -70.00 }
94-
]
85+
def phread(resource, asset, region):
9586

9687
# Build ATL06 Request
9788
parms = { "poly": region,
@@ -122,33 +113,44 @@ def phread(resource, asset):
122113
#
123114
# Plot Actual vs Expected
124115
#
125-
def plotresults(act, exp, ph):
116+
def plotresults(act, exp, ph, region):
117+
118+
# Build Box
119+
box_lon = [coord["lon"] for coord in region]
120+
box_lat = [coord["lat"] for coord in region]
121+
126122
# Create Plot
127-
fig = plt.figure(num=None, figsize=(12, 6))
123+
fig = plt.figure(num=None, figsize=(16, 10))
128124

129125
# Plot Ground Tracks
130-
ax1 = plt.subplot(131,projection=cartopy.crs.PlateCarree())
126+
ax1 = plt.subplot(131,projection=cartopy.crs.SouthPolarStereo())
127+
ax1.gridlines()
131128
ax1.set_title("Ground Tracks")
132-
ax1.scatter(act.geometry.x, act.geometry.y, s=1.5, color='r', zorder=3, transform=cartopy.crs.PlateCarree())
129+
ax1.plot(act.geometry.x, act.geometry.y, linewidth=0.5, color='r', zorder=2, transform=cartopy.crs.Geodetic())
130+
ax1.plot(box_lon, box_lat, linewidth=1.5, color='b', zorder=3, transform=cartopy.crs.Geodetic())
133131
ax1.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')
134132
ax1.add_feature(cartopy.feature.LAKES)
135-
ax1.set_extent((-180,180,-90,90),crs=cartopy.crs.PlateCarree())
136-
ax1.gridlines(xlocs=np.arange(-180.,181.,60.), ylocs=np.arange(-90.,91.,30.))
133+
ax1.set_xmargin(1.0)
134+
ax1.set_ymargin(1.0)
137135

138136
# Plot Elevations
139137
ax2 = plt.subplot(132)
140138
ax2.set_title("Along Track Elevations")
141-
gt1r = act[act["gt"] == icesat2.GT1R]
142-
ax2.scatter(gt1r["time"].values, gt1r["h_mean"].values, s=0.5, color='b', zorder=3)
139+
act_gt1r = act[act["gt"] == icesat2.GT1R]
140+
ax2.scatter(act_gt1r["time"].values, act_gt1r["h_mean"].values, s=0.5, color='b', zorder=3)
143141
ax2.scatter(exp["time"].values, exp["h_mean"].values, s=1.5, color='g', zorder=2)
144142

145143
# Plot Photon Cloud
146144
ax3 = plt.subplot(133)
147145
ax3.set_title("Photon Cloud")
148-
gt1r = ph[ph["pair"] == icesat2.RIGHT_PAIR]
149-
ax3.scatter(gt1r.geometry.x, gt1r["height"].values, c=gt1r["info"], cmap='winter_r', s=0.1)
146+
ph_gt1r = ph[ph["pair"] == icesat2.RIGHT_PAIR]
147+
ax3.scatter(ph_gt1r["time"], ph_gt1r["height"].values, c=ph_gt1r["info"], cmap='winter_r', s=0.1)
148+
act_gt1r = act_gt1r[(act_gt1r.geometry.y > min(box_lat)) & (act_gt1r.geometry.y < max(box_lat))]
149+
act_gt1r = act_gt1r[(act_gt1r.geometry.x > min(box_lon)) & (act_gt1r.geometry.x < max(box_lon))]
150+
ax3.scatter(act_gt1r["time"], act_gt1r["h_mean"].values, color='r', s=0.5)
150151

151152
# Show Plot
153+
fig.tight_layout()
152154
plt.show()
153155

154156
###############################################################################
@@ -160,7 +162,15 @@ def plotresults(act, exp, ph):
160162
url = ["127.0.0.1"]
161163
atl03_asset = "atlas-local"
162164
atl06_asset = "atlas-local"
163-
resource = "_20181019065445_03150111_004_01.h5"
165+
resource = "20181019065445_03150111_004_01"
166+
photon_cloud_region = [
167+
{ "lat": -80.75, "lon": -70.00 },
168+
{ "lat": -81.00, "lon": -70.00 },
169+
{ "lat": -81.00, "lon": -65.00 },
170+
{ "lat": -80.75, "lon": -65.00 },
171+
{ "lat": -80.75, "lon": -70.00 }
172+
]
173+
164174

165175
# configure logging
166176
logging.basicConfig(level=logging.INFO)
@@ -184,17 +194,21 @@ def plotresults(act, exp, ph):
184194
if sys.argv[4] == "bypass":
185195
url = [url]
186196

197+
# Set Resource #
198+
if len(sys.argv) > 5:
199+
resource = sys.argv[5]
200+
187201
# Initialize Icesat2 Package #
188202
icesat2.init(url, True)
189203

190204
# Execute SlideRule Algorithm
191-
act = algoexec("ATL03"+resource, atl03_asset)
205+
act = algoexec("ATL03_"+resource+".h5", atl03_asset)
192206

193207
# Read ATL06 Expected Results
194-
exp = expread("ATL06"+resource, atl06_asset)
208+
exp = expread("ATL06_"+resource+".h5", atl06_asset)
195209

196210
# Read ATL03 Photon Cloud
197-
ph = phread("ATL03"+resource, atl03_asset)
211+
ph = phread("ATL03_"+resource+".h5", atl03_asset, photon_cloud_region)
198212

199213
# Plot Actual vs. Expected
200-
plotresults(act, exp, ph)
214+
plotresults(act, exp, ph, photon_cloud_region)

0 commit comments

Comments
 (0)