Esempio n. 1
0
def main(argv):
    a = wfdb.WFDB_Anninfo()
    annot = wfdb.WFDB_Annotation()
    if len(argv) < 3:
        print "usage:", argv[0], "annotator record"
        sys.exit(1)
    a.name = argv[1]
    a.stat = wfdb.WFDB_READ    
    if wfdb.annopen(argv[2], a, 1) < 0: sys.exit(2)
    rrmax = 3 * wfdb.sampfreq(argv[2])
    if rrmax <= 0: sys.exit(3)
    rrhist = [0] * int(rrmax+1)
    while 1:
        if not (wfdb.getann(0,annot) == 0 and not wfdb.wfdb_isqrs(annot.anntyp)): break
    t = annot.time
    while wfdb.getann(0, annot) == 0:
        if wfdb.wfdb_isqrs(annot.anntyp):
            rr = annot.time - t
            if rr > rrmax: rr = rrmax
            rrhist[rr] += 1
            t = annot.time
    for rr in range(1, int(rrmax)):
        print '%(rr)4d %(time)s' % {'rr': rrhist[rr], 'time': wfdb.mstimstr(rr)}
    rr += 1
    print '%(rr)4d %(time)s (or longer)' % {'rr': rrhist[rr], 'time': wfdb.mstimstr(rr)}
    wfdb.wfdbquit()
Esempio n. 2
0
def get_RR_interval(rec_name, annotation, start_time, end_time):
    #setup wfdb (change annotator here)
    rr_int = 0
    t = 0
    beats = 0
    sig_time = []

    #change annotations
    nsamp, freq, annot, init_time, sdata = ws.setupWfdb(rec_name, annotation)
    RR_sec_func = []
    #num_sample_end=38400; # this translates to 230339 annot time which means 30 mins of data ## check this
    num_sample_start = start_time * 60 * freq
    num_sample_end = end_time * 60 * freq
    ###### check if its the same record or new. if new , shift annot.time

    #         annot.time

    #getann reads next annotation and returns 0 when successful
    # annot.time is time of the annotation, in samples from the beginning of the record.
    #when getting samples for cross-validation and testing, just adjust annot.time so it starts reading samples from there

    t = annot.time
    ##comment june 16
    #print ("annot.time at the beginning is: " + str(annot.time))

    #annot_file=open('/home/ubuntu/Documents/eclispe_workspace/test_one/my_first_pyproj/research_March17/annot_type' +str(record)+'.txt','a');

    while wfdb.getann(0, annot) == 0:
        if annot.time > num_sample_start and annot.time < num_sample_end:
            #code for extracting time:
            time = wfdb.timstr(-annot.time)
            split_time = time.split(":")
            hr_time = split_time[0]
            minute_time = split_time[1]
            if len(split_time) > 2:
                sec_time = split_time[2]

            if wfdb.wfdb_isqrs(annot.anntyp):
                #             if same_as_prev[record] == 1 and int(hr_time) >= 1 and int(hr_time) < 23:
                #annot.time=annot.time + prev_annot_time;
                rr_int = annot.time - t
                beats = beats + 1
                rr_sec = rr_int / freq
                rr_sec_rounded = round(rr_sec, 3)

                ###############testing here############################

                ############################################

                RR_sec_func.append(rr_sec_rounded)
                # sampling intervals (e.g., if the original recording was sampled at 128 samples per second, then an
                t = annot.time
                #print ("annot.time after rr interval is: " + str(t))

                #print ("-annot.time after rr interval is: " +  wfdb.timstr(-annot.time))
                #print ("annot.time in if is: " + str(annot.time))
                #prev_annot_time.append(annot.time)

    #print ("beats = "+ str(beats))
    return RR_sec_func
Esempio n. 3
0
def main(argv):
    an = wfdb.WFDB_AnninfoArray(2)
    annot = wfdb.WFDB_Annotation()
    record = raw_input("Type record name: ")
    iann = raw_input("Type input annotatior name")
    oann = raw_input("Type output annotator name: ")
    
    a = wfdb.WFDB_Anninfo()
    a.name = iann
    a.stat = wfdb.WFDB_READ
    an[0] = a
    
    a = wfdb.WFDB_Anninfo()
    a.name = oann
    a.stat = wfdb.WFDB_WRITE
    an[1] = a
    
    if wfdb.annopen(record ,an , 2) < 0:  sys.exit(1)
    
    while wfdb.getann(0 , annot) ==0:
        if wfdb.wfdb_isqrs(annot.anntyp):
            annot.anntyp = wfdb.NORMAL
            if wfdb.putann(0 , annot)<0: break
    
    wfdb.wfdbquit()
def get_RR_interval(rec_name,annotation,start_time,end_time):
        #setup wfdb (change annotator here)
    rr_int=0;
    t=0;
    beats=0;
    sig_time=[];
    
    #change annotations
    nsamp, freq, annot, init_time = setupWfdb(rec_name,annotation);
    RR_sec_func=[];
    #num_sample=38400; # this translates to 230339 annot time which means 30 mins of data ## check this
    num_sample=end_time*60*freq
    ###### check if its the same record or new. if new , shift annot.time

#         annot.time
    
    #getann reads next annotation and returns 0 when successful
    # annot.time is time of the annotation, in samples from the beginning of the record.
    #when getting samples for cross-validation and testing, just adjust annot.time so it starts reading samples from there
    
    
    t = annot.time;
    ##comment june 16
    #print ("annot.time at the beginning is: " + str(annot.time))
    
    #annot_file=open('/home/ubuntu/Documents/eclispe_workspace/test_one/my_first_pyproj/research_March17/annot_type' +str(record)+'.txt','a');
    
    while wfdb.getann(0, annot) == 0 and annot.time<num_sample:
        #code for extracting time:
        time=wfdb.timstr(-annot.time)
        split_time=time.split(":")
        hr_time=split_time[0];
        minute_time=split_time[1];
        if len(split_time) >2:
            sec_time=split_time[2];
        

        if wfdb.wfdb_isqrs(annot.anntyp):
#             if same_as_prev[record] == 1 and int(hr_time) >= 1 and int(hr_time) < 23: 
                #annot.time=annot.time + prev_annot_time;
            rr_int = annot.time - t
            beats=beats+1;
            rr_sec=rr_int/freq
            rr_sec_rounded=round(rr_sec,3);
            RR_sec_func.append(rr_sec_rounded);
            # sampling intervals (e.g., if the original recording was sampled at 128 samples per second, then an 
            t = annot.time
            #print ("annot.time after rr interval is: " + str(t))
            
            #print ("-annot.time after rr interval is: " +  wfdb.timstr(-annot.time))
            #print ("annot.time in if is: " + str(annot.time))
            #prev_annot_time.append(annot.time)
    
    
    #print ("beats = "+ str(beats))
    return RR_sec_func