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