def _detect_ipython():
    """ Detects if called in an IPython environment.
    Mostly derived from stackoverflow below:
    https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook

    Returns:
        True if in IPython environment.
    """
    try:
        from IPython import get_ipython
        return get_ipython() is not None
    except NameError:
        return False
