files = glob(args.glob) elif args.files: files = args.files else: sys.exit("Must specify either --glob or --files") #Because we are impatient and want to compute statistics before all the jobs are finished, # there may be some directories that do not have a flatchains.hdf5 file flatchainList = [] for file in files: try: # If we've specified HDF5, use h5read # If we've specified csv, use csvread root, ext = os.path.splitext(file) if ext == ".hdf5": flatchainList.append(utils.h5read(file, args.burn, args.thin)) elif ext == ".csv": flatchainList.append(utils.csvread(file, args.burn, args.thin)) except OSError as e: print("{} does not exist, skipping. Or error {}".format(file, e)) print("Using a total of {} flatchains".format(len(flatchainList))) if args.cat: assert len(flatchainList) > 1, "If concatenating samples, must provide more than one flatchain" utils.cat_list(args.output, flatchainList) # Assume that if we are using either args.chain, or args.triangle, we are only suppling one # chain, since these commands don't make sense otherwise. if args.chain: assert len(flatchainList) == 1, "If plotting Markov Chain, only specify one flatchain"
from Starfish import utils # Determine all of the orders we will be fitting spectra = Starfish.data["files"] orders = Starfish.data["orders"] for spectrum_id in range(len(spectra)): for order in orders: npoly = Starfish.config["cheb_degree"] if order == orders[-1]: # Use cheb degree - 1 for the last order npoly -= 1 fname_phi = Starfish.specfmt.format(spectrum_id, order) + "phi.json" phi = PhiParam.load(fname_phi) fname_mc = args.rundir + "/" + Starfish.specfmt.format( spectrum_id, order) + "/mc.hdf5" flatchain = utils.h5read(fname_mc) pars = flatchain[-1, :] phi.cheb = pars[:npoly] phi.sigAmp = float(pars[npoly]) phi.logAmp = float(pars[npoly + 1]) phi.l = float(pars[npoly + 2]) phi.save()
# from http://www.astropython.org/snippet/2009/10/chdir-context-manager @contextlib.contextmanager def chdir(dirname=None): curdir = os.getcwd() try: if dirname is not None: os.chdir(dirname) yield finally: os.chdir(curdir) paths = glob("s*o*/mc.hdf5") if args.triangle: flatchain = utils.h5read("mc.hdf5", args.burn) utils.plot(flatchain, base="") cmd = [ "chain.py", "--files", "mc.hdf5", "-t", "--burn", "{}".format(args.burn) ] for path in paths: dirname, fname = path.split("/") # CD to this directory using context managers with chdir(dirname): subprocess.call(cmd) if args.chain:
# from http://www.astropython.org/snippet/2009/10/chdir-context-manager @contextlib.contextmanager def chdir(dirname=None): curdir = os.getcwd() try: if dirname is not None: os.chdir(dirname) yield finally: os.chdir(curdir) paths = glob("s*o*/mc.hdf5") if args.triangle: flatchain = utils.h5read("mc.hdf5", args.burn) utils.plot(flatchain, base="") cmd = ["chain.py", "--files", "mc.hdf5", "-t", "--burn", "{}".format(args.burn)] for path in paths: dirname, fname = path.split("/") # CD to this directory using context managers with chdir(dirname): subprocess.call(cmd) if args.chain: flatchain = utils.h5read("mc.hdf5", args.burn)
from Starfish import utils # Determine all of the orders we will be fitting spectra = Starfish.data["files"] orders = Starfish.data["orders"] for spectrum_id in range(len(spectra)): for order in orders: npoly = Starfish.config["cheb_degree"] if order == orders[-1]: # Use cheb degree - 1 for the last order npoly -= 1 fname_phi = Starfish.specfmt.format(spectrum_id, order) + "phi.json" phi = PhiParam.load(fname_phi) fname_mc = args.rundir + "/" + Starfish.specfmt.format(spectrum_id, order) + "/mc.hdf5" flatchain = utils.h5read(fname_mc) pars = flatchain[-1,:] phi.cheb = pars[:npoly] phi.sigAmp = float(pars[npoly]) phi.logAmp = float(pars[npoly + 1]) phi.l = float(pars[npoly + 2]) phi.save()
files = glob(args.glob) elif args.files: files = args.files else: sys.exit("Must specify either --glob or --files") #Because we are impatient and want to compute statistics before all the jobs are finished, # there may be some directories that do not have a flatchains.hdf5 file flatchainList = [] for file in files: try: # If we've specified HDF5, use h5read # If we've specified csv, use csvread root, ext = os.path.splitext(file) if ext == ".hdf5": flatchainList.append(utils.h5read(file, args.burn, args.thin)) elif ext == ".csv": flatchainList.append(utils.csvread(file, args.burn, args.thin)) except OSError as e: print("{} does not exist, skipping. Or error {}".format(file, e)) print("Using a total of {} flatchains".format(len(flatchainList))) if args.cat: assert len( flatchainList ) > 1, "If concatenating samples, must provide more than one flatchain" utils.cat_list(args.output, flatchainList) # Assume that if we are using either args.chain, or args.triangle, we are only suppling one # chain, since these commands don't make sense otherwise.