def process_files(fnames, profiles, wait=False, **kwargs): for fname in fnames: if wait: wait_for(fname) with ContextTimer("Loading %s" % fname): fp = h5py.File(fname) siml = CylindricalLangevin.load(fp) fp.close() for profile in profiles.split(','): ofile = fname.replace('.h5', '-%s.png' % profile) with ContextTimer("Writing %s" % ofile): panel(siml, profile, ofile, **kwargs)
def main(): logger.info(" ".join(sys.argv)) parser = get_parser() args = parser.parse_args() if args.vars: list_vars() sys.exit() fp = h5py.File(args.input) all_steps = list(fp["steps"].keys()) if args.step == "all": steps = all_steps elif args.step == "latest": steps = [all_steps[-1]] else: steps = [args.step] rid = os.path.splitext(args.input)[0] params = Parameters() params.h5_load(fp) plugins = [import_object(s)(params, load_files=False) for s in params.plugins] if args.parameters: dump_params(fp) if args.list: list_steps(fp) if args.show and len(steps) > 1: logger.error("For your own good, --show is incompatible with more than 1 plot.") sys.exit(-1) if args.var is None: sys.exit(0) if len(steps) > 1: logger.info("Plotting %d steps." % len(steps)) outdir = args.outdir.format(rid=rid, var=args.var) try: os.mkdir(outdir) except OSError: pass for step in steps: sim = CylindricalLangevin.load(fp, step) for p in plugins: p.initialize(sim) p.load_data(sim, fp["steps/%s" % step]) pylab.figure(figsize=args.figsize) pylab.clf() f = VAR_FUNCS[args.var] v = f(sim, params) plot(sim, v, args, label=f.__doc__) if not args.show: ofile = args.output.format(step=step, var=args.var, rid=rid) ofile = os.path.join(outdir, ofile) pylab.savefig(ofile) pylab.close() logger.info("File '%s' saved" % ofile) if args.show: pylab.show()
def load(g, step, set_dt=False): instance = CylindricalLangevin.load(g, step, set_dt=set_dt, c=Radiative2d) return instance