def correct_bxc_bxd(): UNITS.set_sampling_freq(360.0) ANNOTS_DIR = ('/home/remoto/tomas.teijeiro/Escritorio/anots_dani/') 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 ] for rec in RECORDS: REF = ANNOTS_DIR + str(rec) + '.atr' TEST = ANNOTS_DIR + str(rec) + '.bxd' OUT = ANNOTS_DIR + str(rec) + '.bxD' ref = SortedList(MIT.read_annotations(REF)) test = MIT.read_annotations(TEST) for tann in test: dummy = MIT.MITAnnotation() dummy.time = int(tann.time - UNITS.msec2samples(150)) idx = ref.bisect_left(dummy) try: rann = next( a for a in ref[idx:] if MIT.is_qrs_annotation(a) and abs(a.time - tann.time) <= UNITS.msec2samples(150)) tann.code = rann.code except StopIteration: pass MIT.save_annotations(test, OUT) print('Record {0} processed'.format(rec)) print('The full database was successfully processed')
required=True, help=('Annotations resulting from the abductive ' 'interpretation of the ECG signal')) parser.add_argument('-c', metavar='cluster', required=True, help=('Extension of the file containing the clustering' ' information.')) parser.add_argument('-o', metavar='oann', default='cls', help=('Save annotations with classified QRS complexes' ' as annotator oann (default: cls)')) args = parser.parse_args() rec = MIT.load_MIT_record(args.r) set_sampling_freq(rec.frequency) print('Classifying record {0}'.format(args.r)) #Reconstruction of the abductive interpretation annots = MIT.read_annotations('{0}.{1}'.format(args.r, args.a)) interp = interp2annots.ann2interp(rec, annots) #Cluster information clusters = load_clustering(args.r, args.c, interp.observations) #QRS feature extraction features = get_features(interp) #Cluster feature extraction for c in clusters: clusters[c] = Cluster(clusters[c], get_cluster_features(clusters[c], features)) #Key function to compare clusters: First, we check clusters with more than #30 beats; then, the clusters with more REGULAR or AFIB beats, and finally #we sort by the number of beats in the cluster
ANNOTATOR = 'gqrs' 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] RECORDS = [l.strip() for l in open(DB_DIR + 'RECORDS')] 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)]
# pylint: disable-msg=E1101, E0102, E0202 """ Created on Wed May 06 12:54:17 2015 This module performs the full interpretation of every ECG record in the dataset from the BMI lab. @author: T. Teijeiro """ #Path setting import sys import os sys.path.append(os.getcwd()) from construe.utils.units_helper import (set_sampling_freq, msec2samples as ms2sp) set_sampling_freq(250.0) import construe.utils.MIT.MITAnnotation as MITAnnotation import construe.knowledge.base_evidence.energy as energy import construe.inference.reasoning as reasoning from construe.tests.record_processing import process_record from construe.model.interpretation import Interpretation import time import pprint #Searching settings KFACTOR = 12 #Length of the fragments where we will perform the interpretation. FR_LEN = 23040 #Storage management
@author: T. Teijeiro """ import numpy as np import construe.utils.MIT.MITAnnotation as MIT from construe.utils.units_helper import (samples2msec as sp2ms, msec2samples as ms2sp, set_sampling_freq) if __name__ == "__main__": ANNOTS_DIR = ('/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 ] set_sampling_freq(360.0) #Dictionary to save the discrepancy at record-level dist = {} miss = 0 for rec in RECORDS: dist[rec] = [] REF_FILE = ANNOTS_DIR + str(rec) + '.atr' TEST_FILE = ANNOTS_DIR + str(rec) + '.wbr' reference = np.array([ anot.time for anot in MIT.read_annotations(REF_FILE) if MIT.is_qrs_annotation(anot) ]) test = np.array([ anot.time for anot in MIT.read_annotations(TEST_FILE) if MIT.is_qrs_annotation(anot) ])
parser.add_argument('--show-warnings', action='store_true', help=('Shows warnings using the default python ' 'options. By default they are filtered.')) parser.add_argument('--no-merge', action='store_true', help=('Avoids the use of a branch-merging strategy for' ' interpretation exploration. If the selected ' 'abstraction level is "conduction", this ' 'parameter is ignored.')) args = parser.parse_args() if not args.show_warnings: warnings.simplefilter("ignore") #The first step is to set the global frequency and ADC gain variables that #determine the constant values in the knowledge base, which are initialized #in the first import of a construe knowledge module. 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)