From f6390f6c30dfc655b54302b637216213d0538be5 Mon Sep 17 00:00:00 2001 From: JP Swinski Date: Thu, 4 May 2023 16:54:04 +0000 Subject: [PATCH] initial updates to voila demo to support atl08 --- demo/voila_demo.ipynb | 401 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 358 insertions(+), 43 deletions(-) diff --git a/demo/voila_demo.ipynb b/demo/voila_demo.ipynb index e9164b0..23732a9 100644 --- a/demo/voila_demo.ipynb +++ b/demo/voila_demo.ipynb @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "extensions": { "jupyter_dashboards": { @@ -63,7 +63,15 @@ } } }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Unable to import sklearn... clustering support disabled\n" + ] + } + ], "source": [ "# load the necessary packages\n", "from sliderule import icesat2, ipysliderule, io, sliderule\n", @@ -86,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "extensions": { "jupyter_dashboards": { @@ -107,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "extensions": { "jupyter_dashboards": { @@ -124,8 +132,8 @@ "source": [ "# create global variables\n", "url_textbox = None\n", - "atl06_rsps = None\n", - "atl06_parms = None\n", + "rsps_data = None\n", + "rqst_parms = None\n", "SRwidgets = ipysliderule.widgets()\n", "points_dropdown = None\n", "update_button = widgets.Button(description=\"Update Map\")\n", @@ -139,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "extensions": { "jupyter_dashboards": { @@ -155,7 +163,36 @@ } } }, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "705a50cacf824927aa55b2bd2ca24349", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "cc6c674e69ef420e93f9639f99d91b7c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "def create_map(projection):\n", " # create ipyleaflet map in specified projection\n", @@ -173,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "extensions": { "jupyter_dashboards": { @@ -186,7 +223,36 @@ } } }, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "589523426c604d02b65c7006c3cfaea9", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Dropdown(description='Projection:', options=('Global', 'North', 'South'), tooltip='Projection: …" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "25d21b1534984e2eb86a853280d42f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Update Map', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# update map\n", "def on_update_clicked(b):\n", @@ -209,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "extensions": { "jupyter_dashboards": { @@ -243,7 +309,7 @@ " \n", "# build and transmit requests to SlideRule\n", "def runSlideRule():\n", - " global url_textbox, atl06_parms, granule_count\n", + " global url_textbox, rqst_parms, granule_count\n", " \n", " # reset granule count\n", " granule_count = 0\n", @@ -255,7 +321,7 @@ " asset = SRwidgets.asset.value\n", "\n", " # build sliderule parameters using latest values from widget\n", - " atl06_parms = {\n", + " rqst_parms = {\n", " # surface type: 0-land, 1-ocean, 2-sea ice, 3-land ice, 4-inland water\n", " \"srt\": SRwidgets.surface_type.index,\n", " # length of ATL06-SR segment in meters\n", @@ -278,63 +344,75 @@ " \"sigma_r_max\": SRwidgets.sigma.value\n", " }\n", "\n", + " # add phoreal parameters if selected\n", + " if SRwidgets.api.value == 'atl08':\n", + " rqst_parms[\"phoreal\"]: {\n", + " \"binsize\": 1.0, \n", + " \"geoloc\": \"center\", \n", + " \"use_abs_h\": SRwidgets.use_abs_h.value, \n", + " \"above_classifier\": SRwidgets.use_above.value, \n", + " \"send_waveform\": False\n", + " }\n", + "\n", " # clear existing geodataframe results\n", - " elevations = [sliderule.emptyframe()]\n", + " results = [sliderule.emptyframe()]\n", "\n", " # for each region of interest\n", " for poly in m.regions:\n", " # add polygon from map to sliderule parameters\n", - " atl06_parms[\"poly\"] = poly \n", + " rqst_parms[\"poly\"] = poly \n", " # make the request to the SlideRule (ATL06-SR) endpoint\n", " # and pass it the request parameters to request ATL06 Data\n", - " elevations.append(icesat2.atl06p(atl06_parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n", - "\n", + " if SRwidgets.api.value == 'atl06':\n", + " results.append(icesat2.atl06p(rqst_parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n", + " elif SRwidgets.api.value == 'atl08':\n", + " results.append(icesat2.atl08p(rqst_parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n", " # return concatenated set of results\n", - " gdf = geopandas.pd.concat(elevations)\n", + " gdf = geopandas.pd.concat(results)\n", " return gdf\n", "\n", "# run sliderule action\n", "def on_run_clicked(b):\n", - " global atl06_rsps, points_dropdown\n", + " global rsps_data, points_dropdown\n", " with run_output:\n", " print(f'SlideRule processing request... initiated\\r', end=\"\")\n", " perf_start = time.perf_counter()\n", - " atl06_rsps = runSlideRule()\n", + " rsps_data = runSlideRule()\n", " perf_duration = time.perf_counter() - perf_start\n", - " print(f'SlideRule processing request... completed in {perf_duration:.3f} seconds; returned {atl06_rsps.shape[0]} elevations ')\n", - " if atl06_rsps.shape[0] > 0:\n", + " print(f'SlideRule processing request... completed in {perf_duration:.3f} seconds; returned {rsps_data.shape[0]} results ')\n", + " if rsps_data.shape[0] > 0:\n", " max_plot_points = 10000\n", " if points_dropdown.value == \"100K\":\n", " max_plot_points = 100000\n", " elif points_dropdown.value == \"all\":\n", " max_plot_points = 1000000000\n", - " if max_plot_points > atl06_rsps.shape[0]:\n", - " max_plot_points = atl06_rsps.shape[0]\n", - " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", - " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", + " if max_plot_points > rsps_data.shape[0]:\n", + " max_plot_points = rsps_data.shape[0]\n", + " print(f'Plotting {max_plot_points} of {rsps_data.shape[0]} results. This may take 10-60+ seconds for larger point datasets.')\n", + " m.GeoData(rsps_data, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", "\n", "# refresh action\n", "def on_refresh_clicked(b):\n", - " global atl06_rsps\n", + " global rsps_data\n", " with refresh_output:\n", - " if atl06_rsps is not None and atl06_rsps.shape[0] > 0:\n", + " if rsps_data is not None and rsps_data.shape[0] > 0:\n", " max_plot_points = 10000\n", " if points_dropdown.value == \"100K\":\n", " max_plot_points = 100000\n", " elif points_dropdown.value == \"all\":\n", " max_plot_points = 1000000000\n", - " if max_plot_points > atl06_rsps.shape[0]:\n", - " max_plot_points = atl06_rsps.shape[0]\n", - " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", - " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", + " if max_plot_points > rsps_data.shape[0]:\n", + " max_plot_points = rsps_data.shape[0]\n", + " print(f'Plotting {max_plot_points} of {rsps_data.shape[0]} results. This may take 10-60+ seconds for larger point datasets.')\n", + " m.GeoData(rsps_data, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", "\n", "# show code action\n", "def on_show_code06_clicked(b):\n", - " global url_textbox, atl06_parms\n", + " global url_textbox, rqst_parms\n", " with show_code06_output:\n", " display.clear_output()\n", " print(f'icesat2.init(\"{url_textbox.value}\")')\n", - " print('parms = ', json.dumps(atl06_parms, indent=4), sep='')\n", + " print('parms = ', json.dumps(rqst_parms, indent=4), sep='')\n", " print('gdf = icesat2.atl06p(parms, asset=\"icesat2\")')\n", " \n", "# link buttons\n", @@ -345,7 +423,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "extensions": { "jupyter_dashboards": { @@ -361,7 +439,106 @@ } } }, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "00f81b0ec47d4a52be20c8d783b68dd8", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Text(value='slideruleearth.io', description='URL:', placeholder='Input box for SlideRule url')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ad355077abc842489d8a7e388e91063e", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Dropdown(description='API:', options=('atl06', 'atl08'), tooltip='API: algorithm to execute in …" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b6a7ab916dba425e8a306aaabfde7441", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Run SlideRule!', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "a9bbc8d7eff2403983d9e362628a3c01", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Refresh Plot', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "08cd8dfbe19643f5abd1ecb2140db66d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1878cc1180e448fab6766d75e01ce223", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Show Code', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6270e79e29284b959b86fce17412784d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# url input text box\n", "url_textbox = widgets.Text(\n", @@ -380,8 +557,17 @@ " disabled = False,\n", ")\n", "\n", + "# points to plot drop down\n", + "points_dropdown = widgets.Dropdown(\n", + " options = [\"10K\", \"100K\", \"all\"],\n", + " value = \"10K\",\n", + " description = \"Pts to Draw\",\n", + " disabled = False,\n", + ")\n", + "\n", "# display widgets for setting SlideRule parameters\n", "display.display(widgets.VBox([\n", + " SRwidgets.api, \n", " SRwidgets.surface_type,\n", " SRwidgets.length,\n", " SRwidgets.step,\n", @@ -392,6 +578,8 @@ " SRwidgets.count,\n", " SRwidgets.window,\n", " SRwidgets.sigma,\n", + " SRwidgets.use_abs_h,\n", + " SRwidgets.use_above,\n", " SRwidgets.variable,\n", " SRwidgets.cmap,\n", " points_dropdown,\n", @@ -406,7 +594,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "extensions": { "jupyter_dashboards": { @@ -457,7 +645,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "extensions": { "jupyter_dashboards": { @@ -522,7 +710,7 @@ "\n", "# photon_cloud action\n", "def on_pc_clicked(b):\n", - " global atl03_rsps, atl06_rsps, elev_dropdown\n", + " global atl03_rsps, rsps_data, elev_dropdown\n", " with pc_output:\n", " pc_output.clear_output(True)\n", " \n", @@ -534,14 +722,14 @@ " print(f'SlideRule processing request... completed in {perf_duration:.3f} seconds; returned {atl03_rsps.shape[0]} records ')\n", "\n", " # Create Plots\n", - " if atl03_rsps.shape[0] > 0 and atl06_rsps.shape[0] > 0:\n", + " if atl03_rsps.shape[0] > 0 and rsps_data.shape[0] > 0:\n", " fig,ax = plt.subplots(num=None, figsize=(10, 8))\n", " fig.set_facecolor('white')\n", " fig.canvas.header_visible = False\n", " ax.set_title(\"Photon Cloud\")\n", " ax.set_xlabel('UTC')\n", " ax.set_ylabel('height (m)')\n", - " SRwidgets.plot(atl06_rsps, ax=ax, kind='scatter',\n", + " SRwidgets.plot(rsps_data, ax=ax, kind='scatter',\n", " atl03=atl03_rsps, cmap=SRwidgets.colormap,\n", " classification=SRwidgets.plot_classification.value,\n", " segments=(elev_dropdown.value == 'enabled'),\n", @@ -579,7 +767,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "extensions": { "jupyter_dashboards": { @@ -596,7 +784,134 @@ }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3e5f93dbea264136a64720708a7aecce", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Text(value='0', description='RGT:', tooltip='RGT: Reference Ground Track to plot')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "81bf5b5e2c2c46e3b02e14cc4b0a7a9a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Text(value='0', description='Cycle:', tooltip='Cycle: Orbital cycle to plot')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4f97d534a5d2479e94c18d88f2e3614c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Dropdown(description='Track:', options=('gt1l', 'gt1r', 'gt2l', 'gt2r', 'gt3l', 'gt3r'), tooltip='Track: Groun…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "a09037937424489e860456d4e9d2c73f", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Dropdown(description='Classification', index=1, options=('atl03', 'atl08', 'yapc', 'none'), tooltip='Classific…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3f563f88ac344a2b929b533bc786e5f2", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Dropdown(description='ATL06-SR', options=('enabled', 'disabled'), value='enabled')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "06857342b1534e05aad8df04aade0795", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Plot Photon Cloud', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "36a64ad3df174e148adc4ee785a6c404", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ec60874e0333417b97fcbb8c9c2f2c38", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Show Code', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "735c018c568b4a1486f30ef8537167a3", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# elevation plot drop down\n", "elev_dropdown = widgets.Dropdown(\n",