From 9f1fb76ff9d9f447292103dd0b62c2fa13e574b4 Mon Sep 17 00:00:00 2001 From: Arne Naegel Date: Fri, 14 Jun 2024 06:12:02 +0200 Subject: [PATCH] Protecting pyvista: static, trame,... --- .../tutorial-solver/example01-smoothers.ipynb | 24 ++++++++++++++----- .../tutorial-solver/example01-smoothers.py | 17 +++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/content/tutorial-solver/example01-smoothers.ipynb b/content/tutorial-solver/example01-smoothers.ipynb index ad136da..09ce214 100644 --- a/content/tutorial-solver/example01-smoothers.ipynb +++ b/content/tutorial-solver/example01-smoothers.ipynb @@ -304,12 +304,24 @@ } ], "source": [ - "import pyvista\n", - "#pyvista.start_xvfb()\n", - "#pyvista.set_jupyter_backend('static')\n", - "pyvista.set_jupyter_backend('trame')\n", - "result = pyvista.read( \"Error_gs.vtu\")\n", - "result.plot(scalars=\"u\", show_edges=True, cmap='jet')" + "try:\n", + " import pyvista\n", + "except ModuleNotFoundError:\n", + " print(\"pyvista is required for this demo\")\n", + " exit(0)\n", + "\n", + "try: \n", + " # Activate the following lines binder, colab etc.\n", + " pyvista.start_xvfb()\n", + " pyvista.set_jupyter_backend('static')\n", + "\n", + " # Activate locally, if trame exists.\n", + " # pyvista.set_jupyter_backend('trame')\n", + " \n", + " result = pyvista.read( \"Error_gs.vtu\")\n", + " result.plot(scalars=\"u\", show_edges=True, cmap='jet')\n", + "except:\n", + " print(\"Plotting failed.\")" ] }, { diff --git a/content/tutorial-solver/example01-smoothers.py b/content/tutorial-solver/example01-smoothers.py index 990cad5..5eddccc 100644 --- a/content/tutorial-solver/example01-smoothers.py +++ b/content/tutorial-solver/example01-smoothers.py @@ -223,11 +223,18 @@ def PlotResults(history, title): print("pyvista is required for this demo") exit(0) -#pyvista.start_xvfb() -#pyvista.set_jupyter_backend('static') -pyvista.set_jupyter_backend('trame') -result = pyvista.read( "Error_gs.vtu") -result.plot(scalars="u", show_edges=True, cmap='jet') +try: + # Activate the following lines binder, colab etc. + pyvista.start_xvfb() + pyvista.set_jupyter_backend('static') + + # Activate locally, if trame exists. + # pyvista.set_jupyter_backend('trame') + + result = pyvista.read( "Error_gs.vtu") + result.plot(scalars="u", show_edges=True, cmap='jet') +except: + print("Plotting failed.") # In[ ]: