Пример #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()
Пример #2
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()
Пример #3
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);
Пример #4
0
  def _set_attributes(self):
  #-------------------------
    if self._siginfo is None: return
#    wfdbname = wfdb.wfdbfile(None, None)
#    recname = wfdbname[:-4] if wfdbname.endswith('.hea') else wfdbname
#    if   source.startswith('http://') or recname.startswith('ftp://'):
#      source = wfdbname
#    else:
#      recname = file_uri(recname)
#      source = file_uri(wfdbname)
#    if not uri: uri = recname
    ##logging.debug('rec: %s, source: %s', recname, source)

    self._framerate = wfdb.sampfreq(None)/wfdb.getspf()

    start = wfdb.mstimstr(0)
    if start[0] == '[':
      self.starttime = dateutil.parser.parse(start[1:-1], dayfirst=True)
    if self._siginfo[0].nsamp > 0:
      self.duration = self._siginfo[0].nsamp/float(self._framerate)

    ##duration = dateutil.parser.parse(wfdb.mstimstr(wfdb.strtim('e')))
    ##print duration   ## But has date...

    self._framesize = 0
    self.data_signals = [ ]
    self.annotation_signals = [ ]
    self._offsets = [ ]
    offset = 0
    for n in xrange(self._nsignals):
      if self._siginfo[n].desc != 'EDF Annotations':
        self.data_signals.append(n)
        self.add_signal(WFDBSignal(n, self,
         self._siginfo[n].units,
         metadata =
         { 'label': self._siginfo[n].desc,
           'rate': self._framerate*self._siginfo[n].spf,
         } ))
      else:
        self.annotation_signals.append(n)
      self._framesize += self._siginfo[n].spf
      self._offsets.append((offset, self._framesize))
      offset = self._framesize

    self._sigpoints = np.ones(self._framesize, 'bool')
    for n in xrange(self._nsignals):
      if n in self.annotation_signals:
        for i in xrange(*self._offsets[n]): self._sigpoints[i] = False
Пример #5
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()
Пример #6
0
def main(argv):

    time = maxslope = nslope = scmin = 0
    a = wfdb.WFDB_Anninfo()
    annot = wfdb.WFDB_Annotation()

    if len(argv) < 2:
        print "usage:", argv[0], "record [threshold]"
        sys.exit(1)
    
    a.name = "qrs"
    a.stat = wfdb.WFDB_WRITE

    nsig = wfdb.isigopen(argv[1], None, 0)
    if nsig < 1: sys.exit(2)
    s = wfdb.WFDB_SiginfoArray(nsig)
    v = wfdb.WFDB_SampleArray(nsig)
    if wfdb.wfdbinit(argv[1], a, 1, s.cast(), nsig) != nsig: sys.exit(2)
    if wfdb.sampfreq(None) < 240. or wfdb.sampfreq(None) > 260.:
	wfdb.setifreq(250.)
    if len(argv) > 2: scmin = wfdb.muvadu(0, argv[2])
    if scmin < 1: scmin = wfdb.muvadu(0, 1000)
    slopecrit = scmax = 10 * scmin
    ms160 = wfdb.strtim("0.16")
    ms200 = wfdb.strtim("0.2")
    s2 = wfdb.strtim("2")
    annot.subtyp = annot.chan = annot.num = 0
    annot.aux = None
    wfdb.getvec(v.cast())
    t9 = t8 = t7 = t6 = t5 = t4 = t3 = t2 = t1 = v[0]

    while 1:
        t0 = v[0]
        filter = t0 + 4*t1 + 6*t2 + 4*t3 + t4 - t5 - 4*t6 - 6*t7 - 4*t8 - t9
        if time % s2 == 0:
            if nslope == 0:
                slopecrit -= slopecrit >> 4
                if slopecrit < scmin: slopecrit = scmin
            elif nslope >= 5:
                slopecrit += slopecrit >> 4
                if slopecrit > scmax: slopecrit = scmax
        if nslope == 0 and abs(filter) > slopecrit: 
            nslope = 1
            maxtime = ms160
            if filter > 0:
                sign = 1
            else:
                sign = -1
            qtime = time
        if nslope != 0:
            if filter * sign < -slopecrit: 
                sign = -sign
                nslope = nslope + 1
                if nslope > 4:       
                    maxtime = ms200
                else:
                    maxtime = ms160
            elif filter * sign > slopecrit and \
                     abs(filter) > maxslope:
                maxslope = abs(filter)
            if maxtime < 0:
                if 2 <= nslope and nslope <= 4:
                    slopecrit += ((maxslope>>2) - slopecrit) >> 3
                    if slopecrit < scmin:
                        slopecrit = scmin
                    elif slopecrit > scmax:
                        slopecrit = scmax
                    annot.time = wfdb.strtim("i") - (time - qtime) - 4
                    annot.anntyp = wfdb.NORMAL
                    wfdb.putann(0, annot)
                    time = 0
                elif nslope >= 5: 
                    annot.time = wfdb.strtim("i") - (time - qtime) - 4
                    annot.anntyp = wfdb.ARFCT
                    wfdb.putann(0, annot)
                nslope = 0
            maxtime = maxtime - 1
        t9 = t8
        t8 = t7
        t7 = t6
        t6 = t5
        t5 = t4
        t4 = t3
        t3 = t2
        t2 = t1
        t1 = t0
        time = time + 1
        if not wfdb.getvec(v.cast()) > 0: break

    wfdb.wfdbquit()
Пример #7
0
def main(argv):
    db_path = "/opt/physiobank/database"
    record = ''
    wfdb.setwfdb(db_path)
    # Parse the arguments
    try:
        opts, args = getopt.getopt(argv, "hr:", ["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

    # Read the number of signals in the record
    nsig = wfdb.isigopen(record, None, 0)

    # Exit if the record is not found, or there are no signals
    if nsig < 1:
        usage()
        sys.exit(2)

    siarray = wfdb.WFDB_SiginfoArray(nsig)
    wfdb.isigopen(record, siarray, nsig)

    n = 0
    v = wfdb.intArray(nsig)
    lf = bf_math.intArray(siarray[0].nsamp)
    global sld_samp
    global ln
    global y_axes
    global sr_ds  
    global subplt
    sr = (int)(wfdb.sampfreq(record))
    print "sr:",sr
    sr_ds = 50
    # Loop over each sample and print the signal values.
    while wfdb.getvec(v) > 0:
        for i in range(0,1):
            lf[n] = v[i]
        n = n + 1
    bf_math.filtering(lf,siarray[0].nsamp,sr)
    _nsamp = siarray[0].nsamp
    
    x_axes = xrange(_nsamp*sr_ds/sr)
    print "x_axes:", _nsamp*sr_ds/sr
    y_axes = []
    for i in xrange(_nsamp):
         b, val = bf_math.down_sample(lf[i], sr, sr_ds)
         if (b):
             y_axes.append(val)
    print "y_axes:", len(y_axes)
    plt.figure(1)
    subplt = plt.subplot(111)
    ln, = plt.plot(xrange(0,5*sr_ds), y_axes[0:5*sr_ds] )
    #plt.axis([-100, 100])
    plt.ylim(-300,300)
    #subplt.autoscale_view(True,True,True)
    axcolor = 'lightgoldenrodyellow'
    axsamp = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
    sld_samp = Slider(axsamp, 'samp', 0.1, 33*60, valinit=1)

    sld_samp.on_changed(update)
    plt.show()    
    wfdb.wfdbquit()
Пример #8
0
physig0 = []
physig1 = []

#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
Пример #9
0
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()
physig0=[];
physig1=[];

#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