Skip to content

Commit

Permalink
Keyword-only arguments everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Mar 16, 2019
1 parent 4f83604 commit c420d98
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 112 deletions.
4 changes: 2 additions & 2 deletions doc/examples/horizontal_plane_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def compute_and_plot_soundfield(title):
"""Compute and plot synthesized sound field."""
print('Computing', title)

twin = tapering(selection, talpha)
twin = tapering(selection, alpha=talpha)
p = sfs.fd.synthesize(d, twin, array, secondary_source, grid=grid)

plt.figure(figsize=(15, 15))
plt.cla()
sfs.plot2d.amplitude(p, grid, xnorm)
sfs.plot2d.amplitude(p, grid, xnorm=xnorm)
sfs.plot2d.loudspeakers(array.x, array.n, twin)
sfs.plot2d.virtualsource(xs)
sfs.plot2d.virtualsource([0, 0], npw, type='plane')
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/mirror-image-source-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"source": [
"grid = sfs.util.xyz_grid([0, L[0]], [0, L[1]], 1.5, spacing=0.02)\n",
"P = sfs.fd.source.point_image_sources(omega, x0, grid, L,\n",
" max_order, coeffs=coeffs)"
" max_order=max_order, coeffs=coeffs)"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/sound_field_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#d, selection, secondary_source = sfs.fd.wfs.line_2d(omega, array.x, array.n, xs)

#d, selection, secondary_source = sfs.fd.wfs.plane_2d(omega, array.x, array.n, npw)
d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, npw, xref)
d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, npw, xref=xref)
#d, selection, secondary_source = sfs.fd.wfs.plane_3d(omega, array.x, array.n, npw)

#d, selection, secondary_source = sfs.fd.wfs.point_2d(omega, array.x, array.n, xs)
Expand All @@ -64,16 +64,16 @@

# === compute tapering window ===
#twin = sfs.tapering.none(selection)
#twin = sfs.tapering.kaiser(selection, 8.6)
twin = sfs.tapering.tukey(selection, 0.3)
#twin = sfs.tapering.kaiser(selection, beta=8.6)
twin = sfs.tapering.tukey(selection, alpha=0.3)

# === compute synthesized sound field ===
p = sfs.fd.synthesize(d, twin, array, secondary_source, grid=grid)


# === plot synthesized sound field ===
plt.figure(figsize=(10, 10))
sfs.plot2d.amplitude(p, grid, [0, 0, 0])
sfs.plot2d.amplitude(p, grid, xnorm=[0, 0, 0])
sfs.plot2d.loudspeakers(array.x, array.n, twin)
plt.grid()
plt.savefig('soundfield.png')
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/time_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
d = sfs.td.wfs.driving_signals(d_delay, d_weight, signal)

# test soundfield
twin = sfs.tapering.tukey(selection, .3)
twin = sfs.tapering.tukey(selection, alpha=0.3)

p = sfs.td.synthesize(d, twin, array,
secondary_source, observation_time=t, grid=grid)
Expand All @@ -54,7 +54,7 @@
d = sfs.td.wfs.driving_signals(d_delay, d_weight, signal)

# test soundfield
twin = sfs.tapering.tukey(selection, .3)
twin = sfs.tapering.tukey(selection, alpha=0.3)
p = sfs.td.synthesize(d, twin, array,
secondary_source, observation_time=t, grid=grid)

Expand All @@ -76,7 +76,7 @@
d = sfs.td.wfs.driving_signals(d_delay, d_weight, signal)

# test soundfield
twin = sfs.tapering.tukey(selection, .3)
twin = sfs.tapering.tukey(selection, alpha=0.3)
p = sfs.td.synthesize(d, twin, array,
secondary_source, observation_time=t, grid=grid)
p = p * 100 # scale absolute amplitude
Expand Down
63 changes: 37 additions & 26 deletions sfs/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def as_secondary_source_distribution(arg, **kwargs):
return SecondarySourceDistribution(x, n, a)


