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
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
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)
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),)
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)
def test_conversion_1(): # Convert klusters data to kwik. klusters_to_kwik(filename='test', dir=TEST_FOLDER) fet = read_features(os.path.join(TEST_FOLDER, 'test.fet.1'), nchannels, fetdim, freq, do_process=False) clu = read_clusters(os.path.join(TEST_FOLDER, 'test.clu.1')) with Experiment('test', dir=TEST_FOLDER, mode='r') as exp: # Check cluster / cluster group metadata. assert np.allclose(sorted(exp.channel_groups[1].clusters.main.keys()), range(2, 22)) assert np.allclose(exp.channel_groups[1].clusters.main.color[:], range(1, 21)) assert np.all(exp.channel_groups[1].clusters.main.group[:] == 3) # Check original == main. assert np.allclose( sorted(exp.channel_groups[1].clusters.main.keys()), sorted(exp.channel_groups[1].clusters.original.keys()), ) assert np.allclose( exp.channel_groups[1].clusters.main.color[:], exp.channel_groups[1].clusters.original.color[:], ) assert np.allclose( exp.channel_groups[1].clusters.main.group[:], exp.channel_groups[1].clusters.original.group[:], ) # Test spike clusters. assert np.allclose(exp.channel_groups[1].spikes.clusters.main[:], clu) assert np.allclose(exp.channel_groups[1].spikes.clusters.main[:], exp.channel_groups[1].spikes.clusters.original[:]) # Ensure features masks is contiguous. assert isinstance(exp.channel_groups[1].spikes.features_masks, tb.Array) assert not isinstance(exp.channel_groups[1].spikes.features_masks, tb.EArray) # Check features and waveforms. nspikes = len(exp.channel_groups[1].spikes.clusters.main[:]) assert exp.channel_groups[1].spikes.features_masks.shape[0] == nspikes # No uspk file ==> no waveforms_raw assert exp.channel_groups[1].spikes.waveforms_raw.shape[0] == 0 assert exp.channel_groups[1].spikes.waveforms_filtered.shape[ 0] == nspikes assert exp.channel_groups[1].spikes.time_samples[:].sum() > 0 assert exp.channel_groups[1].spikes.features_masks[:].sum() > 0 assert exp.channel_groups[1].spikes.waveforms_filtered[:].sum() > 0 fet_kwik = exp.channel_groups[1].spikes.features[:] # Check equality between original and kwik (normalized) features array. fet = fet.ravel() fet_kwik = fet_kwik.ravel() ind = fet != 0 d = (fet[ind] / fet_kwik[ind]) assert d.max() - d.min() <= .1