Skip to content

Commit

Permalink
Merge pull request #99 from int-brain-lab/filter_spurious_units
Browse files Browse the repository at this point in the history
Filter "spurious" units from alignment gui
  • Loading branch information
mayofaulkner authored Sep 26, 2023
2 parents cafba88 + 3b53981 commit f372bc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion atlaselectrophysiology/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from neuropixel import trace_header
import ibllib.atlas as atlas
from ibllib.qc.alignment_qc import AlignmentQC
from iblutil.numerical import ismember
from iblutil.util import Bunch
from one.api import ONE
from one.remote import aws
from pathlib import Path
Expand Down Expand Up @@ -259,16 +261,29 @@ def get_data(self):
try:
data['spikes'] = self.one.load_object(self.eid, 'spikes', collection=self.probe_collection,
attribute=['depths', 'amps', 'times', 'clusters'])
data['spikes']['exists'] = True

data['clusters'] = self.one.load_object(self.eid, 'clusters', collection=self.probe_collection,
attribute=['metrics', 'peakToTrough', 'waveforms', 'channels'])

# Remove low firing rate clusters
min_firing_rate = 50. / 3600.
clu_idx = data['clusters'].metrics.firing_rate > min_firing_rate
data['clusters'] = Bunch({k: v[clu_idx] for k, v in data['clusters'].items()})
spike_idx, ib = ismember(data['spikes'].clusters, data['clusters'].metrics.index)
data['clusters'].metrics.reset_index(drop=True, inplace=True)
data['spikes'] = Bunch({k: v[spike_idx] for k, v in data['spikes'].items()})
data['spikes'].clusters = data['clusters'].metrics.index[ib].astype(np.int32)

data['spikes']['exists'] = True
data['clusters']['exists'] = True

data['channels'] = self.one.load_object(self.eid, 'channels', collection=self.probe_collection,
attribute=['rawInd', 'localCoordinates'])
data['channels']['exists'] = True

# Set low firing rate clusters to bad


except alf.exceptions.ALFObjectNotFound:
logger.error(f'Could not load spike sorting for probe insertion {self.probe_id}, GUI'
f' will not work')
Expand Down
4 changes: 2 additions & 2 deletions atlaselectrophysiology/plot_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from matplotlib import cm
import numpy as np
from brainbox.processing import bincount2D
from iblutil.numerical import bincount2D
from brainbox.io.spikeglx import Streamer
from brainbox.population.decode import xcorr
from brainbox.task import passive
Expand Down Expand Up @@ -596,7 +596,7 @@ def get_autocorr(self, clust_idx):
autocorr = xcorr(self.data['spikes']['times'][idx], self.data['spikes']['clusters'][idx],
AUTOCORR_BIN_SIZE, AUTOCORR_WIN_SIZE)

return autocorr[0, 0, :], self.clust_id[clust_idx]
return autocorr[0, 0, :], self.data['clusters'].metrics.cluster_id[self.clust_id[clust_idx]]

def get_template_wf(self, clust_idx):
template_wf = (self.data['clusters']['waveforms'][self.clust_id[clust_idx], :, 0])
Expand Down

0 comments on commit f372bc5

Please sign in to comment.