-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathconvert_ediagnostic_2_wfdb.py
60 lines (41 loc) · 1.42 KB
/
convert_ediagnostic_2_wfdb.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
50
51
52
53
54
55
56
57
# Read data from ediagnostic
from os import listdir, mkdir, system
from os.path import isfile, isdir, join, exists
import json
types = ['II', 'V1']
dataset = 'ediagnostic/'
patients = [f for f in listdir(dataset) if isdir(join(dataset, f))]
print patients
freq = '250'
#Create folder
wfdb_dir = dataset + 'wfdb'
#Create folder
if not exists(wfdb_dir):
mkdir(wfdb_dir)
for p in patients:
if p != 'wfdb':
# Read metadata
metadata_file = dataset + p + '/metadata.json'
data_file = open(metadata_file)
metadata = json.load(data_file)
window = {}
for v in metadata['ventanas']:
tipo = v['tipo']
window[str(tipo)] = v['inicioVentana']
print 'Derivation II: ', window['II'], ':', window['III'], ' V1: ', window['V1'], ':', window['V2']
# 1. Write the desired signal at individual .csv files
signal_file = dataset + p + '/' + p + '.txt'
signal_data = open(signal_file, 'r')
signal_data = signal_data.read()
signal_II = signal_data[window['II']:window['III']]
signal_II_file = dataset + p + '/' + p + '_II.csv'
file_II = open(signal_II_file, 'w')
file_II.write(signal_II)
file_II.close()
# 2. Write the signals and headers at WFDB format
wfdb_filename = wfdb_dir + '/' + p[:-3]
command = 'wrsamp -F ' + freq + ' -i ' + signal_II_file + ' -o ' + wfdb_filename
print(command)
system(command)
# Edit .hea file... metadata['edad'] ....
# header # <age>: 35 <sex>: M <diagnoses>: (none)