Ejemplo n.º 1
0
def phycli(ctx):
    """Interactive visualization and manual spike sorting of large-scale ephys data."""
    add_default_handler(level='DEBUG' if DEBUG else 'INFO',
                        logger=logging.getLogger('phy'))
    add_default_handler(level='DEBUG' if DEBUG else 'INFO',
                        logger=logging.getLogger('phylib'))
    add_default_handler(level='DEBUG' if DEBUG else 'INFO',
                        logger=logging.getLogger('mtscomp'))
Ejemplo n.º 2
0
import warnings

import matplotlib
import numpy as np
from pytest import fixture

from phylib import add_default_handler


#------------------------------------------------------------------------------
# Common fixtures
#------------------------------------------------------------------------------

logger = logging.getLogger('phylib')
logger.setLevel(10)
add_default_handler(5, logger=logger)

# Fix the random seed in the tests.
np.random.seed(2015)

warnings.filterwarnings('ignore', category=matplotlib.cbook.mplDeprecation)
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")


@fixture
def tempdir():
    curdir = os.getcwd()
    tempdir = tempfile.mkdtemp()
    os.chdir(tempdir)
    yield Path(tempdir)
Ejemplo n.º 3
0
def launch_phy(probe_name,
               eid=None,
               subj=None,
               date=None,
               sess_no=None,
               one=None):
    """
    Launch phy given an eid and probe name.

    TODO calculate metrics and save as .tsvs to include in GUI when launching?
    """

    # This is a first draft, no error handling and a draft dataset list.

    # Load data from probe #
    # -------------------- #

    if one is None:
        one = ONE()

    dtypes = [
        'spikes.times',
        'spikes.clusters',
        'spikes.amps',
        'spikes.templates',
        'spikes.samples',
        'spikes.depths',
        'templates.waveforms',
        'templates.waveformsChannels',
        'clusters.uuids',
        'clusters.metrics',
        'clusters.waveforms',
        'clusters.waveformsChannels',
        'clusters.depths',
        'clusters.amps',
        'clusters.channels',
        'channels.probes',
        'channels.rawInd',
        'channels.localCoordinates',
        # 'ephysData.raw.ap'
        '_phy_spikes_subset.waveforms',
        '_phy_spikes_subset.spikes',
        '_phy_spikes_subset.channels'
    ]

    if eid is None:
        eid = one.search(subject=subj, date=date, number=sess_no)[0]

    _ = one.load(eid, dataset_types=dtypes, download_only=True)
    ses_path = one.path_from_eid(eid)
    alf_probe_dir = os.path.join(ses_path, 'alf', probe_name)
    ephys_file_dir = os.path.join(ses_path, 'raw_ephys_data', probe_name)
    raw_files = glob.glob(os.path.join(ephys_file_dir, '*ap.*bin'))
    raw_file = [raw_files[0]] if raw_files else None

    # TODO download ephys meta-data, and extract TemplateController input arg params

    # Launch phy #
    # -------------------- #
    add_default_handler('DEBUG', logging.getLogger("phy"))
    add_default_handler('DEBUG', logging.getLogger("phylib"))
    create_app()
    controller = TemplateController(
        dat_path=raw_file,
        dir_path=alf_probe_dir,
        dtype=np.int16,
        n_channels_dat=384,
        sample_rate=3e4,
        plugins=['IBLMetricsPlugin'],
        plugin_dirs=[Path(__file__).resolve().parent / 'plugins'])
    gui = controller.create_gui()
    gui.show()
    run_app()
    gui.close()
    controller.model.close()