Skip to content

Commit c256737

Browse files
authored
pvanim: make animation side user-definable; add dark/light mode option; fine tune font sizes and scene element placement; display time in minutes; longer simulation for docs homepage (#1639)
1 parent 85f8e73 commit c256737

2 files changed

Lines changed: 125 additions & 134 deletions

File tree

examples/PySDM_examples/_HOWTOs/paraview_hello_world.ipynb

Lines changed: 68 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,34 @@
2222
},
2323
{
2424
"cell_type": "code",
25+
"execution_count": 7,
2526
"id": "93289adf665b5c7f",
2627
"metadata": {
2728
"ExecuteTime": {
2829
"end_time": "2025-05-09T08:27:59.767037Z",
2930
"start_time": "2025-05-09T08:27:59.763173Z"
3031
}
3132
},
33+
"outputs": [],
3234
"source": [
3335
"import sys\n",
3436
"if 'google.colab' in sys.modules:\n",
3537
" !pip --quiet install open-atmos-jupyter-utils\n",
3638
" from open_atmos_jupyter_utils import pip_install_on_colab\n",
3739
" pip_install_on_colab('PySDM-examples')"
38-
],
39-
"outputs": [],
40-
"execution_count": 1
40+
]
4141
},
4242
{
4343
"cell_type": "code",
44+
"execution_count": 8,
4445
"id": "e3537b5faa81e11f",
4546
"metadata": {
4647
"ExecuteTime": {
4748
"end_time": "2025-05-09T08:28:06.258130Z",
4849
"start_time": "2025-05-09T08:28:00.353771Z"
4950
}
5051
},
52+
"outputs": [],
5153
"source": [
5254
"import os\n",
5355
"import subprocess\n",
@@ -65,59 +67,50 @@
6567
"# check if Paraview's pvpython works\n",
6668
"assert subprocess.check_call(['pvpython', '--version'], env=SUBPROCESS_ENV) == 0\n",
6769
"assert subprocess.check_call(['pvpython', '-c', 'import paraview'], env=SUBPROCESS_ENV) == 0"
68-
],
69-
"outputs": [
70-
{
71-
"name": "stdout",
72-
"output_type": "stream",
73-
"text": [
74-
"paraview version 5.13.1\n"
75-
]
76-
}
77-
],
78-
"execution_count": 2
70+
]
7971
},
8072
{
8173
"cell_type": "code",
74+
"execution_count": 11,
8275
"id": "ee889545",
8376
"metadata": {
8477
"ExecuteTime": {
8578
"end_time": "2025-05-09T08:28:08.607057Z",
8679
"start_time": "2025-05-09T08:28:06.263583Z"
8780
}
8881
},
82+
"outputs": [],
8983
"source": [
9084
"from PySDM_examples.Arabas_et_al_2015 import Settings, SpinUp\n",
9185
"from PySDM_examples.utils.kinematic_2d import Simulation, Storage\n",
9286
"from PySDM.exporters import VTKExporter\n",
9387
"from PySDM_examples.utils import ProgBarController\n",
88+
"from PySDM.physics import si\n",
9489
"from PySDM import products as PySDM_products\n",
9590
"import PySDM_examples\n",
9691
"import glob\n",
9792
"import platform\n",
9893
"import pathlib"
99-
],
100-
"outputs": [],
101-
"execution_count": 3
94+
]
10295
},
10396
{
10497
"cell_type": "code",
98+
"execution_count": 2,
10599
"id": "f0d2581f",
106100
"metadata": {
107101
"ExecuteTime": {
108102
"end_time": "2025-05-09T08:28:08.617918Z",
109103
"start_time": "2025-05-09T08:28:08.615072Z"
110104
}
111105
},
106+
"outputs": [],
112107
"source": [
113108
"products = [\n",
114109
" PySDM_products.EffectiveRadius(unit='um'),\n",
115110
" PySDM_products.FlowVelocityComponent(component = 0, name = 'cx'),\n",
116111
" PySDM_products.FlowVelocityComponent(component = 1, name = 'cy')\n",
117112
"]"
118-
],
119-
"outputs": [],
120-
"execution_count": 4
113+
]
121114
},
122115
{
123116
"cell_type": "markdown",
@@ -128,12 +121,29 @@
128121
]
129122
},
130123
{
131-
"metadata": {},
132124
"cell_type": "code",
133-
"outputs": [],
134125
"execution_count": null,
126+
"id": "c7634bb25cdbbe46",
127+
"metadata": {},
128+
"outputs": [
129+
{
130+
"data": {
131+
"application/vnd.jupyter.widget-view+json": {
132+
"model_id": "61d7c35b77214683bb1b3ed29d10c44d",
133+
"version_major": 2,
134+
"version_minor": 0
135+
},
136+
"text/plain": [
137+
"FloatProgress(value=0.0, description='progress:', max=1.0)"
138+
]
139+
},
140+
"metadata": {},
141+
"output_type": "display_data"
142+
}
143+
],
135144
"source": [
136145
"settings = Settings()\n",
146+
"settings.simulation_time = 100 * si.minute\n",
137147
"storage = Storage()\n",
138148
"simulation = Simulation(settings, storage, SpinUp=SpinUp)\n",
139149
"simulation.reinit(products)\n",
@@ -142,119 +152,69 @@
142152
"\n",
143153
"simulation.run(ProgBarController(\"progress:\"), vtk_exporter=vtk_exporter)\n",
144154
"vtk_exporter.write_pvd()"
145-
],
146-
"id": "c7634bb25cdbbe46"
155+
]
147156
},
148157
{
149158
"cell_type": "markdown",
150159
"id": "066f9c18",
151160
"metadata": {},
152-
"source": "#### 2. execute ``PySDM_examples/utils/pvanim.py`` script using `pvpython`"
161+
"source": [
162+
"#### 2. execute ``PySDM_examples/utils/pvanim.py`` script using `pvpython`"
163+
]
153164
},
154165
{
166+
"cell_type": "code",
167+
"execution_count": 9,
168+
"id": "154ce67d9a84a51d",
155169
"metadata": {
156170
"ExecuteTime": {
157171
"end_time": "2025-05-09T08:52:00.913288Z",
158172
"start_time": "2025-05-09T08:51:55.311337Z"
159173
}
160174
},
161-
"cell_type": "code",
175+
"outputs": [],
162176
"source": [
163177
"pvanim = pathlib.Path(PySDM_examples.__file__).parent / \"utils\" / \"pvanim.py\"\n",
164178
"result = subprocess.run([\"pvpython\", str(pvanim), '--help'], check=True, env=SUBPROCESS_ENV)"
165-
],
166-
"id": "154ce67d9a84a51d",
167-
"outputs": [
168-
{
169-
"name": "stdout",
170-
"output_type": "stream",
171-
"text": [
172-
"usage: pvanim.py [-h] [--multiplicity_preset MULTIPLICITY_PRESET]\n",
173-
" [--multiplicity_logscale]\n",
174-
" [--effectiveradius_preset EFFECTIVERADIUS_PRESET]\n",
175-
" [--effectiveradius_logscale]\n",
176-
" [--effectiveradius_nan_color EFFECTIVERADIUS_NAN_COLOR EFFECTIVERADIUS_NAN_COLOR EFFECTIVERADIUS_NAN_COLOR]\n",
177-
" [--sd_products_opacity SD_PRODUCTS_OPACITY]\n",
178-
" [--calculator1_opacity CALCULATOR1_OPACITY]\n",
179-
" [--sd_attributes_opacity SD_ATTRIBUTES_OPACITY]\n",
180-
" [--animationframename ANIMATIONFRAMENAME]\n",
181-
" [--animationname ANIMATIONNAME] [--framerate FRAMERATE]\n",
182-
" product_path attributes_path output_path\n",
183-
"\n",
184-
"positional arguments:\n",
185-
" product_path path to pvd products file\n",
186-
" attributes_path path to pvd attributes file\n",
187-
" output_path path where to write output files\n",
188-
"\n",
189-
"options:\n",
190-
" -h, --help show this help message and exit\n",
191-
" --multiplicity_preset MULTIPLICITY_PRESET\n",
192-
" Preset for multiplicity (default: Inferno\n",
193-
" (matplotlib))\n",
194-
" --multiplicity_logscale\n",
195-
" Use log scale for multiplicity (default: True)\n",
196-
" --effectiveradius_preset EFFECTIVERADIUS_PRESET\n",
197-
" Preset for effectiveradius (default: Black, Blue and\n",
198-
" White)\n",
199-
" --effectiveradius_logscale\n",
200-
" Use log scale for effectiveradius (default: True)\n",
201-
" --effectiveradius_nan_color EFFECTIVERADIUS_NAN_COLOR EFFECTIVERADIUS_NAN_COLOR EFFECTIVERADIUS_NAN_COLOR\n",
202-
" Nan color in RGB format for effectiveradius (default:\n",
203-
" [0.666, 0.333, 1.0])\n",
204-
" --sd_products_opacity SD_PRODUCTS_OPACITY\n",
205-
" Opacity for sd_products (default: 0.9)\n",
206-
" --calculator1_opacity CALCULATOR1_OPACITY\n",
207-
" Opacity for calculator1 (default: 0.19)\n",
208-
" --sd_attributes_opacity SD_ATTRIBUTES_OPACITY\n",
209-
" Opacity for sd_attributes (default: 0.77)\n",
210-
" --animationframename ANIMATIONFRAMENAME\n",
211-
" Name of the file with animation last frame (default:\n",
212-
" None)\n",
213-
" --animationname ANIMATIONNAME\n",
214-
" Name of the file with animation (default: None)\n",
215-
" --framerate FRAMERATE\n",
216-
" Number of frame rates. (default: 15)\n"
217-
]
218-
}
219-
],
220-
"execution_count": 10
179+
]
221180
},
222181
{
223182
"cell_type": "code",
183+
"execution_count": 10,
224184
"id": "23e0cf61",
225185
"metadata": {
226186
"ExecuteTime": {
227187
"end_time": "2025-05-09T08:27:54.021909Z",
228188
"start_time": "2025-05-09T08:25:42.918680Z"
229189
}
230190
},
191+
"outputs": [],
231192
"source": [
232193
"product = pathlib.Path(\"./output/sd_products.pvd\").absolute()\n",
233194
"attributes = pathlib.Path(\"./output/sd_attributes.pvd\").absolute()\n",
234195
"\n",
235196
"try:\n",
236-
" result = subprocess.run(\n",
237-
" [\n",
238-
" \"pvpython\",\n",
239-
" \"--force-offscreen-rendering\",\n",
240-
" str(pvanim),\n",
241-
" str(product),\n",
242-
" str(attributes),\n",
243-
" str(pathlib.Path('./output').absolute()),\n",
244-
" \"--animationname\", \"docs_intro_animation.ogv\",\n",
245-
" \"--animationframename\", \"last_animation_frame.pdf\"\n",
246-
" ],\n",
247-
" check=platform.system() != \"Windows\",\n",
248-
" capture_output=True,\n",
249-
" text=True,\n",
250-
" env=SUBPROCESS_ENV,\n",
251-
" )\n",
197+
" for mode in ('light', 'dark'):\n",
198+
" result = subprocess.run(\n",
199+
" [\n",
200+
" \"pvpython\",\n",
201+
" \"--force-offscreen-rendering\",\n",
202+
" str(pvanim),\n",
203+
" str(product),\n",
204+
" str(attributes),\n",
205+
" str(pathlib.Path('./output').absolute()),\n",
206+
" \"--animationname\", \"docs_intro_animation.ogv\",\n",
207+
" \"--mode\", mode,\n",
208+
" ] + ([\"--animationframename\", \"last_animation_frame.pdf\"] if mode == 'light' else []),\n",
209+
" check=platform.system() != \"Windows\",\n",
210+
" capture_output=True,\n",
211+
" text=True,\n",
212+
" env=SUBPROCESS_ENV,\n",
213+
" )\n",
252214
"except subprocess.CalledProcessError as e:\n",
253215
" print(e.stderr)\n",
254216
" assert False"
255-
],
256-
"outputs": [],
257-
"execution_count": 13
217+
]
258218
},
259219
{
260220
"cell_type": "markdown",
@@ -266,34 +226,29 @@
266226
},
267227
{
268228
"cell_type": "code",
229+
"execution_count": 16,
269230
"id": "3e170fdc",
270231
"metadata": {
271232
"ExecuteTime": {
272233
"end_time": "2025-05-09T08:27:54.022827Z",
273234
"start_time": "2025-05-09T08:26:10.268239Z"
274235
}
275236
},
237+
"outputs": [],
276238
"source": [
277239
"if platform.system() != 'Windows':\n",
278240
" for file in glob.glob('output/anim_frame_*.pdf'):\n",
279241
" subprocess.run(['ps2pdf', file, file+'_'], capture_output=True, check=True)\n",
280242
" subprocess.run(['mv', file+'_', file], check=True)"
281-
],
282-
"outputs": [],
283-
"execution_count": 14
243+
]
284244
},
285245
{
286246
"cell_type": "code",
287-
"id": "9d3e4a35",
288-
"metadata": {
289-
"ExecuteTime": {
290-
"end_time": "2025-05-09T08:27:54.022911Z",
291-
"start_time": "2025-05-09T08:26:10.277448Z"
292-
}
293-
},
294-
"source": [],
247+
"execution_count": null,
248+
"id": "7df317e6",
249+
"metadata": {},
295250
"outputs": [],
296-
"execution_count": null
251+
"source": []
297252
}
298253
],
299254
"metadata": {

0 commit comments

Comments
 (0)