Skip to content

Commit 5a10942

Browse files
authored
Fixes scattering in the ray tracing simulator, make simulation deterministic. (#426)
* Fixes scattering in the ray tracing simulator. Adds a function to seed the RNG in libroom. * Moves all numerical constants used in libroom into a common header shared accross the package. * Adds a test for the Lambertian reflection sampler. * Adds a package wide random number generator and some methods to fix the seeds of this RNG and the one used in libroom. * Make the room simulation deterministic. * Document the new RNG related routines. * Fixes room.is_inside. * Fix the fix of is_inside. * Adding pre-commit hooks and flake8 configs.
1 parent 9d3769e commit 5a10942

30 files changed

+539
-117
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203
4+
# E203 is ignored because it conflicts with Black's whitespace handling

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Global exclude: ignore build folders, virtual environments, and C++ dependencies
2+
exclude: '^(pyroomacoutics/libroom_src/ext/|build/|dist/|venv/|extern/)'
3+
4+
repos:
5+
- repo: https://github.com/pycqa/isort
6+
rev: 7.0.0
7+
hooks:
8+
- id: isort
9+
files: ^(pyroomacoustics/|examples/|setup\.py)
10+
11+
- repo: https://github.com/psf/black
12+
rev: 26.1.0
13+
hooks:
14+
- id: black
15+
files: ^(pyroomacoustics/|examples/|setup\.py)
16+
17+
# - repo: https://github.com/pycqa/flake8
18+
# rev: 7.3.0
19+
# hooks:
20+
# - id: flake8
21+
# files: ^(pyroomacoustics/|examples/|setup\.py)
22+
#
23+
# - repo: https://github.com/pre-commit/mirrors-clang-format
24+
# rev: v21.1.8
25+
# hooks:
26+
# - id: clang-format
27+
# # Only run on your C++ source and headers
28+
# files: \.(cpp|h|hpp|cc)$
29+
30+

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`_.
1111
`Unreleased`_
1212
-------------
1313

14+
Added
15+
~~~~~
16+
17+
- A new ``random`` sub-module that contains a Numpy random number generator to use
18+
package wide and some methods to set the seeds for this generator and that of
19+
the libroom module.
20+
1421
Changed
1522
~~~~~~~
1623

24+
- Adds random "bending" of the rays to account for scattering in the ray tracing.
25+
1726
- Refactor the way the RIR is weighted with the histogram in simulation/rt.py.
1827

1928
- Improves ``pra.experimental.measure_rt60``: Compute the T60 using a fit. Default is

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ Indices and tables
3232
* :ref:`genindex`
3333
* :ref:`modindex`
3434
* :ref:`search`
35-

docs/pyroomacoustics.random.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Randomness
2+
==========
3+
4+
.. automodule:: pyroomacoustics.random
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
Random Number Generator
10+
-----------------------
11+
12+
.. automodule:: pyroomacoustics.random.generator
13+
:members:
14+
:show-inheritance:

docs/pyroomacoustics.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Subpackages
1313
pyroomacoustics.doa
1414
pyroomacoustics.experimental
1515
pyroomacoustics.phase
16+
pyroomacoustics.random
1617
pyroomacoustics.transform
1718

1819
Submodules

examples/directivities/simulate_binaural_recording.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
Get more SOFA files at https://www.sofaconventions.org/mediawiki/index.php/Files
99
"""
10+
1011
import argparse
1112
from pathlib import Path
1213

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ requires = ["setuptools", "wheel", "numpy>=1.13.0", "Cython", "pybind11>=2.2"]
55
[tool.pytest.ini_options]
66
filterwarnings = [
77
'ignore:Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.:UserWarning'
8-
]
8+
]
9+
10+
[tool.isort]
11+
profile = "black"
12+
line_length = 88

pyroomacoustics/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
107107
:py:obj:`pyroomacoustics.phase`
108108
Phase-related processing
109109
110+
:py:obj:`pyroomacoustics.random`
111+
Routines for random number generation.
112+
110113
:py:obj:`pyroomacoustics.transform`
111114
Block frequency domain processing tools
112115
@@ -129,6 +132,7 @@
129132
from .metrics import *
130133
from .multirate import *
131134
from .parameters import *
135+
from .random import get_rng, seed
132136
from .recognition import *
133137
from .room import *
134138
from .soundsource import *

pyroomacoustics/doa/doa.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ def locate_sources(
322322
self.src_idx = np.zeros(self.num_src, dtype=np.int64)
323323
self.angle_of_arrival = None
324324
if X.shape[0] != self.M:
325-
raise ValueError("Number of signals (rows) does not match the \
326-
number of microphones.")
325+
raise ValueError(
326+
"Number of signals (rows) does not match the number of microphones."
327+
)
327328
if X.shape[1] != self.max_bin:
328329
raise ValueError("Mismatch in FFT length.")
329330
self.num_snap = X.shape[2]
@@ -574,8 +575,9 @@ def _check_num_src(self, num_src):
574575
# str(self.M) + '.')
575576
# num_src = self.M
576577
if num_src < 1:
577-
warnings.warn("Number of sources must be at least 1. Changing \
578-
number of sources to 1.")
578+
warnings.warn(
579+
"Number of sources must be at least 1. Changing number of sources to 1."
580+
)
579581
num_src = 1
580582
valid = int(num_src)
581583
return valid

0 commit comments

Comments
 (0)