Blackrock sorting: spike frames are truncated, so ~2% of spikes land one sample early
Los mantenedores suelen responder en 2 días
@h-mayorquin ya está trabajando en esto.
Desde el 5/11/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
NeoSortingSegment.get_unit_spike_train turns Neo's spike times back into frames with
spike_frames = ((spike_times_seconds - t_start) * self._sampling_frequency).astype("int64")
(src/spikeinterface/extractors/neoextractors/neobaseextractor.py, line 647 on main). For Blackrock, Neo converts the integer .nev ticks to seconds, and this line converts them back. Float round-off leaves some products just under an integer, for example 30936 / 30000 * 30000 == 30935.999999999996, and astype truncates, so those spikes move one sample earlier.
Reproduce with blackrock/blackrock_2_1/l101210-001.nev from ephy_testing_data. Its timestamp resolution is 30 kHz, the same as sampling_frequency, so frames should equal ticks exactly:
import numpy as np
from spikeinterface.extractors import read_blackrock_sorting
sorting = read_blackrock_sorting(file_path="blackrock/blackrock_2_1/l101210-001.nev", sampling_frequency=30000.0)
neo = sorting.neo_reader
diffs, units_off = [], 0
for i, unit_id in enumerate(sorting.unit_ids):
ticks = neo.get_spike_timestamps(block_index=0, seg_index=0, spike_channel_index=i).astype(np.int64)
d = sorting.get_unit_spike_train(unit_id) - ticks
diffs.append(d)
units_off += bool(np.any(d))
d = np.concatenate(diffs)
values, counts = np.unique(d, return_counts=True)
print(f"spikes: {d.size}, frame - tick: { {int(v): int(c) for v, c in zip(values, counts)} }")
print(f"units with at least one shifted spike: {units_off} of {len(sorting.unit_ids)}")
spikes: 14210, frame - tick: {-1: 272, 0: 13938}
units with at least one shifted spike: 107 of 218
So 272 of 14,210 spikes (1.9%) come out one sample early, and none late. Over tick values 0 to 109,225, 2.3% truncate this way.
Affected readers: those with neo_returns_frames = False, which in 0.105.4 are Blackrock and MEArec. NeuroConv's BlackrockSortingInterface goes through this path, so NWB units tables written from .nev files carry the shift.
Suggested fix:
spike_frames = np.round((spike_times_seconds - t_start) * self._sampling_frequency).astype("int64")
With that change all 14,210 spikes match the .nev ticks exactly.
Environment: Windows 11, Python 3.12.13, spikeinterface 0.105.4 (the line is unchanged on main), neo 0.14.6, numpy 2.5.4.
I found this while checking a NeuroConv conversion against the raw files: https://github.com/JamesBelanger/blackrock-nwb-roundtrip (script: repro/si_spike_truncation.py).
- Lenguaje dominante
- Python
- Estrellas
- 883
- Forks
- 291
- Merge medio
- 3 d 17 h
- PR fusionados (30 d)
- 40
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de SpikeInterface/spikeinterface
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
SpikeInterface/spikeinterface#5008 ·
Los mantenedores suelen responder en 2 días
-
`plot_potential_merges` draws the correlograms of other units when a merge group is not sortedAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
SpikeInterface/spikeinterface#5007 ·
Los mantenedores suelen responder en 2 días
-
`plot_unit_presence` shows bin indices on the `Time (s)` axis when `time_range` is not givenAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
SpikeInterface/spikeinterface#5006 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
SpikeInterface/spikeinterface#5005 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
SpikeInterface/spikeinterface#5004 ·
Los mantenedores suelen responder en 2 días
Todos los issues de SpikeInterface/spikeinterface
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
daniel-ospina/tortoise#15308 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
difficulty:easy prio:low type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
NatronGitHub/Natron#2405 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Jstar269/nakagawa-recomp#3746 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día