Skip to content

Commit 33eab32

Browse files
authored
Hide warnings for a few undefined points
1 parent 725d1a7 commit 33eab32

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

sfs/fd/source.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ def point(omega, x0, grid, *, c=None):
8282
grid = util.as_xyz_components(grid)
8383

8484
r = np.linalg.norm(grid - x0)
85-
return 1 / (4*np.pi) * np.exp(-1j * k * r) / r
85+
# If r is 0, the sound pressure is complex infinity
86+
numerator = np.exp(-1j * k * r) / (4*np.pi)
87+
with np.errstate(invalid='ignore', divide='ignore'):
88+
return numerator / r
8689

8790

8891
def point_velocity(omega, x0, grid, *, c=None, rho0=None):
@@ -395,7 +398,9 @@ def point_image_sources(omega, x0, grid, L, *, max_order, coeffs=None, c=None):
395398
p = 0
396399
for position, strength in zip(xs, source_strengths):
397400
if strength != 0:
398-
p += strength * point(omega, position, grid, c=c)
401+
# point can be complex infinity
402+
with np.errstate(invalid='ignore'):
403+
p += strength * point(omega, position, grid, c=c)
399404

400405
return p
401406

sfs/td/source.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ def point(xs, signal, observation_time, grid, c=None):
7979
if c is None:
8080
c = default.c
8181
r = np.linalg.norm(grid - xs)
82-
# evaluate g over grid
83-
weights = 1 / (4 * np.pi * r)
82+
# If r is +-0, the sound pressure is +-infinity
83+
with np.errstate(divide='ignore'):
84+
weights = 1 / (4 * np.pi * r)
8485
delays = r / c
8586
base_time = observation_time - signal_offset
86-
return weights * np.interp(base_time - delays,
87+
points_at_time = np.interp(base_time - delays,
8788
np.arange(len(data)) / samplerate,
8889
data, left=0, right=0)
90+
# weights can be +-infinity
91+
with np.errstate(invalid='ignore'):
92+
return weights * points_at_time
8993

9094

9195
def point_image_sources(x0, signal, observation_time, grid, L, max_order,

0 commit comments

Comments
 (0)