Skip to content

Commit

Permalink
very simple update to show code... stop gap until more rubst function…
Browse files Browse the repository at this point in the history
…ality added
  • Loading branch information
jpswinski committed Dec 6, 2022
1 parent d5e4e8b commit 9a3d45b
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions examples/voila_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"import logging\n",
"import warnings\n",
"import time\n",
"import json\n",
"from IPython.display import clear_output\n",
"# atl03 plotting imports\n",
"import numpy as np\n",
"import matplotlib.lines\n",
Expand Down Expand Up @@ -123,15 +125,17 @@
"# create global variables\n",
"url_textbox = None\n",
"atl06_rsps = None\n",
"parms = None\n",
"atl06_parms = None\n",
"results = []\n",
"SRwidgets = ipysliderule.widgets()\n",
"points_dropdown = None\n",
"update_button = widgets.Button(description=\"Update Map\")\n",
"run_button = widgets.Button(description=\"Run SlideRule!\")\n",
"run_output = widgets.Output()\n",
"refresh_button = widgets.Button(description=\"Refresh Plot\")\n",
"refresh_output = widgets.Output()"
"refresh_output = widgets.Output()\n",
"show_code06_button = widgets.Button(description=\"Show Code\")\n",
"show_code06_output = widgets.Output()"
]
},
{
Expand Down Expand Up @@ -228,7 +232,7 @@
"\n",
"# build and transmit requests to SlideRule\n",
"def runSlideRule():\n",
" global url_textbox, parms, results\n",
" global url_textbox, atl06_parms, results\n",
" \n",
" # set the url for the sliderule service\n",
" icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n",
Expand All @@ -237,7 +241,7 @@
" asset = SRwidgets.asset.value\n",
"\n",
" # build sliderule parameters using latest values from widget\n",
" parms = {\n",
" atl06_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",
Expand Down Expand Up @@ -267,10 +271,10 @@
" # for each region of interest\n",
" for poly in m.regions:\n",
" # add polygon from map to sliderule parameters\n",
" parms[\"poly\"] = poly \n",
" atl06_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",
" gdf = gdf.append(icesat2.atl06p(parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n",
" gdf = gdf.append(icesat2.atl06p(atl06_parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n",
" \n",
" return gdf\n",
"\n",
Expand Down Expand Up @@ -309,9 +313,19 @@
" 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",
"\n",
"# show code action\n",
"def on_show_code06_clicked(b):\n",
" global url_textbox, atl06_parms\n",
" with show_code06_output:\n",
" clear_output()\n",
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
" print('parms = ', json.dumps(atl06_parms, indent=4), sep='')\n",
" print('gdf = icesat2.atl06p(parms, asset=\"nsidc-s3\")')\n",
" \n",
"# link buttons\n",
"run_button.on_click(on_run_clicked)\n",
"refresh_button.on_click(on_refresh_clicked)"
"refresh_button.on_click(on_refresh_clicked)\n",
"show_code06_button.on_click(on_show_code06_clicked)"
]
},
{
Expand Down Expand Up @@ -371,7 +385,8 @@
"\n",
"# display buttons\n",
"display(run_button)\n",
"display(refresh_button, refresh_output)"
"display(refresh_button, refresh_output)\n",
"display(show_code06_button, show_code06_output)"
]
},
{
Expand All @@ -393,6 +408,9 @@
"source": [
"# globals for atl03 processing\n",
"atl03_rsps = None\n",
"atl03_parms = None\n",
"show_code03_button = widgets.Button(description=\"Show Code\")\n",
"show_code03_output = widgets.Output()\n",
"elev_dropdown = None\n",
"pc_button = widgets.Button(description=\"Plot Photon Cloud\")\n",
"pc_output = widgets.Output()\n",
Expand Down Expand Up @@ -445,7 +463,7 @@
"%matplotlib widget\n",
"# ATL03 Subsetter\n",
"def runATL03Subsetter():\n",
" global url_textbox, parms\n",
" global url_textbox, atl03_parms\n",
" \n",
" # set the url for the sliderule service\n",
" if url_textbox.value == 'local':\n",
Expand All @@ -458,7 +476,7 @@
" asset = SRwidgets.asset.value\n",
"\n",
" # build sliderule parameters using latest values from widget\n",
" parms = {\n",
" atl03_parms = {\n",
" # processing parameters\n",
" \"srt\": SRwidgets.surface_type.index,\n",
" \"len\": SRwidgets.length.value,\n",
Expand All @@ -482,7 +500,7 @@
" }\n",
"\n",
" # make call to sliderule\n",
" rsps = icesat2.atl03sp(parms, asset)\n",
" rsps = icesat2.atl03sp(atl03_parms, asset)\n",
" \n",
" # return geodataframe\n",
" return rsps\n",
Expand Down Expand Up @@ -529,7 +547,19 @@
" SRwidgets.ground_track.value = gt2str[feature[\"properties\"][\"gt\"]]\n",
"\n",
"# install click handler callback\n",
"m.add_selected_callback(click_handler)"
"m.add_selected_callback(click_handler)\n",
"\n",
"# show code action\n",
"def on_show_code03_clicked(b):\n",
" global url_textbox, atl03_parms\n",
" with show_code03_output:\n",
" clear_output()\n",
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
" print('parms = ', json.dumps(atl03_parms, indent=4), sep='')\n",
" print('gdf = icesat2.atl03sp(parms, asset=\"nsidc-s3\")')\n",
" \n",
"# install click handler callback\n",
"show_code03_button.on_click(on_show_code03_clicked)"
]
},
{
Expand Down Expand Up @@ -566,7 +596,8 @@
"display(SRwidgets.plot_classification)\n",
"display(elev_dropdown)\n",
"display(pc_button)\n",
"display(pc_output)"
"display(pc_output)\n",
"display(show_code03_button, show_code03_output)"
]
}
],
Expand Down Expand Up @@ -604,7 +635,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.8.15"
},
"toc-showtags": false
},
Expand Down

0 comments on commit 9a3d45b

Please sign in to comment.