Skip to content

Commit fb7d108

Browse files
authored
Merge pull request #39 from ICESat2-SlideRule/widgets
add land class widget
2 parents 44ebec4 + 0441c8b commit fb7d108

File tree

1 file changed

+50
-22
lines changed

1 file changed

+50
-22
lines changed

examples/api_widgets_demo.ipynb

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"source": [
142142
"# dropdown menu for setting asset\n",
143143
"AssetDropdown = widgets.Dropdown(\n",
144-
" options=['atlas-local', 'atlas-s3'],\n",
144+
" options=['atlas-local', 'atlas-s3', 'nsidc-s3'],\n",
145145
" value='atlas-s3',\n",
146146
" description='Asset:',\n",
147147
" disabled=False,\n",
@@ -198,6 +198,20 @@
198198
" readout_format='d'\n",
199199
")\n",
200200
"\n",
201+
"# selection for land surface classifications\n",
202+
"land_options = [\n",
203+
" 'atl08_noise',\n",
204+
" 'atl08_ground',\n",
205+
" 'atl08_canopy',\n",
206+
" 'atl08_top_of_canopy',\n",
207+
" 'atl08_unclassified'\n",
208+
"]\n",
209+
"ClassSelect = widgets.SelectMultiple(\n",
210+
" options=land_options,\n",
211+
" description='Land Class:',\n",
212+
" disabled=False\n",
213+
")\n",
214+
"\n",
201215
"# slider for setting maximum number of iterations\n",
202216
"# (not including initial least-squares-fit selection)\n",
203217
"IterationSlider = widgets.IntSlider(\n",
@@ -275,6 +289,7 @@
275289
" LengthSlider,\n",
276290
" StepSlider,\n",
277291
" ConfSlider,\n",
292+
" ClassSelect,\n",
278293
" IterationSlider,\n",
279294
" SpreadSlider,\n",
280295
" CountSlider,\n",
@@ -312,6 +327,8 @@
312327
" \"res\": StepSlider.value,\n",
313328
" # confidence level for PE selection (default: 4)\n",
314329
" \"cnf\": ConfSlider.value,\n",
330+
" # ATL08 land surface classifications\n",
331+
" \"atl08_class\": list(ClassSelect.value),\n",
315332
" # maximum iterations, not including initial least-squares-fit selection (default: 1)\n",
316333
" \"maxi\": IterationSlider.value,\n",
317334
" # minimum along track spread (default: 20.0)\n",
@@ -359,31 +376,42 @@
359376
"# adjust subplot within figure\n",
360377
"f1.subplots_adjust(left=0.02,right=0.98,bottom=0.05,top=0.98)\n",
361378
"\n",
362-
"# output plot of fit height for each segment\n",
363-
"spots = rsps['spot'].unique()\n",
364-
"f2, ax2 = plt.subplots(num=2,ncols=len(spots),sharey=True,figsize=(8,6))\n",
365-
"for j,spot in enumerate(spots):\n",
366-
" rsps_per_spot = rsps[rsps[\"spot\"]==spot]\n",
367-
" ax2[j].plot(rsps_per_spot['segment_id'],rsps_per_spot['h_mean'],'r')\n",
368-
" ax2[j].set_xlabel('Segment ID')\n",
369-
" ax2[j].set_title('Spot {0:d}'.format(spot))\n",
370-
"ax2[0].set_ylabel('Along Track Elevation [m]')\n",
371-
"title = 'SlideRule ATL06 Segment Fits\\nSegment Length {0:d}m, Step Size {1:d}m'\n",
372-
"f2.suptitle(title.format(LengthSlider.value,StepSlider.value))\n",
373-
"f2.subplots_adjust(wspace=0.05)\n",
374-
"\n",
375-
"# show plots\n",
379+
"# output map of heights\n",
380+
"f2, ax2 = plt.subplots(num=2, nrows=1, ncols=1, figsize=(10,6),\n",
381+
" subplot_kw=dict(projection=cartopy.crs.PlateCarree()))\n",
382+
"# create scatter plot of elevations\n",
383+
"sc = ax2.scatter(gdf.geometry.x,gdf.geometry.y,c=gdf.h_mean,\n",
384+
" s=1,edgecolor='none',cmap=plt.cm.viridis,\n",
385+
" transform=cartopy.crs.PlateCarree())\n",
386+
"# extract latitude and longitude of polygon\n",
387+
"lon = [r['lon'] for r in regions[0]]\n",
388+
"lat = [r['lat'] for r in regions[0]]\n",
389+
"ax2.plot(lon, lat, 'r', lw=1.5, transform=cartopy.crs.PlateCarree())\n",
390+
"# add coastlines with filled land and lakes\n",
391+
"ax2.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')\n",
392+
"ax2.add_feature(cartopy.feature.LAKES)\n",
393+
"#-- Add colorbar axes at position rect [left, bottom, width, height]\n",
394+
"cbar_ax = f2.add_axes([0.87, 0.015, 0.0325, 0.94])\n",
395+
"#-- add extension triangles to upper and lower bounds\n",
396+
"cbar = f2.colorbar(sc, cax=cbar_ax, extend='both', extendfrac=0.0375,\n",
397+
" drawedges=False, orientation='vertical')\n",
398+
"#-- rasterized colorbar to remove lines\n",
399+
"cbar.solids.set_rasterized(True)\n",
400+
"#-- Add label to the colorbar and adjust coordinates\n",
401+
"cbar.ax.set_ylabel('Height above WGS84 Ellipsoid',labelpad=10)\n",
402+
"cbar.ax.set_xlabel('m', rotation=0)\n",
403+
"cbar.ax.xaxis.set_label_coords(0.5, 1.05)\n",
404+
"cbar.ax.tick_params(which='both', width=1, direction='in')\n",
405+
"# stronger linewidth on frame\n",
406+
"ax2.spines['geo'].set_linewidth(2.0)\n",
407+
"ax2.spines['geo'].set_capstyle('projecting')\n",
408+
"# adjust subplot within figure\n",
409+
"f2.subplots_adjust(left=0.02,right=0.86,bottom=0.05,top=0.98)\n",
410+
"# show the figures\n",
376411
"plt.show()"
377412
],
378413
"outputs": [],
379414
"metadata": {}
380-
},
381-
{
382-
"cell_type": "code",
383-
"execution_count": null,
384-
"source": [],
385-
"outputs": [],
386-
"metadata": {}
387415
}
388416
],
389417
"metadata": {

0 commit comments

Comments
 (0)