clean_flatlines fails with AttributeError on a dataset loaded with an empty etc

Aperta Adatta ai principianti
#533 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia da update_clean_channel_mask in eegprep/plugins/clean_rawdata/private/channel_removal.py, dove il traceback raggiunge etc.get, e segui come pop_loadset rappresenta un etc vuoto. Confrontalo con la normalizzazione suggerita nell’issue. Il lavoro è terminato quando clean_flatlines gestisce il dataset riprodotto quando rimuove un canale piatto; riesegui la riproduzione fornita per verificarlo.

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

Descrizione

clean_flatlines raises AttributeError when it removes a channel from a dataset that pop_loadset returned with an empty etc, so a plain save and load of a dataset whose etc is empty breaks it.

Reproduction

eegprep 0.5.0, Python 3.12:

import numpy as np
from eegprep import clean_flatlines, eeg_checkset, eeg_emptyset, pop_loadset, pop_saveset

eeg = eeg_emptyset()  # eeg["etc"] is {}
data = np.random.default_rng(0).standard_normal((4, 2500)).astype("float32")
data[3, 100:] = 0  # channel 4 is flat
eeg.update(data=data, nbchan=4, pnts=2500, trials=1, srate=250.0, xmin=0.0, xmax=9.996, chanlocs=[{"labels": f"C{i}"} for i in range(4)])
pop_saveset(eeg_checkset(eeg), "t.set")
loaded = pop_loadset("t.set")
print(type(loaded["etc"]), loaded["etc"].shape)  # <class 'numpy.ndarray'> (0, 0)
clean_flatlines(loaded)  # AttributeError: 'numpy.ndarray' object has no attribute 'get'

Traceback ends in eegprep/plugins/clean_rawdata/private/channel_removal.py, update_clean_channel_mask, at mask = etc.get("clean_channel_mask").

Cause

pop_saveset writes an empty etc as an empty matrix, and pop_loadset reads it back as a numpy.ndarray of shape (0, 0). update_clean_channel_mask then does etc = EEG.setdefault("etc", {}), which returns the existing array because the key is present, and calls .get on it. The call is reached only when a channel is actually removed, so a dataset without flat channels passes. Setting loaded["etc"] = {} before the call avoids the error.

Suggested fix

Treat an etc that is not a dict as empty where etc is used as a dict (for example if not isinstance(etc, dict): etc = {}; EEG["etc"] = etc in update_clean_channel_mask), or normalise an empty etc to {} in pop_loadset.

Lingua principale
Python
Stelle
38
Fork
7
Merge medio
22h 11m
PR unite (30g)
65

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

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 sccn/eegprep

Tutte le issue di sccn/eegprep

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.