|
72 | 72 | "import logging\n",
|
73 | 73 | "import warnings\n",
|
74 | 74 | "import time\n",
|
| 75 | + "import json\n", |
| 76 | + "from IPython.display import clear_output\n", |
75 | 77 | "# atl03 plotting imports\n",
|
76 | 78 | "import numpy as np\n",
|
77 | 79 | "import matplotlib.lines\n",
|
|
123 | 125 | "# create global variables\n",
|
124 | 126 | "url_textbox = None\n",
|
125 | 127 | "atl06_rsps = None\n",
|
126 |
| - "parms = None\n", |
| 128 | + "atl06_parms = None\n", |
127 | 129 | "results = []\n",
|
128 | 130 | "SRwidgets = ipysliderule.widgets()\n",
|
129 | 131 | "points_dropdown = None\n",
|
130 | 132 | "update_button = widgets.Button(description=\"Update Map\")\n",
|
131 | 133 | "run_button = widgets.Button(description=\"Run SlideRule!\")\n",
|
132 | 134 | "run_output = widgets.Output()\n",
|
133 | 135 | "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()" |
135 | 139 | ]
|
136 | 140 | },
|
137 | 141 | {
|
|
228 | 232 | "\n",
|
229 | 233 | "# build and transmit requests to SlideRule\n",
|
230 | 234 | "def runSlideRule():\n",
|
231 |
| - " global url_textbox, parms, results\n", |
| 235 | + " global url_textbox, atl06_parms, results\n", |
232 | 236 | " \n",
|
233 | 237 | " # set the url for the sliderule service\n",
|
234 | 238 | " icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n",
|
|
237 | 241 | " asset = SRwidgets.asset.value\n",
|
238 | 242 | "\n",
|
239 | 243 | " # build sliderule parameters using latest values from widget\n",
|
240 |
| - " parms = {\n", |
| 244 | + " atl06_parms = {\n", |
241 | 245 | " # surface type: 0-land, 1-ocean, 2-sea ice, 3-land ice, 4-inland water\n",
|
242 | 246 | " \"srt\": SRwidgets.surface_type.index,\n",
|
243 | 247 | " # length of ATL06-SR segment in meters\n",
|
|
267 | 271 | " # for each region of interest\n",
|
268 | 272 | " for poly in m.regions:\n",
|
269 | 273 | " # add polygon from map to sliderule parameters\n",
|
270 |
| - " parms[\"poly\"] = poly \n", |
| 274 | + " atl06_parms[\"poly\"] = poly \n", |
271 | 275 | " # make the request to the SlideRule (ATL06-SR) endpoint\n",
|
272 | 276 | " # 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", |
274 | 278 | " \n",
|
275 | 279 | " return gdf\n",
|
276 | 280 | "\n",
|
|
287 | 291 | " max_plot_points = 10000\n",
|
288 | 292 | " if points_dropdown.value == \"100K\":\n",
|
289 | 293 | " max_plot_points = 100000\n",
|
290 |
| - " elif points_dropdown.value == \"unlimited\":\n", |
| 294 | + " elif points_dropdown.value == \"all\":\n", |
291 | 295 | " max_plot_points = 1000000000\n",
|
| 296 | + " if max_plot_points > atl06_rsps.shape[0]:\n", |
| 297 | + " max_plot_points = atl06_rsps.shape[0]\n", |
| 298 | + " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", |
292 | 299 | " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n",
|
293 | 300 | "\n",
|
294 | 301 | "# refresh action\n",
|
295 | 302 | "def on_refresh_clicked(b):\n",
|
296 | 303 | " global atl06_rsps\n",
|
297 | 304 | " with refresh_output:\n",
|
298 |
| - " if atl06_rsps and atl06_rsps.shape[0] > 0:\n", |
| 305 | + " if atl06_rsps is not None and atl06_rsps.shape[0] > 0:\n", |
299 | 306 | " max_plot_points = 10000\n",
|
300 | 307 | " if points_dropdown.value == \"100K\":\n",
|
301 | 308 | " max_plot_points = 100000\n",
|
302 |
| - " elif points_dropdown.value == \"unlimited\":\n", |
| 309 | + " elif points_dropdown.value == \"all\":\n", |
303 | 310 | " max_plot_points = 1000000000\n",
|
| 311 | + " if max_plot_points > atl06_rsps.shape[0]:\n", |
| 312 | + " max_plot_points = atl06_rsps.shape[0]\n", |
| 313 | + " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", |
304 | 314 | " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n",
|
305 | 315 | "\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", |
306 | 325 | "# link buttons\n",
|
307 | 326 | "run_button.on_click(on_run_clicked)\n",
|
308 |
| - "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)" |
309 | 329 | ]
|
310 | 330 | },
|
311 | 331 | {
|
|
339 | 359 | "\n",
|
340 | 360 | "# points to plot drop down\n",
|
341 | 361 | "points_dropdown = widgets.Dropdown(\n",
|
342 |
| - " options = [\"10K\", \"100K\", \"unlimited\"],\n", |
| 362 | + " options = [\"10K\", \"100K\", \"all\"],\n", |
343 | 363 | " value = \"10K\",\n",
|
344 | 364 | " description = \"Pts to Draw\",\n",
|
345 | 365 | " disabled = False,\n",
|
|
365 | 385 | "\n",
|
366 | 386 | "# display buttons\n",
|
367 | 387 | "display(run_button)\n",
|
368 |
| - "display(refresh_button, refresh_output)" |
| 388 | + "display(refresh_button, refresh_output)\n", |
| 389 | + "display(show_code06_button, show_code06_output)" |
369 | 390 | ]
|
370 | 391 | },
|
371 | 392 | {
|
|
387 | 408 | "source": [
|
388 | 409 | "# globals for atl03 processing\n",
|
389 | 410 | "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", |
390 | 414 | "elev_dropdown = None\n",
|
391 | 415 | "pc_button = widgets.Button(description=\"Plot Photon Cloud\")\n",
|
392 | 416 | "pc_output = widgets.Output()\n",
|
|
439 | 463 | "%matplotlib widget\n",
|
440 | 464 | "# ATL03 Subsetter\n",
|
441 | 465 | "def runATL03Subsetter():\n",
|
442 |
| - " global url_textbox, parms\n", |
| 466 | + " global url_textbox, atl03_parms\n", |
443 | 467 | " \n",
|
444 | 468 | " # set the url for the sliderule service\n",
|
445 | 469 | " if url_textbox.value == 'local':\n",
|
|
452 | 476 | " asset = SRwidgets.asset.value\n",
|
453 | 477 | "\n",
|
454 | 478 | " # build sliderule parameters using latest values from widget\n",
|
455 |
| - " parms = {\n", |
| 479 | + " atl03_parms = {\n", |
456 | 480 | " # processing parameters\n",
|
457 | 481 | " \"srt\": SRwidgets.surface_type.index,\n",
|
458 | 482 | " \"len\": SRwidgets.length.value,\n",
|
|
476 | 500 | " }\n",
|
477 | 501 | "\n",
|
478 | 502 | " # make call to sliderule\n",
|
479 |
| - " rsps = icesat2.atl03sp(parms, asset)\n", |
| 503 | + " rsps = icesat2.atl03sp(atl03_parms, asset)\n", |
480 | 504 | " \n",
|
481 | 505 | " # return geodataframe\n",
|
482 | 506 | " return rsps\n",
|
|
523 | 547 | " SRwidgets.ground_track.value = gt2str[feature[\"properties\"][\"gt\"]]\n",
|
524 | 548 | "\n",
|
525 | 549 | "# install click handler callback\n",
|
526 |
| - "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)" |
527 | 563 | ]
|
528 | 564 | },
|
529 | 565 | {
|
|
560 | 596 | "display(SRwidgets.plot_classification)\n",
|
561 | 597 | "display(elev_dropdown)\n",
|
562 | 598 | "display(pc_button)\n",
|
563 |
| - "display(pc_output)" |
| 599 | + "display(pc_output)\n", |
| 600 | + "display(show_code03_button, show_code03_output)" |
564 | 601 | ]
|
565 |
| - }, |
566 |
| - { |
567 |
| - "cell_type": "code", |
568 |
| - "execution_count": null, |
569 |
| - "metadata": {}, |
570 |
| - "outputs": [], |
571 |
| - "source": [] |
572 | 602 | }
|
573 | 603 | ],
|
574 | 604 | "metadata": {
|
|
605 | 635 | "name": "python",
|
606 | 636 | "nbconvert_exporter": "python",
|
607 | 637 | "pygments_lexer": "ipython3",
|
608 |
| - "version": "3.8.13" |
| 638 | + "version": "3.8.15" |
609 | 639 | },
|
610 | 640 | "toc-showtags": false
|
611 | 641 | },
|
|
0 commit comments