def process_mcmc(datrnk, sample, cap, cosmology, cutoffval): mcmcfns = glob("{0}/out/sim/{1}/{2}/{3}/mcmc/new/*.mock". format(datrnk, sample, cap, cosmology)) sim_nz = nzobj(datrnk, sample, cap, cosmology, cutoffval) sim_nz.read_json() downfns = glob("{0}/out/sim/{1}/{2}/{3}/mcmc/new/*.down". format(datrnk, sample, cap, cosmology)) for mock in mcmcfns: simdown = mock[:-4] + "down" print simdown if not simdown in downfns: try: sim_nz.mock = np.genfromtxt(mock) sim_nz.fibre_collisions() sim_nz.sim_down(simdown) except: continue
def process_mocks(dattop, sample, cap, cosmology, cutoffval): # First get the polynomial fit to the average of all the mock number densities # mock_avg_poly() # initialise an nzobj mock_nz = nzobj(dattop, sample, cap, cosmology, cutoffval) # load the json data into the nzobj mock_nz.read_json() # give the nzobj the polynomial coefficients to use for downsampling mock_nz.popt = np.loadtxt(dattop + "/out/{0}/{1}/{2}/mocks/avg_poly_coeffs.dat".format(sample, cap, cosmology)) # glob all the mocks mockfns = glob("{0}/in/boss/{1}/{2}/mocks/*.rdz". format(dattop, sample, cap)) # now process all those bad boys for mockfn in mockfns: mockN = mockfn.split("/")[-1].split("_")[1].split(".")[0] print "\n", "mock\t", mockN, "\n" mock_nz.radecz = np.loadtxt(mockfn) mock_nz.rdz_down("/mocks/rdz/{0}.dat".format(mockN))
def plot_nz(fn): werds = fn.split("/") outi = werds.index("out") dattop = "/".join(werds[:outi]) sample = werds[outi + 1] cap = werds[outi + 2] cosmo = werds[outi + 3] nob = nzobj(dattop, sample, cap, cosmo, 0.65) nob.read_json() nob.radecz = np.loadtxt(fn) nob._compute_z_nbar() fig = plt.figure() ax = fig.add_subplot(111) l, = ax.plot(nob.z_cen, nob.nbar) ax.set_xlabel(r"$z$") ax.set_ylabel(r"$ n(z)$") picname = ''.join(os.path.basename(fn).split(".")[:-1]) + ".pdf" plotaddress = os.path.dirname(fn) + "/plots/" + picname fig.savefig(plotaddress) os.system("scp {0} broiler:~/public_html/tinker/".format(plotaddress)) os.system("ssh broiler chmod 644 /home/kilian/public_html/tinker/{0}" .format(picname))
def process_mocks(dattop, sample, cap, cosmology, cutoffval): # First get the polynomial fit to the average of all the mock number densities # mock_avg_poly() # initialise an nzobj mock_nz = nzobj(dattop, sample, cap, cosmology, cutoffval) # load the json data into the nzobj mock_nz.read_json() # give the nzobj the polynomial coefficients to use for downsampling mock_nz.popt = np.loadtxt(dattop + "/out/{0}/{1}/{2}/mocks/avg_poly_coeffs.dat". format(sample, cap, cosmology)) # glob all the mocks mockfns = glob("{0}/in/boss/{1}/{2}/mocks/*.rdz".format( dattop, sample, cap)) # now process all those bad boys for mockfn in mockfns: mockN = mockfn.split("/")[-1].split("_")[1].split(".")[0] print "\n", "mock\t", mockN, "\n" mock_nz.radecz = np.loadtxt(mockfn) mock_nz.rdz_down("/mocks/rdz/{0}.dat".format(mockN))
def plot_nz(dirnam): werds = dirnam.split("/") outi = werds.index("out") dattop = "/".join(werds[:outi]) sample = werds[outi + 1] cap = werds[outi + 2] cosmo = werds[outi + 3] allmocks = glob(dirnam + "/*.dat") nob = nzobj(dattop, sample, cap, cosmo, 0.65) nob.read_json() fig = plt.figure() ax = fig.add_subplot(111) lines = [] i = 0 # just get the first 100 for fn in allmocks: i += 1 if i > 100: break nob.radecz = np.loadtxt(fn) nob._compute_z_nbar() lines.append(ax.plot(nob.z_cen, nob.nbar, color='b', alpha=0.05)) datfn = dattop + "/".join([sample, cap, cosmo]) + "/radecz.dat" nob.radecz = np.loadtxt(datfn) nob._compute_z_nbar() lines.append(ax.plot(nob.z_cen, nob.nbar, color='r', alpha=0.5)) ax.set_xlabel(r"$z$") ax.set_ylabel(r"$ n(z)$") ax.set_ylim([0.0002, 0.0003]) picname = "mock_dat_nbars.pdf" plotaddress = dirnam + "/plots/" + picname fig.savefig(plotaddress) os.system("scp {0} broiler:~/public_html/tinker/".format(plotaddress)) os.system( "ssh broiler chmod 644 /home/kilian/public_html/tinker/{0}".format( picname))
def plot_nz(dirnam): werds = dirnam.split("/") outi = werds.index("out") dattop = "/".join(werds[:outi]) sample = werds[outi + 1] cap = werds[outi + 2] cosmo = werds[outi + 3] allmocks = glob(dirnam + "/*.dat") nob = nzobj(dattop, sample, cap, cosmo, 0.65) nob.read_json() fig = plt.figure() ax = fig.add_subplot(111) lines = [] i = 0 # just get the first 100 for fn in allmocks: i += 1 if i > 100: break nob.radecz = np.loadtxt(fn) nob._compute_z_nbar() lines.append(ax.plot(nob.z_cen, nob.nbar, color='b', alpha=0.05)) datfn = dattop + "/out/" + "/".join([sample, cap, cosmo]) + "/radecz.dat" nob.radecz = np.loadtxt(datfn) nob._compute_z_nbar() lines.append(ax.plot(nob.z_cen, nob.nbar, color='r', alpha=0.5)) ax.set_xlabel(r"$z$") ax.set_ylabel(r"$ n(z)$") ax.set_ylim([0.000224, 0.000226]) picname = "mock_dat_nbars.pdf" plotaddress = dirnam + "/plots/" + picname fig.savefig(plotaddress) os.system("scp {0} broiler:~/public_html/tinker/".format(plotaddress)) os.system("ssh broiler chmod 644 /home/kilian/public_html/tinker/{0}" .format(picname))
def process_sim(datrnk, simfile, sample, cap, cosmology, cutoffval): simout = datrnk + "/out/sim/" + sample + "/" + cap + "/" + cosmology + "/" + simfile sim_nz = nzobj(datrnk, sample, cap, cosmology, cutoffval) sim_nz.read_json() sim_nz.mock = np.genfromtxt(simout) sim_nz.fibre_collisions() hodroot = simfile.split(".")[0] print os.path.dirname(simout) sim_nz.sim_down(os.path.dirname(simout) + hodroot + ".down")
def process_data(dattop, sample, cap, cosmology, cutoffval): data_nz = nzobj(dattop, sample, cap, cosmology, cutoffval) data_nz.get_zrange() # get the galaxy data to compute number density from galfits = fits.open( glob("{0}/in/boss/{1}/{2}/*.fits".format(dattop, sample, cap))[0]) # array of all the RAs Decs and redshifts radecz = np.dstack((galfits[1].data["RA"], galfits[1].data["DEC"], galfits[1].data["Z"]))[0] # give the rdz to the nzobj data_nz.radecz = radecz data_nz.fit_polynom() data_nz.rdz_down("/radecz.dat") data_nz.write_json()
def process_data(dattop, sample, cap, cosmology, cutoffval): data_nz = nzobj(dattop, sample, cap, cosmology, cutoffval) data_nz.get_zrange() # get the galaxy data to compute number density from galfits = fits.open(glob("{0}/in/boss/{1}/{2}/*.fits". format(dattop, sample, cap))[0]) # array of all the RAs Decs and redshifts radecz = np.dstack((galfits[1].data["RA"], galfits[1].data["DEC"], galfits[1].data["Z"]))[0] # give the rdz to the nzobj data_nz.radecz = radecz data_nz.fit_polynom() data_nz.rdz_down("/radecz.dat") data_nz.write_json()
def plot_nz(fn): werds = fn.split("/") outi = werds.index("out") dattop = "/".join(werds[:outi]) sample = werds[outi + 1] cap = werds[outi + 2] cosmo = werds[outi + 3] nob = nzobj(dattop, sample, cap, cosmo, 0.65) nob.read_json() nob.radecz = np.loadtxt(fn) nob._compute_z_nbar() fig = plt.figure() ax = fig.add_subplot(111) l, = ax.plot(nob.z_cen, nob.nbar) ax.set_xlabel(r"$z$") ax.set_ylabel(r"$ n(z)$") picname = ''.join(os.path.basename(fn).split(".")[:-1]) + ".pdf" plotaddress = os.path.dirname(fn) + "/plots/" + picname fig.savefig(plotaddress) os.system("scp {0} broiler:~/public_html/tinker/".format(plotaddress)) os.system( "ssh broiler chmod 644 /home/kilian/public_html/tinker/{0}".format( picname))
def plot_nz(datrnk, fndown): sample = "CMASS" cap = "NGC" fig = plt.figure() ax = fig.add_subplot(111) # plot corrected nob = nzobj(datrnk, sample, cap, "WMAP", 0.65) nob.get_zrange() ax.scatter(nob.nbar_corr[:, 0], nob.nbar_full, color='m', label=r"$n_{corrected}$") # plot raw data galfits = fits.open(glob("{0}/in/boss/{1}/{2}/*.fits". format(datrnk, sample, cap))[0]) # array of all the RAs Decs and redshifts radecz = np.dstack((galfits[1].data["RA"], galfits[1].data["DEC"], galfits[1].data["Z"]))[0] buf = len(nob.zcen) # give the rdz to the nzobj nob.radecz = radecz nob._compute_z_nbar(buf=buf) ldat, = ax.plot(nob.z_cen, nob.nbar, label=r"$n_{data}$") # plot downsampled nbar nob.radecz = np.loadtxt(fndown) nob._compute_z_nbar(buf=5) nob.nbar[:5] = 0. nob.nbar[-5:] = 0. ldown, = ax.plot(nob.z_cen, nob.nbar, color='r', label=r"$n_{downsampled}$") ax.set_xlabel(r"$z$") ax.set_ylabel(r"$ n(z)$ $(Mpc / h)^{-3}$") ax.set_title("CMASS NGC Number Densities") ax.set_xlim([0.3, 0.75]) ax.set_ylim([0., 0.0005]) handles, labels = ax.get_legend_handles_labels() ax.legend(handles, labels) picname = "nbar_talk.pdf" plotaddress = picname fig.savefig(plotaddress) os.system("scp {0} broiler:~/public_html/tinker/".format(plotaddress)) os.system("ssh broiler chmod 644 /home/kilian/public_html/tinker/{0}" .format(picname))