Skip to content

Commit

Permalink
Moves spherical histogram into doa sub-package. Fixes test_rejection …
Browse files Browse the repository at this point in the history
…pre-test.
  • Loading branch information
fakufaku committed Nov 8, 2024
1 parent b51ed82 commit c5250cc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyroomacoustics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

import warnings

from . import adaptive, bss, datasets, denoise, doa, experimental
from . import adaptive, bss, datasets, denoise, doa, experimental, random
from . import libroom as libroom
from . import phase, transform
from .acoustics import *
Expand Down
2 changes: 1 addition & 1 deletion pyroomacoustics/directivities/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _pattern(self, x):
return cardioid_func(
x.T,
direction=self._loc,
coef=self._coeff,
p=self._coeff,
gain=1.0,
normalize=False,
magnitude=True,
Expand Down
1 change: 1 addition & 0 deletions pyroomacoustics/doa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
from .tops import *
from .utils import *
from .waves import *
from .histogram import SphericalHistogram

# Create this dictionary as a shortcut to different algorithms
algorithms = {
Expand Down
5 changes: 1 addition & 4 deletions pyroomacoustics/doa/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __init__(
# If no list was provided, samples points on the sphere
# as uniformly as possible

self.x, self.y, self.z = fibonacci_spherical_sampling(n_points)
self.x[:], self.y[:], self.z[:] = fibonacci_spherical_sampling(n_points)

# Create convenient arrays
# to access both in cartesian and spherical coordinates
Expand Down Expand Up @@ -389,10 +389,7 @@ def plot(
def plot_old(self, plot_points=False, mark_peaks=0):
"""Plot the points on the sphere with their values"""

from scipy import rand

try:
import matplotlib.colors as colors
import matplotlib.pyplot as plt

# from mpl_toolkits.mplot3d import Axes3D
Expand Down
8 changes: 6 additions & 2 deletions pyroomacoustics/doa/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ def __init__(self, n_bins, dim=3, enable_peak_finding=False):

if self.n_dim == 3:
self._grid = GridSphere(
n_points=self.n_bins, enable_peak_finding=enable_peak_finding
n_points=self.n_bins, precompute_neighbors=enable_peak_finding
)
else:
raise NotImplementedError("Only 3D histogram has been implemented")

import pdb

pdb.set_trace()

# we need to know the area of each bin
self._voronoi = SphericalVoronoi(self._grid.cartesian.T)
self._areas = self._voronoi.calculate_areas()
Expand All @@ -51,7 +55,7 @@ def __init__(self, n_bins, dim=3, enable_peak_finding=False):
self._kd_tree = cKDTree(self._grid.cartesian.T)

# the counter variables for every bin
self._bins = np.zeros(self.n_bins, dtype=np.int)
self._bins = np.zeros(self.n_bins, dtype=int)

# the total number of points in the histogram
self._total_count = 0
Expand Down
7 changes: 3 additions & 4 deletions pyroomacoustics/random/tests/test_rejection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@

for loc, scale in zip([[1, 1, 1]], [10, 1, 0.1]):
print(loc, scale)
sampler = CardioidFamilySampler(
loc=loc, coeff=pra.DirectivityPattern.FIGURE_EIGHT.value
)
# Figure-of-eight
sampler = CardioidFamilySampler(loc=loc, p=0)

points = sampler(size=10000).T # shape (n_dim, n_points)

# Create a spherical histogram
hist = pra.SphericalHistogram(n_bins=500)
hist = pra.doa.SphericalHistogram(n_bins=500)
hist.push(points)
hist.plot()

Expand Down

0 comments on commit c5250cc

Please sign in to comment.