Пример #1
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
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
Пример #3
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
    wfdb.sampfreq(argv[2])
    if wfdb.annopen(argv[2], a, 1) < 0:
        sys.exit(2)
    while wfdb.getann(0, annot) == 0:
        if annot.aux is not None:
            aux = annot.aux[1:]
        else:
            aux = ""
        print wfdb.timstr(-annot.time), "(" + str(annot.time) + ")", wfdb.annstr(
            annot.anntyp
        ), annot.subtyp, annot.chan, annot.num, aux
    wfdb.wfdbquit()
Пример #4
0
def main(argv):
    if len(argv) < 2:
        print "usage:", argv[0], "record"
        sys.exit(1)
    nsig = wfdb.isigopen(argv[1], None, 0)
    if nsig < 1: sys.exit(2)
    s = wfdb.WFDB_SiginfoArray(nsig)
    if wfdb.isigopen(argv[1], s.cast(), nsig) != nsig: sys.exit(2)
    print "Record", argv[1]
    print "Starting time:", wfdb.timstr(0)
    print "Sampling frequency: %(sf)g Hz" % {'sf': wfdb.sampfreq(argv[1])}
    print nsig, "signals"
    for i in range(0,nsig):
        print "Group %(g)d, Signal %(s)d:" % {'g': s[i].group, 's': i }
        print " File:", s[i].fname
        print " Description:", s[i].desc
        print " Gain:",
        if s[i].gain == 0.:
            print "uncalibrated; assume", wfdb.WFDB_DEFGAIN,
        else:
            print "%(gain)g" % {'gain': s[i].gain},
        if s[i].units is not None:
            print "adu/" + s[i].units
        else:
            print "adu/mV"
        print " Initial value:", s[i].initval
        print " Storage format:", s[i].fmt
        print " I/O:",
        if s[i].bsize == 0:
            print "can be unbuffered"
        else:
            print str(s[i].bsize) + "-byte blocks"
        print " ADC resolution:", s[i].adcres, "bits"
        print " ADC zero:", s[i].adczero
        if s[i].nsamp > 0:
            print " Length:", wfdb.timstr(s[i].nsamp), \
                  "(" + str(s[i].nsamp) + " sample intervals)"
            print " Checksum:", s[i].cksum
        else:
            print " Length undefined"
    wfdb.wfdbquit()
Пример #5
0
def setupWfdb(rec_name, annotator ):
    nsig = openWfdbSignal(rec_name);
    
    #Allocate memory for sig info array
    #we can use siarray to access WFDB_Siginfo structure
    siarray = wfdb.WFDB_SiginfoArray(nsig);
    
    #Allocate memory for data
    sdata = wfdb.WFDB_SampleArray(nsig);
    
    #Open WFDB record
    wfdb.isigopen(rec_name, siarray.cast(), nsig);
    
    
    #read annotations from file
    #WFDB_Anninfor() contains name and attributes of annotator .atr etc
    a = wfdb.WFDB_Anninfo();
    
    #WFDB_Annotation describes the attributes of signals 
    #declare object in c : WFDB_Annotation annot; see below for declaring object in python
    annot = wfdb.WFDB_Annotation();
    
    #read name and status of annotation file
    #a.name="atr";
    #a.name="ecg";
    #a.name="output_annotator"
    a.name=annotator;
    a.stat = wfdb.WFDB_READ;
    
    freq=wfdb.sampfreq(rec_name);
    nsamp=siarray[0].nsamp;
    print ("sampling frequency is: " + str(freq))
    init_time=wfdb.timstr(0);
    #print("strtim for starting value is: " + str(wfdb.strtim(init_time)));
    
    ##comment june 16
    ###### print signal specification #####
    record_info=wfdb.getinfo(rec_name)
    #print("getinfor is " + str(record_info));

    # print("total num of samples: " + str(nsamp));
    # print "Starting time of record is: "+ str(init_time);
    # print("sampling frequency is:"+ str(freq));      
    ########## READ ANNOTATION ##################
    if wfdb.annopen(rec_name, a, 1) < 0: 
        print("cannot open aanopen");
        exit();
    
    return (nsamp, freq, annot, init_time,sdata);
Пример #6
0
def get_ecg_signal(rec_name, annotation, start_time, end_time):
    #variables and arrays

    iteration = []
    sig_time = []
    #count=0;
    #ann_graph=[];
    #split_time0=[];
    #annotator_array=[];

    nsamp, freq, annot, init_time, sdata = ws.setupWfdb(rec_name, annotation)

    sig0 = []
    sig1 = []

    #physig0 is array with physical units
    physig0 = []
    physig1 = []

    print type(init_time)
    #print("strtim for starting value is: " + str(wfdb.strtim(init_time)));

    #print("total num of samples: " + str(nsamp));
    #print "Starting time of record is: "+ str(init_time);
    #print("sampling frequency is:"+ str(freq));

    #sample interval

    #required length of signal in seconds
    #num_sample_start=start_time*60*freq
    num_sample_end = end_time * 60 * freq
    loop_iteration = int(math.floor(num_sample_end))

    #print("loop iteration = " +str(loop_iteration));

    # loop runs for loop_iteration times to extract signal samples

    num_value = loop_iteration

    for i in range(0, num_value):
        if wfdb.getvec(sdata.cast()) < 0:
            print "ERROR: getvec() < 0"
            exit()
        else:
            #signal values in adu units:
            sig0.append(sdata[0])
            sig1.append(sdata[1])

            sig_time.append(gettime(i, freq, init_time))
            #print("time for sample " + str(i) + "is: " + str(sig_time[i]));
            #convert adu units to physical units and save in physig0 and 1 (later generalise it for n number of signals)
            physig0.append(aduphys(0, sig0[i]))
            physig1.append(aduphys(1, sig1[i]))

            #append iteration number as value in
            iteration.append(i)

    #getann reads next annotation and returns 0 when successful
    while wfdb.getann(0, annot) == 0:
        if annot.time > num_value:
            #print("annot.time>number of samples extracted");
            break
        #  annot.time is time of the annotation, in samples from the beginning of the record.
        print wfdb.timstr(-annot.time), "(" + str(
            annot.time) + ")", wfdb.annstr(
                annot.anntyp), annot.subtyp, annot.chan, annot.num
        print("signal value at this annotation is : " +
              str(physig0[annot.time]) + " " + str(sig_time[annot.time]))

    return (physig0, physig1, sig_time)
