ncl[1].info.qrs.tag = tag classified.append(ncl) clist.remove(ncl) #Comparative classification while clist: c, nxt = clist.pop(0) tag = comparative_classification(nxt, classified) for b in nxt.beats: b.tag = tag #The cluster representant also is assigned the classification. nxt.info.qrs.tag = tag classified.append((c, nxt)) #Afib code is now changed to normality to fit the convention for _, (beats, _) in classified: for b in (b for b in beats if isinstance(b, o.QRS)): if b.tag == AFTAG: b.tag = C.NORMAL annots = interp2annots.interp2ann(interp) #We also include the clustered artifacts. for b in interp.get_observations( o.RDeflection, filt=lambda ba: any([ ba in cl.beats and any(isinstance(b, o.QRS) for b in cl.beats) for cl in clusters.values() ])): a = MIT.MITAnnotation.MITAnnotation() a.code = b.tag a.time = b.time.start annots.add(a) MIT.save_annotations(annots, '{0}.{1}'.format(args.r, args.o))
#The rhythm is assumed to be part of the afib. afib.end.cpy(nrhythm.end) interp.observations.remove(nrhythm) rpks = tmprpks else: break else: break else: break i += 1 anns = i2a.interp2ann(interp) for b in interp.get_observations(o.BeatAnn): a = MIT.MITAnnotation.MITAnnotation() a.code = MIT.ECGCodes.ARFCT a.time = b.time.start anns.add(a) #Now we select only rhythm annotations and we remove repeated annotations. anns = [a for a in anns if a.code == COD.RHYTHM] i = 1 while i < len(anns): if (anns[i].aux in (b'(N', b'(SVTA', b'(SBR', b'(AFIB', b'(T', b'(B', b'(VFL') and anns[i].aux == anns[i-1].aux): anns.pop(i) else: i += 1 MIT.save_annotations(anns, DB+rec+OANN) del interp print('All records successfully processed')