Common utilities

Common utility functions.

arlpy.utils.broadcastable_to(x, shape, axis=None)

Convert 1D array to be broadcastable along specified axis.

Parameters:
  • x – array to broadcast
  • shape – shape to broadcast to
  • axis – axis to broadcast along

Reshapes the array to the minimum dimensions such that it can be broadcasted to the given shape along the specified axis. If an axis is not specified, the first axis that matches the size of x is used.

>>> import arlpy
>>> import numpy as np
>>> arlpy.utils.broadcastable_to(np.array([1,2,3]), (5,3,2), 1)
array([[1],
       [2],
       [3]])
arlpy.utils.db2mag(x)

Convert dB quantity to magnitude.

arlpy.utils.db2pow(x)

Convert dB quantity to power.

arlpy.utils.linspace2d(start0, stop0, num0, start1, stop1, num1)

Generate linearly spaced coordinates in 2D space.

Parameters:
  • start0 – first value on axis 0
  • stop0 – last value on axis 0
  • num0 – number of values on axis 0
  • start1 – first value on axis 1
  • stop1 – last value on axis 1
  • num1 – number of values on axis 1
>>> from arlpy import bf
>>> bf.linspace2d(0, 1, 2, 0, 1, 3)
[[ 0. ,  0. ],
 [ 0. ,  0.5],
 [ 0. ,  1. ],
 [ 1. ,  0. ],
 [ 1. ,  0.5],
 [ 1. ,  1. ]]
arlpy.utils.linspace3d(start0, stop0, num0, start1, stop1, num1, start2, stop2, num2)

Generate linearly spaced coordinates in 2D space.

Parameters:
  • start0 – first value on axis 0
  • stop0 – last value on axis 0
  • num0 – number of values on axis 0
  • start1 – first value on axis 1
  • stop1 – last value on axis 1
  • num1 – number of values on axis 1
  • start2 – first value on axis 2
  • stop2 – last value on axis 2
  • num2 – number of values on axis 2
>>> from arlpy import bf
>>> bf.linspace3d(0, 1, 2, 0, 1, 3, 0, 0, 1)
[[ 0. ,  0. , 0. ],
 [ 0. ,  0.5, 0. ],
 [ 0. ,  1. , 0. ],
 [ 1. ,  0. , 0. ],
 [ 1. ,  0.5, 0. ],
 [ 1. ,  1. , 0. ]]
arlpy.utils.mag2db(x)

Convert magnitude quantity to dB.

arlpy.utils.pow2db(x)

Convert power quantity to dB.

arlpy.utils.progress(n, width=50)

Display progress bar for long running operations.

Parameters:
  • n – total number of steps to completion
  • width – width of the progress bar (only for the text version)
>>> import arlpy
>>> progress = arlpy.utils.progress(100)
>>> for j in range(100):
        next(progress)
arlpy.utils.rotation_matrix(alpha, beta, gamma)

Generates a 3D rotation matrix.

Parameters:
  • alpha – rotation angle around x-axis
  • beta – rotation angle around y-axis
  • gamma – rotation angle around z-axis

Rotation is applied around x, y and z axis in that order.