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(v1, v2[, vi])

Angle between point v1 and v2(s) with initial point vi.

area_triangle(p1, p2, p3)

calculate area of any triangle given coordinates of its corners p.

asarray_1d(a, **kwargs)

Squeeze the input and check if the result is one-dimensional.

cart2dir(x, y, z)

Vectorized conversion of cartesian coordinates to (azi, zen).

cart2sph(x, y, z[, positive_azi, steady_zen])

Conversion of cartesian to spherical coordinates.

db(x[, power])

Convert ratio x to decibel.

deg2rad(deg)

Convert from degree [0, 360) to radiant [0, 2*pi).

dir2cart(azi, zen)

Vectorized conversion of direction to cartesian coordinates.

from_db(db[, power])

Convert decibel back to ratio.

haversine(azi1, zen1, azi2, zen2[, r])

Calculate the spherical distance between two points on the sphere.

interleave_channels(left_channel, right_channel)

Interleave left and right channels (Nchannel x Nsamples).

matlab_sph2cart(az, elev[, r])

Matlab port with ELEVATION.

rad2deg(rad)

Convert from radiant [0, 2*pi) to degree [0, 360).

rms(x[, axis])

RMS (root-mean-squared) along given axis.

rotation_euler([yaw, pitch, roll])

Matrix rotating by Yaw (around z), pitch (around y), roll (around x).

rotation_rodrigues(k, theta)

Matrix rotating around axis defined by unit vector k, by angle theta.

rotation_vecvec(f, t)

Matrix rotating from vector f to vector t, forces unit length.

sph2cart(azi, zen[, r])

Conversion of spherical to cartesian coordinates.

stack(vector_1, vector_2)

Stack two 2D vectors along the same-sized or the smaller dimension.

test_diff(v1, v2[, msg, axis, test_lim, VERBOSE])

Test if the cumulative element-wise difference between v1 and v2.

vec2dir(vec)

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.deg2rad(deg)[source]

Convert from degree [0, 360) to radiant [0, 2*pi).

spaudiopy.utils.rad2deg(rad)[source]

Convert from radiant [0, 2*pi) to degree [0, 360).

spaudiopy.utils.cart2sph(x, y, z, positive_azi=False, steady_zen=False)[source]

Conversion of cartesian to spherical coordinates.

spaudiopy.utils.sph2cart(azi, zen, r=1)[source]

Conversion of spherical to cartesian coordinates.

spaudiopy.utils.matlab_sph2cart(az, elev, r=1)[source]

Matlab port with ELEVATION.

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.vec2dir(vec)[source]

Convert (along last axis) vec: [x, y, z] to dir: [azi, zen].

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

https://en.wikipedia.org/wiki/Haversine_formula

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.

spaudiopy.utils.test_diff(v1, v2, msg=None, axis=None, test_lim=1e-06, VERBOSE=True)[source]

Test if the cumulative element-wise difference between v1 and v2. Return difference and be verbose if is greater test_lim.

spaudiopy.utils.interleave_channels(left_channel, right_channel, style=None)[source]

Interleave left and right channels (Nchannel x Nsamples). Style = ‘SSR’ checks if we total 360 channels.