I've been running into an occasional NaN issue when simulating with the new ray tracing scattering. I'm using Pyroomacoustics 0.10.0. Managed to boil it down to the following example.
The NaN occurs when negative values reach the np.sqrt in rt.py at:
# Impulse response for every octave band for each microphone.
rir_bands[b, :] = seq_bp * np.sqrt(hist)
Only occurs when scattering materials are used with raytracing enabled and the receiver is closer to a wall than the receiver_radius.
Example where it occurs:
import warnings
import numpy as np
import pyroomacoustics as pra
for receiver_radius in [0.5, 0.1]: # the 0.1 case leaves the mic farther from the wall than the receiver_radius
for use_scattering in [False, True]:
pra.random.seed(140) # this seed seems to reproduce the NaN issue reliably on my machine.
room = pra.ShoeBox(
[4.144901752471924, 6.039876461029053, 2.7347633838653564],
fs=24000,
materials=pra.Material(energy_absorption=0.13035287, scattering=0.1 if use_scattering else 0.0),
max_order=0,
ray_tracing=True,
air_absorption=True,
)
room.set_ray_tracing(receiver_radius=receiver_radius)
# The microphone is fairly close to the wall. Within the default receiver_radius (0.5 m)
room.add_microphone([2.304156303866167, 0.17025121891320288, 1.4909059943866196])
room.add_source([1.9948741012396916, 3.8261834557486685, 0.8465485818395717])
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
room.compute_rir()
sqrt_warns = [x for x in w if "invalid value encountered in sqrt" in str(x.message)]
has_nan = np.any(np.isnan(room.rir[0][0]))
print(f"RT scattering: {use_scattering}. Receiver radius: {receiver_radius}. Sqrt warn: {len(sqrt_warns)}, RIR has NaN: {has_nan}")
Script output:
RT scattering: False. Receiver radius: 0.5. Sqrt warn: 0, RIR has NaN: False
RT scattering: True. Receiver radius: 0.5. Sqrt warn: 1, RIR has NaN: True
RT scattering: False. Receiver radius: 0.1. Sqrt warn: 0, RIR has NaN: False
RT scattering: True. Receiver radius: 0.1. Sqrt warn: 0, RIR has NaN: False
I've been running into an occasional NaN issue when simulating with the new ray tracing scattering. I'm using Pyroomacoustics 0.10.0. Managed to boil it down to the following example.
The NaN occurs when negative values reach the np.sqrt in rt.py at:
Only occurs when scattering materials are used with raytracing enabled and the receiver is closer to a wall than the receiver_radius.
Example where it occurs:
Script output: