MIT-LCP / MIT-LCP/wfdb-python

Correct sampto behaviour using rdsamp and rdann?

Ouverte
#470 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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

When reading the signal with rdsamp and the corresponding annotations with rdann using the same sampto value results in an IndexError when accessing the signal array it includes an annotation outside the array.

In the example below, to read the first 100 entries, sampto must be 100. If using the same value for the annotations up to and including 100 are read, rather than stopping at 99 (i.e., the 100th entry in a 0-indexed array).

Is this the expected behaviour?

Using: python 3.9.18 with wfdb 4.1.2

import numpy as np
import wfdb

# create test data
n = 250
test_sig = np.zeros((n, 1))
test_sig[:, 0] = np.linspace(0, 1, n)
print(f'original shape: {test_sig.shape}')

# write to file
wfdb.wrsamp('test', fs = 250, units=['mV'], sig_name=['test'], p_signal=test_sig, fmt=['16'])

# create annotation and write
wfdb.Annotation(
    record_name='test', 
    extension='atr',
    sample=np.array([0, 99, 100, 249]), 
    symbol=['N', 'N', 'N', 'N']
).wrann()

samp_from = 0
samp_to = 100

# read values
values, _ = wfdb.rdsamp('test', sampfrom=samp_from, sampto=samp_to)
print(f'sampto shape: {values.shape}')


atr_1 = wfdb.rdann('test', extension='atr', sampfrom=samp_from, sampto=samp_to, shift_samps=True)
print(f'samples: {atr_1.sample}')
# IndexError
# print(f'values at samples: {values[atr_1.sample, :]}')

samp_to_minus_1 = samp_to - 1
atr_2 = wfdb.rdann('test', extension='atr', sampfrom=samp_from, sampto=samp_to_minus_1, shift_samps=True)
print(f'samples: {atr_2.sample}')
# No IndexError
# print(f'values at samples: {values[atr_2.sample, :]}')

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter la reproduction Python fournie avec wfdb.rdsamp et wfdb.rdann, en utilisant la même valeur de sampto et l’échantillon à l’index 100. Suivez la manière dont chaque point d’entrée gère la limite supérieure ; c’est terminé lorsque la sémantique des plages est cohérente et que l’indexation des annotations renvoyées ne lève pas d’IndexError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
backend-api-design
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.