|
15 | 15 | "title: Viz\n", |
16 | 16 | "subtitle: Visualizing native-grid output in Python\n", |
17 | 17 | "label: page:viz\n", |
| 18 | + "kernelspec:\n", |
| 19 | + " name: python3\n", |
18 | 20 | "---" |
19 | 21 | ] |
20 | 22 | }, |
|
62 | 64 | }, |
63 | 65 | "outputs": [], |
64 | 66 | "source": [ |
| 67 | + "import os\n", |
65 | 68 | "from pathlib import Path\n", |
66 | 69 | "\n", |
67 | 70 | "import cartopy.crs as ccrs\n", |
|
75 | 78 | "import uxarray as ux\n", |
76 | 79 | "import xarray as xr\n", |
77 | 80 | "\n", |
78 | | - "# https://docs.pyvista.org/user-guide/jupyter/index.html\n", |
| 81 | + "CI = os.environ.get(\"CI\", \"false\").strip() == \"true\"\n", |
| 82 | + "\n", |
| 83 | + "# https://docs.pyvista.org/user-guide/jupyter/\n", |
79 | 84 | "pv.set_jupyter_backend(\"static\")\n", |
80 | 85 | "\n", |
81 | 86 | "_ = xr.set_options(display_expand_data=False)" |
|
648 | 653 | "metadata": {}, |
649 | 654 | "outputs": [], |
650 | 655 | "source": [ |
651 | | - "conn = np.ma.masked_where(g.verticesOnCell == 0, g.verticesOnCell, copy=False) - 1\n", |
| 656 | + "if not CI:\n", |
| 657 | + " conn = np.ma.masked_where(g.verticesOnCell == 0, g.verticesOnCell, copy=False) - 1\n", |
| 658 | + "\n", |
| 659 | + " mesh = gv.Transform.from_unstructured(\n", |
| 660 | + " np.rad2deg(g.lonVertex),\n", |
| 661 | + " np.rad2deg(g.latVertex),\n", |
| 662 | + " connectivity=conn,\n", |
| 663 | + " data=area,\n", |
| 664 | + " )\n", |
652 | 665 | "\n", |
653 | | - "mesh = gv.Transform.from_unstructured(\n", |
654 | | - " np.rad2deg(g.lonVertex),\n", |
655 | | - " np.rad2deg(g.latVertex),\n", |
656 | | - " connectivity=conn,\n", |
657 | | - " data=area,\n", |
658 | | - ")\n", |
| 666 | + " pl = gv.GeoPlotter()\n", |
| 667 | + "\n", |
| 668 | + " sargs = {\"title\": r\"Grid cell area [km²]\", \"shadow\": True}\n", |
| 669 | + " pl.add_mesh(\n", |
| 670 | + " mesh,\n", |
| 671 | + " scalar_bar_args=sargs,\n", |
| 672 | + " cmap=\"gnuplot_r\",\n", |
| 673 | + " )\n", |
659 | 674 | "\n", |
660 | | - "pl = gv.GeoPlotter()\n", |
| 675 | + " # pl.add_base_layer(texture=gv.natural_earth_hypsometric())\n", |
| 676 | + " pl.add_coastlines(color=\"white\")\n", |
| 677 | + " pl.add_graticule(lon_step=None, lat_step=None, show_labels=False)\n", |
661 | 678 | "\n", |
662 | | - "sargs = {\"title\": r\"Grid cell area [km²]\", \"shadow\": True}\n", |
663 | | - "pl.add_mesh(\n", |
664 | | - " mesh,\n", |
665 | | - " scalar_bar_args=sargs,\n", |
666 | | - " cmap=\"gnuplot_r\",\n", |
667 | | - ")\n", |
| 679 | + " pl.view_yz()\n", |
| 680 | + " pl.camera.zoom(1.5)\n", |
| 681 | + "\n", |
| 682 | + " pl.show()" |
| 683 | + ] |
| 684 | + }, |
| 685 | + { |
| 686 | + "cell_type": "markdown", |
| 687 | + "id": "27", |
| 688 | + "metadata": {}, |
| 689 | + "source": [ |
668 | 690 | "\n", |
669 | | - "# pl.add_base_layer(texture=gv.natural_earth_hypsometric())\n", |
670 | | - "pl.add_coastlines(color=\"white\")\n", |
671 | | - "pl.add_graticule(lon_step=None, lat_step=None, show_labels=False)\n", |
| 691 | + "````{dropdown} Result\n", |
672 | 692 | "\n", |
673 | | - "pl.view_yz()\n", |
674 | | - "pl.camera.zoom(1.5)\n", |
| 693 | + "```{image} geovista-globe-preview.png\n", |
675 | 694 | "\n", |
676 | | - "pl.show()" |
| 695 | + "```\n", |
| 696 | + "````" |
677 | 697 | ] |
678 | 698 | }, |
679 | 699 | { |
680 | 700 | "cell_type": "code", |
681 | 701 | "execution_count": null, |
682 | | - "id": "27", |
| 702 | + "id": "28", |
683 | 703 | "metadata": {}, |
684 | 704 | "outputs": [], |
685 | 705 | "source": [ |
686 | | - "pl = gv.GeoPlotter(crs=\"ESRI:54030\") # Robinson\n", |
| 706 | + "if not CI:\n", |
| 707 | + " pl = gv.GeoPlotter(crs=\"ESRI:54030\") # Robinson\n", |
687 | 708 | "\n", |
688 | | - "sargs = {\"title\": \"Grid cell area [km²]\", \"shadow\": True}\n", |
689 | | - "pl.add_mesh(\n", |
690 | | - " mesh,\n", |
691 | | - " scalar_bar_args=sargs,\n", |
692 | | - " cmap=\"gnuplot_r\",\n", |
693 | | - ")\n", |
| 709 | + " sargs = {\"title\": \"Grid cell area [km²]\", \"shadow\": True}\n", |
| 710 | + " pl.add_mesh(\n", |
| 711 | + " mesh,\n", |
| 712 | + " scalar_bar_args=sargs,\n", |
| 713 | + " cmap=\"gnuplot_r\",\n", |
| 714 | + " )\n", |
694 | 715 | "\n", |
695 | | - "# pl.add_base_layer(texture=gv.natural_earth_hypsometric())\n", |
696 | | - "pl.add_coastlines(color=\"white\")\n", |
697 | | - "pl.add_graticule(lon_step=None, lat_step=None, show_labels=False)\n", |
| 716 | + " # pl.add_base_layer(texture=gv.natural_earth_hypsometric())\n", |
| 717 | + " pl.add_coastlines(color=\"white\")\n", |
| 718 | + " pl.add_graticule(lon_step=None, lat_step=None, show_labels=False)\n", |
698 | 719 | "\n", |
699 | | - "pl.view_xy()\n", |
700 | | - "pl.enable_image_style() # better interactivity for 2-D plots\n", |
701 | | - "pl.camera.zoom(1.5)\n", |
| 720 | + " pl.view_xy()\n", |
| 721 | + " pl.enable_image_style() # better interactivity for 2-D plots\n", |
| 722 | + " pl.camera.zoom(1.5)\n", |
702 | 723 | "\n", |
703 | | - "pl.show()" |
| 724 | + " pl.show()" |
704 | 725 | ] |
705 | 726 | }, |
706 | 727 | { |
707 | 728 | "cell_type": "markdown", |
708 | | - "id": "28", |
| 729 | + "id": "29", |
| 730 | + "metadata": {}, |
| 731 | + "source": [ |
| 732 | + "````{dropdown} Result\n", |
| 733 | + "\n", |
| 734 | + "```{image} geovista-flat-preview.png\n", |
| 735 | + "\n", |
| 736 | + "```\n", |
| 737 | + "````" |
| 738 | + ] |
| 739 | + }, |
| 740 | + { |
| 741 | + "cell_type": "markdown", |
| 742 | + "id": "30", |
709 | 743 | "metadata": { |
710 | 744 | "editable": true, |
711 | 745 | "slideshow": { |
|
717 | 751 | "# lonboard\n", |
718 | 752 | "\n", |
719 | 753 | "[lonboard](https://developmentseed.org/lonboard/) provides GPU-accelerated interactive visualiation of geospatial vector data.\n", |
720 | | - "We can pass it cell polygons. An easy way to get these is using uxarray.\n", |
721 | | - "\n", |
722 | | - "````{dropdown} Static preview of the result\n", |
723 | | - "\n", |
724 | | - "For when kernel is not active.\n", |
725 | | - "\n", |
726 | | - "```{image} lonboard-preview.png\n", |
727 | | - "\n", |
728 | | - "```\n", |
729 | | - "````" |
| 754 | + "We can pass it cell polygons. An easy way to get these is using uxarray." |
730 | 755 | ] |
731 | 756 | }, |
732 | 757 | { |
733 | 758 | "cell_type": "code", |
734 | 759 | "execution_count": null, |
735 | | - "id": "29", |
| 760 | + "id": "31", |
736 | 761 | "metadata": { |
737 | 762 | "editable": true, |
738 | 763 | "slideshow": { |
|
765 | 790 | "m = Map(layer)\n", |
766 | 791 | "m" |
767 | 792 | ] |
| 793 | + }, |
| 794 | + { |
| 795 | + "cell_type": "markdown", |
| 796 | + "id": "32", |
| 797 | + "metadata": {}, |
| 798 | + "source": [ |
| 799 | + "````{dropdown} Static preview of the result\n", |
| 800 | + "\n", |
| 801 | + "For when kernel is not active.\n", |
| 802 | + "\n", |
| 803 | + "```{image} lonboard-preview.png\n", |
| 804 | + "\n", |
| 805 | + "```\n", |
| 806 | + "````" |
| 807 | + ] |
768 | 808 | } |
769 | 809 | ], |
770 | 810 | "metadata": { |
|
0 commit comments