"""Miscellenious utility functions
"""
import sys
from itertools import cycle
spinner = cycle(['-', '/', '|', '\\'])


def env_info():
    """ Guess environment based on sys.modules.

    Returns
    -------
    env : string{'jupyter_notebook', 'ipython_terminal', 'terminal'}
       Guesed environment
    """
    if 'ipykernel' in sys.modules:
        return 'jupyter_notebook'
    elif 'IPython' in sys.modules:
        return 'ipython_terminal'
    else:
        return 'terminal'
    return ip


__env = env_info()


def progress_bar(curIDX, maxIDX=None, description='Progress'):
    """ Display a spinner or a progress bar

    Parameters
    ----------
    curIDX : int
       Current position in the loop
    maxIDX : int, optional
       Number of iterations. Will force a spinner if set to None. [Default: None]
    description : string, optional
       Clarify what's taking time
    """
    if maxIDX is None:
        print('\r' + description + ': ' + next(spinner), end='', flush=True)
    else:
        maxIDX = (int(maxIDX) - 1)
        if maxIDX == 0:
            amount_done = 1
        else:
            amount_done = curIDX / maxIDX
        print('\r' + description + ': [{0:50s}] {1:.1f}%'.format('#' * int(amount_done * 50), amount_done * 100), end="", flush=True)
        if amount_done >= 1:
            print('\n')

@@ -71,16 +71,45 @@
 t cycle%0A
+from numpy import log10, abs%0A
 spinner 
@@ -1361,8 +1361,447 @@
 t('%5Cn')%0A
+%0A%0Adef db(data, power=False):%0A    '''Convenience function to calculate the 20*log10(abs(x))%0A%0A    Parameters%0A    ----------%0A    data : array_like%0A       signals to be converted to db%0A    power : boolean%0A       data is a power signal and only needs factor 10%0A%0A    Returns%0A    -------%0A    db : array_like%0A       20 * log10(abs(data))%0A    '''%0A    if power:%0A        factor = 10%0A    else:%0A        factor = 20%0A    return factor * log10(abs(data))%0A

add db()