Skip to content

Commit bfeb512

Browse files
committed
viewspikes: examples on reproducible ephys
1 parent 9bec05e commit bfeb512

File tree

3 files changed

+105
-3
lines changed

3 files changed

+105
-3
lines changed

viewspikes/examples_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"ce397420-3cd2-4a55-8fd1-5e28321981f4",
2626

2727
# Example 1
28-
pid, t0 = ("8413c5c6-b42b-4ec6-b751-881a54413628", 810)
28+
pid, t0 = ("ce24bbe9-ae70-4659-9e9c-564d1a865de8", 810)
2929
bin_file = next(RAW_PATH.joinpath(pid).rglob("*.ap.bin"))
3030
sr = spikeglx.Reader(bin_file)
3131
sel = slice(int(t0 * sr.fs), int((t0 + 4) * sr.fs))
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import numpy as np
2+
import scipy
3+
import matplotlib.pyplot as plt
4+
from easyqc.gui import viewseis
5+
6+
7+
from oneibl.one import ONE
8+
from ibllib.ephys import neuropixel
9+
from ibllib.dsp import voltage
10+
from brainbox.plot import driftmap
11+
import alf.io
12+
13+
from needles2 import run_needles2
14+
from viewspikes.data import stream, get_ks2, get_spikes
15+
from viewspikes.plots import plot_insertion, show_psd, overlay_spikes
16+
17+
one = ONE()
18+
19+
eids = ['56b57c38-2699-4091-90a8-aba35103155e',
20+
'746d1902-fa59-4cab-b0aa-013be36060d5',
21+
'7b26ce84-07f9-43d1-957f-bc72aeb730a3',
22+
'dac3a4c1-b666-4de0-87e8-8c514483cacf',
23+
'6f09ba7e-e3ce-44b0-932b-c003fb44fb89',
24+
'73918ae1-e4fd-4c18-b132-00cb555b1ad2',
25+
'f312aaec-3b6f-44b3-86b4-3a0c119c0438',
26+
'dda5fc59-f09a-4256-9fb5-66c67667a466',
27+
'ee40aece-cffd-4edb-a4b6-155f158c666a',
28+
'ecb5520d-1358-434c-95ec-93687ecd1396',
29+
'54238fd6-d2d0-4408-b1a9-d19d24fd29ce',
30+
'e535fb62-e245-4a48-b119-88ce62a6fe67',
31+
'b03fbc44-3d8e-4a6c-8a50-5ea3498568e0',
32+
'db4df448-e449-4a6f-a0e7-288711e7a75a',
33+
'064a7252-8e10-4ad6-b3fd-7a88a2db5463',
34+
'41872d7f-75cb-4445-bb1a-132b354c44f0',
35+
'dfd8e7df-dc51-4589-b6ca-7baccfeb94b4',
36+
'4a45c8ba-db6f-4f11-9403-56e06a33dfa4',
37+
'4b00df29-3769-43be-bb40-128b1cba6d35',
38+
'862ade13-53cd-4221-a3fa-dda8643641f2',
39+
'3638d102-e8b6-4230-8742-e548cd87a949',
40+
'c7248e09-8c0d-40f2-9eb4-700a8973d8c8',
41+
'aad23144-0e52-4eac-80c5-c4ee2decb198',
42+
'd0ea3148-948d-4817-94f8-dcaf2342bbbe',
43+
'7f6b86f9-879a-4ea2-8531-294a221af5d0',
44+
'd23a44ef-1402-4ed7-97f5-47e9a7a504d9']
45+
46+
insertions = one.alyx.rest('insertions', 'list', django=f'session__in,{eids}')
47+
48+
## Example 1: Stream one second of ephys data
49+
# pid, t0 = ("e864fca7-40e3-4a80-b736-51d4662405e4", 2155)
50+
# pid, t0 = ('ce24bbe9-ae70-4659-9e9c-564d1a865de8', 610)
51+
52+
pid, t0 = (insertions[10]['id'], 2500)
53+
54+
55+
sr, dsets = stream(pid, t0=t0, one=one, cache=True)
56+
raw = sr[:, :-1].T
57+
58+
## Example: Plot Insertion for a given PID (todo: use Needles 2 for interactive)
59+
av = run_needles2.view(lazy=True)
60+
av.add_insertion_by_id(pid)
61+
62+
## Example: Display the raw / pre-proc and KS2 parts -
63+
h = neuropixel.trace_header()
64+
sos = scipy.signal.butter(3, 300 / sr.fs / 2, btype='highpass', output='sos')
65+
butt = scipy.signal.sosfiltfilt(sos, raw)
66+
fk_kwargs ={'dx': 1, 'vbounds': [0, 1e6], 'ntr_pad': 160, 'ntr_tap': 0, 'lagc': .01, 'btype': 'lowpass'}
67+
destripe = voltage.destripe(raw, fs=sr.fs, fk_kwargs=fk_kwargs, tr_sel=np.arange(raw.shape[0]))
68+
ks2 = get_ks2(raw, dsets, one)
69+
eqc_butt = viewseis(butt.T, si=1 / sr.fs, h=h, t0=t0, title='butt', taxis=0)
70+
eqc_dest = viewseis(destripe.T, si=1 / sr.fs, h=h, t0=t0, title='destr', taxis=0)
71+
eqc_ks2 = viewseis(ks2.T, si=1 / sr.fs, h=h, t0=t0, title='ks2', taxis=0)
72+
73+
74+
## Example: overlay the spikes on the existing easyqc instances
75+
spikes, clusters, channels = get_spikes(dsets, one)
76+
_, tspi, xspi = overlay_spikes(eqc_butt, spikes, clusters, channels)
77+
overlay_spikes(eqc_dest, spikes, clusters, channels)
78+
overlay_spikes(eqc_ks2, spikes, clusters, channels)
79+
80+
## Get the behaviour information
81+
eid = dsets[0]['session'][-36:]
82+
tdsets = one.alyx.rest('datasets', 'list', session=eid, django='name__icontains,trials.')
83+
one.download_datasets(tdsets)
84+
trials = alf.io.load_object(one.path_from_eid(eid).joinpath('alf'), 'trials')
85+
rewards = trials['feedback_times'][trials['feedbackType'] == 1]
86+
87+
## Do the drift map with some task information overlaid
88+
fig, ax = plt.subplots()
89+
driftmap(spikes['times'], spikes['depths'], t_bin=0.1, d_bin=5, ax=ax)
90+
from ibllib.plots import vertical_lines
91+
vertical_lines(rewards, ymin=0, ymax=3800, ax=ax)
92+

