Skip to content

Commit 8f63770

Browse files
committed
examples: animations numpy2.x related changes
1 parent c060b93 commit 8f63770

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

doc/examples/animations-pulsating-sphere.ipynb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@
147147
"metadata": {},
148148
"outputs": [],
149149
"source": [
150-
"grid = hex_grid([xmin, xmax], [ymin, ymax], 0.0125, 'vertical')\n",
150+
"grid = sfs.util.as_xyz_components(hex_grid([xmin, xmax],\n",
151+
" [ymin, ymax],\n",
152+
" 0.0125,\n",
153+
" 'vertical'))\n",
151154
"ani = animation.particle_displacement(\n",
152155
" omega, center, radius, amplitude, grid, frames, figsize, c='Gray')\n",
153156
"plt.close()\n",
@@ -167,8 +170,9 @@
167170
"metadata": {},
168171
"outputs": [],
169172
"source": [
170-
"grid = [np.random.uniform(xmin, xmax, 4000),\n",
171-
" np.random.uniform(ymin, ymax, 4000), 0]\n",
173+
"grid = sfs.util.as_xyz_components([np.random.uniform(xmin, xmax, 4000),\n",
174+
" np.random.uniform(ymin, ymax, 4000),\n",
175+
" 0])\n",
172176
"ani = animation.particle_displacement(\n",
173177
" omega, center, radius, amplitude, grid, frames, figsize, c='Gray')\n",
174178
"plt.close()\n",

doc/examples/animations_pulsating_sphere.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
from matplotlib import pyplot as plt
55
from matplotlib import animation
6+
import warnings
7+
warnings.simplefilter("ignore", np.exceptions.ComplexWarning)
68

79

810
def particle_displacement(omega, center, radius, amplitude, grid, frames,
@@ -18,7 +20,7 @@ def particle_displacement(omega, center, radius, amplitude, grid, frames,
1820
scat = sfs.plot2d.particles(grid + displacement, **kwargs)
1921

2022
def update_frame_displacement(i):
21-
position = (grid + displacement * phasor**i).apply(np.real)
23+
position = np.real((grid + displacement * phasor**i))
2224
position = np.column_stack([position[0].flatten(),
2325
position[1].flatten()])
2426
scat.set_offsets(position)
@@ -43,7 +45,7 @@ def particle_velocity(omega, center, radius, amplitude, grid, frames,
4345
**kwargs)
4446

4547
def update_frame_velocity(i):
46-
quiv.set_UVC(*(velocity[:2] * phasor**i).apply(np.real))
48+
np.real(quiv.set_UVC(*(velocity[:2] * phasor**i)))
4749
return [quiv]
4850

4951
return animation.FuncAnimation(

doc/examples/plot_particle_density.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# normal vector of plane wave
1515
npw = sfs.util.direction_vector(np.radians(pw_angle))
1616
# random grid for velocity
17-
grid = [np.random.uniform(-3, 3, 40000), np.random.uniform(-3, 3, 40000), 0]
17+
grid = sfs.util.as_xyz_components([np.random.uniform(-3, 3, 40000),
18+
np.random.uniform(-3, 3, 40000),
19+
0])
1820

1921

2022
def plot_particle_displacement(title):

0 commit comments

Comments
 (0)