Skip to content

Commit

Permalink
Merge pull request #54 from int-brain-lab/raw_data
Browse files Browse the repository at this point in the history
Raw data
  • Loading branch information
mayofaulkner authored Feb 11, 2022
2 parents 892569c + d39cce7 commit 660f5bc
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 16 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
2 changes: 1 addition & 1 deletion atlaselectrophysiology/load_histology.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def download_histology_data(subject, lab):
path_to_image = Path(CACHE_DIR, file)
if not path_to_image.exists():
url = (baseurl + '/' + file)
http_download_file(url, cache_dir=CACHE_DIR,
http_download_file(url, target_dir=CACHE_DIR,
username=par.HTTP_DATA_SERVER_LOGIN,
password=par.HTTP_DATA_SERVER_PWD)

Expand Down
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
14 changes: 6 additions & 8 deletions dlc/overview_plot_dlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,16 @@ def get_ME(eid, video_type):
return Times, ME


Times = cam0['times']

def get_example_images(eid):


eids = get_repeated_sites()
# eid = eids[23]
# video_type = 'body'
# eids = get_repeated_sites()
## eid = eids[23]
## video_type = 'body'

#eids = ['15f742e1-1043-45c9-9504-f1e8a53c1744']
eids = ['4a45c8ba-db6f-4f11-9403-56e06a33dfa4']
# #eids = ['15f742e1-1043-45c9-9504-f1e8a53c1744']
# eids = ['4a45c8ba-db6f-4f11-9403-56e06a33dfa4']
frts = {'body':30, 'left':60,'right':150}

one=ONE()
Expand Down Expand Up @@ -1265,7 +1264,6 @@ def plot_all(eid):

plt.tight_layout()

s2 = ' '.join(l)

# print QC outcome in title and DLC task version
one = ONE()
Expand Down Expand Up @@ -1338,7 +1336,7 @@ def plot_all(eid):
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
#plt.savefig(f'/home/mic/reproducible_dlc/overviewJune/{eid}.png')
#plt.savefig(f'/home/mic/reproducible_dlc/all_DLC/{s1}_{eid}.png')
plt.savefig(f'/home/mic/reproducible_dlc/miles_QC_update/{s1}_{eid}.png')
plt.savefig(f'/home/mic/reproducible_dlc/motor_correlate/{s1}_{eid}.png')
plt.close()


Expand Down

0 comments on commit 660f5bc

Please sign in to comment.