This commit is contained in:
Noe Brucy
2019-05-24 16:29:27 +02:00
parent aa8ba76162
commit 6b3f127878
2 changed files with 117 additions and 25 deletions
+67 -23
View File
@@ -35,6 +35,7 @@ P.rcParams["savefig.dpi"] = 400
def make_image_disk( def make_image_disk(
path, path,
num, num,
rad=0.5,
path_out=None, path_out=None,
order="<", order="<",
save_data=True, save_data=True,
@@ -67,7 +68,6 @@ def make_image_disk(
ro = pymses.RamsesOutput(path, num, order=order) ro = pymses.RamsesOutput(path, num, order=order)
amr = ro.amr_source(["rho", "vel", "P"]) amr = ro.amr_source(["rho", "vel", "P"])
rad = 0.5
center = [0.5, 0.5, 0.5] center = [0.5, 0.5, 0.5]
return make_image_aux( return make_image_aux(
@@ -258,6 +258,7 @@ def make_image_aux(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(name_im) P.savefig(name_im)
P.close() P.close()
@@ -323,6 +324,7 @@ def make_image_aux(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(name_im) P.savefig(name_im)
P.close() P.close()
@@ -352,6 +354,7 @@ def make_image_aux(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(name_im) P.savefig(name_im)
P.close() P.close()
@@ -398,7 +401,13 @@ def make_image_aux(
# maps_disk['Q_' + ax_los] = map_Q # maps_disk['Q_' + ax_los] = map_Q
im = P.imshow( im = P.imshow(
map_Q, extent=im_extent, origin="lower", norm=mpl.colors.LogNorm() map_Q,
extent=im_extent,
origin="lower",
cmap="RdBu",
norm=mpl.colors.LogNorm(),
vmin=0.01,
vmax=100.0,
) )
P.locator_params(axis="x", nbins=ntick) P.locator_params(axis="x", nbins=ntick)
@@ -416,6 +425,7 @@ def make_image_aux(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(name_im) P.savefig(name_im)
P.close() P.close()
@@ -449,6 +459,7 @@ def make_image_aux(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(name_im) P.savefig(name_im)
P.close() P.close()
@@ -696,7 +707,7 @@ def disk_prop(
f.close() f.close()
def plot_disk_prop(path, num, force=False, tag="", interactive=False): def plot_disk_prop(path, num, force=False, tag="", interactive=False, put_title=False):
""" """
Plot properties of a disk Plot properties of a disk
@@ -740,6 +751,7 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/rho_disk_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/rho_disk_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -749,10 +761,12 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
P.plot(rad, prop_disk["temp"], color="k", linewidth=2) P.plot(rad, prop_disk["temp"], color="k", linewidth=2)
P.ylabel(r"$T \, (K)$") P.ylabel(r"$T \, (K)$")
P.xlabel("disk radius") P.xlabel("disk radius")
P.title(title) if put_title:
P.title(title)
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/T_disk_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/T_disk_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -771,6 +785,7 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/V_disk_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/V_disk_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -780,10 +795,12 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
P.plot(rad, prop_disk["coldens"], color="k", linewidth=2) P.plot(rad, prop_disk["coldens"], color="k", linewidth=2)
P.ylabel(r"$N\, (cm^{-2})$") P.ylabel(r"$N\, (cm^{-2})$")
P.xlabel("disk radius ") P.xlabel("disk radius ")
P.title(title) if put_title:
P.title(title)
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/coldens_disk_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/coldens_disk_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -813,11 +830,12 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
linewidth=2, linewidth=2,
label=r"$\alpha_{tot}$", label=r"$\alpha_{tot}$",
) )
P.title( if put_title:
title P.title(
+ r", $\bar{\alpha}_{Reynolds} = %.1e, \bar{\alpha}_{grav} = %.1e$" title
% (alpha_rey_mean, alpha_grav_mean) + r", $\bar{\alpha}_{Reynolds} = %.1e, \bar{\alpha}_{grav} = %.1e$"
) % (alpha_rey_mean, alpha_grav_mean)
)
P.legend() P.legend()
P.ylabel(r"$\alpha$") P.ylabel(r"$\alpha$")
@@ -826,23 +844,26 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/alpha_disk_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/alpha_disk_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
# Q # Q
P.ylim([0, 10.0]) P.ylim([0, 3.0])
P.xlim([0, 0.5]) P.xlim([0, 0.25])
P.yticks(np.arange(0.0, 11, 1.0)) P.yticks(np.arange(0.0, 3, 1.0))
P.grid() P.grid()
P.plot(rad, abs(prop_disk["Q_kepl"]), color="b", linewidth=2) P.plot(rad, abs(prop_disk["Q_kepl"]), color="b", linewidth=2)
P.plot(rad, abs(prop_disk["Q_mean"]) * np.ones(len(rad)), "b:", linewidth=1) # P.plot(rad, abs(prop_disk['Q_mean']) * np.ones(len(rad)), 'b:', linewidth=1)
P.ylabel(r"$Q$") P.ylabel(r"$Q$")
P.xlabel("disk radius ") P.xlabel("disk radius ")
P.title(title + ", mass of disk = {} (code)".format(mass)) if put_title:
P.title(title + ", mass of disk = {} (code)".format(mass))
if interactive: if interactive:
pass pass
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/Q_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/Q_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -851,11 +872,13 @@ def plot_disk_prop(path, num, force=False, tag="", interactive=False):
P.plot(rad, abs(prop_disk["height"] / rad), color="b", linewidth=2) P.plot(rad, abs(prop_disk["height"] / rad), color="b", linewidth=2)
P.ylabel(r"H ratio") P.ylabel(r"H ratio")
P.xlabel("disk radius ") P.xlabel("disk radius ")
P.title(title + ", mass of box = {} (code)".format(prop_disk["mass_box"])) if put_title:
P.title(title + ", mass of box = {} (code)".format(prop_disk["mass_box"]))
if interactive: if interactive:
pass pass
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/H_r_" + str(num).zfill(5) + out_ext) P.savefig(path + "/H_r_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -958,7 +981,7 @@ def disk_pdf(
P.yscale("log") P.yscale("log")
P.ylim([0.5 / nb_cells, 1.0]) P.ylim([0.5 / nb_cells, 1.0])
P.xlabel(r"$\log(N / \bar{N})$") P.xlabel(r"$\log(N / \bar{N})$")
P.ylabel(r"\mathcal{P}_N") P.ylabel(r"$\mathcal{P}_N$")
if put_title: if put_title:
P.title(title) P.title(title)
values, edges, _ = P.hist( values, edges, _ = P.hist(
@@ -972,14 +995,17 @@ def disk_pdf(
# Compute the slope of the right part of the histogramm # Compute the slope of the right part of the histogramm
mask_fit = (centers > 0.25) & (centers < 1.25) & (values > 0) mask_fit = (centers > 0.25) & (centers < 1.25) & (values > 0)
if np.sum(mask_fit > 0): if np.sum(mask_fit > 0):
(a, b, rho, _, _) = linregress(centers[mask_fit], np.log10(values[mask_fit])) (a, b, rho, _, stderr) = linregress(
P.plot(centers, 10 ** (a * centers + b), "--") centers[mask_fit], np.log10(values[mask_fit])
)
P.plot(centers, 10 ** (a * centers + b), "--", linewidth=2)
print("a=%e, b=%e, rho=%e" % (a, b, rho)) print("a=%e, b=%e, rho=%e" % (a, b, rho))
fit = { fit = {
"beta": int(tag.split("_")[1][4:]), "beta": int(tag.split("_")[1][4:]),
"slope": a, "slope": a,
"origin": b, "origin": b,
"correlation": rho, "correlation": rho,
"stderr": stderr,
} }
f = open(name_prop, "w") f = open(name_prop, "w")
prop_disk["fit"] = fit prop_disk["fit"] = fit
@@ -989,6 +1015,7 @@ def disk_pdf(
if interactive: if interactive:
pass pass
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/dcol_hist_" + tag + "_" + str(num).zfill(5) + out_ext) P.savefig(path + "/dcol_hist_" + tag + "_" + str(num).zfill(5) + out_ext)
P.close() P.close()
@@ -1010,6 +1037,7 @@ def disk_pdf(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(name_im) P.savefig(name_im)
P.close() P.close()
@@ -1049,11 +1077,14 @@ def compare(
if pdf: if pdf:
beta = np.zeros(len(runs)) beta = np.zeros(len(runs))
slope = np.zeros(len(runs)) slope = np.zeros(len(runs))
slope_std = np.zeros(len(runs))
for i, run in enumerate(runs): for i, run in enumerate(runs):
path_run = path + "/" + run path_run = path + "/" + run
nb_outputs = 0 nb_outputs = 0
slope_run = []
for num in nums: for num in nums:
try: try:
# Load property file # Load property file
@@ -1076,7 +1107,7 @@ def compare(
if pdf: if pdf:
fit = prop_disk["fit"] fit = prop_disk["fit"]
beta[i] = fit["beta"] beta[i] = fit["beta"]
slope[i] = slope[i] + fit["slope"] slope_run.append(fit["slope"])
nb_outputs = nb_outputs + 1 nb_outputs = nb_outputs + 1
print(run, num, nb_outputs) print(run, num, nb_outputs)
@@ -1089,7 +1120,8 @@ def compare(
alpha_grav[i] = alpha_grav[i] / nb_outputs alpha_grav[i] = alpha_grav[i] / nb_outputs
Q[i] = Q[i] / nb_outputs Q[i] = Q[i] / nb_outputs
if pdf: if pdf:
slope[i] = slope[i] / nb_outputs slope[i] = np.mean(slope_run)
slope_std[i] = np.std(slope_run)
else: else:
for array in [alpha_rey, alpha_grav, Q]: for array in [alpha_rey, alpha_grav, Q]:
array[i] = np.nan array[i] = np.nan
@@ -1119,6 +1151,7 @@ def compare(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path_out + "/alphaQ_" + nums_name + out_ext) P.savefig(path_out + "/alphaQ_" + nums_name + out_ext)
P.close() P.close()
@@ -1138,21 +1171,27 @@ def compare(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path_out + "/alphaQ0_" + nums_name + out_ext) P.savefig(path_out + "/alphaQ0_" + nums_name + out_ext)
P.close() P.close()
if pdf: if pdf:
# slope of the pdf = f(beta) # slope of the pdf = f(beta)
P.grid() P.grid()
P.plot(beta, slope, "o-.") P.errorbar(beta, slope, yerr=slope_std, fmt="o")
P.legend() P.legend()
P.ylabel(r"$d\log\% / d\logN$") P.ylabel(r"$d\log\mathcal{P}_N / d\logN$")
P.xlabel(r"$\beta$") P.xlabel(r"$\beta$")
(a, b, rho, _, stderr) = linregress(beta, slope)
P.plot(beta, a * beta + b, "--", linewidth=1.5)
print("a=%e, b=%e, rho^2=%e" % (a, b, rho ** 2))
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path_out + "/dcolslopebeta_" + nums_name + out_ext) P.savefig(path_out + "/dcolslopebeta_" + nums_name + out_ext)
P.close() P.close()
@@ -1175,6 +1214,7 @@ def compare(
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path_out + "/alphabeta_" + nums_name + out_ext) P.savefig(path_out + "/alphabeta_" + nums_name + out_ext)
P.close() P.close()
@@ -1248,6 +1288,7 @@ def evolution(path, nums, force=False, interactive=False, pdf=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/alpha_time" + out_ext) P.savefig(path + "/alpha_time" + out_ext)
P.close() P.close()
@@ -1263,6 +1304,7 @@ def evolution(path, nums, force=False, interactive=False, pdf=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/Q_time" + out_ext) P.savefig(path + "/Q_time" + out_ext)
P.close() P.close()
@@ -1278,6 +1320,7 @@ def evolution(path, nums, force=False, interactive=False, pdf=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/mass_time" + out_ext) P.savefig(path + "/mass_time" + out_ext)
P.close() P.close()
@@ -1292,5 +1335,6 @@ def evolution(path, nums, force=False, interactive=False, pdf=False):
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1)
P.savefig(path + "/dcolslope_time" + out_ext) P.savefig(path + "/dcolslope_time" + out_ext)
P.close() P.close()
+50 -2
View File
@@ -44,6 +44,40 @@ parser.add_argument(
parser.add_argument("-i", "--interactive", help="Interactive mode", action="store_true") parser.add_argument("-i", "--interactive", help="Interactive mode", action="store_true")
parser.add_argument(
"-d", "--disk", help="compute specific disk radial analysis", action="store_true"
)
parser.add_argument(
"-pd", "--plot_disk", help="plot specific disk radial analysis", action="store_true"
)
parser.add_argument("-m", "--maps", help="do generic maps", action="store_true")
parser.add_argument(
"-c", "--compare", help="compare different runs", action="store_true"
)
parser.add_argument(
"-ev",
"--evolution",
help="plot evolution of quantities over time",
action="store_true",
)
parser.add_argument(
"--pdf", help="plot pdf of fluctuations of column density", action="store_true"
)
parser.add_argument(
"--fft", help="use quick and dirty fft rendering", action="store_true"
)
parser.add_argument("--level", help="plot levels", action="store_true")
parser.add_argument("--cpu", help="plot cpu", action="store_true")
parser.add_argument("--zoom", help="zoom", type=float, default=2.0)
parser.add_argument(
"-ms",
"--mapsize",
help="size of the maps created in he map mode (in pixel)",
type=int,
default=1024,
)
parser.add_argument( parser.add_argument(
"-d", "--disk", help="do specific disk radial analysis", action="store_true" "-d", "--disk", help="do specific disk radial analysis", action="store_true"
) )
@@ -108,10 +142,11 @@ parser.add_argument(
parser.add_argument( parser.add_argument(
"--format", "--format",
help="Format of the output", help="Format of the output",
choices=["png", "jpeg", "pdf", "ps"], choices=["png", "jpeg", "pdf", "svg", "ps"],
default="jpeg", default="jpeg",
) )
parser.add_argument("--dpi", help="Resolution of the output", type=int, default=400) parser.add_argument("--dpi", help="Resolution of the output", type=int, default=400)
parser.add_argument("--beamer", help="Beamer mode", action="store_true")
args = parser.parse_args() args = parser.parse_args()
@@ -123,8 +158,17 @@ first = args.begin
last = args.end last = args.end
step = args.step step = args.step
rad = 0.5 / args.zoom
# extension for out files # extension for out files
dp.out_ext = "." + args.format dp.out_ext = "." + args.format
if format == "pdf":
dp.P.style.use("pdf")
if args.beamer:
dp.P.rcParams["font.family"] = "sans-serif"
dp.P.rcParams["figure.figsize"] = (5, 3.5)
# Plot properties # Plot properties
dp.P.rcParams["image.cmap"] = args.colormap dp.P.rcParams["image.cmap"] = args.colormap
dp.P.rcParams["savefig.dpi"] = args.dpi dp.P.rcParams["savefig.dpi"] = args.dpi
@@ -159,6 +203,7 @@ for run in runs:
maps_disk = dp.make_image_disk( maps_disk = dp.make_image_disk(
path_in, path_in,
i, i,
rad=rad,
path_out=path_out, path_out=path_out,
tag=run, tag=run,
map_size=args.mapsize, map_size=args.mapsize,
@@ -168,6 +213,7 @@ for run in runs:
pos_star=np.array([args.x, args.y, args.z]), pos_star=np.array([args.x, args.y, args.z]),
fft=args.fft, fft=args.fft,
interactive=args.interactive, interactive=args.interactive,
put_title=(not args.beamer),
) )
print("[{}, {}] maps computed".format(run, i)) print("[{}, {}] maps computed".format(run, i))
if args.disk: if args.disk:
@@ -183,7 +229,7 @@ for run in runs:
pos_star=np.array([args.x, args.y, args.z]), pos_star=np.array([args.x, args.y, args.z]),
) )
print("[{}, {}] disk_props computed".format(run, i)) print("[{}, {}] disk_props computed".format(run, i))
if args.disk: if args.plot_disk:
print("[{}, {}] plotting disk props".format(run, i)) print("[{}, {}] plotting disk props".format(run, i))
dp.plot_disk_prop( dp.plot_disk_prop(
path_out, path_out,
@@ -191,6 +237,7 @@ for run in runs:
tag=run, tag=run,
force=args.force_redo, force=args.force_redo,
interactive=args.interactive, interactive=args.interactive,
put_title=(not args.beamer),
) )
print("[{}, {}] disk props plotted".format(run, i)) print("[{}, {}] disk props plotted".format(run, i))
if args.pdf: if args.pdf:
@@ -203,6 +250,7 @@ for run in runs:
force=args.force_redo, force=args.force_redo,
tag=run, tag=run,
interactive=args.interactive, interactive=args.interactive,
put_title=(not args.beamer),
) )
print("[{}, {}] pdf computed".format(run, i)) print("[{}, {}] pdf computed".format(run, i))
# If we are here, success ! # If we are here, success !