Skip to content

Commit c51390b

Browse files
committed
Add spike_ampltiudes to units table
1 parent bdb545e commit c51390b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/npc_ephys/spikeinterface.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ def decoder_label(self, probe: str) -> npt.NDArray[np.str_]:
447447
)
448448

449449
@functools.cache
450-
def spike_amplitudes(self, probe: str) -> npt.NDArray[np.floating]:
451-
return np.load(
450+
def spike_amplitudes(self, probe: str) -> tuple[npt.NDArray[np.floating], ...]:
451+
"""array of amplitudes for each unit in order of unique('unit_indexes')"""
452+
spike_amplitudes = np.load(
452453
io.BytesIO(
453454
self.get_correct_path(
454455
self.postprocessed(probe),
@@ -457,7 +458,14 @@ def spike_amplitudes(self, probe: str) -> npt.NDArray[np.floating]:
457458
).read_bytes()
458459
)
459460
)
460-
461+
unit_indexes = self.unit_indexes(probe)
462+
spike_amplitudes_by_unit: list[npt.NDArray[np.floating]] = []
463+
for index in sorted(np.unique(unit_indexes)):
464+
spike_amplitudes_by_unit.append(
465+
spike_amplitudes[np.where(unit_indexes == index)[0]]
466+
)
467+
return tuple(spike_amplitudes_by_unit)
468+
461469
@functools.cache
462470
def unit_locations(self, probe: str) -> npt.NDArray[np.floating]:
463471
return np.load(

src/npc_ephys/units.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def _device_helper(
224224
[len(unit) for unit in units_x_spike_times],
225225
), "Mismatch between rows in spike_times and metrics.csv"
226226
df_device_metrics["spike_times"] = units_x_spike_times
227+
df_device_metrics["spike_amplitudes"] = spike_interface_data.spike_amplitudes(electrode_group_name)
228+
assert all(len(df_device_metrics["spike_amplitudes"][i]) == len(spike_times) for i, spike_times in enumerate(units_x_spike_times)), "Mismatch between spike_times and spike_amplitudes"
227229

228230
return df_device_metrics
229231

0 commit comments

Comments
 (0)