-
Notifications
You must be signed in to change notification settings - Fork 117
/
gettingData.py
49 lines (39 loc) · 1.51 KB
/
gettingData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def get_records():
""" Get paths for data in data/mit/ directory """
#Download if doesn't exist
# There are 3 files for each record
# *.atr is one of them
paths = glob('/path/to/MITDB/dataset/*.atr')
# Get rid of the extension
paths = [path[:-4] for path in paths]
paths.sort()
return paths
def beat_annotations(annotation):
""" Get rid of non-beat markers """
"""'N' for normal beats. Similarly we can give the input 'L' for left bundle branch block beats. 'R' for right bundle branch block
beats. 'A' for Atrial premature contraction. 'V' for ventricular premature contraction. '/' for paced beat. 'E' for Ventricular
escape beat."""
good = ['N']
ids = np.in1d(annotation.symbol, good)
# We want to know only the positions
beats = annotation.sample[ids]
return beats
def segmentation(records):
Normal = []
for e in records:
signals, fields = wfdb.rdsamp(e, channels = [0])
ann = wfdb.rdann(e, 'atr')
good = ['N']
ids = np.in1d(ann.symbol, good)
imp_beats = ann.sample[ids]
beats = (ann.sample)
for i in imp_beats:
beats = list(beats)
j = beats.index(i)
if(j!=0 and j!=(len(beats)-1)):
x = beats[j-1]
y = beats[j+1]
diff1 = abs(x - beats[j])//2
diff2 = abs(y - beats[j])//2
Normal.append(signals[beats[j] - diff1: beats[j] + diff2, 0])
return Normal