Пример #7
0
#read annotations from file
#WFDB_Anninfor() contains name and attributes of annotator .atr etc
a = wfdb.WFDB_Anninfo()

#WFDB_Annotation describes the attributes of signals
#declare object in c : WFDB_Annotation annot; see below for declaring object in python
annot = wfdb.WFDB_Annotation()
#read name and status of annotation file

a.name = annotation
print a.name
a.stat = wfdb.WFDB_READ
freq = wfdb.sampfreq(rec_name)
nsamp = siarray[0].nsamp
init_time = wfdb.timstr(0)
print type(init_time)
print("strtim for starting value is: " + str(wfdb.strtim(init_time)))

print("total num of samples: " + str(nsamp))
print "Starting time of record is: " + str(init_time)
print("sampling frequency is:" + str(freq))


def gettime(sample_num, freq, init_time):
    return float(sample_num) / float(freq)


#sample interval

#required length of signal in seconds
#read annotations from file
#WFDB_Anninfor() contains name and attributes of annotator .atr etc
a = wfdb.WFDB_Anninfo();

#WFDB_Annotation describes the attributes of signals 
#declare object in c : WFDB_Annotation annot; see below for declaring object in python
annot = wfdb.WFDB_Annotation();
#read name and status of annotation file

a.name=annotation;
print a.name
a.stat = wfdb.WFDB_READ;
freq=wfdb.sampfreq(rec_name);
nsamp=siarray[0].nsamp;
init_time=wfdb.timstr(0);
print type(init_time);
print("strtim for starting value is: " + str(wfdb.strtim(init_time)));

print("total num of samples: " + str(nsamp));
print "Starting time of record is: "+ str(init_time);
print("sampling frequency is:"+ str(freq));


def gettime(sample_num, freq, init_time):
    return float(sample_num)/float(freq)

#sample interval

#required length of signal in seconds
siglength_sec=1;
Пример #9
0
def get_ecg_signal(rec_name,annotation,start_time,end_time):
    #variables and arrays 
    
    iteration=[];
    sig_time=[];
    #count=0;
    #ann_graph=[];
    #split_time0=[];
    #annotator_array=[];
    
    
    nsamp, freq, annot, init_time,sdata = ws.setupWfdb(rec_name,annotation);
  
    sig0 = [];
    sig1 = [];
    
    #physig0 is array with physical units
    physig0=[];
    physig1=[];
    
    print type(init_time);
    #print("strtim for starting value is: " + str(wfdb.strtim(init_time)));
    
    #print("total num of samples: " + str(nsamp));
    #print "Starting time of record is: "+ str(init_time);
    #print("sampling frequency is:"+ str(freq));
    

    #sample interval
    
    #required length of signal in seconds
    #num_sample_start=start_time*60*freq
    num_sample_end=end_time*60*freq
    loop_iteration=int(math.floor(num_sample_end));
    
    #print("loop iteration = " +str(loop_iteration));
    
    
    # loop runs for loop_iteration times to extract signal samples
    
    num_value=loop_iteration;
    
    for i in range(0,num_value):
        if wfdb.getvec(sdata.cast()) < 0:
            print "ERROR: getvec() < 0";
            exit();
        else:
            #signal values in adu units:
            sig0.append(sdata[0]);
            sig1.append(sdata[1]);
            
            sig_time.append(gettime(i, freq, init_time));
            #print("time for sample " + str(i) + "is: " + str(sig_time[i]));
            #convert adu units to physical units and save in physig0 and 1 (later generalise it for n number of signals)
            physig0.append(aduphys(0,sig0[i]));
            physig1.append(aduphys(1,sig1[i]));
           
            #append iteration number as value in 
            iteration.append(i);
            
        
    #getann reads next annotation and returns 0 when successful
    while wfdb.getann(0,annot) ==0:
        if annot.time>num_value:
            #print("annot.time>number of samples extracted");
            break;
        #  annot.time is time of the annotation, in samples from the beginning of the record.
        print wfdb.timstr(-annot.time),"(" + str(annot.time)+ ")",wfdb.annstr(annot.anntyp), annot.subtyp,annot.chan, annot.num
        print ("signal value at this annotation is : " + str(physig0[annot.time])+" "+ str(sig_time[annot.time]));
    
    
    return(physig0,physig1,sig_time)