Пример #1
0
def run_manual(kwik_path, clustering=None, interactive=False,
               cluster_ids=None):
    import phy
    from phy.cluster import Session
    from phy.gui import start_qt_app, run_qt_app

    if not op.exists(kwik_path):
        print("The file `{}` doesn't exist.".format(kwik_path))
        return 1

    print("\nLoading {}...".format(kwik_path))
    session = Session(kwik_path,
                      clustering=clustering,
                      )
    print("Data successfully loaded!\n")
    session.model.describe()

    start_qt_app()
    gui = session.show_gui(cluster_ids=cluster_ids, show=False)

    print("\nPress `ctrl+h` to see the list of keyboard shortcuts.\n")

    # Interactive mode with IPython.
    if interactive:
        print("\nStarting IPython...")
        from IPython import start_ipython

        # Namespace.
        ns = {'phy': phy,
              'session': session,
              'model': session.model,
              'kwik_path': kwik_path,
              'gui': gui,
              }
        start_ipython(["--gui=qt", "-i", "-c='gui.show()'"], user_ns=ns)
    else:
        gui.show()
        run_qt_app()
Пример #2
0
def main(args=None):
    p = ParserCreator()
    if args is None:
        args = sys.argv[1:]
    elif isinstance(args, string_types):
        args = args.split(' ')
    args = p.parse(args)
    if args is None:
        return

    if args.profiler or args.line_profiler:
        from phy.utils.testing import _enable_profiler, _profile
        prof = _enable_profiler(args.line_profiler)
    else:
        prof = None

    import phy
    if args.debug:
        phy.debug()

    # Hide the traceback.
    if args.hide_traceback:
        def exception_handler(exception_type, exception, traceback):
            print("{}: {}".format(exception_type.__name__, exception))

        sys.excepthook = exception_handler

    # Activate IPython debugger.
    if args.pdb:
        from IPython.core import ultratb
        sys.excepthook = ultratb.FormattedTB(mode='Verbose',
                                             color_scheme='Linux',
                                             call_pdb=1,
                                             )

    func = args.func
    if func is None:
        p.parser.print_help()
        return

    out = func(args)
    if not out:
        return
    cmd, ns = out
    if not cmd:
        return
    requires_qt = ns.pop('requires_qt', False)
    requires_vispy = ns.pop('requires_vispy', False)

    # Default variables in namespace.
    ns.update(phy=phy, path=args.file)
    if 'session' in ns:
        ns['model'] = ns['session'].model

    # Interactive mode with IPython.
    if args.ipython:
        print("\nStarting IPython...")
        from IPython import start_ipython
        args_ipy = ["-i", "-c='{}'".format(cmd)]
        if requires_qt or requires_vispy:
            # Activate Qt event loop integration with Qt.
            args_ipy += ["--gui=qt"]
        start_ipython(args_ipy, user_ns=ns)
    else:
        if not prof:
            exec_(cmd, {}, ns)
        else:
            _profile(prof, cmd, {}, ns)

        if requires_qt:
            # Launch the Qt app.
            from phy.gui import run_qt_app
            run_qt_app()
        elif requires_vispy:
            # Launch the VisPy Qt app.
            from vispy.app import use_app, run
            use_app('pyqt4')
            run()
Пример #3
0
def main(args=None):
    p = ParserCreator()
    if args is None:
        args = sys.argv[1:]
    elif isinstance(args, string_types):
        args = args.split(' ')
    args = p.parse(args)
    if args is None:
        return

    if args.profiler or args.line_profiler:
        from phy.utils.testing import _enable_profiler, _profile
        prof = _enable_profiler(args.line_profiler)
    else:
        prof = None

    import phy
    if args.debug:
        phy.debug()

    # Hide the traceback.
    if args.hide_traceback:

        def exception_handler(exception_type, exception, traceback):
            print("{}: {}".format(exception_type.__name__, exception))

        sys.excepthook = exception_handler

    # Activate IPython debugger.
    if args.pdb:
        from IPython.core import ultratb
        sys.excepthook = ultratb.FormattedTB(
            mode='Verbose',
            color_scheme='Linux',
            call_pdb=1,
        )

    func = args.func
    if func is None:
        p.parser.print_help()
        return

    out = func(args)
    if not out:
        return
    cmd, ns = out
    if not cmd:
        return
    requires_qt = ns.pop('requires_qt', False)
    requires_vispy = ns.pop('requires_vispy', False)

    # Default variables in namespace.
    ns.update(phy=phy, path=args.file)
    if 'session' in ns:
        ns['model'] = ns['session'].model

    # Interactive mode with IPython.
    if args.ipython:
        print("\nStarting IPython...")
        from IPython import start_ipython
        args_ipy = ["-i", "-c='{}'".format(cmd)]
        if requires_qt or requires_vispy:
            # Activate Qt event loop integration with Qt.
            args_ipy += ["--gui=qt"]
        start_ipython(args_ipy, user_ns=ns)
    else:
        if not prof:
            exec_(cmd, {}, ns)
        else:
            _profile(prof, cmd, {}, ns)

        if requires_qt:
            # Launch the Qt app.
            from phy.gui import run_qt_app
            run_qt_app()
        elif requires_vispy:
            # Launch the VisPy Qt app.
            from vispy.app import use_app, run
            use_app('pyqt4')
            run()