Skip to content

Commit

Permalink
add raw data plots to alignment gui
Browse files Browse the repository at this point in the history
  • Loading branch information
mayofaulkner committed Feb 10, 2022
1 parent 7d0f6a1 commit 0a4da71
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
5 changes: 2 additions & 3 deletions atlaselectrophysiology/alignment_with_easyqc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from easyqc.gui import viewseis
from ibllib.dsp import voltage
from ibllib.ephys import neuropixel
from viewspikes.data import stream, get_ks2
from viewspikes.data import stream
from viewspikes.plots import overlay_spikes
import scipy
from PyQt5 import QtCore, QtGui
Expand Down Expand Up @@ -140,12 +140,11 @@ def stream_ap(self, t):
sos = scipy.signal.butter(3, 300 / self.ap.fs / 2, btype='highpass', output='sos')
butt = scipy.signal.sosfiltfilt(sos, raw)
destripe = voltage.destripe(raw, fs=self.ap.fs)
ks2 = get_ks2(raw, dsets, self.loaddata.one)

self.eqc['butterworth'] = viewseis(butt.T, si=1 / self.ap.fs, h=h, t0=t0, title='butt',
taxis=0)
self.eqc['destripe'] = viewseis(destripe.T, si=1 / self.ap.fs, h=h, t0=t0, title='destr',
taxis=0)
self.eqc['ks2'] = viewseis(ks2.T, si=1 / self.ap.fs, h=h, t0=t0, title='ks2', taxis=0)

overlay_spikes(self.eqc['butterworth'], self.plotdata.spikes, self.plotdata.clusters,
self.plotdata.channels)
Expand Down
7 changes: 6 additions & 1 deletion atlaselectrophysiology/ephys_atlas_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,11 @@ def data_button_pressed(self):
self.probe_rfmap, self.rfmap_boundaries = self.plotdata.get_rfmap_data()
self.img_stim_data = self.plotdata.get_passive_events()

if not self.offline:
self.img_raw_data = self.plotdata.get_raw_data_image(self.loaddata.probe_id, one=self.loaddata.one)
else:
self.img_raw_data = {}

if self.histology_exists:
self.slice_data = self.loaddata.get_slice_images(self.ephysalign.xyz_samples)
else:
Expand Down Expand Up @@ -2113,7 +2118,7 @@ def viewer(probe_id, one=None, histology=False, spike_collection=None, title=Non

parser = argparse.ArgumentParser(description='Offline vs online mode')
parser.add_argument('-o', '--offline', default=False, required=False, help='Offline mode')
parser.add_argument('-r', '--remote', default=False, required=False, action='store_true', help='Remote mode')
parser.add_argument('-r', '--remote', default=False, required=False, action='store_true', help='Remote mode')
parser.add_argument('-i', '--insertion', default=None, required=False, help='Insertion mode')
args = parser.parse_args()

Expand Down
8 changes: 8 additions & 0 deletions atlaselectrophysiology/ephys_gui_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def init_menubar(self):
img_options.addAction(scatter_amp)
self.img_options_group.addAction(scatter_amp)

raw_type = list(self.img_raw_data.keys())
for raw in raw_type:
img = QtWidgets.QAction(raw, self, checkable=True, checked=False)
img.triggered.connect(lambda checked, item=raw: self.plot_image(
self.img_raw_data[item]))
img_options.addAction(img)
self.img_options_group.addAction(img)

stim_type = list(self.img_stim_data.keys())
for stim in stim_type:
img = QtWidgets.QAction(stim, self, checkable=True, checked=False)
Expand Down
3 changes: 0 additions & 3 deletions atlaselectrophysiology/example_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@


av = viewer(probe_id, one=one)


# To add trials to the window
34 changes: 34 additions & 0 deletions atlaselectrophysiology/plot_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import numpy as np
import one.alf as alf
from brainbox.processing import bincount2D
from brainbox.io.spikeglx import stream
from brainbox.population.decode import xcorr
from brainbox.task import passive
from ibllib.dsp import voltage
import scipy
from PyQt5 import QtGui

Expand Down Expand Up @@ -472,6 +474,38 @@ def median_subtract(a):

return data_img, data_probe

# only for IBL sorry
def get_raw_data_image(self, pid, t0=(1000, 2000, 3000), one=None):

def gain2level(gain):
return 10 ** (gain / 20) * 4 * np.array([-1, 1])
data_img = dict()
for t in t0:

sr, t = stream(pid, t, one=one)
raw = sr[:, :-sr.nsync].T
channel_labels, channel_features = voltage.detect_bad_channels(raw, sr.fs)
raw = voltage.destripe(raw, fs=sr.fs, channel_labels=channel_labels)
raw_image = raw[:, int((450 / 1e3) * sr.fs):int((500 / 1e3) * sr.fs)].T
x_range = np.array([0, raw_image.shape[0] - 1]) / sr.fs * 1e3
levels = gain2level(-90)
xscale = (x_range[1] - x_range[0]) / raw_image.shape[0]
yscale = (self.chn_max - self.chn_min) / raw_image.shape[1]

data_raw = {
'img': raw_image,
'scale': np.array([xscale, yscale]),
'levels': levels,
'offset': np.array([0, 0]),
'cmap': 'bone',
'xrange': x_range,
'xaxis': 'Time (ms)',
'title': 'Power (uV)'
}
data_img[f'Raw data t={t}'] = data_raw

return data_img

def get_lfp_spectrum_data(self):
freq_bands = np.vstack(([0, 4], [4, 10], [10, 30], [30, 80], [80, 200]))
data_probe = {}
Expand Down

0 comments on commit 0a4da71

Please sign in to comment.