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 __HOLE__:    
        raise ValueError("Wrong shape.")
    shape = list(levels.shape)
    shape[axis] = shape[axis] // 3
    shape.insert(axis+1, 3)
    levels = np.reshape(levels, shape)
    return np.squeeze(acoustics.decibel.dbsum(levels, axis=axis+1))
dataset/ETHPy150Open python-acoustics/python-acoustics/acoustics/bands.py/third2oct