Skip to content

Commit 2dcdc50

Browse files
committed
viewspikes: co-locate driftmap and PSD in one figure
1 parent 067db9b commit 2dcdc50

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

viewspikes/examples.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import numpy as np
22
import scipy
3+
import matplotlib.pyplot as plt
34
from easyqc.gui import viewseis
45

6+
57
from oneibl.one import ONE
68
from ibllib.ephys import neuropixel
79
from ibllib.dsp import voltage
10+
from ibllib.plots import color_cycle
11+
from brainbox.plot import driftmap
812

913
from iblapps.needles2 import run_needles2
1014
from iblapps.viewspikes.data import stream, get_ks2, get_spikes
@@ -22,7 +26,9 @@
2226

2327
## Example 3: Show the PSD
2428
raw = sr[:, :-1].T
25-
show_psd(raw, sr.fs)
29+
fig, axes = plt.subplots(1, 2)
30+
fig.set_size_inches(18, 7)
31+
show_psd(raw, sr.fs, ax=axes[0])
2632

2733
## Example 4: Display the raw / pre-proc and KS2 parts -
2834
h = neuropixel.trace_header()
@@ -41,6 +47,16 @@
4147
overlay_spikes(eqc_dest, spikes, clusters, channels)
4248
overlay_spikes(eqc_ks2, spikes, clusters, channels)
4349

44-
# hhh = {k: np.tile(h[k], 3) for k in h}
50+
# Do the driftmap
51+
driftmap(spikes['times'], spikes['depths'], t_bin=0.1, d_bin=5, ax=axes[1])
52+
53+
4554
# eqc_concat = viewseis(np.r_[butt, destripe, ks2], si=1 / sr.fs, h=hhh, t0=t0, title='concat')
4655
# overlay_spikes(eqc_concat, spikes, clusters, channels)
56+
from easyqc import qt
57+
import datetime
58+
qtapp = qt.create_app()
59+
screenshot = qtapp.primaryScreen().grabWindow(eqc_butt.winId())
60+
61+
fn = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S')
62+
screenshot.save(f'/home/olivier/Pictures/{fn}.png', 'png')

viewspikes/plots.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
import ibllib.atlas as atlas
88
from ibllib.ephys.neuropixel import SITES_COORDINATES
99
from ibllib.pipes.ephys_alignment import EphysAlignment
10-
from ibllib.plots import wiggle
10+
from ibllib.plots import wiggle, color_cycle
1111

1212
brain_atlas = atlas.AllenAtlas()
1313
# Instantiate brain atlas and one
1414

1515

16-
def show_psd(data, fs):
16+
def show_psd(data, fs, ax=None):
1717
psd = np.zeros((data.shape[0], 129))
1818
for tr in np.arange(data.shape[0]):
1919
f, psd[tr, :] = scipy.signal.welch(data[tr, :], fs=fs)
2020

21-
plt.figure()
22-
plt.plot(f, 10 * np.log10(psd.T), color='gray', alpha=0.1)
23-
plt.plot(f, 10 * np.log10(np.mean(psd, axis=0).T), color='red')
24-
plt.xlabel('Frequency (Hz)')
25-
plt.ylabel('PSD (dB rel V/Hz)')
26-
plt.gca()
27-
plt.gca().set_ylim(-150, -110)
28-
plt.gca().set_xlim(0, fs / 2)
21+
if ax is None:
22+
fig, ax = plt.subplots()
23+
ax.plot(f, 10 * np.log10(psd.T), color='gray', alpha=0.1)
24+
ax.plot(f, 10 * np.log10(np.mean(psd, axis=0).T), color='red')
25+
ax.set_xlabel('Frequency (Hz)')
26+
ax.set_ylabel('PSD (dB rel V/Hz)')
27+
ax.set_ylim(-150, -110)
28+
ax.set_xlim(0, fs / 2)
2929
plt.show()
3030

3131

@@ -146,7 +146,11 @@ def overlay_spikes(self, spikes, clusters, channels):
146146
sc = self.layers['default']['layer']
147147
sc.setSize(8)
148148
sc.setSymbol('x')
149-
sc.setPen(pg.mkPen((0, 255, 0, 155), width=1))
149+
# sc.setPen(pg.mkPen((0, 255, 0, 155), width=1))
150+
rgbs = [list((rgb * 255).astype(np.uint8)) for rgb in color_cycle(spikes['clusters'][ifirst:ilast])]
151+
sc.setBrush([pg.mkBrush(rgb) for rgb in rgbs])
152+
sc.setPen([pg.mkPen(rgb) for rgb in rgbs])
153+
return sc
150154

151155
# sc.setData(x=xspi, y=tspi, brush=pg.mkBrush((255, 0, 0)))
152156
def callback(sc, points, evt):

0 commit comments

Comments
 (0)