viewspikes/examples_stream.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
"f86e9571-63ff-4116-9c40-aa44d57d2da9", # CSHL049_2020-01-08_probe00 a bit stripy but fine
2222
"675952a4-e8b3-4e82-a179-cc970d5a8b01", # CSH_ZAD_029_2020-09-19_probe01 a bit stripy as well
2323

24-
## Example 1: Stream one second of ephys data
25-
pid, t0 = ("e864fca7-40e3-4a80-b736-51d4662405e4", 2155)
24+
# Example 1: Stream one second of ephys data
25+
# pid, t0 = ("e864fca7-40e3-4a80-b736-51d4662405e4", 2155)
26+
# pid, t0 = ('ce24bbe9-ae70-4659-9e9c-564d1a865de8', 610)
27+
28+
pid, t0 = ("0ece5c6a-7d1e-4365-893d-ac1cc04f1d7b", 3000)
29+
30+
2631
sr, dsets = stream(pid, t0=t0, one=one, cache=True)
2732

2833
## Example 2: Plot Insertion for a given PID (todo: use Needles 2 for interactive)
@@ -41,8 +46,13 @@
4146
butt = scipy.signal.sosfiltfilt(sos, raw)
4247
fk_kwargs ={'dx': 1, 'vbounds': [0, 1e6], 'ntr_pad': 160, 'ntr_tap': 0, 'lagc': .01, 'btype': 'lowpass'}
4348
destripe = voltage.destripe(raw, fs=sr.fs, fk_kwargs=fk_kwargs, tr_sel=np.arange(raw.shape[0]))
49+
ks2 = get_ks2(raw, dsets, one)
4450
eqc_butt = viewseis(butt.T, si=1 / sr.fs, h=h, t0=t0, title='butt', taxis=0)
4551
eqc_dest = viewseis(destripe.T, si=1 / sr.fs, h=h, t0=t0, title='destr', taxis=0)
52+
eqc_ks2 = viewseis(ks2.T, si=1 / sr.fs, h=h, t0=t0, title='ks2', taxis=0)
53+
54+
55+
4656

4757
# Example 5: overlay the spikes on the existing easyqc instances
4858
spikes, clusters, channels = get_spikes(dsets, one)

0 commit comments

Comments
 (0)