Example #1
0
 def run(self):
     h = open(self.fn, "w")
     try:
         source_state = [SourceReadingState(src) for src in self.sources]
         if self.cb is not None:
             status_all = 0
             for src in source_state:
                 status_all += len(src.xdata)
             status_cur = 0
         heapq.heapify(source_state)
         ann_lst = copy.copy(self.annotations)
         ann_lst.sort(cmp=lambda (name1, start1, end1), (name2, start2, end2): cmp(start1, start2))
         # ann_state keeps all active annotations with the timestamp when they end
         ann_state = dict()
         while len(source_state) > 0:
             # Fetch the next data point from the sources
             ak = source_state[0].pop()
             # If the active source doesn't have any data points, drop it from the queue
             # and start anew
             if ak is None:
                 heapq.heappop(source_state)
                 continue
             # Check for annotations that have expired
             while len(ann_lst) > 0 and ann_lst[0][2] < ak[0]:
                 # key = ann_lst[0][0]
                 # if key in ann_state:
                 #    del ann_state[key]
                 del ann_lst[0]
             for k, i in ann_state.items():
                 if i < ak[0]:
                     del ann_state[k]
             # Check for annotations that have become active
             while len(ann_lst) > 0 and ann_lst[0][1] < ak[0]:
                 ann_state[ann_lst[0][0]] = ann_lst[0][2]
                 del ann_lst[0]
             cur_date = _from_ordinalf(ak[0], tz.tzutc())
             h.write(str(calendar.timegm(cur_date.utctimetuple())))
             h.write(cur_date.strftime(".%f"))
             h.write("\t")
             h.write(",".join(ann_state.keys()))
             h.write("\t")
             h.write(source_state[0].name)
             h.write("\t")
             if ak[1].__class__ == numpy.ndarray:
                 for v in ak[1]:
                     h.write(str(v))
                     h.write(" ")
             else:
                 h.write(str(ak[1]))
             h.write("\n")
             heapq.heapreplace(source_state, source_state[0])
             if self.cb is not None:
                 status_cur += 1
                 self.cb(float(status_cur) / status_all)
     finally:
         h.close()
     if self.end_cb is not None:
         self.end_cb()
Example #2
0
 def from_annpkg(handle,rootname,attrs):
     fn = attrs['file'].nodeValue
     name = attrs['name'].nodeValue
     chans = set([int(i) for i in attrs['channels'].nodeValue.split(',')])
     member = handle.getmember(fn)
     src = gst_numpy.PySrc(handle.extractfile(member),member.size)
     return AudioSource(fn,name,chans,
                        _from_ordinalf(float(attrs['offset'].nodeValue)),
                        src.el)
Example #3
0
 def put_files(self,handle):
     w = StringIO()
     for i in range(len(self.ydata)):
         stamp = _from_ordinalf(self.timedata[i])
         ms = str(stamp.microsecond)
         ms = "0"*(6-len(ms)) + ms
         
         print >>w,str(calendar.timegm(stamp.timetuple()))+"."+ms,self.ydata[i,0],self.ydata[i,1],self.ydata[i,2]
         #print >>w,str(self.timedata[i]),self.ydata[i,0],self.ydata[i,1],self.ydata[i,2]
     buf = w.getvalue()
     inf = tarfile.TarInfo(self.fn)
     inf.size = len(buf)
     handle.addfile(inf,StringIO(buf))