Skip to content

Commit

Permalink
Merge pull request #39 from ICESat2-SlideRule/widgets
Browse files Browse the repository at this point in the history
add land class widget
  • Loading branch information
jpswinski authored Sep 3, 2021
2 parents 44ebec4 + 0441c8b commit fb7d108
Showing 1 changed file with 50 additions and 22 deletions.
72 changes: 50 additions & 22 deletions examples/api_widgets_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"source": [
"# dropdown menu for setting asset\n",
"AssetDropdown = widgets.Dropdown(\n",
" options=['atlas-local', 'atlas-s3'],\n",
" options=['atlas-local', 'atlas-s3', 'nsidc-s3'],\n",
" value='atlas-s3',\n",
" description='Asset:',\n",
" disabled=False,\n",
Expand Down Expand Up @@ -198,6 +198,20 @@
" readout_format='d'\n",
")\n",
"\n",
"# selection for land surface classifications\n",
"land_options = [\n",
" 'atl08_noise',\n",
" 'atl08_ground',\n",
" 'atl08_canopy',\n",
" 'atl08_top_of_canopy',\n",
" 'atl08_unclassified'\n",
"]\n",
"ClassSelect = widgets.SelectMultiple(\n",
" options=land_options,\n",
" description='Land Class:',\n",
" disabled=False\n",
")\n",
"\n",
"# slider for setting maximum number of iterations\n",
"# (not including initial least-squares-fit selection)\n",
"IterationSlider = widgets.IntSlider(\n",
Expand Down Expand Up @@ -275,6 +289,7 @@
" LengthSlider,\n",
" StepSlider,\n",
" ConfSlider,\n",
" ClassSelect,\n",
" IterationSlider,\n",
" SpreadSlider,\n",
" CountSlider,\n",
Expand Down Expand Up @@ -312,6 +327,8 @@
" \"res\": StepSlider.value,\n",
" # confidence level for PE selection (default: 4)\n",
" \"cnf\": ConfSlider.value,\n",
" # ATL08 land surface classifications\n",
" \"atl08_class\": list(ClassSelect.value),\n",
" # maximum iterations, not including initial least-squares-fit selection (default: 1)\n",
" \"maxi\": IterationSlider.value,\n",
" # minimum along track spread (default: 20.0)\n",
Expand Down Expand Up @@ -359,31 +376,42 @@
"# adjust subplot within figure\n",
"f1.subplots_adjust(left=0.02,right=0.98,bottom=0.05,top=0.98)\n",
"\n",
"# output plot of fit height for each segment\n",
"spots = rsps['spot'].unique()\n",
"f2, ax2 = plt.subplots(num=2,ncols=len(spots),sharey=True,figsize=(8,6))\n",
"for j,spot in enumerate(spots):\n",
" rsps_per_spot = rsps[rsps[\"spot\"]==spot]\n",
" ax2[j].plot(rsps_per_spot['segment_id'],rsps_per_spot['h_mean'],'r')\n",
" ax2[j].set_xlabel('Segment ID')\n",
" ax2[j].set_title('Spot {0:d}'.format(spot))\n",
"ax2[0].set_ylabel('Along Track Elevation [m]')\n",
"title = 'SlideRule ATL06 Segment Fits\\nSegment Length {0:d}m, Step Size {1:d}m'\n",
"f2.suptitle(title.format(LengthSlider.value,StepSlider.value))\n",
"f2.subplots_adjust(wspace=0.05)\n",
"\n",
"# show plots\n",
"# output map of heights\n",
"f2, ax2 = plt.subplots(num=2, nrows=1, ncols=1, figsize=(10,6),\n",
" subplot_kw=dict(projection=cartopy.crs.PlateCarree()))\n",
"# create scatter plot of elevations\n",
"sc = ax2.scatter(gdf.geometry.x,gdf.geometry.y,c=gdf.h_mean,\n",
" s=1,edgecolor='none',cmap=plt.cm.viridis,\n",
" transform=cartopy.crs.PlateCarree())\n",
"# extract latitude and longitude of polygon\n",
"lon = [r['lon'] for r in regions[0]]\n",
"lat = [r['lat'] for r in regions[0]]\n",
"ax2.plot(lon, lat, 'r', lw=1.5, transform=cartopy.crs.PlateCarree())\n",
"# add coastlines with filled land and lakes\n",
"ax2.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')\n",
"ax2.add_feature(cartopy.feature.LAKES)\n",
"#-- Add colorbar axes at position rect [left, bottom, width, height]\n",
"cbar_ax = f2.add_axes([0.87, 0.015, 0.0325, 0.94])\n",
"#-- add extension triangles to upper and lower bounds\n",
"cbar = f2.colorbar(sc, cax=cbar_ax, extend='both', extendfrac=0.0375,\n",
" drawedges=False, orientation='vertical')\n",
"#-- rasterized colorbar to remove lines\n",
"cbar.solids.set_rasterized(True)\n",
"#-- Add label to the colorbar and adjust coordinates\n",
"cbar.ax.set_ylabel('Height above WGS84 Ellipsoid',labelpad=10)\n",
"cbar.ax.set_xlabel('m', rotation=0)\n",
"cbar.ax.xaxis.set_label_coords(0.5, 1.05)\n",
"cbar.ax.tick_params(which='both', width=1, direction='in')\n",
"# stronger linewidth on frame\n",
"ax2.spines['geo'].set_linewidth(2.0)\n",
"ax2.spines['geo'].set_capstyle('projecting')\n",
"# adjust subplot within figure\n",
"f2.subplots_adjust(left=0.02,right=0.86,bottom=0.05,top=0.98)\n",
"# show the figures\n",
"plt.show()"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"outputs": [],
"metadata": {}
}
],
"metadata": {
Expand Down

0 comments on commit fb7d108

Please sign in to comment.