Esempio n. 1
0
series = {}
for record in RECORDS:
    rec = DB_DIR + str(record)
    mitr = load_MIT_record(rec)
    set_sampling_freq(mitr.frequency)
    slen = len(mitr.signal[0])
    wlen = int(ms2sp(30 * 60 * 1000))
    leads = get_leads(rec)
    tmpann = 'tmp'
    annotators = []
    for lead in leads:
        command = ['gqrs', '-r', rec, '-outputName', tmpann, '-s', lead]
        subprocess.check_call(command)
        annpath = rec + '.' + tmpann
        annotators.append(read_annotations(annpath)[1:])
        os.remove(annpath)
    series[record] = np.array([[a.num for a in ann] for ann in annotators])
    for i in range(len(leads)):
        series[record][i] = series[record][i] / np.mean(series[record][i])
    #bestann = annotators[best_quality_lead(mitr)]
    annots = []
    i = 0
    while i < slen:
        wannots = truncate_annotators(annotators, i, i + wlen)
        bestann = best_quality_annotator(wannots, i)
        annots.extend(
            improve_annotations(bestann,
                                [ann
                                 for ann in wannots if ann is not bestann]))
        i += wlen
Esempio n. 2
0
 set_ADCGain(get_gain(args.r))
 set_sampling_freq(get_sampling_frequency(args.r))
 #The initial evidence is now obtained
 if args.a is None:
     #A temporary annotations file with the 'gqrs' application is created,
     #loaded and immediately removed. We ensure that no collisions occur
     #with other annotators.
     aname = 0
     gqname = 'gq{0:02d}'
     rname, ext = os.path.splitext(args.r)
     while os.path.exists(rname + '.' + gqname.format(aname)):
         aname += 1
     command = ['gqrs', '-r', rname, '-outputName', gqname.format(aname)]
     subprocess.check_call(command)
     annpath = rname + '.' + gqname.format(aname)
     annots = read_annotations(annpath)
     os.remove(annpath)
 else:
     rname, ext = os.path.splitext(args.r)
     annots = read_annotations(rname + '.' + args.a)
 t0 = time.time()
 #Conduction or rhythm interpretation
 if args.level == 'conduction':
     from record_processing import process_record_conduction
     length = 512000 if args.l == 0 else args.l
     result = process_record_conduction(rname, annots, length, args.f,
                                        args.t, args.exclude_pwaves,
                                        args.exclude_twaves, args.v)
 else:
     from record_processing import process_record_rhythm
     #Merge strategy
Esempio n. 3
0
DB = '/tmp/mit/'
RECORDS = [
    100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 111, 112, 113, 114, 115,
    116, 117, 118, 119, 121, 122, 123, 124, 200, 201, 202, 203, 205, 207, 208,
    209, 210, 212, 213, 214, 215, 217, 219, 220, 221, 222, 223, 228, 230, 231,
    232, 233, 234
]

flut = collections.defaultdict(list)

plt.ioff()
for record in RECORDS:
    rpath = DB + str(record)
    try:
        annots = iter(read_annotations(rpath + '.wbr'))
    except IOError:
        continue
    rec = load_MIT_record(rpath)
    while True:
        try:
            vfon = next(a for a in annots if a.code == ECGCodes.VFON)
            vfoff = next(a for a in annots if a.code == ECGCodes.VFOFF)
            flut[record].append(rec.signal[:, vfon.time:vfoff.time + 1])
        except StopIteration:
            break
    for i in range(len(flut[record])):
        fl = flut[record][i]
        for l in (0, 1):
            isvf = _is_VF(fl[l])
            #FIXME this command only works if the _is_VF function internally
Esempio n. 4
0
        sg = np.sign(np.diff(sigfr))
        idx = len(sg) - 1
        while idx >= 0 and sg[idx] == sg[-1]:
            idx -= 1
        pts.append(idx + 1)
    ann.time = beg + min(pts)


DB_DIR = '/tmp/mit/'
ORIG_ANNOTATOR = 'atr'
OUT_ANNOTATOR = 'batr'

RECORDS = [
    100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 111, 112, 113, 114, 115,
    116, 117, 118, 119, 121, 122, 123, 124, 200, 201, 202, 203, 205, 207, 208,
    209, 210, 212, 213, 214, 215, 217, 219, 220, 221, 222, 223, 228, 230, 231,
    232, 233, 234
]
#RECORDS = [101]

for record in RECORDS:
    rec = DB_DIR + str(record)
    mitr = load_MIT_record(rec)
    set_sampling_freq(mitr.frequency)
    slen = len(mitr.signal[0])
    annots = read_annotations(rec + '.' + ORIG_ANNOTATOR)
    for ann in (a for a in annots if is_qrs_annotation(a)):
        move_to_qrs_onset(ann, mitr)
    save_annotations(annots, rec + '.' + OUT_ANNOTATOR)
    print('Record {0} processed.'.format(record))