Ejemplo n.º 1
0
def third2oct(levels, axis=None):
    """
    Calculate Octave levels from third octave levels.
    
    :param levels: Array containing third octave levels.
    :type: :class:`np.ndarray`
    :param axis: Axis over which to perform the summation. 
    :type axis: :class:`int`
    
    :returns: Third octave levels
    :rtype: :class:`np.ndarray`
    
    .. note:: The number of elements along the summation axis should be a factor of 3.
    """
    
    levels = np.array(levels)
    axis = axis if axis is not None else levels.ndim - 1
    
    try:
        assert(levels.shape[axis]%3 == 0)
    except AssertionError:    
        raise ValueError("Wrong shape.")
    shape = list(levels.shape)
    shape[axis] = shape[axis] // 3
    shape.insert(axis+1, 3)
    levels = np.reshape(levels, shape)
    return esum(levels, axis=axis+1)
Ejemplo n.º 2
0
def third2oct(levels, axis=None):
    """
    Calculate Octave levels from third octave levels.
    
    :param levels: Array containing third octave levels.
    :type: :class:`np.ndarray`
    :param axis: Axis over which to perform the summation. 
    :type axis: :class:`int`
    
    :returns: Third octave levels
    :rtype: :class:`np.ndarray`
    
    .. note:: The number of elements along the summation axis should be a factor of 3.
    """

    levels = np.array(levels)
    axis = axis if axis is not None else levels.ndim - 1

    try:
        assert (levels.shape[axis] % 3 == 0)
    except AssertionError:
        raise ValueError("Wrong shape.")
    shape = list(levels.shape)
    shape[axis] = shape[axis] // 3
    shape.insert(axis + 1, 3)
    levels = np.reshape(levels, shape)
    return esum(levels, axis=axis + 1)
Ejemplo n.º 3
0
def test_esum_2d_axis0():
    calculated = esum(np.array([[90, 90, 90], [80, 80, 80]]), axis=0)
    real = np.array([90.41392685, 90.41392685, 90.41392685])
    assert_almost_equal(calculated, real)
Ejemplo n.º 4
0
def test_esum_2d_default_axis():
    calculated = esum(np.array([[90, 90, 90], [80, 80, 80]]))
    real = np.array(95.18513939877889)
    #real = np.array([94.77121255, 84.77121255])
    assert_array_almost_equal(calculated, real)
Ejemplo n.º 5
0
def test_esum_1d():
    calculated = esum(np.array([90, 90, 90]))
    real = 94.77121255
    assert_almost_equal(calculated, real)
Ejemplo n.º 6
0
def test_esum_2d_axis0():
    calculated = esum(np.array([[90, 90, 90], [80, 80, 80]]), axis=0)
    real = np.array([90.41392685, 90.41392685, 90.41392685])
    assert_almost_equal(calculated, real)
Ejemplo n.º 7
0
def test_esum_2d_default_axis():
    calculated = esum(np.array([[90, 90, 90], [80, 80, 80]]))
    real = np.array(95.18513939877889)
    #real = np.array([94.77121255, 84.77121255])
    assert_array_almost_equal(calculated, real)
Ejemplo n.º 8
0
def test_esum_1d():
    calculated = esum(np.array([90, 90, 90]))
    real = 94.77121255
    assert_almost_equal(calculated, real)