def main(): palette.configure(False) d_indiv, n_indiv = np.loadtxt("indiv_dx_min.txt").T d_global, n_global = np.loadtxt("global_dx_min.txt").T d_rot_global, n_rot_global = np.loadtxt("global_rotation.txt").T d_window_indiv, n_window_indiv = np.loadtxt("rotate_window_indiv.txt").T d_mean_indiv, n_mean_indiv = np.loadtxt("rotate_mean_indiv.txt").T d_mode_indiv, n_mode_indiv = np.loadtxt("rotate_mode_indiv.txt").T plt.plot(d_indiv, n_indiv, color=pc("k"), label=r"${\rm individual\ (\Delta x)_{\rm min}}$") plt.plot(d_global, n_global, color=pc("r"), label=r"${\rm global\ (\Delta x)_{\rm min}}$") plt.plot(d_rot_global, n_rot_global, color=pc("o"), label=r"${\rm global\ rotation}$") plt.plot(d_rot_global - 2**16, n_rot_global, color=pc("o")) plt.plot(d_window_indiv, n_window_indiv, color=pc("g"), label=r"${\rm individual\ rotation\ (window)}$") plt.plot(d_window_indiv - 2**16, n_window_indiv, color=pc("g")) plt.plot(d_mean_indiv, n_mean_indiv, color=pc("b"), label=r"${\rm individual\ rotation\ (mean)}$") plt.plot(d_mean_indiv - 2**16, n_mean_indiv, color=pc("b")) plt.plot(d_mode_indiv, n_mode_indiv, color=pc("p"), label=r"${\rm individual\ rotation\ (mode)}$") plt.plot(d_mode_indiv - 2**16, n_mode_indiv, color=pc("p")) plt.legend(loc="upper left", frameon=True, fontsize=16) xlo, xhi = plt.xlim(-400, 2000) ylo, yhi = plt.ylim() plt.ylim(ylo, yhi) plt.xlabel(r"$\Delta x$") plt.ylabel(r"$N(\Delta x)$") n = -512 while n < xhi: plt.plot([n, n], [ylo, yhi], ":", lw=1, c="k") n += 256 plt.show()
def plot_dev(i_acc): ratios = np.zeros((6, 7*7*7)) acc = acc_strs[i_acc] plt.figure(i_acc) for i_snap, snap in enumerate(snaps): color = colors[i_snap] sizes = np.loadtxt(target % (acc, snap), usecols=(0,)) names = np.loadtxt(target % (acc, snap), usecols=(1,), dtype=str) sizes = np.reshape(sizes, (8, 8, 8)) names = np.reshape(names, (8, 8, 8)) mean_size = np.mean(sizes) block_sizes = ratios[i_snap, :] i = 0 for ox in range(7): for oy in range(7): for oz in range(7): block = sizes[ox:ox+2, oy:oy+2, oz:oz+2] block_sizes[i] = np.mean(block) i += 1 block_sizes /= mean_size plt.plot(block_sizes, c=color, lw=1.5) x_low, x_high = plt.xlim() plt.xlim(x_low, x_high) dev = np.sqrt(np.sum((ratios-1)**2, axis=0)/6) plt.plot([x_low, x_high], [1, 1], "--", lw=2, c="k") plt.figure(4) color = [pc("r"), pc("o"), pc("b")][i_acc] plt.plot(dev, c=color, lw=1.5) plt.yscale("log")
def main(): palette.configure(True) file_names = [ "profiles/phi_pts/phi_pts_4_1.25.txt", "profiles/phi_pts/phi_pts_4_2.5.txt", "profiles/phi_pts/phi_pts_4_5.txt", "profiles/phi_pts/phi_pts_4_10.txt", "profiles/phi_pts/phi_pts_4_20.txt" ] log_r, phi = np.loadtxt(file_names[0]).T log_r_2, phi_2 = np.loadtxt(file_names[-1]).T mvir = 5.112e+09 vvir = mvir_to_vvir(mvir) rvir = mvir_to_rvir(mvir) log_r -= np.log10(rvir) log_r_2 -= np.log10(rvir) phi /= vvir**2 phi_2 /= vvir**2 plt.plot([-12, 5], [-12, 5], "--", lw=2, c=pc("a")) plt.plot(phi, phi_2, ".", c="k") plt.xlim(-12, 5) plt.ylim(-12, 5) plt.xlabel(r"$\Phi_{\rm true}/V_{\rm vir}^2$") plt.ylabel(r"$\Phi(\delta_v = 0.8 V_{\rm vir})/V_{\rm vir}^2$") plt.fill_between([0, 5], [0, 0], [-12, -12], color=pc("b"), alpha=0.2) plt.fill_between([-12, 0], [5, 5], [0, 0], color=pc("r"), alpha=0.2) plt.savefig("plots/fig4_vvir_boundedness.png")
def plot_subhaloes(mpeak, limit, rvir, vec): """ plot_subhaloes plots all subhaloes with mpeak > limit. Subhaloes are plotted as circles with radius rvir with their positions relative to the halo center. Only the (x, y) projection is plotted. """ ok = mpeak > limit # mpeak, rvir, vec = mpeak[ok], rvir[ok], vec[ok] for i in range(len(mpeak)): if i == 0: c, lw = "k", 3 # color and linewidth else: c, lw = pc(), 2 dx, dy = vec[i, 0] - vec[0, 0], vec[i, 1] - vec[0, 1], plot_circle(dx, dy, rvir[i], c, lw=lw) # Leave a small buffer around each halo. spacing = 1.2 plt.xlim(-rvir[0] * spacing, +rvir[0] * spacing) plt.ylim(-rvir[0] * spacing, +rvir[0] * spacing) plt.xlabel(r"$X\,(h^{-1}{\rm Mpc})$") plt.ylabel(r"$Y\,(h^{-1}{\rm Mpc})$")
palette.configure() def gaussian(mu, sigma, x): return np.exp(-(x - mu)**2 / (2 * sigma**2)) / np.sqrt(2 * np.pi * sigma**2) x = np.linspace(0, 1, 100) for c in palette.colors[:0:-1]: plt.figure() for sigma in np.linspace(0.2, 1.0, 10): plt.plot(x, gaussian(sigma, sigma, x), ls, lw=lw, c=pc(c, sigma)) if c == "red": plt.savefig("README_images/color_range.png") plt.figure() x = np.linspace(-1, 1, 100) plt.plot(x, gaussian(0, 0.5, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(0.5, 0.5, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(0.25, 0.4, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(-0.3, 0.6, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(-0.5, 0.3, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(-0.75, 1.0, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(0.75, 0.75, x), ls, c=pc(), lw=lw) plt.plot(x, gaussian(0.1, 0.35, x), ls, c=pc(), lw=lw)
def main(): snap_to_z, snap_to_a = snap_lookup_tables("profiles/redshifts.txt") L, sim_name = Ls[0], sim_names[0] dx_means = [0] * len(accuracies[0]) dv_means = [0] * len(accuracies[0]) spacing = L / 1024 for i, acc in enumerate(accuracies[0]): str_acc = str(acc) dx_file_name = "profiles/sizes/%s/dx_%s.txt" % (sim_name, str_acc) dv_file_name = "profiles/sizes/%s/dv_%s.txt" % (sim_name, str_acc) snap = np.arange(101) snap = snap[snap != 63] dx_size = np.loadtxt(dx_file_name, usecols=(0, ))[:-1] dv_size = np.loadtxt(dv_file_name, usecols=(0, ))[:-1] dx_size = dx_size[dx_size != 0] dv_size = dv_size[dv_size != 0] exp_small = 1024**3 * (4 + 12) / 4**3 / 2**10 exp_large = 1024**3 * (4 + 12) / 2**10 dx_ratio = np.zeros(len(dx_size)) dx_ratio[:-1] = dx_size[:-1] / exp_small dx_ratio[-1] = dx_size[-1] / exp_large dv_ratio = np.zeros(len(dv_size)) dv_ratio[:-1] = dv_size[:-1] / exp_small dv_ratio[-1] = dv_size[-1] / exp_large dx_means[i], dv_means[i] = np.mean(dx_ratio), np.mean(dv_ratio) if i == 1: plt.plot(snap_to_a[snap], dx_ratio, c=pc("r"), label=r"$\delta x = %.3f\,l$" % (acc / spacing / 1e3)) plt.plot([1 / 21, 1], [dx_means[i], dx_means[i]], "--", lw=2, c=pc("r")) if i == 3: plt.plot(snap_to_a[snap], dv_ratio, c=pc("b"), label=r"$\delta v = %s\,{\rm km\,s^{-1}}$" % str_acc) plt.plot([1 / 21, 1], [dx_means[i], dx_means[i]], "--", lw=2, c=pc("b")) plt.legend(loc="upper left", fontsize=16) plt.xscale("log") plt.ylabel(r"${\rm Compression\ ratio}$") plt.xlabel(r"$a(z)$") plt.xlim(1 / 21, 1) plt.savefig("plots/fig_2a_ratio_vs_a.png") plt.figure() acc = np.array(accuracies[0]) plt.plot(np.log10(acc), dv_means, c=pc("b"), label=r"$\vec{v}$") plt.plot(np.log10(acc), dv_means, "o", c=pc("b")) plt.xlabel(r"$\log_{10}(\delta v)\ ({\rm km\,s^{-1}})$", color=pc("b")) plt.ylabel(r"${\rm Compression\ ratio}$") plt.tick_params(axis="x", colors=pc("b")) plt.twiny() plt.plot(np.log10(acc / spacing / 1e3), dx_means, c=pc("r"), label=r"$\vec{x}$") plt.plot(np.log10(acc / spacing / 1e3), dx_means, "o", c=pc("r")) plt.xlabel(r"$\log_{10}(\delta x / l)$", color=pc("r")) plt.ylabel(r"${\rm Compression\ ratio}$") plt.tick_params(axis="x", colors=pc("r")) plt.savefig("plots/fig_2b_ratio_vs_accuracy.png")
import numpy as np import matplotlib.pyplot as plt import palette from palette import pc sim_names = ["Erebos_CBol_L63"] accuracies = [[1.25, 2.5, 5, 10, 20]] Ls = [62.5] colors = [pc("r"), pc("o"), pc("g"), pc("b"), pc("p")] def snap_lookup_tables(file_name): snap, z, a = np.loadtxt(file_name).T z[63] = 10**((np.log10(z[62]) + np.log10(z[64])) / 2) a[63] = 10**((np.log10(a[62]) + np.log10(a[64])) / 2) return z, a def main(): snap_to_z, snap_to_a = snap_lookup_tables("profiles/redshifts.txt") L, sim_name = Ls[0], sim_names[0] dx_means = [0] * len(accuracies[0]) dv_means = [0] * len(accuracies[0]) spacing = L / 1024 for i, acc in enumerate(accuracies[0]): str_acc = str(acc) dx_file_name = "profiles/sizes/%s/dx_%s.txt" % (sim_name, str_acc)