|
129 | 129 | "update_button = widgets.Button(description=\"Update Map\")\n", |
130 | 130 | "run_button = widgets.Button(description=\"Run SlideRule!\")\n", |
131 | 131 | "run_output = widgets.Output()\n", |
132 | | - "refresh_button = widgets.Button(description=\"Refresh Plot\")\n", |
133 | | - "refresh_output = widgets.Output()\n", |
134 | 132 | "download_output = widgets.Output()\n", |
135 | 133 | "download_atl06_button = widgets.Button(description=\"Download File\")\n", |
136 | 134 | "download_atl03_button = widgets.Button(description=\"Download File\")\n", |
|
280 | 278 | "\n", |
281 | 279 | " # clear existing geodataframe results\n", |
282 | 280 | " elevations = [sliderule.emptyframe()]\n", |
| 281 | + " sliderule.logger.warning('No valid regions to run') if not m.regions else None\n", |
283 | 282 | "\n", |
284 | 283 | " # for each region of interest\n", |
285 | 284 | " for poly in m.regions:\n", |
|
295 | 294 | "\n", |
296 | 295 | "# run sliderule action\n", |
297 | 296 | "def on_run_clicked(b):\n", |
298 | | - " global atl06_rsps, points_dropdown\n", |
| 297 | + " global atl06_rsps, points_dropdown, stride\n", |
299 | 298 | " with run_output:\n", |
300 | 299 | " print(f'SlideRule processing request... initiated\\r', end=\"\")\n", |
301 | 300 | " perf_start = time.perf_counter()\n", |
|
307 | 306 | " if points_dropdown.value == \"100K\":\n", |
308 | 307 | " max_plot_points = 100000\n", |
309 | 308 | " elif points_dropdown.value == \"all\":\n", |
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", |
| 309 | + " max_plot_points = np.inf\n", |
| 310 | + " # limit number of points to plot\n", |
| 311 | + " plot_points = np.minimum(max_plot_points, atl06_rsps.shape[0])\n", |
| 312 | + " stride = int(atl06_rsps.shape[0]//plot_points)\n", |
| 313 | + " print(f'Plotting {plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", |
314 | 314 | " fields = atl06_rsps.leaflet.default_atl06_fields()\n", |
315 | 315 | " atl06_rsps.leaflet.GeoData(m.map,\n", |
316 | 316 | " column_name=SRwidgets.variable.value,\n", |
317 | 317 | " cmap=SRwidgets.colormap,\n", |
318 | | - " max_plot_points=max_plot_points,\n", |
| 318 | + " stride=stride,\n", |
319 | 319 | " tooltip=True,\n", |
320 | 320 | " colorbar=True,\n", |
321 | 321 | " fields=fields\n", |
|
326 | 326 | " m.add_region_callback(atl06_rsps.leaflet.handle_region)\n", |
327 | 327 | "\n", |
328 | 328 | "# refresh action\n", |
329 | | - "def on_refresh_clicked(b):\n", |
330 | | - " global atl06_rsps\n", |
331 | | - " with refresh_output:\n", |
332 | | - " if atl06_rsps is not None and atl06_rsps.shape[0] > 0:\n", |
| 329 | + "def refresh_leaflet_draw(sender):\n", |
| 330 | + " global atl06_rsps, points_dropdown, stride\n", |
| 331 | + " if atl06_rsps is not None and atl06_rsps.shape[0] > 0:\n", |
| 332 | + " if isinstance(sender['new'], str) and (sender['new'] == \"10K\"):\n", |
333 | 333 | " max_plot_points = 10000\n", |
334 | | - " if points_dropdown.value == \"100K\":\n", |
335 | | - " max_plot_points = 100000\n", |
336 | | - " elif points_dropdown.value == \"all\":\n", |
337 | | - " max_plot_points = 1000000000\n", |
338 | | - " if max_plot_points > atl06_rsps.shape[0]:\n", |
339 | | - " max_plot_points = atl06_rsps.shape[0]\n", |
340 | | - " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", |
341 | | - " fields = atl06_rsps.leaflet.default_atl06_fields()\n", |
342 | | - " atl06_rsps.leaflet.GeoData(m.map,\n", |
343 | | - " column_name=SRwidgets.variable.value,\n", |
344 | | - " cmap=SRwidgets.colormap,\n", |
345 | | - " max_plot_points=max_plot_points,\n", |
346 | | - " tooltip=True,\n", |
347 | | - " colorbar=True,\n", |
348 | | - " fields=fields\n", |
349 | | - " )\n", |
350 | | - " # install handlers and callbacks\n", |
351 | | - " atl06_rsps.leaflet.set_observables(SRwidgets)\n", |
352 | | - " atl06_rsps.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n", |
353 | | - " m.add_region_callback(atl06_rsps.leaflet.handle_region)\n", |
| 334 | + " elif isinstance(sender['new'], str) and (sender['new'] == \"100K\"):\n", |
| 335 | + " max_plot_points = 100000\n", |
| 336 | + " elif isinstance(sender['new'], str) and (sender['new'] == \"all\"):\n", |
| 337 | + " max_plot_points = np.inf\n", |
| 338 | + " else:\n", |
| 339 | + " return\n", |
| 340 | + " # limit number of points to plot\n", |
| 341 | + " plot_points = np.minimum(max_plot_points, atl06_rsps.shape[0])\n", |
| 342 | + " stride_new = int(atl06_rsps.shape[0]//plot_points)\n", |
| 343 | + " if (stride_new == stride):\n", |
| 344 | + " return\n", |
| 345 | + " # update stride\n", |
| 346 | + " stride = stride_new\n", |
| 347 | + " print(f'Plotting {plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", |
| 348 | + " # sliced geodataframe for plotting\n", |
| 349 | + " atl06_rsps.leaflet._gdf_selected = atl06_rsps.leaflet._gdf[slice(None,None,stride)]\n", |
| 350 | + " atl06_rsps.leaflet._gdf_selected['data'] = atl06_rsps.leaflet._gdf_selected[atl06_rsps.leaflet.column_name]\n", |
| 351 | + " atl06_rsps.leaflet.redraw()\n", |
354 | 352 | "\n", |
355 | 353 | "# show code action\n", |
356 | 354 | "def on_show_code06_clicked(b):\n", |
|
398 | 396 | "\n", |
399 | 397 | "# link buttons\n", |
400 | 398 | "run_button.on_click(on_run_clicked)\n", |
401 | | - "refresh_button.on_click(on_refresh_clicked)\n", |
402 | 399 | "show_code06_button.on_click(on_show_code06_clicked)\n", |
403 | 400 | "download_atl06_button.on_click(on_atl06_download_clicked)" |
404 | 401 | ] |
|
430 | 427 | " description = \"Pts to Draw\",\n", |
431 | 428 | " disabled = False,\n", |
432 | 429 | ")\n", |
| 430 | + "points_dropdown.observe(refresh_leaflet_draw)\n", |
433 | 431 | "\n", |
434 | 432 | "# display widgets for setting SlideRule parameters\n", |
435 | 433 | "display.display(widgets.VBox([\n", |
|
449 | 447 | "]))\n", |
450 | 448 | "\n", |
451 | 449 | "# display buttons\n", |
452 | | - "display.display(SRwidgets.HBox([run_button, refresh_button, refresh_output]))\n", |
| 450 | + "display.display(run_button)\n", |
453 | 451 | "display.display(SRwidgets.HBox([download_atl06_button, SRwidgets.file_format]))\n", |
454 | | - "display.display(SRwidgets.HBox([show_code06_button, show_code06_output]))\n" |
| 452 | + "display.display(SRwidgets.HBox([show_code06_button, show_code06_output]))" |
455 | 453 | ] |
456 | 454 | }, |
457 | 455 | { |
|
564 | 562 | "\n", |
565 | 563 | "# photon_cloud action\n", |
566 | 564 | "def on_pc_clicked(b):\n", |
567 | | - " global atl03_rsps, atl06_rsps, elev_dropdown\n", |
| 565 | + " global atl03_rsps, atl06_rsps, elev_dropdown, fig\n", |
568 | 566 | " with pc_output:\n", |
569 | 567 | " pc_output.clear_output(True)\n", |
570 | 568 | "\n", |
|
597 | 595 | " **SRwidgets.plot_kwargs)\n", |
598 | 596 | " # draw and show plot\n", |
599 | 597 | " plt.show()\n", |
600 | | - " plt.draw()\n", |
601 | | - "\n", |
| 598 | + " fig.canvas.draw()\n", |
| 599 | + "\n", |
| 600 | + "def refresh_ATL03_plot(sender):\n", |
| 601 | + " global atl03_rsps, atl06_rsps, elev_dropdown, fig\n", |
| 602 | + " if isinstance(sender['new'], str):\n", |
| 603 | + " # reset figure and axes\n", |
| 604 | + " fig.clear()\n", |
| 605 | + " fig.set_facecolor('white')\n", |
| 606 | + " fig.canvas.header_visible = False\n", |
| 607 | + " ax = fig.add_subplot(111)\n", |
| 608 | + " # reset title and labels\n", |
| 609 | + " ax.set_title(\"Photon Cloud\")\n", |
| 610 | + " ax.set_ylabel('height (m)')\n", |
| 611 | + " # start at the first segment\n", |
| 612 | + " x_offset = atl03_rsps['segment_dist'].min()\n", |
| 613 | + " # plot ATL03 and ATL06 data\n", |
| 614 | + " atl03_rsps.icesat2.plot(ax=ax, kind='scatter',\n", |
| 615 | + " data_type='atl03', cmap=SRwidgets.colormap,\n", |
| 616 | + " classification=SRwidgets.plot_classification.value,\n", |
| 617 | + " x_offset=x_offset, legend=True, legend_frameon=True,\n", |
| 618 | + " **SRwidgets.plot_kwargs)\n", |
| 619 | + " if (elev_dropdown.value == 'enabled'):\n", |
| 620 | + " atl06_rsps.icesat2.plot(ax=ax, kind='scatter',\n", |
| 621 | + " data_type='atl06', x_offset=x_offset,\n", |
| 622 | + " legend=True, legend_frameon=True,\n", |
| 623 | + " **SRwidgets.plot_kwargs)\n", |
| 624 | + " # draw and show plot\n", |
| 625 | + " fig.canvas.draw()\n", |
| 626 | + " \n", |
602 | 627 | "# create button to display geodataframe\n", |
603 | 628 | "pc_button.on_click(on_pc_clicked)\n", |
604 | 629 | "\n", |
|
638 | 663 | { |
639 | 664 | "cell_type": "code", |
640 | 665 | "execution_count": null, |
641 | | - "metadata": { |
642 | | - "extensions": { |
643 | | - "jupyter_dashboards": { |
644 | | - "version": 1, |
645 | | - "views": { |
646 | | - "default_view": { |
647 | | - "col": 0, |
648 | | - "height": 15, |
649 | | - "row": 32, |
650 | | - "width": 3 |
651 | | - } |
652 | | - } |
653 | | - } |
654 | | - }, |
655 | | - "tags": [] |
656 | | - }, |
| 666 | + "metadata": {}, |
657 | 667 | "outputs": [], |
658 | 668 | "source": [ |
659 | 669 | "# elevation plot drop down\n", |
|
672 | 682 | "display.display(pc_button)\n", |
673 | 683 | "display.display(pc_output)\n", |
674 | 684 | "display.display(SRwidgets.HBox([download_atl03_button, SRwidgets.file_format]))\n", |
675 | | - "display.display(show_code03_button, show_code03_output)" |
| 685 | + "display.display(show_code03_button, show_code03_output)\n", |
| 686 | + "SRwidgets.plot_classification.observe(refresh_ATL03_plot)\n", |
| 687 | + "elev_dropdown.observe(refresh_ATL03_plot)" |
676 | 688 | ] |
677 | 689 | }, |
678 | 690 | { |
|
717 | 729 | "name": "python", |
718 | 730 | "nbconvert_exporter": "python", |
719 | 731 | "pygments_lexer": "ipython3", |
720 | | - "version": "3.12.0" |
| 732 | + "version": "3.10.13" |
721 | 733 | }, |
722 | 734 | "toc-showtags": false |
723 | 735 | }, |
|
0 commit comments