def challenge(record, alarm_type): """Evaluates the presence of a given alarm in a given record""" assert alarm_type in (ASYST, BRAD, TACH, VFLUT, VTACH), ('Unknown alarm type {0}'.format(alarm_type)) annots = MIT.read_annotations(INTERP_DIR + str(record) + '.igqrs') rec = None if alarm_type == VTACH: rec = MIT.load_MIT_record(DB_DIR + str(record)) rec.leads = [VALID_LEAD_NAMES[l] for l in rec.leads] return EVAL_ALARM_F[alarm_type](annots, rec)
metavar='ann', 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
#DB = '/home/tomas/Escritorio/afdb/' #DB = '/tmp/mit/' ANN = '.iqrs' #ANN = '.ibatr' OANN = '.rhy' RECORDS = [l.strip() for l in open(DB + 'RECORDS')] for rec in RECORDS: if os.path.isfile(DB+rec+OANN): print('Annotator "{0}" already exists. Skipping record {1}'.format( OANN, rec)) continue print('Converting record {0}'.format(rec)) anns = MIT.read_annotations(DB+rec+ANN) record = MIT.load_MIT_record(DB+rec) assert record.frequency == SAMPLING_FREQ record.leads = [VALID_LEAD_NAMES[l] for l in record.leads] interp = i2a.ann2interp(record, anns) afibs = list(interp.get_observations(o.Atrial_Fibrillation)) i = 0 while i < len(afibs): print('{0}/{1}'.format(i,len(afibs))) afib = afibs[i] beats = list(interp.get_observations(o.QRS, filt=lambda q, af=afib: af.earlystart <= q.time.start <= af.lateend)) rpks = np.array([qrs.time.start for qrs in beats]) #We obtain the shape representing the AFIB morphology as the qrs #matching the shape with more other qrss within the rhythm. ctr = collections.Counter() for qrs in beats: