Skip to content

Commit

Permalink
Split "plot" module into "plot2d" and "plot3d"
Browse files Browse the repository at this point in the history
See #26.
  • Loading branch information
mgeier committed Mar 16, 2019
1 parent e9b2698 commit 4f83604
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 109 deletions.
6 changes: 3 additions & 3 deletions doc/examples/animations_pulsating_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def particle_displacement(omega, center, radius, amplitude, grid, frames,

fig, ax = plt.subplots(figsize=figsize)
ax.axis([grid[0].min(), grid[0].max(), grid[1].min(), grid[1].max()])
scat = sfs.plot.particles(grid + displacement, **kwargs)
scat = sfs.plot2d.particles(grid + displacement, **kwargs)

def update_frame_displacement(i):
position = (grid + displacement * phasor**i).apply(np.real)
Expand All @@ -38,7 +38,7 @@ def particle_velocity(omega, center, radius, amplitude, grid, frames,

fig, ax = plt.subplots(figsize=figsize)
ax.axis([grid[0].min(), grid[0].max(), grid[1].min(), grid[1].max()])
quiv = sfs.plot.vectors(
quiv = sfs.plot2d.vectors(
velocity, grid, clim=[-omega * amplitude, omega * amplitude],
**kwargs)

Expand All @@ -59,7 +59,7 @@ def sound_pressure(omega, center, radius, amplitude, grid, frames,
phasor = np.exp(1j * 2 * np.pi / frames)

fig, ax = plt.subplots(figsize=figsize)
im = sfs.plot.soundfield(np.real(pressure), grid, **kwargs)
im = sfs.plot2d.amplitude(np.real(pressure), grid, **kwargs)
ax.axis([grid[0].min(), grid[0].max(), grid[1].min(), grid[1].max()])

def update_frame_pressure(i):
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/horizontal_plane_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def compute_and_plot_soundfield(title):

plt.figure(figsize=(15, 15))
plt.cla()
sfs.plot.soundfield(p, grid, xnorm)
sfs.plot.loudspeaker_2d(array.x, array.n, twin)
sfs.plot.virtualsource_2d(xs)
sfs.plot.virtualsource_2d([0, 0], npw, type='plane')
sfs.plot2d.amplitude(p, grid, xnorm)
sfs.plot2d.loudspeakers(array.x, array.n, twin)
sfs.plot2d.virtualsource(xs)
sfs.plot2d.virtualsource([0, 0], npw, type='plane')
plt.title(title)
plt.grid()
plt.savefig(title + '.png')
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/mirror-image-source-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"metadata": {},
"outputs": [],
"source": [
"sfs.plot.soundfield(P, grid, xnorm=[L[0]/2, L[1]/2, L[2]/2]);"
"sfs.plot2d.amplitude(P, grid, xnorm=[L[0]/2, L[1]/2, L[2]/2]);"
]
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
"metadata": {},
"outputs": [],
"source": [
"sfs.plot.level(p, grid)\n",
"sfs.plot.virtualsource_2d(x0)"
"sfs.plot2d.level(p, grid)\n",
"sfs.plot2d.virtualsource(x0)"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/modal-room-acoustics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"metadata": {},
"outputs": [],
"source": [
"sfs.plot.soundfield(p, grid);"
"sfs.plot2d.amplitude(p, grid);"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/plot_particle_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def plot_particle_displacement(title):
# plot displacement
plt.figure(figsize=(15, 15))
plt.cla()
sfs.plot.particles(X, facecolor='black', s=3, trim=[-3, 3, -3, 3])
sfs.plot2d.particles(X, facecolor='black', s=3, trim=[-3, 3, -3, 3])
plt.axis('off')
plt.title(title)
plt.grid()
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/sound_field_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@

# === plot synthesized sound field ===
plt.figure(figsize=(10, 10))
sfs.plot.soundfield(p, grid, [0, 0, 0])
sfs.plot.loudspeaker_2d(array.x, array.n, twin)
sfs.plot2d.amplitude(p, grid, [0, 0, 0])
sfs.plot2d.loudspeakers(array.x, array.n, twin)
plt.grid()
plt.savefig('soundfield.png')


#sfs.plot.loudspeaker_3d(array.x, array.n, twin)
#sfs.plot3d.secondary_sources(array.x, array.n, twin)
#plt.savefig('loudspeakers.png')
8 changes: 4 additions & 4 deletions doc/examples/soundfigures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@

# plot and save synthesized sound field
plt.figure(figsize=(10, 10))
sfs.plot.soundfield(p, grid, xnorm=[0, -2.2, 0], cmap='BrBG', colorbar=False,
vmin=-1, vmax=1)
sfs.plot2d.amplitude(p, grid, xnorm=[0, -2.2, 0], cmap='BrBG', colorbar=False,
vmin=-1, vmax=1)
plt.title('Synthesized Sound Field')
plt.savefig('soundfigure.png')

# plot and save level of synthesized sound field
plt.figure(figsize=(12.5, 12.5))
im = sfs.plot.level(p, grid, xnorm=[0, -2.2, 0], vmin=-50, vmax=0,
colorbar_kwargs=dict(label='dB'))
im = sfs.plot2d.level(p, grid, xnorm=[0, -2.2, 0], vmin=-50, vmax=0,
colorbar_kwargs=dict(label='dB'))
plt.title('Level of Synthesized Sound Field')
plt.savefig('soundfigure_level.png')
18 changes: 9 additions & 9 deletions doc/examples/time_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
p = p * 100 # scale absolute amplitude

plt.figure(figsize=(10, 10))
sfs.plot.level(p, grid, cmap=my_cmap)
sfs.plot.loudspeaker_2d(array.x, array.n, twin)
sfs.plot2d.level(p, grid, cmap=my_cmap)
sfs.plot2d.loudspeakers(array.x, array.n, twin)
plt.grid()
sfs.plot.virtualsource_2d(xs)
sfs.plot2d.virtualsource(xs)
plt.title('impulse_ps_wfs_25d')
plt.savefig('impulse_ps_wfs_25d.png')

Expand All @@ -59,10 +59,10 @@
secondary_source, observation_time=t, grid=grid)

plt.figure(figsize=(10, 10))
sfs.plot.level(p, grid, cmap=my_cmap)
sfs.plot.loudspeaker_2d(array.x, array.n, twin)
sfs.plot2d.level(p, grid, cmap=my_cmap)
sfs.plot2d.loudspeakers(array.x, array.n, twin)
plt.grid()
sfs.plot.virtualsource_2d([0, 0], npw, type='plane')
sfs.plot2d.virtualsource([0, 0], npw, type='plane')
plt.title('impulse_pw_wfs_25d')
plt.savefig('impulse_pw_wfs_25d.png')

Expand All @@ -82,9 +82,9 @@
p = p * 100 # scale absolute amplitude

plt.figure(figsize=(10, 10))
sfs.plot.level(p, grid, cmap=my_cmap)
sfs.plot.loudspeaker_2d(array.x, array.n, twin)
sfs.plot2d.level(p, grid, cmap=my_cmap)
sfs.plot2d.loudspeakers(array.x, array.n, twin)
plt.grid()
sfs.plot.virtualsource_2d(xs)
sfs.plot2d.virtualsource(xs)
plt.title('impulse_fs_wfs_25d')
plt.savefig('impulse_fs_wfs_25d.png')
12 changes: 6 additions & 6 deletions doc/examples/time_domain_nfchoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
observation_time=t, grid=grid)

plt.figure()
sfs.plot.level(p, grid)
sfs.plot.loudspeaker_2d(array.x, array.n)
sfs.plot.virtualsource_2d([0, 0], ns=npw, type='plane')
sfs.plot2d.level(p, grid)
sfs.plot2d.loudspeakers(array.x, array.n)
sfs.plot2d.virtualsource([0, 0], ns=npw, type='plane')
plt.savefig('impulse_pw_nfchoa_25d.png')

# Point source
Expand All @@ -44,7 +44,7 @@
observation_time=t, grid=grid)

plt.figure()
sfs.plot.level(p, grid)
sfs.plot.loudspeaker_2d(array.x, array.n)
sfs.plot.virtualsource_2d(xs, type='point')
sfs.plot2d.level(p, grid)
sfs.plot2d.loudspeakers(array.x, array.n)
sfs.plot2d.virtualsource(xs, type='point')
plt.savefig('impulse_ps_nfchoa_25d.png')
9 changes: 7 additions & 2 deletions sfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
td
array
tapering
plot
plot2d
plot3d
util
"""
Expand Down Expand Up @@ -59,7 +60,11 @@ def reset(self):
from . import array
from . import util
try:
from . import plot
from . import plot2d
except ImportError:
pass
try:
from . import plot3d
except ImportError:
pass

Expand Down
26 changes: 13 additions & 13 deletions sfs/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def linear(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
:context: close-figs
x0, n0, a0 = sfs.array.linear(16, 0.2, orientation=[0, -1, 0])
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -141,7 +141,7 @@ def linear_diff(distances, center=[0, 0, 0], orientation=[1, 0, 0]):
x0, n0, a0 = sfs.array.linear_diff(4 * [0.3] + 6 * [0.15] + 4 * [0.3],
orientation=[0, -1, 0])
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -182,7 +182,7 @@ def linear_random(N, min_spacing, max_spacing, center=[0, 0, 0],
N=12,
min_spacing=0.15, max_spacing=0.4,
orientation=[0, -1, 0])
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -216,7 +216,7 @@ def circular(N, R, center=[0, 0, 0]):
:context: close-figs
x0, n0, a0 = sfs.array.circular(16, 1)
sfs.plot.loudspeaker_2d(x0, n0, a0, size=0.2, show_numbers=True)
sfs.plot2d.loudspeakers(x0, n0, a0, size=0.2, show_numbers=True)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -262,7 +262,7 @@ def rectangular(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
:context: close-figs
x0, n0, a0 = sfs.array.rectangular((4, 8), 0.2)
sfs.plot.loudspeaker_2d(x0, n0, a0, show_numbers=True)
sfs.plot2d.loudspeakers(x0, n0, a0, show_numbers=True)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -309,7 +309,7 @@ def rounded_edge(Nxy, Nr, dx, center=[0, 0, 0], orientation=[1, 0, 0]):
:context: close-figs
x0, n0, a0 = sfs.array.rounded_edge(8, 5, 0.2)
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -380,7 +380,7 @@ def edge(Nxy, dx, center=[0, 0, 0], orientation=[1, 0, 0]):
:context: close-figs
x0, n0, a0 = sfs.array.edge(8, 0.2)
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -441,7 +441,7 @@ def planar(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
x0, n0, a0 = sfs.array.planar(
(4,3), 0.5, orientation=[0, 1, 0]) # 4 sources along x, 3 sources along z
sfs.plot.loudspeaker_2d(x0, n0, a0) # plot the last ssd in 2D
sfs.plot2d.loudspeakers(x0, n0, a0) # plot the last ssd in 2D
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -488,7 +488,7 @@ def cube(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
x0, n0, a0 = sfs.array.cube(
N=2, spacing=0.5,
center=[0, 0, 0], orientation=[1, 0, 0])
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -547,7 +547,7 @@ def sphere_load(file, radius, center=[0, 0, 0]):
'../data/arrays/example_array_6LS_3D.txt',
radius=2,
center=[0, 0, 0])
sfs.plot.loudspeaker_2d(x0, n0, a0, size=0.25)
sfs.plot2d.loudspeakers(x0, n0, a0, size=0.25)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -590,7 +590,7 @@ def load(file, center=[0, 0, 0], orientation=[1, 0, 0]):
:context: close-figs
x0, n0, a0 = sfs.array.load('../data/arrays/example_array_4LS_2D.csv')
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand All @@ -600,7 +600,7 @@ def load(file, center=[0, 0, 0], orientation=[1, 0, 0]):
x0, n0, a0 = sfs.array.load(
'../data/arrays/wfs_university_rostock_2018.csv')
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down Expand Up @@ -695,7 +695,7 @@ def concatenate(*arrays):
ssd1 = sfs.array.edge(10, 0.2)
ssd2 = sfs.array.edge(20, 0.1, center=[2, 2, 0], orientation=[-1, 0, 0])
x0, n0, a0 = sfs.array.concatenate(ssd1, ssd2)
sfs.plot.loudspeaker_2d(x0, n0, a0)
sfs.plot2d.loudspeakers(x0, n0, a0)
plt.axis('equal')
plt.xlabel('x / m')
plt.ylabel('y / m')
Expand Down
4 changes: 2 additions & 2 deletions sfs/fd/nfchoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
def plot(d, selection, secondary_source):
p = sfs.fd.synthesize(d, selection, array, secondary_source, grid=grid)
sfs.plot.soundfield(p, grid)
sfs.plot.loudspeaker_2d(array.x, array.n, selection * array.a, size=0.15)
sfs.plot2d.amplitude(p, grid)
sfs.plot2d.loudspeakers(array.x, array.n, selection * array.a, size=0.15)
"""

Expand Down
4 changes: 2 additions & 2 deletions sfs/fd/sdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
def plot(d, selection, secondary_source):
p = sfs.fd.synthesize(d, selection, array, secondary_source, grid=grid)
sfs.plot.soundfield(p, grid)
sfs.plot.loudspeaker_2d(array.x, array.n, selection * array.a, size=0.15)
sfs.plot2d.amplitude(p, grid)
sfs.plot2d.loudspeakers(array.x, array.n, selection * array.a, size=0.15)
"""

Expand Down

0 comments on commit 4f83604

Please sign in to comment.