Skip to content

Commit

Permalink
Merge pull request #2173 from DradeAW/faster_empty_units
Browse files Browse the repository at this point in the history
Improvement to `get_empty_units()`
  • Loading branch information
samuelgarcia authored Nov 17, 2023
2 parents e7be6b6 + 849a5ac commit 960781c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/spikeinterface/core/basesorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def remove_units(self, remove_unit_ids) -> BaseSorting:
def remove_empty_units(self):
"""
Returns a new sorting object which contains only units with at least one spike.
For multi-segments, a unit is considered empty if it contains no spikes in all segments.
Returns
-------
Expand All @@ -389,16 +389,12 @@ def remove_empty_units(self):
return self.select_units(non_empty_units)

def get_non_empty_unit_ids(self):
non_empty_units = []
for segment_index in range(self.get_num_segments()):
for unit in self.get_unit_ids():
if len(self.get_unit_spike_train(unit, segment_index=segment_index)) > 0:
non_empty_units.append(unit)
non_empty_units = np.unique(non_empty_units)
return non_empty_units
num_spikes_per_unit = self.count_num_spikes_per_unit()

return np.array([unit_id for unit_id in self.unit_ids if num_spikes_per_unit[unit_id] != 0])

def get_empty_unit_ids(self):
unit_ids = self.get_unit_ids()
unit_ids = self.unit_ids
empty_units = unit_ids[~np.isin(unit_ids, self.get_non_empty_unit_ids())]
return empty_units

Expand Down

0 comments on commit 960781c

Please sign in to comment.