def linear(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
def linear(N, spacing, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return linear, equidistantly sampled secondary source distribution.
Parameters
Expand Down Expand Up @@ -119,7 +119,7 @@ def linear(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
return _linear_helper(np.arange(N) * spacing, center, orientation)


def linear_diff(distances, center=[0, 0, 0], orientation=[1, 0, 0]):
def linear_diff(distances, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return linear secondary source distribution from a list of distances.
Parameters
Expand Down Expand Up @@ -152,7 +152,7 @@ def linear_diff(distances, center=[0, 0, 0], orientation=[1, 0, 0]):
return _linear_helper(ycoordinates, center, orientation)


def linear_random(N, min_spacing, max_spacing, center=[0, 0, 0],
def linear_random(N, min_spacing, max_spacing, *, center=[0, 0, 0],
orientation=[1, 0, 0], seed=None):
"""Return randomly sampled linear array.
Expand Down Expand Up @@ -190,10 +190,10 @@ def linear_random(N, min_spacing, max_spacing, center=[0, 0, 0],
"""
r = np.random.RandomState(seed)
distances = r.uniform(min_spacing, max_spacing, size=N-1)
return linear_diff(distances, center, orientation)
return linear_diff(distances, center=center, orientation=orientation)


def circular(N, R, center=[0, 0, 0]):
def circular(N, R, *, center=[0, 0, 0]):
"""Return circular secondary source distribution parallel to the xy-plane.
Parameters
Expand Down Expand Up @@ -235,7 +235,7 @@ def circular(N, R, center=[0, 0, 0]):
return SecondarySourceDistribution(positions, normals, weights)


def rectangular(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
def rectangular(N, spacing, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return rectangular secondary source distribution.
Parameters
Expand Down Expand Up @@ -272,18 +272,22 @@ def rectangular(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
offset1 = spacing * (N2 - 1) / 2 + spacing / np.sqrt(2)
offset2 = spacing * (N1 - 1) / 2 + spacing / np.sqrt(2)
positions, normals, weights = concatenate(
linear(N1, spacing, [-offset1, 0, 0], [1, 0, 0]), # left
linear(N2, spacing, [0, offset2, 0], [0, -1, 0]), # upper
linear(N1, spacing, [offset1, 0, 0], [-1, 0, 0]), # right
linear(N2, spacing, [0, -offset2, 0], [0, 1, 0]), # lower
# left
linear(N1, spacing, center=[-offset1, 0, 0], orientation=[1, 0, 0]),
# upper
linear(N2, spacing, center=[0, offset2, 0], orientation=[0, -1, 0]),
# right
linear(N1, spacing, center=[offset1, 0, 0], orientation=[-1, 0, 0]),
# lower
linear(N2, spacing, center=[0, -offset2, 0], orientation=[0, 1, 0]),
)
positions, normals = _rotate_array(positions, normals,
[1, 0, 0], orientation)
positions += center
return SecondarySourceDistribution(positions, normals, weights)


def rounded_edge(Nxy, Nr, dx, center=[0, 0, 0], orientation=[1, 0, 0]):
def rounded_edge(Nxy, Nr, dx, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return SSD along the xy-axis with rounded edge at the origin.
Parameters
Expand Down Expand Up @@ -357,7 +361,7 @@ def rounded_edge(Nxy, Nr, dx, center=[0, 0, 0], orientation=[1, 0, 0]):
return SecondarySourceDistribution(positions, directions, weights)


def edge(Nxy, dx, center=[0, 0, 0], orientation=[1, 0, 0]):
def edge(Nxy, dx, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return SSD along the xy-axis with sharp edge at the origin.
Parameters
Expand Down Expand Up @@ -409,7 +413,7 @@ def edge(Nxy, dx, center=[0, 0, 0], orientation=[1, 0, 0]):
return SecondarySourceDistribution(positions, directions, weights)


def planar(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
def planar(N, spacing, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return planar secondary source distribtion.
Parameters
Expand Down Expand Up @@ -460,7 +464,7 @@ def planar(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
return SecondarySourceDistribution(positions, normals, weights)


def cube(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
def cube(N, spacing, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Return cube-shaped secondary source distribtion.
Parameters
Expand Down Expand Up @@ -496,24 +500,31 @@ def cube(N, spacing, center=[0, 0, 0], orientation=[1, 0, 0]):
"""
N1, N2, N3 = (N, N, N) if np.isscalar(N) else N
offset1 = spacing * (N2 - 1) / 2 + spacing / np.sqrt(2)
offset2 = spacing * (N1 - 1) / 2 + spacing / np.sqrt(2)
offset3 = spacing * (N3 - 1) / 2 + spacing / np.sqrt(2)
d = spacing
offset1 = d * (N2 - 1) / 2 + d / np.sqrt(2)
offset2 = d * (N1 - 1) / 2 + d / np.sqrt(2)
offset3 = d * (N3 - 1) / 2 + d / np.sqrt(2)
positions, directions, weights = concatenate(
planar((N1, N3), spacing, [-offset1, 0, 0], [1, 0, 0]), # west
planar((N2, N3), spacing, [0, offset2, 0], [0, -1, 0]), # north
planar((N1, N3), spacing, [offset1, 0, 0], [-1, 0, 0]), # east
planar((N2, N3), spacing, [0, -offset2, 0], [0, 1, 0]), # south
planar((N2, N1), spacing, [0, 0, -offset3], [0, 0, 1]), # bottom
planar((N2, N1), spacing, [0, 0, offset3], [0, 0, -1]), # top
# west
planar((N1, N3), d, center=[-offset1, 0, 0], orientation=[1, 0, 0]),
# north
planar((N2, N3), d, center=[0, offset2, 0], orientation=[0, -1, 0]),
# east
planar((N1, N3), d, center=[offset1, 0, 0], orientation=[-1, 0, 0]),
# south
planar((N2, N3), d, center=[0, -offset2, 0], orientation=[0, 1, 0]),
# bottom
planar((N2, N1), d, center=[0, 0, -offset3], orientation=[0, 0, 1]),
# top
planar((N2, N1), d, center=[0, 0, offset3], orientation=[0, 0, -1]),
)
positions, directions = _rotate_array(positions, directions,
[1, 0, 0], orientation)
positions += center
return SecondarySourceDistribution(positions, directions, weights)


def sphere_load(file, radius, center=[0, 0, 0]):
def sphere_load(file, radius, *, center=[0, 0, 0]):
"""Load spherical secondary source distribution from file.
ASCII Format (see MATLAB SFS Toolbox) with 4 numbers (3 for the cartesian
Expand Down Expand Up @@ -562,7 +573,7 @@ def sphere_load(file, radius, center=[0, 0, 0]):
return SecondarySourceDistribution(positions, normals, weights)


def load(file, center=[0, 0, 0], orientation=[1, 0, 0]):
def load(file, *, center=[0, 0, 0], orientation=[1, 0, 0]):
"""Load secondary source distribution from file.
Comma Separated Values (CSV) format with 7 values
Expand Down Expand Up @@ -615,7 +626,7 @@ def load(file, center=[0, 0, 0], orientation=[1, 0, 0]):
return SecondarySourceDistribution(positions, normals, weights)


def weights_midpoint(positions, closed):
def weights_midpoint(positions, *, closed):
"""Calculate loudspeaker weights for a simply connected array.
The weights are calculated according to the midpoint rule.
Expand Down
4 changes: 2 additions & 2 deletions sfs/fd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def secondary_source_point(omega, c):
"""Create a point source for use in `sfs.fd.synthesize()`."""

def secondary_source(position, _, grid):
return source.point(omega, position, grid, c)
return source.point(omega, position, grid, c=c)

return secondary_source

Expand All @@ -72,7 +72,7 @@ def secondary_source_line(omega, c):
"""Create a line source for use in `sfs.fd.synthesize()`."""

def secondary_source(position, _, grid):
return source.line(omega, position, grid, c)
return source.line(omega, position, grid, c=c)

return secondary_source

Expand Down
16 changes: 8 additions & 8 deletions sfs/fd/esa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from . import secondary_source_line, secondary_source_point


def plane_2d_edge(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None,
c=None):
def plane_2d_edge(omega, x0, n=[0, 1, 0], *, alpha=3/2*np.pi, Nc=None, c=None):
r"""Driving function for 2-dimensional plane wave with edge ESA.
Driving function for a virtual plane wave using the 2-dimensional ESA
Expand Down Expand Up @@ -87,8 +86,8 @@ def plane_2d_edge(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None,
return 4*np.pi/alpha * d, selection, secondary_source_line(omega, c)


def plane_2d_edge_dipole_ssd(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None,
c=None):
def plane_2d_edge_dipole_ssd(omega, x0, n=[0, 1, 0], *, alpha=3/2*np.pi,
Nc=None, c=None):
r"""Driving function for 2-dimensional plane wave with edge dipole ESA.
Driving function for a virtual plane wave using the 2-dimensional ESA
Expand Down Expand Up @@ -155,7 +154,7 @@ def plane_2d_edge_dipole_ssd(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None,
return 4*np.pi/alpha * d


def line_2d_edge(omega, x0, xs, alpha=3/2*np.pi, Nc=None, c=None):
def line_2d_edge(omega, x0, xs, *, alpha=3/2*np.pi, Nc=None, c=None):
r"""Driving function for 2-dimensional line source with edge ESA.
Driving function for a virtual line source using the 2-dimensional ESA
Expand Down Expand Up @@ -229,7 +228,8 @@ def line_2d_edge(omega, x0, xs, alpha=3/2*np.pi, Nc=None, c=None):
return -1j*np.pi/alpha * d, selection, secondary_source_line(omega, c)


def line_2d_edge_dipole_ssd(omega, x0, xs, alpha=3/2*np.pi, Nc=None, c=None):
def line_2d_edge_dipole_ssd(omega, x0, xs, *, alpha=3/2*np.pi, Nc=None,
c=None):
r"""Driving function for 2-dimensional line source with edge dipole ESA.
Driving function for a virtual line source using the 2-dimensional ESA
Expand Down Expand Up @@ -300,8 +300,8 @@ def line_2d_edge_dipole_ssd(omega, x0, xs, alpha=3/2*np.pi, Nc=None, c=None):
return -1j*np.pi/alpha * d


def point_25d_edge(omega, x0, xs, xref=[2, -2, 0], alpha=3/2*np.pi,
Nc=None, c=None):
def point_25d_edge(omega, x0, xs, *, xref=[2, -2, 0], alpha=3/2*np.pi,
Nc=None, c=None):
r"""Driving function for 2.5-dimensional point source with edge ESA.
Driving function for a virtual point source using the 2.5-dimensional
Expand Down
6 changes: 3 additions & 3 deletions sfs/fd/nfchoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def plot(d, selection, secondary_source):
from . import secondary_source_point


def plane_2d(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
def plane_2d(omega, x0, r0, n=[0, 1, 0], *, max_order=None, c=None):
r"""Driving function for 2-dimensional NFC-HOA for a virtual plane wave.
Parameters
Expand Down Expand Up @@ -101,7 +101,7 @@ def plane_2d(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
return -2j / (np.pi*r0) * d, selection, secondary_source_point(omega, c)


def point_25d(omega, x0, r0, xs, max_order=None, c=None):
def point_25d(omega, x0, r0, xs, *, max_order=None, c=None):
r"""Driving function for 2.5-dimensional NFC-HOA for a virtual point source.
Parameters
Expand Down Expand Up @@ -169,7 +169,7 @@ def point_25d(omega, x0, r0, xs, max_order=None, c=None):
return d / (2 * np.pi * r0), selection, secondary_source_point(omega, c)


def plane_25d(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
def plane_25d(omega, x0, r0, n=[0, 1, 0], *, max_order=None, c=None):
r"""Driving function for 2.5-dimensional NFC-HOA for a virtual plane wave.
Parameters
Expand Down
12 changes: 6 additions & 6 deletions sfs/fd/sdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def plot(d, selection, secondary_source):
from . import secondary_source_line, secondary_source_point


def line_2d(omega, x0, n0, xs, c=None):
def line_2d(omega, x0, n0, xs, *, c=None):
r"""Driving function for 2-dimensional SDM for a virtual line source.
Parameters
Expand Down Expand Up @@ -87,7 +87,7 @@ def line_2d(omega, x0, n0, xs, c=None):
return d, selection, secondary_source_line(omega, c)


def plane_2d(omega, x0, n0, n=[0, 1, 0], c=None):
def plane_2d(omega, x0, n0, n=[0, 1, 0], *, c=None):
r"""Driving function for 2-dimensional SDM for a virtual plane wave.
Parameters
Expand Down Expand Up @@ -142,7 +142,7 @@ def plane_2d(omega, x0, n0, n=[0, 1, 0], c=None):
return d, selection, secondary_source_line(omega, c)


def plane_25d(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
def plane_25d(omega, x0, n0, n=[0, 1, 0], *, xref=[0, 0, 0], c=None):
r"""Driving function for 2.5-dimensional SDM for a virtual plane wave.
Parameters
Expand Down Expand Up @@ -182,7 +182,7 @@ def plane_25d(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
:context: close-figs
d, selection, secondary_source = sfs.fd.sdm.plane_25d(
omega, array.x, array.n, npw, [0, -1, 0])
omega, array.x, array.n, npw, xref=[0, -1, 0])
plot(d, selection, secondary_source)
"""
Expand All @@ -197,7 +197,7 @@ def plane_25d(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
return d, selection, secondary_source_point(omega, c)


def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None):
def point_25d(omega, x0, n0, xs, *, xref=[0, 0, 0], c=None):
r"""Driving function for 2.5-dimensional SDM for a virtual point source.
Parameters
Expand Down Expand Up @@ -237,7 +237,7 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None):
:context: close-figs
d, selection, secondary_source = sfs.fd.sdm.point_25d(
omega, array.x, array.n, xs, [0, -1, 0])
omega, array.x, array.n, xs, xref=[0, -1, 0])
plot(d, selection, secondary_source)
"""
Expand Down

0 comments on commit c420d98

Please sign in to comment.