Skip to content

Commit 69fc196

Browse files
committed
Fix JB2 in CI
1 parent d7c3c5f commit 69fc196

File tree

4 files changed

+162
-51
lines changed

4 files changed

+162
-51
lines changed

.github/workflows/deploy.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,93 @@ jobs:
1919
environment:
2020
name: github-pages
2121
url: ${{ steps.deployment.outputs.page_url }}
22+
defaults:
23+
run:
24+
shell: bash -leo pipefail {0}
2225
runs-on: ubuntu-latest
2326
steps:
2427
- uses: actions/checkout@v5
2528

2629
- name: Set up Pages
2730
uses: actions/configure-pages@v5
2831

29-
- name: Set up Python
32+
- name: Set up conda env
3033
uses: mamba-org/setup-micromamba@v2
3134
with:
3235
environment-file: environment.yml
3336
cache-environment: true
37+
# create-args: >-
38+
# libegl
39+
# libgles
40+
# mesalib
41+
# ipywidgets
42+
# trame
43+
# trame-vtk
44+
# trame-vuetify
45+
46+
- name: Install JB2
47+
run: python -m pip install -U --pre "jupyter-book==2.*" --no-deps -v
48+
49+
# - name: Set up PyVista
50+
# # libglx-mesa0, libgl1, xvfb already present in ubuntu-24.04
51+
# run: |
52+
# sudo apt-get update
53+
# sudo apt-get install -y libgl1-mesa-dri
54+
# # sudo apt-get install -y libosmesa6
55+
56+
# - name: Start xvfb
57+
# run: python -c "import pyvista as pv; pv.start_xvfb()"
58+
59+
# - name: PyVista test
60+
# # xvfb-run -s "-screen 0 1024x768x24" python -c '
61+
# run: |
62+
# python -c '
63+
# import os
64+
# import vtk
65+
# import pyvista as pv
66+
67+
# # pv.BUILDING_GALLERY = True
68+
69+
# print("=== Environment variables ===")
70+
# print("VTK_DEFAULT_OPENGL_WINDOW =", os.environ.get("VTK_DEFAULT_OPENGL_WINDOW"))
71+
# print("PYVISTA_OFF_SCREEN =", os.environ.get("PYVISTA_OFF_SCREEN"))
72+
73+
# print("\n=== VTK backend check ===")
74+
# rw = vtk.vtkRenderWindow()
75+
# print("RenderWindow backend:", rw.GetClassName())
76+
77+
# print("\n=== PyVista backend check ===")
78+
# # print("PyVista rendering_backend:", pv.global_theme.rendering_backend)
79+
80+
# # Force PyVista to off-screen if not already
81+
# # pv.global_theme.off_screen = True
82+
# print("PyVista OFF_SCREEN before:", pv.OFF_SCREEN)
83+
# pv.OFF_SCREEN = True
84+
85+
# print("\n=== Rendering test ===")
86+
# sphere = pv.Sphere()
87+
# plotter = pv.Plotter(off_screen=True)
88+
# plotter.add_mesh(sphere, color="tomato")
89+
# plotter.show(screenshot="backend_test.png")
90+
# print("Rendered sphere saved as backend_test.png")
91+
# '
92+
# env:
93+
# PYVISTA_OFF_SCREEN: true
94+
# # VTK_DEFAULT_OPENGL_WINDOW: vtkOSOpenGLRenderWindow
95+
# # VTK_DEFAULT_OPENGL_WINDOW: vtkXOpenGLRenderWindow
96+
97+
# JB2 has --execute, but this way we can see how long it takes
98+
- name: Execute the notebook
99+
run: jupyter nbconvert --to notebook --execute --inplace 03-viz.ipynb
100+
env:
101+
PYVISTA_OFF_SCREEN: true
102+
# VTK_DEFAULT_BACKEND: X
103+
# VTK_USE_OSMESA: "1"
104+
# VTK_DEFAULT_OPENGL_WINDOW: vtkOSOpenGLRenderWindow
105+
# VTK_DEFAULT_OPENGL_WINDOW: vtkXOpenGLRenderWindow
34106

35107
- name: Build HTML
36-
run: jupyter-book build --html --execute --strict --ci
37-
shell: micromamba-shell {0}
108+
run: jupyter book build --html --strict --ci
38109

39110
- name: Upload artifact
40111
uses: actions/upload-pages-artifact@v4

03-viz.ipynb

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"title: Viz\n",
1616
"subtitle: Visualizing native-grid output in Python\n",
1717
"label: page:viz\n",
18+
"kernelspec:\n",
19+
" name: python3\n",
1820
"---"
1921
]
2022
},
@@ -62,6 +64,7 @@
6264
},
6365
"outputs": [],
6466
"source": [
67+
"import os\n",
6568
"from pathlib import Path\n",
6669
"\n",
6770
"import cartopy.crs as ccrs\n",
@@ -75,7 +78,9 @@
7578
"import uxarray as ux\n",
7679
"import xarray as xr\n",
7780
"\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",
7984
"pv.set_jupyter_backend(\"static\")\n",
8085
"\n",
8186
"_ = xr.set_options(display_expand_data=False)"
@@ -648,64 +653,93 @@
648653
"metadata": {},
649654
"outputs": [],
650655
"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",
652665
"\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",
659674
"\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",
661678
"\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": [
668690
"\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",
672692
"\n",
673-
"pl.view_yz()\n",
674-
"pl.camera.zoom(1.5)\n",
693+
"```{image} geovista-globe-preview.png\n",
675694
"\n",
676-
"pl.show()"
695+
"```\n",
696+
"````"
677697
]
678698
},
679699
{
680700
"cell_type": "code",
681701
"execution_count": null,
682-
"id": "27",
702+
"id": "28",
683703
"metadata": {},
684704
"outputs": [],
685705
"source": [
686-
"pl = gv.GeoPlotter(crs=\"ESRI:54030\") # Robinson\n",
706+
"if not CI:\n",
707+
" pl = gv.GeoPlotter(crs=\"ESRI:54030\") # Robinson\n",
687708
"\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",
694715
"\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",
698719
"\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",
702723
"\n",
703-
"pl.show()"
724+
" pl.show()"
704725
]
705726
},
706727
{
707728
"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",
709743
"metadata": {
710744
"editable": true,
711745
"slideshow": {
@@ -717,22 +751,13 @@
717751
"# lonboard\n",
718752
"\n",
719753
"[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."
730755
]
731756
},
732757
{
733758
"cell_type": "code",
734759
"execution_count": null,
735-
"id": "29",
760+
"id": "31",
736761
"metadata": {
737762
"editable": true,
738763
"slideshow": {
@@ -765,6 +790,21 @@
765790
"m = Map(layer)\n",
766791
"m"
767792
]
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+
]
768808
}
769809
],
770810
"metadata": {

geovista-flat-preview.png

295 KB
Loading

geovista-globe-preview.png

207 KB
Loading

0 commit comments

Comments
 (0)