Handle all-NaN channels in calc_adc_params
Personne n'a encore pris cette issue.
- Langage dominant
- Jupyter Notebook
- Étoiles
- 853
- Forks
- 322
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
If all samples in a channel are NaN, calc_adc_params will fail:
>>> wfdb.wrsamp("xxx", fs=500, units=["mV"], sig_name=["I"], p_signal=numpy.array([[numpy.nan]]), fmt=["16"])
/home/bmoody/work/wfdb-python/wfdb/io/_signal.py:740: RuntimeWarning: All-NaN slice encountered
minvals = np.nanmin(self.p_signal, axis=0)
/home/bmoody/work/wfdb-python/wfdb/io/_signal.py:741: RuntimeWarning: All-NaN slice encountered
maxvals = np.nanmax(self.p_signal, axis=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bmoody/work/wfdb-python/wfdb/io/record.py", line 2943, in wrsamp
record.set_d_features(do_adc=1)
File "/home/bmoody/work/wfdb-python/wfdb/io/_signal.py", line 470, in set_d_features
self.adc_gain, self.baseline = self.calc_adc_params()
File "/home/bmoody/work/wfdb-python/wfdb/io/_signal.py", line 787, in calc_adc_params
baseline = int(np.floor(baseline))
ValueError: cannot convert float NaN to integer
A couple things are wrong here:
-
if pmin == np.nandoesn't do what you think. -
nanminandnanmaxwill give a RuntimeWarning if all samples in a channel are NaN.
(1) is easy to fix. (2) is a little weirder; have a look at the code of nanmin:
if type(a) is np.ndarray and a.dtype != np.object_:
# Fast, but not safe for subclasses of ndarray, or object arrays,
# which do not implement isnan (gh-9009), or fmin correctly (gh-8975)
res = np.fmin.reduce(a, axis=axis, out=out, **kwargs)
if np.isnan(res).any():
warnings.warn("All-NaN slice encountered", RuntimeWarning,
stacklevel=3)
In other words, for ordinary numeric numpy arrays, np.fmin.reduce gives what we want (minimum non-NaN value if there is one, otherwise NaN, and no warning.) It might not work if the array is something more exotic (e.g. a numpy-compatible array class created by some other python package.)
I think I understand the comment about object arrays (https://github.com/numpy/numpy/issues/8975, https://github.com/numpy/numpy/issues/9009), but I don't understand the "subclasses of ndarray" comment. When I try creating a trivial subclass of ndarray, fmin still appears to work as expected. So I don't see why the strict is np.ndarray is needed.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans wfdb/io/_signal.py, au niveau de calc_adc_params, et suivez la gestion de nanmin/nanmax utilisée par wfdb.wrsamp. Reproduisez l’exemple d’un canal contenant uniquement des valeurs NaN, puis vérifiez que les canaux contenant uniquement des valeurs NaN ne déclenchent plus d’avertissement et n’échouent plus, tandis que les canaux contenant des valeurs conservent leur comportement actuel.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- numpy, python
- Domaine
- data
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100