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 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()
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);
def main(argv): an = wfdb.WFDB_AnninfoArray(2) annot = wfdb.WFDB_Annotation() if len(argv) < 2: print "usage:", argv[0], "record" sys.exit(1) a = an[0] a.name = "atr" a.stat = wfdb.WFDB_READ an[0] = a a = an[1] a.name = "aha" a.stat = wfdb.WFDB_AHA_WRITE an[1] = a if wfdb.annopen(argv[1], an.cast(), 2) < 0: sys.exit(2) while 1: if not (wfdb.getann(0, annot) == 0 and wfdb.putann(0,annot) == 0): break wfdb.wfdbquit()
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()
# end_sec=5*60 # start_val=int(math.floor(start_sec*freq)); # end_val=int(math.floor(end_sec*freq)); # #loop_iteration=int(math.floor(siglength_sec*freq)); # for i in range(start_val,end_val): # # #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])); # wfdb.timstr(-annot.time),"(" + str(annot.time)+ ")",wfdb.annstr(annot.anntyp), annot.subtyp,annot.chan, annot.num # #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:
def main(argv): # First get a wrapper object to C array of Anninfo structures. an = wfdb.WFDB_AnninfoArray(2) # In early versions of the wrapper this would have also allocated # the WFDB_Anninfo C-structures in the array. As of SWIG v2.0.8 # it appears that only the array is allocated, not the Anninfo # structures within. # Get a wrapper object for an annotation structure annot = wfdb.WFDB_Annotation() # Check to see if there is command line argument if len(argv) < 2: # no command line argument, so print usage and exit print "usage:", argv[0], "record" sys.exit(1) record = argv[1] # the record name is the first argument # Now we're going to setup the Anninfo structures so we can call # annopen later # First get a new Anninfo structure. a = wfdb.WFDB_Anninfo() # In the early version this line was: # a = an[0] # because calling wfdb.AnninfoArray(2), previously allocated # each Anninfo info the the array as well. Now we need to explicitly # allocate a new Anninfo struct instead of getting one from the # AnninfoArray "an" # now assign the values of a a.name = "atr" a.stat = wfdb.WFDB_READ # finally assign the anninfo struct, "a", to its place in the # array "an" an[0] = a # repeat for output annotation a = wfdb.WFDB_Anninfo() a.name = "aha" a.stat = wfdb.WFDB_AHA_WRITE an[1] = a # We call annopen with the record name, given on the command line, # and the AnninfoArray, "an", we just setup. if wfdb.annopen(record, an, 2) < 0: sys.exit(2) # note that in previous versions, it was necessary to use 'an.cast()', # rather then simply 'an', when passing an AnninfoArray to a wfdb # functoin. Now the wrappers no longer require the 'cast()' in most # cases. # now iterate until all annotations have been ready while 1: # read an annotation from the input annotator and put it into # the output, AHA formatted, annotator if not (wfdb.getann(0, annot) == 0 and wfdb.putann(0,annot) == 0): break wfdb.wfdbquit()
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()
# end_sec=5*60 # start_val=int(math.floor(start_sec*freq)); # end_val=int(math.floor(end_sec*freq)); # #loop_iteration=int(math.floor(siglength_sec*freq)); # for i in range(start_val,end_val): # # #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])); # wfdb.timstr(-annot.time),"(" + str(annot.time)+ ")",wfdb.annstr(annot.anntyp), annot.subtyp,annot.chan, annot.num # #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: