Exemple #1
0
def test_run_1():
    """Read from NumPy array file."""
    # Run the algorithm.
    with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp:
        run(raw_data, experiment=exp, prm=prm, probe=Probe(prb),)

    # Open the data files.
    with Experiment('myexperiment', dir=DIRPATH) as exp:
        nspikes = len(exp.channel_groups[0].spikes)
        assert exp.channel_groups[0].spikes.clusters.main.shape[0] == nspikes
        assert exp.channel_groups[0].spikes.features_masks.shape[0] == nspikes
        assert exp.channel_groups[0].spikes.waveforms_filtered.shape[0] == nspikes

        assert isinstance(exp.channel_groups[0]._node.pca_waveforms,
            tb.Array)

        # Assert the log file exists.
        logfile = exp.gen_filename('log')
        assert os.path.exists(logfile)

        assert exp.recordings[0].raw.shape == (nsamples, nchannels)
        assert exp.recordings[0].high.shape == (nsamples, nchannels)
        assert exp.recordings[0].low.shape[0] in range(nsamples // 16 - 2,
                                                       nsamples // 16 + 3)
        assert exp.recordings[0].low.shape[1] == nchannels
Exemple #2
0
def run_spikedetekt(prm_filename, dir=None, debug=False):
    info = _load_files_info(prm_filename, dir=dir)
    experiment_name = info['experiment_name']
    prm = info['prm']
    prb = info['prb']
    data = info['data']
    dir = dir or info['dir']
    nchannels = info['nchannels']
    
    # Make sure spikedetekt does not run if the .kwik file already exists
    # (i.e. prevent running it twice on the same data)
    assert not files_exist(experiment_name, dir=dir, types=['kwik']), "The .kwik file already exists, please use the --overwrite option."
    
    # Create files.
    create_files(experiment_name, dir=dir, prm=prm, prb=prb, 
                 create_default_info=True, overwrite=False)
    
    # Run SpikeDetekt.
    with Experiment(experiment_name, dir=dir, mode='a') as exp:
        # Avoid reopening the KWD file if it's already opened.
        if isinstance(data, str) and data.endswith('kwd'):
            data = exp._files['raw.kwd']
        run(read_raw(data, nchannels=nchannels), 
            experiment=exp, prm=prm, probe=Probe(prb),
            _debug=debug)
Exemple #3
0
def run_spikedetekt(prm_filename, dir=None, debug=False):
    info = _load_files_info(prm_filename, dir=dir)
    experiment_name = info['experiment_name']
    prm = info['prm']
    prb = info['prb']
    data = info['data']
    dir = dir or info['dir']
    nchannels = info['nchannels']

    # Make sure spikedetekt does not run if the .kwik file already exists
    # (i.e. prevent running it twice on the same data)
    assert not files_exist(experiment_name, dir=dir, types=[
        'kwik'
    ]), "The .kwik file already exists, please use the --overwrite option."

    # Create files.
    create_files(experiment_name,
                 dir=dir,
                 prm=prm,
                 prb=prb,
                 create_default_info=True,
                 overwrite=False)

    # Run SpikeDetekt.
    with Experiment(experiment_name, dir=dir, mode='a') as exp:
        # Avoid reopening the KWD file if it's already opened.
        if isinstance(data, str) and data.endswith('kwd'):
            data = exp._files['raw.kwd']
        run(read_raw(data, nchannels=nchannels),
            experiment=exp,
            prm=prm,
            probe=Probe(prb),
            _debug=debug)
Exemple #4
0
def test_run_nospikes():
    """Read from NumPy array file."""
    # Run the algorithm.
    with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp:
        run(np.zeros((nsamples, nchannels)),
            experiment=exp, prm=prm, probe=Probe(prb))

    # Open the data files.
    with Experiment('myexperiment', dir=DIRPATH) as exp:
        assert len(exp.channel_groups[0].spikes) == 0
Exemple #5
0
def test_run_canonical_pcs():
    prm_canonical = prm.copy()

    canonical_pcs = np.ones((prm['nfeatures_per_channel'],
                             prm['waveforms_nsamples'],
                             prm['nchannels']))
    prm_canonical['canonical_pcs'] = canonical_pcs

    with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp:
        run(raw_data, experiment=exp, prm=prm_canonical, probe=Probe(prb),)
Exemple #6
0
def test_run_2():
    """Read from .dat file."""
    path = os.path.join(DIRPATH, 'mydatfile.dat')
    (raw_data * 1e4).astype(np.int16).tofile(path)

    # Run the algorithm.
    with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp:
        run(path, experiment=exp, prm=prm, probe=Probe(prb))

    # Open the data files.
    with Experiment('myexperiment', dir=DIRPATH) as exp:
        assert len(exp.channel_groups[0].spikes)
Exemple #7
0
def test_run_1():
    """Read from NumPy array file."""
    # Run the algorithm.
    with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp:
        run(raw_data, experiment=exp, prm=prm, probe=Probe(prb))
    
    # Open the data files.
    with Experiment('myexperiment', dir=DIRPATH) as exp:
        print(len(exp.channel_groups[0].spikes))
        # Assert the log file exists.
        logfile = exp.gen_filename('log')
        assert os.path.exists(logfile)
Exemple #8
0
def test_diagnostics():

    dir = tempfile.mkdtemp()

    path = op.join(dir, 'diagnostics.py')
    with open(path, 'w') as f:
        f.write(
        'def diagnostics(prm=None, **kwargs):\n'
        '   print(prm)\n'
        '\n')

    prm['diagnostics_path'] = path

    with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp:
        run(np.zeros((nsamples, nchannels)),
            experiment=exp, prm=prm, probe=Probe(prb))

    shutil.rmtree(dir)