Skip to content

Commit 8d24c10

Browse files
committed
Doc
1 parent f89e815 commit 8d24c10

File tree

6 files changed

+63
-18
lines changed

6 files changed

+63
-18
lines changed

docs/pyroomacoustics.directivities.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Directional Source and Microphone Responses
2-
===========================================
1+
Directional Sources and Microphones
2+
===================================
33

44
.. automodule:: pyroomacoustics.directivities
55
:members:
@@ -26,8 +26,7 @@ Built-in SOFA Files Database
2626
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2727

2828
.. automodule:: pyroomacoustics.datasets.sofa
29-
:members:
30-
:show-inheritance:
29+
:members: SOFADatabase, get_sofa_db
3130
:noindex:
3231

3332

pyroomacoustics/datasets/sofa.py

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def is_dirpat(name):
6262

6363

6464
def get_sofa_db():
65+
"""
66+
A helper function to quickly load the SOFA database
67+
"""
6568
# we want to avoid loading the database multiple times
6669
global sofa_db
6770
try:

pyroomacoustics/directivities/analytic.py

+30-12
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def __init__(self, gain=1.0):
383383
self._pattern_name = "omni"
384384

385385

386-
def cardioid_func(x, direction, coef, gain=1.0, normalize=True, magnitude=False):
386+
def cardioid_func(x, direction, p, gain=1.0, normalize=True, magnitude=False):
387387
"""
388388
One-shot function for computing cardioid response.
389389
@@ -392,36 +392,54 @@ def cardioid_func(x, direction, coef, gain=1.0, normalize=True, magnitude=False)
392392
x: array_like, shape (n_dim, ...)
393393
Cartesian coordinates
394394
direction: array_like, shape (n_dim)
395-
Direction vector, should be normalized.
396-
coef: float
397-
Parameter for the cardioid function.
395+
Direction vector, should be normalized
396+
p: float
397+
Parameter for the cardioid function (between 0 and 1)
398398
gain: float
399-
The gain.
399+
The gain
400400
normalize : bool
401-
Whether to normalize coordinates and direction vector.
401+
Whether to normalize coordinates and direction vector
402402
magnitude : bool
403-
Whether to return magnitude, default is False.
403+
Whether to return magnitude, default is False
404404
405405
Returns
406406
-------
407407
resp : :py:class:`~numpy.ndarray`
408408
Response at provided angles for the speficied cardioid function.
409409
"""
410-
assert coef >= 0.0
411-
assert coef <= 1.0
410+
if not 0.0 <= p <= 1.0:
411+
raise ValueError("The parameter p must be between 0 and 1.")
412412

413413
# normalize positions
414414
if normalize:
415415
x /= np.linalg.norm(x, axis=0)
416416
direction /= np.linalg.norm(direction)
417417

418418
# compute response
419-
resp = gain * (coef + (1 - coef) * np.matmul(direction, x))
419+
resp = gain * (p + (1 - p) * np.matmul(direction, x))
420420
if magnitude:
421421
return np.abs(resp)
422422
else:
423423
return resp
424424

425425

426-
def cardioid_energy(coef, gain=1.0):
427-
return gain**2 * (4.0 * np.pi / 3.0) * (4 * coef**2 - 2 * coef + 1)
426+
def cardioid_energy(p, gain=1.0):
427+
r"""
428+
This function gives the exact value of the surface integral of the cardioid
429+
(family) function on the unit sphere
430+
431+
.. math::
432+
433+
E(p, G) = \iint_{\mathbb{S}^2} G^2 \left( p + (1 - p) \boldsymbol{d}^\top \boldsymbol{r} \right)^2 d\boldsymbol{r}
434+
= \frac{4 \pi}{3} G^2 \left( 4 p^2 - 2 p + 1 \right).
435+
436+
This can be used to normalize the energy sent/received.
437+
438+
Parameters
439+
---------
440+
p: float
441+
The parameter of the cardioid function (between 0 and 1)
442+
gain: float
443+
The gain of the cardioid function
444+
"""
445+
return gain**2 * (4.0 * np.pi / 3.0) * (4 * p**2 - 2 * p + 1)

pyroomacoustics/directivities/measured.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ def get_response(
174174

175175
@requires_matplotlib
176176
def plot(self, freq_bin=0, n_grid=100, ax=None, depth=False, offset=None):
177+
"""
178+
Plot the directivity pattern at a given frequency.
179+
180+
Parameters
181+
----------
182+
freq_bin: int
183+
The frequency bin to plot
184+
n_grid: int
185+
The number of points to use for the interpolation grid
186+
ax: matplotlib.axes.Axes, optional
187+
The axes to plot on. If not provided, a new figure is created
188+
depth: bool
189+
If ``True``, directive response is both depicted by color and depth
190+
of the surface. If ``False``, then only the color map denotes the
191+
intensity. (default ``False``)
192+
offset: float
193+
An offset to apply to the directivity pattern
194+
195+
Returns
196+
-------
197+
ax: matplotlib.axes.Axes
198+
The axes on which the directivity is plotted
199+
"""
177200
import matplotlib.pyplot as plt
178201
from matplotlib import cm
179202

@@ -225,7 +248,7 @@ def plot(self, freq_bin=0, n_grid=100, ax=None, depth=False, offset=None):
225248
class MeasuredDirectivityFile:
226249
"""
227250
This class reads measured directivities from a
228-
`SOFA <https://www.sofaconventions.org>`_ format file.
251+
`SOFA`_ format file.
229252
Optionally, it can perform interpolation of the impulse responses onto a finer grid.
230253
The interpolation is done in the spherical harmonics domain.
231254

pyroomacoustics/directivities/sofa.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# You should have received a copy of the MIT License along with this program. If
2323
# not, see <https://opensource.org/licenses/MIT>.
2424
r"""
25-
`SOFA <https://www.sofaconventions.org/>` is a very flexible file format for storing
25+
`SOFA <https://www.sofaconventions.org/>`_ is a very flexible file format for storing
2626
direction impulse responses. This module provides a function to read SOFA files and
2727
extract the impulse responses in a format that can be used for simulation.
2828
"""

pyroomacoustics/utilities.py

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from __future__ import division
2525

2626
import itertools
27+
import functools
2728

2829
import numpy as np
2930
import soxr
@@ -36,6 +37,7 @@
3637

3738

3839
def requires_matplotlib(func):
40+
@functools.wraps(func) # preserves name, docstrings, and signature of function
3941
def function_wrapper(*args, **kwargs):
4042
try:
4143
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)