DOA Utilities

This module contains useful functions to compute distances and errors on on circles and spheres.

class pyroomacoustics.doa.utils.RegularGrid(azimuth, colatitude)

Bases: tuple

azimuth

Alias for field number 0

colatitude

Alias for field number 1

pyroomacoustics.doa.utils.cart2spher(vectors)
Parameters:

vectors (array_like, shape (3, n_vectors)) – The vectors to transform

Returns:

  • azimuth (numpy.ndarray, shape (n_vectors,)) – The azimuth of the vectors

  • colatitude (numpy.ndarray, shape (n_vectors,)) – The colatitude of the vectors

  • r (numpy.ndarray, shape (n_vectors,)) – The length of the vectors

pyroomacoustics.doa.utils.circ_dist(azimuth1, azimuth2, r=1.0)

Returns the shortest distance between two points on a circle

Parameters:
  • azimuth1 – azimuth of point 1

  • azimuth2 – azimuth of point 2

  • r (optional) – radius of the circle (Default 1)

pyroomacoustics.doa.utils.detect_regular_grid(azimuth, colatitude)

This function checks that the linearized azimuth/colatitude where sampled from a regular grid.

It also checks that the azimuth are uniformly spread in [0, 2 * np.pi). The colatitudes can have arbitrary positions.

Parameters:
  • azimuth (numpy.ndarray (npoints,)) – The azimuth values in radian

  • colatitude (numpy.ndarray (npoints,)) – The colatitude values in radian

Returns:

regular_grid – A dictionary with entries for the sorted distinct azimuth an colatitude values of the grid, if the points form a grid. Returns None if the points do not form a grid.

Return type:

dict[“azimuth”, “colatitude”] or None

pyroomacoustics.doa.utils.fibonacci_spherical_sampling(n_points)

This function computes nearly equidistant points on the sphere using the fibonacci method

Parameters:

n_points (int) – The number of points to sample

Returns:

points – The cartesian coordinates of the points

Return type:

numpy.ndarray, (3, n_points)

References

http://lgdv.cs.fau.de/uploads/publications/spherical_fibonacci_mapping.pdf http://stackoverflow.com/questions/9600801/evenly-distributing-n-points-on-a-sphere

pyroomacoustics.doa.utils.great_circ_dist(r, colatitude1, azimuth1, colatitude2, azimuth2)

calculate great circle distance for points located on a sphere

Parameters:
Returns:

great-circle distance

Return type:

float or ndarray

pyroomacoustics.doa.utils.polar_distance(x1, x2)

Given two arrays of numbers x1 and x2, pairs the cells that are the closest and provides the pairing matrix index: x1(index(1,:)) should be as close as possible to x2(index(2,:)). The function outputs the average of the absolute value of the differences abs(x1(index(1,:))-x2(index(2,:))).

Parameters:
  • x1 – vector 1

  • x2 – vector 2

Returns:

  • d – minimum distance between d

  • index – the permutation matrix

pyroomacoustics.doa.utils.spher2cart(azimuth, colatitude=None, r=1, degrees=False)

Convert a spherical point to cartesian coordinates.

Parameters:
  • azimuth – azimuth

  • colatitude – colatitude

  • r – radius

  • degrees – If True, indicates that the input angles are in degree (instead of radian)

Returns:

An ndarray containing the Cartesian coordinates of the points as its columns.

Return type:

ndarray