spaudiopy.utils
A few helpers.
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['axes.grid'] = True
import spaudiopy as spa
Functions
|
Angle between point v1 and v2(s) with initial point vi. |
|
calculate area of any triangle given coordinates of its corners p. |
|
Squeeze the input and check if the result is one-dimensional. |
|
Vectorized conversion of cartesian coordinates to (azi, zen). |
|
Conversion of cartesian to spherical coordinates. |
|
Convert ratio x to decibel. |
|
Convert from degree [0, 360) to radiant [0, 2*pi). |
|
Vectorized conversion of direction to cartesian coordinates. |
|
Convert decibel back to ratio. |
|
Calculate the spherical distance between two points on the sphere. |
|
Interleave left and right channels (Nchannel x Nsamples). |
|
Matlab port with ELEVATION. |
|
Convert from radiant [0, 2*pi) to degree [0, 360). |
|
RMS (root-mean-squared) along given axis. |
|
Matrix rotating by Yaw (around z), pitch (around y), roll (around x). |
|
Matrix rotating around axis defined by unit vector k, by angle theta. |
|
Matrix rotating from vector f to vector t, forces unit length. |
|
Conversion of spherical to cartesian coordinates. |
|
Stack two 2D vectors along the same-sized or the smaller dimension. |
|
Test if the cumulative element-wise difference between v1 and v2. |
|
Convert (along last axis) vec: [x, y, z] to dir: [azi, zen]. |
- spaudiopy.utils.asarray_1d(a, **kwargs)[source]
Squeeze the input and check if the result is one-dimensional.
Returns a converted to a numpy.ndarray and stripped of all singleton dimensions. Scalars are “upgraded” to 1D arrays. The result must have exactly one dimension. If not, an error is raised.
- spaudiopy.utils.cart2sph(x, y, z, positive_azi=False, steady_zen=False)[source]
Conversion of cartesian to spherical coordinates.
- spaudiopy.utils.cart2dir(x, y, z)[source]
Vectorized conversion of cartesian coordinates to (azi, zen).
- spaudiopy.utils.dir2cart(azi, zen)[source]
Vectorized conversion of direction to cartesian coordinates.
- spaudiopy.utils.angle_between(v1, v2, vi=None)[source]
Angle between point v1 and v2(s) with initial point vi.
- spaudiopy.utils.rotation_euler(yaw=0, pitch=0, roll=0)[source]
Matrix rotating by Yaw (around z), pitch (around y), roll (around x). See https://mathworld.wolfram.com/RotationMatrix.html
- spaudiopy.utils.rotation_rodrigues(k, theta)[source]
Matrix rotating around axis defined by unit vector k, by angle theta. See https://mathworld.wolfram.com/RodriguesRotationFormula.html
- spaudiopy.utils.rotation_vecvec(f, t)[source]
Matrix rotating from vector f to vector t, forces unit length.
- spaudiopy.utils.haversine(azi1, zen1, azi2, zen2, r=1)[source]
Calculate the spherical distance between two points on the sphere. The spherical distance is central angle for r=1.
- Parameters:
azi1 ((n,) float, array_like)
zen1 ((n,) float, array_like)
azi2 ((n,) float, array_like)
zen2 ((n,) float, array_like)
r (float, optional.)
- Returns:
c ((n,) array_like) – Haversine distance between pairs of points.
References
- spaudiopy.utils.area_triangle(p1, p2, p3)[source]
calculate area of any triangle given coordinates of its corners p.
- spaudiopy.utils.db(x, power=False)[source]
Convert ratio x to decibel.
- Parameters:
x (array_like) – Input data. Values of 0 lead to negative infinity.
power (bool, optional) – If
power=False
(the default), x is squared before conversion.
- spaudiopy.utils.from_db(db, power=False)[source]
Convert decibel back to ratio.
- Parameters:
db (array_like) – Input data.
power (bool, optional) – If
power=False
(the default), was used for conversion to dB.
- spaudiopy.utils.rms(x, axis=-1)[source]
RMS (root-mean-squared) along given axis.
- Parameters:
x (array_like) – Input data.
axis (int, optional) – Axis along which RMS is calculated
- spaudiopy.utils.stack(vector_1, vector_2)[source]
Stack two 2D vectors along the same-sized or the smaller dimension.