def iter_genomes(prof, outpath, gpaths): """ Walk a list of genome paths, yielding them in an order suitable for the `genomes` argument of `create_jobs()`. """ gdb = db.connect('.') for gpath in gpaths: try: gnm, basename = gdb.get_anim(gpath) except IOError: continue odir = os.path.join(outpath, basename) if (os.path.isfile(os.path.join(odir, 'COMPLETE')) or os.path.isfile( os.path.join(outpath, 'ref', basename + '.ts'))): continue gprof = profile.wrap(prof, gnm) ghash = util.hash(gnm) times = list(profile.enumerate_times(gprof)) if not os.path.isdir(odir): os.makedirs(odir) with open(os.path.join(odir, 'NFRAMES'), 'w') as fp: fp.write(str(len(times))) outmod = output.get_output_for_profile(gprof) for i, t in times: opath = os.path.join(odir, '%05d' % i) if not os.path.isfile(opath + outmod.suffix): yield Task(opath, ghash, prof, gnm, t)
def iter_genomes(prof, outpath, gpaths): """ Walk a list of genome paths, yielding them in an order suitable for the `genomes` argument of `create_jobs()`. """ gdb = db.connect(".") for gpath in gpaths: try: gnm, basename = gdb.get_anim(gpath) except IOError: continue odir = os.path.join(outpath, basename) if os.path.isfile(os.path.join(odir, "COMPLETE")) or os.path.isfile( os.path.join(outpath, "ref", basename + ".ts") ): continue gprof = profile.wrap(prof, gnm) ghash = util.hash(gnm) times = list(profile.enumerate_times(gprof)) if not os.path.isdir(odir): os.makedirs(odir) with open(os.path.join(odir, "NFRAMES"), "w") as fp: fp.write(str(len(times))) outmod = output.get_output_for_profile(gprof) for i, t in times: opath = os.path.join(odir, "%05d" % i) if not os.path.isfile(opath + outmod.suffix): yield Task(opath, ghash, prof, gnm, t)
def main(args, prof): gdb = db.connect(args.genomedb) gnm, basename = gdb.get_anim(args.flame, args.half) if getattr(args, 'print'): print convert.to_json(gnm) return gprof = profile.wrap(prof, gnm) if args.name is not None: basename = args.name prefix = os.path.join(args.dir, basename) if args.subdir: if not os.path.isdir(prefix): os.mkdir(prefix) prefix_plus = prefix + '/' else: prefix_plus = prefix + '_' frames = [('%s%05d%s' % (prefix_plus, i, args.suffix), t) for i, t in profile.enumerate_times(gprof)] # We don't initialize a CUDA context until here. This keeps other # functions like --help and --print snappy. import pycuda.autoinit rmgr = render.RenderManager() rdr = render.Renderer(gnm, gprof) def render_iter(): m = os.path.getmtime(args.flame) first = True for name, times in frames: if args.resume: fp = name + rdr.out.suffix if os.path.isfile(fp) and m < os.path.getmtime(fp): continue for idx, t in enumerate(times): evt, buf = rmgr.queue_frame(rdr, gnm, gprof, t, first) first = False while not evt.query(): time.sleep(0.01) yield None save(rdr.out, name, buf) if args.rawfn: try: buf.tofile(args.rawfn + '.tmp') os.rename(args.rawfn + '.tmp', args.rawfn) except e: print 'Failed to write %s: %s' % (args.rawfn, e) print '%s (%3d/%3d), %dms' % (name, idx, len(times), evt.time()) yield name, buf save(rdr.out, name, None) if args.gfx: pyglet_preview(args, gprof, render_iter()) else: for i in render_iter(): pass
def test_nframes_for_sharding_equal(self): name, prof = self._get_profile( ['-P', '720p', '--fps=1', '--duration=5', '--shard=5']) gprof = profile.wrap(prof, {"type":"edge"}) frames = list(profile.enumerate_times(gprof)) frame_times = np.linspace(0, 1 - 1/5., 5) + 0.5/5 self.assertEquals(len(frames), 1) self.assertEquals(frames[0][0], 1) self.assertItemsEqual(frames[0][1], frame_times)
def test_nframes_for_sharding_equal(self): name, prof = self._get_profile( ['-P', '720p', '--fps=1', '--duration=5', '--shard=5']) gprof = profile.wrap(prof, {"type": "edge"}) frames = list(profile.enumerate_times(gprof)) frame_times = np.linspace(0, 1 - 1 / 5., 5) + 0.5 / 5 self.assertEquals(len(frames), 1) self.assertEquals(frames[0][0], 1) self.assertItemsEqual(frames[0][1], frame_times)
def main(args, prof): gdb = db.connect(args.genomedb) gnm, basename = gdb.get_anim(args.flame, args.half) if getattr(args, "print"): print convert.to_json(gnm) return gprof = profile.wrap(prof, gnm) if args.name is not None: basename = args.name prefix = os.path.join(args.dir, basename) if args.subdir: if not os.path.isdir(prefix): os.mkdir(prefix) prefix_plus = prefix + "/" else: prefix_plus = prefix + "_" frames = [("%s%05d%s" % (prefix_plus, i, args.suffix), t) for i, t in profile.enumerate_times(gprof)] # We don't initialize a CUDA context until here. This keeps other # functions like --help and --print snappy. import pycuda.autoinit rmgr = render.RenderManager() rdr = render.Renderer(gnm, gprof) def render_iter(): m = os.path.getmtime(args.flame) first = True for name, times in frames: if args.resume: fp = name + rdr.out.suffix if os.path.isfile(fp) and m < os.path.getmtime(f[0] + ext): continue for t in times: evt, buf = rmgr.queue_frame(rdr, gnm, gprof, t, first) first = False while not evt.query(): time.sleep(0.01) yield None save(rdr.out, name, buf) print name, evt.time() yield name, buf save(rdr.out, name, None) if args.gfx: pyglet_preview(args, gprof, render_iter()) else: for i in render_iter(): pass
def test_enumerate_times(self): name, prof = self._get_profile() gprof = profile.wrap(prof, {"type":"edge"}) frames = list(profile.enumerate_times(gprof)) frame_times = np.linspace(0, 1 - 1/720., 720) + 0.5/720 self.assertEquals(frames, list(enumerate(frame_times, 1)))
def test_enumerate_times(self): name, prof = self._get_profile() gprof = profile.wrap(prof, {"type": "edge"}) frames = list(profile.enumerate_times(gprof)) frame_times = np.linspace(0, 1 - 1 / 720., 720) + 0.5 / 720 self.assertEquals(frames, list(enumerate(frame_times, 1)))