Skip to content

Commit

Permalink
add installation of paraview to run on colab (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgnieszkaZaba authored Jan 7, 2025
1 parent a16f63f commit 824a94d
Showing 1 changed file with 117 additions and 78 deletions.
195 changes: 117 additions & 78 deletions examples/PySDM_examples/_HOWTOs/paraview_hello_world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,105 @@
"id": "35dba30bf42bd326",
"metadata": {},
"source": [
"# TODO #1417\n",
"### TODO #1417 add description\n",
"### TODO #1490 fix installation on binder\n",
"For more informations about Paraview please refere to [Paraview documentation](https://docs.paraview.org/en/latest/Tutorials/SelfDirectedTutorial/)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "93289adf665b5c7f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-24T09:44:03.286946Z",
"start_time": "2024-12-24T09:44:03.263186Z"
"end_time": "2025-01-06T20:42:41.598955Z",
"start_time": "2025-01-06T20:42:41.591955Z"
}
},
"outputs": [],
"source": [
"import sys\n",
"if 'google.colab' in sys.modules:\n",
" !pip --quiet install open-atmos-jupyter-utils\n",
" from open_atmos_jupyter_utils import pip_install_on_colab\n",
" pip_install_on_colab('PySDM-examples')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e3537b5faa81e11f",
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-06T20:42:48.835403Z",
"start_time": "2025-01-06T20:42:42.286569Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"paraview version 5.13.1\n"
]
}
],
"outputs": [],
"execution_count": 4
"source": [
"import os\n",
"import subprocess\n",
"SUBPROCESS_ENV = os.environ.copy()\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !apt-get install -qq ghostscript\n",
" !wget -nv \"https://paraview.org/paraview-downloads/download.php?submit=Download&version=v5.13&type=binary&os=Linux&downloadFile=ParaView-5.13.1-egl-MPI-Linux-Python3.10-x86_64.tar.gz\" -O paraview.tar.gz\n",
" !tar xzf paraview.tar.gz\n",
" SUBPROCESS_ENV['PATH'] += ':' + subprocess.check_output(['bash', '-c', \"echo `pwd`/`dirname ParaView*/bin/pvpython`\"], text=True)[:-1]\n",
" \n",
" # check if Ghostscript's ps2pdf works\n",
" assert subprocess.check_call(['type', 'ps2pdf'], shell=True) == 0\n",
" \n",
"# check if Paraview's pvpython works\n",
"assert subprocess.check_call(['pvpython', '--version'], env=SUBPROCESS_ENV) == 0\n",
"assert subprocess.check_call(['pvpython', '-c', 'import paraview'], env=SUBPROCESS_ENV) == 0"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ee889545",
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-24T09:44:06.619086Z",
"start_time": "2024-12-24T09:44:03.326051Z"
"end_time": "2025-01-06T20:42:48.845075Z",
"start_time": "2025-01-06T20:42:48.842291Z"
}
},
"outputs": [],
"source": [
"from PySDM_examples.Arabas_et_al_2015 import Settings, SpinUp\n",
"from PySDM_examples.Szumowski_et_al_1998 import Simulation, Storage\n",
"from PySDM.exporters import VTKExporter\n",
"from PySDM_examples.utils import ProgBarController\n",
"from PySDM import products as PySDM_products\n",
"import subprocess\n",
"import glob\n",
"import platform"
],
"outputs": [],
"execution_count": 5
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f0d2581f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-24T09:44:06.635813Z",
"start_time": "2024-12-24T09:44:06.633731Z"
"end_time": "2025-01-06T20:42:49.673689Z",
"start_time": "2025-01-06T20:42:49.664256Z"
}
},
"outputs": [],
"source": [
"products = [\n",
" PySDM_products.EffectiveRadius(unit='um')\n",
"]"
],
"outputs": [],
"execution_count": 6
]
},
{
"cell_type": "markdown",
Expand All @@ -87,41 +125,41 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "74c00944",
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-24T09:45:09.597772Z",
"start_time": "2024-12-24T09:44:06.656496Z"
"end_time": "2025-01-06T20:43:31.937868Z",
"start_time": "2025-01-06T20:42:51.814553Z"
}
},
"source": [
"settings = Settings()\n",
"storage = Storage()\n",
"simulation = Simulation(settings, storage, SpinUp=SpinUp)\n",
"simulation.reinit(products)\n",
"\n",
"vtk_exporter = VTKExporter(path='.') \n",
"\n",
"simulation.run(ProgBarController(\"progress:\"), vtk_exporter=vtk_exporter)\n",
"vtk_exporter.write_pvd()"
],
"outputs": [
{
"data": {
"text/plain": [
"FloatProgress(value=0.0, description='progress:', max=1.0)"
],
"application/vnd.jupyter.widget-view+json": {
"model_id": "f9d581fdc60345ff804d5265fc156e1c",
"version_major": 2,
"version_minor": 0,
"model_id": "b4d654a45ee143bb86ba1784844568c0"
}
"version_minor": 0
},
"text/plain": [
"FloatProgress(value=0.0, description='progress:', max=1.0)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": 7
"source": [
"settings = Settings()\n",
"storage = Storage()\n",
"simulation = Simulation(settings, storage, SpinUp=SpinUp)\n",
"simulation.reinit(products)\n",
"\n",
"vtk_exporter = VTKExporter(path='.') \n",
"\n",
"simulation.run(ProgBarController(\"progress:\"), vtk_exporter=vtk_exporter)\n",
"vtk_exporter.write_pvd()"
]
},
{
"cell_type": "markdown",
Expand All @@ -133,34 +171,23 @@
},
{
"cell_type": "code",
"id": "94041d98fa896fba",
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-24T09:45:09.607338Z",
"start_time": "2024-12-24T09:45:09.604990Z"
}
},
"source": [
"if 'google.colab' in sys.modules:\n",
" !apt-get -qq install python3-paraview\n",
" \n",
" # Workaround for a bug in Ubuntu package described here\n",
" # (https://discourse.paraview.org/t/paraview-error-while-loading-shared-libraries-libpdal-base-so-13-cannot-open-shared-object-file/14000);\n",
" # with solution taken from that comment: https://github.com/qgis/QGIS/issues/52433#issuecomment-1792285094.\n",
" ! if [ ! -f /usr/lib/libpdal_base.so.13 ]; then ln -s /usr/lib/libpdal_base.so.15 /usr/lib/libpdal_base.so.13; fi "
],
"outputs": [],
"execution_count": 8
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2030d8e7",
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-24T09:45:09.621096Z",
"start_time": "2024-12-24T09:45:09.615386Z"
"end_time": "2025-01-06T20:43:32.052989Z",
"start_time": "2025-01-06T20:43:32.046624Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting pvscript.py\n"
]
}
],
"source": [
"%%writefile pvscript.py\n",
"\n",
Expand Down Expand Up @@ -297,17 +324,7 @@
" Rasterize3Dgeometry= False,\n",
" GL2PSdepthsortmethod= 'BSP sorting (slow, best)',\n",
" )"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting pvscript.py\n"
]
}
],
"execution_count": 9
]
},
{
"cell_type": "markdown",
Expand All @@ -319,17 +336,29 @@
},
{
"cell_type": "code",
"execution_count": 7,
"id": "79477d3d",
"metadata": {
"ExecuteTime": {
"start_time": "2024-12-24T09:45:09.652231Z"
"end_time": "2025-01-06T20:44:22.171797Z",
"start_time": "2025-01-06T20:43:32.099529Z"
}
},
"source": [
"subprocess.run(['pvpython', '--force-offscreen-rendering', 'pvscript.py'], check=platform.system() != 'Windows')"
"outputs": [
{
"data": {
"text/plain": [
"CompletedProcess(args=['pvpython', '--force-offscreen-rendering', 'pvscript.py'], returncode=0)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"execution_count": 10
"source": [
"subprocess.run(['pvpython', '--force-offscreen-rendering', 'pvscript.py'], check=platform.system() != 'Windows', env=SUBPROCESS_ENV)"
]
},
{
"cell_type": "markdown",
Expand All @@ -343,7 +372,12 @@
"cell_type": "code",
"execution_count": 8,
"id": "23e0cf61",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-06T20:44:32.623050Z",
"start_time": "2025-01-06T20:44:22.257021Z"
}
},
"outputs": [],
"source": [
"if platform.system() != 'Windows':\n",
Expand All @@ -354,9 +388,14 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "9d3e4a35",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-06T20:42:10.669031Z",
"start_time": "2025-01-06T20:42:10.667667Z"
}
},
"outputs": [],
"source": []
}
Expand Down

0 comments on commit 824a94d

Please sign in to comment.