Skip to content

Commit 9a3d45b

Browse files
committed
very simple update to show code... stop gap until more rubst functionality added
1 parent d5e4e8b commit 9a3d45b

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

examples/voila_demo.ipynb

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"import logging\n",
7373
"import warnings\n",
7474
"import time\n",
75+
"import json\n",
76+
"from IPython.display import clear_output\n",
7577
"# atl03 plotting imports\n",
7678
"import numpy as np\n",
7779
"import matplotlib.lines\n",
@@ -123,15 +125,17 @@
123125
"# create global variables\n",
124126
"url_textbox = None\n",
125127
"atl06_rsps = None\n",
126-
"parms = None\n",
128+
"atl06_parms = None\n",
127129
"results = []\n",
128130
"SRwidgets = ipysliderule.widgets()\n",
129131
"points_dropdown = None\n",
130132
"update_button = widgets.Button(description=\"Update Map\")\n",
131133
"run_button = widgets.Button(description=\"Run SlideRule!\")\n",
132134
"run_output = widgets.Output()\n",
133135
"refresh_button = widgets.Button(description=\"Refresh Plot\")\n",
134-
"refresh_output = widgets.Output()"
136+
"refresh_output = widgets.Output()\n",
137+
"show_code06_button = widgets.Button(description=\"Show Code\")\n",
138+
"show_code06_output = widgets.Output()"
135139
]
136140
},
137141
{
@@ -228,7 +232,7 @@
228232
"\n",
229233
"# build and transmit requests to SlideRule\n",
230234
"def runSlideRule():\n",
231-
" global url_textbox, parms, results\n",
235+
" global url_textbox, atl06_parms, results\n",
232236
" \n",
233237
" # set the url for the sliderule service\n",
234238
" icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n",
@@ -237,7 +241,7 @@
237241
" asset = SRwidgets.asset.value\n",
238242
"\n",
239243
" # build sliderule parameters using latest values from widget\n",
240-
" parms = {\n",
244+
" atl06_parms = {\n",
241245
" # surface type: 0-land, 1-ocean, 2-sea ice, 3-land ice, 4-inland water\n",
242246
" \"srt\": SRwidgets.surface_type.index,\n",
243247
" # length of ATL06-SR segment in meters\n",
@@ -267,10 +271,10 @@
267271
" # for each region of interest\n",
268272
" for poly in m.regions:\n",
269273
" # add polygon from map to sliderule parameters\n",
270-
" parms[\"poly\"] = poly \n",
274+
" atl06_parms[\"poly\"] = poly \n",
271275
" # make the request to the SlideRule (ATL06-SR) endpoint\n",
272276
" # and pass it the request parameters to request ATL06 Data\n",
273-
" gdf = gdf.append(icesat2.atl06p(parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n",
277+
" gdf = gdf.append(icesat2.atl06p(atl06_parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n",
274278
" \n",
275279
" return gdf\n",
276280
"\n",
@@ -309,9 +313,19 @@
309313
" print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n",
310314
" m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n",
311315
"\n",
316+
"# show code action\n",
317+
"def on_show_code06_clicked(b):\n",
318+
" global url_textbox, atl06_parms\n",
319+
" with show_code06_output:\n",
320+
" clear_output()\n",
321+
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
322+
" print('parms = ', json.dumps(atl06_parms, indent=4), sep='')\n",
323+
" print('gdf = icesat2.atl06p(parms, asset=\"nsidc-s3\")')\n",
324+
" \n",
312325
"# link buttons\n",
313326
"run_button.on_click(on_run_clicked)\n",
314-
"refresh_button.on_click(on_refresh_clicked)"
327+
"refresh_button.on_click(on_refresh_clicked)\n",
328+
"show_code06_button.on_click(on_show_code06_clicked)"
315329
]
316330
},
317331
{
@@ -371,7 +385,8 @@
371385
"\n",
372386
"# display buttons\n",
373387
"display(run_button)\n",
374-
"display(refresh_button, refresh_output)"
388+
"display(refresh_button, refresh_output)\n",
389+
"display(show_code06_button, show_code06_output)"
375390
]
376391
},
377392
{
@@ -393,6 +408,9 @@
393408
"source": [
394409
"# globals for atl03 processing\n",
395410
"atl03_rsps = None\n",
411+
"atl03_parms = None\n",
412+
"show_code03_button = widgets.Button(description=\"Show Code\")\n",
413+
"show_code03_output = widgets.Output()\n",
396414
"elev_dropdown = None\n",
397415
"pc_button = widgets.Button(description=\"Plot Photon Cloud\")\n",
398416
"pc_output = widgets.Output()\n",
@@ -445,7 +463,7 @@
445463
"%matplotlib widget\n",
446464
"# ATL03 Subsetter\n",
447465
"def runATL03Subsetter():\n",
448-
" global url_textbox, parms\n",
466+
" global url_textbox, atl03_parms\n",
449467
" \n",
450468
" # set the url for the sliderule service\n",
451469
" if url_textbox.value == 'local':\n",
@@ -458,7 +476,7 @@
458476
" asset = SRwidgets.asset.value\n",
459477
"\n",
460478
" # build sliderule parameters using latest values from widget\n",
461-
" parms = {\n",
479+
" atl03_parms = {\n",
462480
" # processing parameters\n",
463481
" \"srt\": SRwidgets.surface_type.index,\n",
464482
" \"len\": SRwidgets.length.value,\n",
@@ -482,7 +500,7 @@
482500
" }\n",
483501
"\n",
484502
" # make call to sliderule\n",
485-
" rsps = icesat2.atl03sp(parms, asset)\n",
503+
" rsps = icesat2.atl03sp(atl03_parms, asset)\n",
486504
" \n",
487505
" # return geodataframe\n",
488506
" return rsps\n",
@@ -529,7 +547,19 @@
529547
" SRwidgets.ground_track.value = gt2str[feature[\"properties\"][\"gt\"]]\n",
530548
"\n",
531549
"# install click handler callback\n",
532-
"m.add_selected_callback(click_handler)"
550+
"m.add_selected_callback(click_handler)\n",
551+
"\n",
552+
"# show code action\n",
553+
"def on_show_code03_clicked(b):\n",
554+
" global url_textbox, atl03_parms\n",
555+
" with show_code03_output:\n",
556+
" clear_output()\n",
557+
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
558+
" print('parms = ', json.dumps(atl03_parms, indent=4), sep='')\n",
559+
" print('gdf = icesat2.atl03sp(parms, asset=\"nsidc-s3\")')\n",
560+
" \n",
561+
"# install click handler callback\n",
562+
"show_code03_button.on_click(on_show_code03_clicked)"
533563
]
534564
},
535565
{
@@ -566,7 +596,8 @@
566596
"display(SRwidgets.plot_classification)\n",
567597
"display(elev_dropdown)\n",
568598
"display(pc_button)\n",
569-
"display(pc_output)"
599+
"display(pc_output)\n",
600+
"display(show_code03_button, show_code03_output)"
570601
]
571602
}
572603
],
@@ -604,7 +635,7 @@
604635
"name": "python",
605636
"nbconvert_exporter": "python",
606637
"pygments_lexer": "ipython3",
607-
"version": "3.10.6"
638+
"version": "3.8.15"
608639
},
609640
"toc-showtags": false
610641
},

0 commit comments

Comments
 (0)