`plot_isi_distribution` adds the per-segment densities with several segments

Aperta Adatta ai principianti
#5,008 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
83/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
matplotlib, numpy, python

Direzione di ricerca

Inizia da widgets/isi_distribution.py e ispeziona il ciclo che calcola e combina l’istogramma di ogni segmento. L’issue suggerisce di sommare i conteggi con density=False e normalizzare una sola volta dopo il ciclo; usa i due esempi forniti per verificare che l’area totale sia 1 e che un segmento con un solo picco produca barre finite. Chi ha segnalato il problema si offre di aggiungere un test, ma non viene indicato alcun file di test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I found this while reading widgets/isi_distribution.py, not in my own analyses, so this is a "for the sake of improvement" report.

With several segments, the histogram of each segment is computed with density=True and the densities are added (there is a TODO about this in the loop). The area is then the number of segments, and a segment with 10 spikes weighs as much as one with 5000, without an error. If one segment has a single spike, all the bars of the unit are NaN.

import matplotlib

matplotlib.use("Agg")
import numpy as np
from spikeinterface.core import NumpySorting
from spikeinterface.widgets import plot_isi_distribution

rng = np.random.default_rng(0)
seg0 = np.cumsum(rng.integers(150, 600, 5000))  # 5000 spikes, ISI 5-20 ms
seg1 = np.cumsum(rng.integers(2100, 2700, 10))  # 10 spikes, ISI 70-90 ms
sorting = NumpySorting.from_unit_dict([{0: seg0}, {0: seg1}], sampling_frequency=30000.0)

w = plot_isi_distribution(sorting, window_ms=100.0, bin_ms=1.0)
heights = np.array([bar.get_height() for bar in w.axes.flatten()[0].patches])
print("area:", heights.sum() * 1.0)
# area: 2.0  expected 1.0
print("fraction of ISI in 70-90 ms:", heights[70:90].sum() / heights.sum())
# fraction of ISI in 70-90 ms: 0.5  expected about 0.002 (9 of 5008 intervals)

sorting = NumpySorting.from_unit_dict([{0: seg0}, {0: seg1[:1]}], sampling_frequency=30000.0)
w = plot_isi_distribution(sorting, window_ms=100.0, bin_ms=1.0)
heights = np.array([bar.get_height() for bar in w.axes.flatten()[0].patches])
print("finite bars:", np.isfinite(heights).sum(), "of", heights.size)
# finite bars: 0 of 99  expected 99 of 99

Fix: add the counts of all segments with density=False and normalize once after the loop.

I can open a PR with a test if you agree.

Lingua principale
Python
Stelle
883
Fork
291
Merge medio
3g 17h
PR unite (30g)
40

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SpikeInterface/spikeinterface

Tutte le issue di SpikeInterface/spikeinterface

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.