コード例 #1
0
def wfdbAnnotation(e):
#=====================
  import wfdb
  mark = wfdb.annstr(int(e))
  ##  text = "Pacing on" if t < 100 else "Pacing off"   ########
  ##  chart.annotate(text, t, 0.0, textpos=(t, 1.05))
  if mark in "NLRBAaJSVrFejnE/fQ?":
    if mark == 'N': mark = u'\u2022'  # Unicode bullet
    return (mark, wfdb.anndesc(int(e)))
  return ('', '')
コード例 #2
0
ファイル: example3.py プロジェクト: crowdEEG/wfdb-swig
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()
コード例 #3
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)
コード例 #4
0
#         #append iteration number as value in
#         iteration.append(i);

##########        READ ANNOTATION ##################
if wfdb.annopen(rec_name, a, 1) < 0:
    print("cannot open aanopen")
    exit()

#getann reads next annotation and returns 0 when successful
while wfdb.getann(0, annot) == 0:
    if annot.time > num_value:
        #if annot.time>=start_val and annot.time<=end_val:
        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]));

#else:
#print("getann not working");
#exit();

#write signals to file

# f=open('/home/ubuntu/Documents/eclispe_workspace/test_one/my_first_pyproj/sig_file.txt','a');
# f.write("sig_time values: \t signal 0 values: \t signal 1 values: \n");
# for i in range(0,len(physig0)):
#     f.write(str(sig_time[i])+ "\t");
#     f.write(str(physig0[i]) + "\t");
#     f.write(str(physig1[i]) + "\n");
# # #f.write(str(ann_graph));
コード例 #5
0
ファイル: example9.py プロジェクト: crowdEEG/wfdb-swig
def main(argv):
    nbeats = stoptime = 0
    a = wfdb.WFDB_Anninfo()
    annot = wfdb.WFDB_Annotation()

    if len(argv) < 3:
        print "usage:", argv[0], "annotator record [beat-type from to]",
        sys.exit(1)    
    a.name = argv[1]
    a.stat = wfdb.WFDB_READ
    nsig = wfdb.isigopen(argv[2], None, 0)
    if nsig < 1: sys.exit(2)
    s = wfdb.WFDB_SiginfoArray(nsig)
    v = wfdb.WFDB_SampleArray(nsig)
    vb = wfdb.WFDB_SampleArray(nsig)
    sum = [None] * nsig
    if wfdb.wfdbinit(argv[2], a, 1, s.cast(), nsig) != nsig: sys.exit(3)
    hwindow = wfdb.strtim(".05")
    window = 2*hwindow + 1
    for i in range(nsig):
        sum[i] = [0] * window
    if len(argv) > 3:
        btype = wfdb.strann(argv[3])
    else:
        btype = wfdb.NORMAL
    if len(argv) > 4: wfdb.iannsettime(wfdb.strtim(argv[4]))
    if len(argv) > 5:
        stoptime = wdfb.strtim(argv[5])
        if stoptime < 0:
            stoptime = -stoptime
        if s[0].nsamp > 0 and stoptime > s[0].nsamp:
            stoptime = s[0].nsamp    
    else:
        stoptime = s[0].nsamp
    if stoptime > 0: stoptime -= hwindow

    while 1:
        if not (wfdb.getann(0, annot) == 0 and annot.time < hwindow): break 
    while 1:        
        if annot.anntyp == btype:
            wfdb.isigsettime(annot.time - hwindow - 1)
            wfdb.getvec(vb.cast())
            j=0
            while j < window and wfdb.getvec(v.cast()) > 0:
                for i in range(nsig):
                    sum[i][j] += v[i] - vb[i]
                j += 1
            nbeats += 1
        if not (wfdb.getann(0, annot) == 0 and \
           (stoptime == 0L or annot.time < stoptime)): break
    
    if nbeats < 1:
        print argv[0] + ": no `" + wfdb.annstr(btype) + "' beats found"
        sys.exit(4)

    print "Average of", nbeats, "`" + wfdb.annstr(btype) + "' beats:"
    for j in range(window):
        for i in range(nsig):
            print "%(av)g" % {'av': float(sum[i][j])/nbeats},
            sys.stdout.write("") # surpress next space
            if i < nsig-1:
                print "\t",
            else:
                print
    wfdb.wfdbquit()
コード例 #6
0
ファイル: rdann.py プロジェクト: crowdEEG/wfdb-swig
def main(argv):
    record = ''
    annotator = ''

    # parse the arguments
    try:
        opts, args = getopt.getopt(argv, "hr:a:", ["help"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt == '-r':
            record = arg
        elif opt == '-a':
            annotator = arg

    if len(record) == 0 or len(annotator) == 0:
        usage()
        sys.exit(2)
        
    # set the sampling frequency
    sps = wfdb.sampfreq(record)
    if sps < 0:
        sps = wfdb.WFDB_DEFFREQ
        wfdb.setsampfreq(sps)
            
    # get a new anninfo object
    ai = wfdb.WFDB_Anninfo()
    
    # set ai fields
    ai.name = annotator
    ai.stat = wfdb.WFDB_READ
    
    # open the annotation
    result = wfdb.annopen( record, ai, 1 )
    
    if result < 0:
        usage()
        sys.exit(2)
        
    # get a new annotation object
    annot = wfdb.WFDB_Annotation()
    
    while wfdb.getann(0, annot) == 0:

        # remove first char from aux string, if there is one
        if annot.aux is not None:
            aux = annot.aux[1:]
        else:
            aux = ""
                
        print "%s\t%d\t%s\t%d\t%d\t%d\t%s" % ( \
              wfdb.mstimstr(-annot.time), \
              annot.time, \
              wfdb.annstr(annot.anntyp),
              annot.subtyp,
              annot.chan, \
              annot.num, \
              aux)

    wfdb.wfdbquit()
コード例 #7
0
#         #append iteration number as value in 
#         iteration.append(i);
        
##########        READ ANNOTATION ##################
if wfdb.annopen(rec_name, a, 1) < 0: 
    print("cannot open aanopen");
    exit();
    
#getann reads next annotation and returns 0 when successful
while wfdb.getann(0,annot) ==0:
    if annot.time>num_value:
    #if annot.time>=start_val and annot.time<=end_val: 
        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]));
    
    
#else:
    #print("getann not working");
    #exit();

#write signals to file

# f=open('/home/ubuntu/Documents/eclispe_workspace/test_one/my_first_pyproj/sig_file.txt','a');
# f.write("sig_time values: \t signal 0 values: \t signal 1 values: \n");
# for i in range(0,len(physig0)):   
#     f.write(str(sig_time[i])+ "\t");
#     f.write(str(physig0[i]) + "\t");
#     f.write(str(physig1[i]) + "\n");
コード例 #8
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)