Beispiel #1
0
    def test_spike_detection(self):
        """
        Test that creates a synthetic dataset with spikes and an amplitude decay function
        with the probe gemetry, and then pastes spikes all around the dataset and detects and
        de-duplicates
        The test is feeding the detections in a new round of simulation, and then computing
        the zero-lag cross-correlation between input and simulated output, and asserting on
        the similarity
        """

        fs = 30000
        nspikes = 1200
        h = neuropixel.trace_header(version=1)
        ns, nc = (10000, len(h['x']))
        nss, ncs = (121, 21)
        np.random.seed(973)
        display = False
        data = make_synthetic_data(ns, nc, nss, ncs, nspikes)
        detects = spikes.detection(data, fs=fs, h=h, detect_threshold=-0.8, time_tol=.0006)

        sample_out = (detects.time * fs + nss / 2 - 4).astype(np.int32)
        tr_out = detects.trace.astype(np.int32)
        data_out = make_synthetic_data(ns, nc, nss, ncs, tr=tr_out, sample=sample_out)

        if display:
            from easyqc.gui import viewseis
            eqc = viewseis(data, si=1 / 30000 * 1e3, taxis=0, title='data')
            eqc.ctrl.add_scatter(detects.time * 1e3, detects.trace)
            eqco = viewseis(data_out, si=1 / 30000 * 1e3, taxis=0, title='data_out')  # noqa

        xcor = np.zeros(nc)
        for tr in np.arange(nc):
            if np.all(data[:, tr] == 0):
                xcor[tr] = 1
                continue
            xcor[tr] = np.corrcoef(data[:, tr], data_out[:, tr])[1, 0]

        assert np.mean(xcor > .8) > .95
        assert np.nanmedian(xcor) > .99
Beispiel #2
0
#
plot_insertion(pid, one)


h = neuropixel.trace_header()
raw = sr[:, :-1].T

sos = scipy.signal.butter(3, 300 / sr.fs / 2, btype='highpass', output='sos')
butt = scipy.signal.sosfiltfilt(sos, raw)
# show_psd(butt, sr.fs)

fk_kwargs ={'dx': 1, 'vbounds': [0, 1e6], 'ntr_pad': 160, 'ntr_tap': 0, 'lagc': .01, 'btype': 'lowpass'}
destripe = voltage.destripe(raw, fs=sr.fs, fk_kwargs=fk_kwargs, tr_sel=np.arange(raw.shape[0]))
ks2 = get_ks2(raw, dsets, one)

# get the spikes corresponding to current chunk, here needs to go through samples for sync reasons
spikes, clusters, channels = get_spikes(dsets, one)

if SIDE_BY_SIDE:
    hhh = {k: np.tile(h[k], 3) for k in h}
    eqc_concat = viewseis(np.r_[butt, destripe, ks2], si=1 / sr.fs, h=hhh, t0=t0, title='concat')
    overlay_spikes(eqc_concat, spikes, clusters, channels)
else:
    eqc_butt = viewseis(butt.T, si=1 / sr.fs, h=h, t0=t0, title='butt', taxis=0)
    eqc_dest = viewseis(destripe.T, si=1 / sr.fs, h=h, t0=t0, title='destr', taxis=0)
    eqc_ks2 = viewseis(ks2.T, si=1 / sr.fs, h=h, t0=t0, title='ks2', taxis=0)
    overlay_spikes(eqc_butt, spikes, clusters, channels)
    overlay_spikes(eqc_dest, spikes, clusters, channels)
    overlay_spikes(eqc_ks2, spikes, clusters, channels)
Beispiel #3
0
## Example 2: Plot Insertion for a given PID (todo: use Needles 2 for interactive)
av = run_needles2.view(lazy=True)
av.add_insertion_by_id(pid)

## Example 3: Show the PSD
raw = sr[:, :-1].T
fig, axes = plt.subplots(1, 2)
fig.set_size_inches(18, 7)
show_psd(raw, sr.fs, ax=axes[0])

## Example 4: Display the raw / pre-proc and KS2 parts -
h = neuropixel.trace_header()
sos = scipy.signal.butter(3, 300 / sr.fs / 2, btype='highpass', output='sos')
butt = scipy.signal.sosfiltfilt(sos, raw)
fk_kwargs ={'dx': 1, 'vbounds': [0, 1e6], 'ntr_pad': 160, 'ntr_tap': 0, 'lagc': .01, 'btype': 'lowpass'}
destripe = voltage.destripe(raw, fs=sr.fs, fk_kwargs=fk_kwargs, tr_sel=np.arange(raw.shape[0]))
ks2 = get_ks2(raw, dsets, one)
eqc_butt = viewseis(butt.T, si=1 / sr.fs, h=h, t0=t0, title='butt', taxis=0)
eqc_dest = viewseis(destripe.T, si=1 / sr.fs, h=h, t0=t0, title='destr', taxis=0)
eqc_ks2 = viewseis(ks2.T, si=1 / sr.fs, h=h, t0=t0, title='ks2', taxis=0)

# Example 5: overlay the spikes on the existing easyqc instances
spikes, clusters, channels = get_spikes(dsets, one)
overlay_spikes(eqc_butt, spikes, clusters, channels)
overlay_spikes(eqc_dest, spikes, clusters, channels)
overlay_spikes(eqc_ks2, spikes, clusters, channels)

# Do the driftmap
driftmap(spikes['times'], spikes['depths'], t_bin=0.1, d_bin=5, ax=axes[1])
Beispiel #4
0
h = neuropixel.trace_header()
sos = scipy.signal.butter(3, 300 / sr.fs / 2, btype='highpass', output='sos')
butt = scipy.signal.sosfiltfilt(sos, raw)
fk_kwargs = {
    'dx': 1,
    'vbounds': [0, 1e6],
    'ntr_pad': 160,
    'ntr_tap': 0,
    'lagc': .01,
    'btype': 'lowpass'
}
destripe = voltage.destripe(raw,
                            fs=sr.fs,
                            fk_kwargs=fk_kwargs,
                            tr_sel=np.arange(raw.shape[0]))
eqc_butt = viewseis(butt.T, si=1 / sr.fs, h=h, t0=t0, title='butt', taxis=0)
eqc_dest = viewseis(destripe.T,
                    si=1 / sr.fs,
                    h=h,
                    t0=t0,
                    title='destr',
                    taxis=0)
eqc_dest_ = viewseis(destripe.T,
                     si=1 / sr.fs,
                     h=h,
                     t0=t0,
                     title='destr_',
                     taxis=0)
# Example 5: overlay the spikes on the existing easyqc instances
from ibllib.plots import color_cycle
ss = {}