Skip to content

Commit 824a94d

Browse files
add installation of paraview to run on colab (#1486)
1 parent a16f63f commit 824a94d

File tree

1 file changed

+117
-78
lines changed

1 file changed

+117
-78
lines changed

examples/PySDM_examples/_HOWTOs/paraview_hello_world.ipynb

Lines changed: 117 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,105 @@
1515
"id": "35dba30bf42bd326",
1616
"metadata": {},
1717
"source": [
18-
"# TODO #1417\n",
18+
"### TODO #1417 add description\n",
19+
"### TODO #1490 fix installation on binder\n",
1920
"For more informations about Paraview please refere to [Paraview documentation](https://docs.paraview.org/en/latest/Tutorials/SelfDirectedTutorial/)"
2021
]
2122
},
2223
{
2324
"cell_type": "code",
25+
"execution_count": 1,
2426
"id": "93289adf665b5c7f",
2527
"metadata": {
2628
"ExecuteTime": {
27-
"end_time": "2024-12-24T09:44:03.286946Z",
28-
"start_time": "2024-12-24T09:44:03.263186Z"
29+
"end_time": "2025-01-06T20:42:41.598955Z",
30+
"start_time": "2025-01-06T20:42:41.591955Z"
2931
}
3032
},
33+
"outputs": [],
3134
"source": [
3235
"import sys\n",
3336
"if 'google.colab' in sys.modules:\n",
3437
" !pip --quiet install open-atmos-jupyter-utils\n",
3538
" from open_atmos_jupyter_utils import pip_install_on_colab\n",
3639
" pip_install_on_colab('PySDM-examples')"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 2,
45+
"id": "e3537b5faa81e11f",
46+
"metadata": {
47+
"ExecuteTime": {
48+
"end_time": "2025-01-06T20:42:48.835403Z",
49+
"start_time": "2025-01-06T20:42:42.286569Z"
50+
}
51+
},
52+
"outputs": [
53+
{
54+
"name": "stdout",
55+
"output_type": "stream",
56+
"text": [
57+
"paraview version 5.13.1\n"
58+
]
59+
}
3760
],
38-
"outputs": [],
39-
"execution_count": 4
61+
"source": [
62+
"import os\n",
63+
"import subprocess\n",
64+
"SUBPROCESS_ENV = os.environ.copy()\n",
65+
"\n",
66+
"if 'google.colab' in sys.modules:\n",
67+
" !apt-get install -qq ghostscript\n",
68+
" !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",
69+
" !tar xzf paraview.tar.gz\n",
70+
" SUBPROCESS_ENV['PATH'] += ':' + subprocess.check_output(['bash', '-c', \"echo `pwd`/`dirname ParaView*/bin/pvpython`\"], text=True)[:-1]\n",
71+
" \n",
72+
" # check if Ghostscript's ps2pdf works\n",
73+
" assert subprocess.check_call(['type', 'ps2pdf'], shell=True) == 0\n",
74+
" \n",
75+
"# check if Paraview's pvpython works\n",
76+
"assert subprocess.check_call(['pvpython', '--version'], env=SUBPROCESS_ENV) == 0\n",
77+
"assert subprocess.check_call(['pvpython', '-c', 'import paraview'], env=SUBPROCESS_ENV) == 0"
78+
]
4079
},
4180
{
4281
"cell_type": "code",
82+
"execution_count": 3,
4383
"id": "ee889545",
4484
"metadata": {
4585
"ExecuteTime": {
46-
"end_time": "2024-12-24T09:44:06.619086Z",
47-
"start_time": "2024-12-24T09:44:03.326051Z"
86+
"end_time": "2025-01-06T20:42:48.845075Z",
87+
"start_time": "2025-01-06T20:42:48.842291Z"
4888
}
4989
},
90+
"outputs": [],
5091
"source": [
5192
"from PySDM_examples.Arabas_et_al_2015 import Settings, SpinUp\n",
5293
"from PySDM_examples.Szumowski_et_al_1998 import Simulation, Storage\n",
5394
"from PySDM.exporters import VTKExporter\n",
5495
"from PySDM_examples.utils import ProgBarController\n",
5596
"from PySDM import products as PySDM_products\n",
56-
"import subprocess\n",
5797
"import glob\n",
5898
"import platform"
59-
],
60-
"outputs": [],
61-
"execution_count": 5
99+
]
62100
},
63101
{
64102
"cell_type": "code",
103+
"execution_count": 4,
65104
"id": "f0d2581f",
66105
"metadata": {
67106
"ExecuteTime": {
68-
"end_time": "2024-12-24T09:44:06.635813Z",
69-
"start_time": "2024-12-24T09:44:06.633731Z"
107+
"end_time": "2025-01-06T20:42:49.673689Z",
108+
"start_time": "2025-01-06T20:42:49.664256Z"
70109
}
71110
},
111+
"outputs": [],
72112
"source": [
73113
"products = [\n",
74114
" PySDM_products.EffectiveRadius(unit='um')\n",
75115
"]"
76-
],
77-
"outputs": [],
78-
"execution_count": 6
116+
]
79117
},
80118
{
81119
"cell_type": "markdown",
@@ -87,41 +125,41 @@
87125
},
88126
{
89127
"cell_type": "code",
128+
"execution_count": 5,
90129
"id": "74c00944",
91130
"metadata": {
92131
"ExecuteTime": {
93-
"end_time": "2024-12-24T09:45:09.597772Z",
94-
"start_time": "2024-12-24T09:44:06.656496Z"
132+
"end_time": "2025-01-06T20:43:31.937868Z",
133+
"start_time": "2025-01-06T20:42:51.814553Z"
95134
}
96135
},
97-
"source": [
98-
"settings = Settings()\n",
99-
"storage = Storage()\n",
100-
"simulation = Simulation(settings, storage, SpinUp=SpinUp)\n",
101-
"simulation.reinit(products)\n",
102-
"\n",
103-
"vtk_exporter = VTKExporter(path='.') \n",
104-
"\n",
105-
"simulation.run(ProgBarController(\"progress:\"), vtk_exporter=vtk_exporter)\n",
106-
"vtk_exporter.write_pvd()"
107-
],
108136
"outputs": [
109137
{
110138
"data": {
111-
"text/plain": [
112-
"FloatProgress(value=0.0, description='progress:', max=1.0)"
113-
],
114139
"application/vnd.jupyter.widget-view+json": {
140+
"model_id": "f9d581fdc60345ff804d5265fc156e1c",
115141
"version_major": 2,
116-
"version_minor": 0,
117-
"model_id": "b4d654a45ee143bb86ba1784844568c0"
118-
}
142+
"version_minor": 0
143+
},
144+
"text/plain": [
145+
"FloatProgress(value=0.0, description='progress:', max=1.0)"
146+
]
119147
},
120148
"metadata": {},
121149
"output_type": "display_data"
122150
}
123151
],
124-
"execution_count": 7
152+
"source": [
153+
"settings = Settings()\n",
154+
"storage = Storage()\n",
155+
"simulation = Simulation(settings, storage, SpinUp=SpinUp)\n",
156+
"simulation.reinit(products)\n",
157+
"\n",
158+
"vtk_exporter = VTKExporter(path='.') \n",
159+
"\n",
160+
"simulation.run(ProgBarController(\"progress:\"), vtk_exporter=vtk_exporter)\n",
161+
"vtk_exporter.write_pvd()"
162+
]
125163
},
126164
{
127165
"cell_type": "markdown",
@@ -133,34 +171,23 @@
133171
},
134172
{
135173
"cell_type": "code",
136-
"id": "94041d98fa896fba",
137-
"metadata": {
138-
"ExecuteTime": {
139-
"end_time": "2024-12-24T09:45:09.607338Z",
140-
"start_time": "2024-12-24T09:45:09.604990Z"
141-
}
142-
},
143-
"source": [
144-
"if 'google.colab' in sys.modules:\n",
145-
" !apt-get -qq install python3-paraview\n",
146-
" \n",
147-
" # Workaround for a bug in Ubuntu package described here\n",
148-
" # (https://discourse.paraview.org/t/paraview-error-while-loading-shared-libraries-libpdal-base-so-13-cannot-open-shared-object-file/14000);\n",
149-
" # with solution taken from that comment: https://github.com/qgis/QGIS/issues/52433#issuecomment-1792285094.\n",
150-
" ! if [ ! -f /usr/lib/libpdal_base.so.13 ]; then ln -s /usr/lib/libpdal_base.so.15 /usr/lib/libpdal_base.so.13; fi "
151-
],
152-
"outputs": [],
153-
"execution_count": 8
154-
},
155-
{
156-
"cell_type": "code",
174+
"execution_count": 6,
157175
"id": "2030d8e7",
158176
"metadata": {
159177
"ExecuteTime": {
160-
"end_time": "2024-12-24T09:45:09.621096Z",
161-
"start_time": "2024-12-24T09:45:09.615386Z"
178+
"end_time": "2025-01-06T20:43:32.052989Z",
179+
"start_time": "2025-01-06T20:43:32.046624Z"
162180
}
163181
},
182+
"outputs": [
183+
{
184+
"name": "stdout",
185+
"output_type": "stream",
186+
"text": [
187+
"Overwriting pvscript.py\n"
188+
]
189+
}
190+
],
164191
"source": [
165192
"%%writefile pvscript.py\n",
166193
"\n",
@@ -297,17 +324,7 @@
297324
" Rasterize3Dgeometry= False,\n",
298325
" GL2PSdepthsortmethod= 'BSP sorting (slow, best)',\n",
299326
" )"
300-
],
301-
"outputs": [
302-
{
303-
"name": "stdout",
304-
"output_type": "stream",
305-
"text": [
306-
"Overwriting pvscript.py\n"
307-
]
308-
}
309-
],
310-
"execution_count": 9
327+
]
311328
},
312329
{
313330
"cell_type": "markdown",
@@ -319,17 +336,29 @@
319336
},
320337
{
321338
"cell_type": "code",
339+
"execution_count": 7,
322340
"id": "79477d3d",
323341
"metadata": {
324342
"ExecuteTime": {
325-
"start_time": "2024-12-24T09:45:09.652231Z"
343+
"end_time": "2025-01-06T20:44:22.171797Z",
344+
"start_time": "2025-01-06T20:43:32.099529Z"
326345
}
327346
},
328-
"source": [
329-
"subprocess.run(['pvpython', '--force-offscreen-rendering', 'pvscript.py'], check=platform.system() != 'Windows')"
347+
"outputs": [
348+
{
349+
"data": {
350+
"text/plain": [
351+
"CompletedProcess(args=['pvpython', '--force-offscreen-rendering', 'pvscript.py'], returncode=0)"
352+
]
353+
},
354+
"execution_count": 7,
355+
"metadata": {},
356+
"output_type": "execute_result"
357+
}
330358
],
331-
"outputs": [],
332-
"execution_count": 10
359+
"source": [
360+
"subprocess.run(['pvpython', '--force-offscreen-rendering', 'pvscript.py'], check=platform.system() != 'Windows', env=SUBPROCESS_ENV)"
361+
]
333362
},
334363
{
335364
"cell_type": "markdown",
@@ -343,7 +372,12 @@
343372
"cell_type": "code",
344373
"execution_count": 8,
345374
"id": "23e0cf61",
346-
"metadata": {},
375+
"metadata": {
376+
"ExecuteTime": {
377+
"end_time": "2025-01-06T20:44:32.623050Z",
378+
"start_time": "2025-01-06T20:44:22.257021Z"
379+
}
380+
},
347381
"outputs": [],
348382
"source": [
349383
"if platform.system() != 'Windows':\n",
@@ -354,9 +388,14 @@
354388
},
355389
{
356390
"cell_type": "code",
357-
"execution_count": 9,
391+
"execution_count": null,
358392
"id": "9d3e4a35",
359-
"metadata": {},
393+
"metadata": {
394+
"ExecuteTime": {
395+
"end_time": "2025-01-06T20:42:10.669031Z",
396+
"start_time": "2025-01-06T20:42:10.667667Z"
397+
}
398+
},
360399
"outputs": [],
361400
"source": []
362401
}

0 commit comments

Comments
 (0)