Corrected errors

This commit is contained in:
Noe Brucy
2019-06-14 14:14:02 +02:00
parent 84fcf81dfc
commit 3afc117e2a
2 changed files with 166 additions and 165 deletions
+145 -144
View File
@@ -21,6 +21,7 @@ except:
import tables import tables
from scipy.stats import linregress from scipy.stats import linregress
from pymses.sources.ramses import output from pymses.sources.ramses import output
from pymses.sources.hop.file_formats import *
from pymses.analysis import Camera, raytracing, slicing, splatting from pymses.analysis import Camera, raytracing, slicing, splatting
from pymses.filters import CellsToPoints from pymses.filters import CellsToPoints
from pymses.analysis import ScalarOperator, FractionOperator, MaxLevelOperator from pymses.analysis import ScalarOperator, FractionOperator, MaxLevelOperator
@@ -317,18 +318,15 @@ def plot_maps(
): ):
continue continue
map_disk = maps_disk[image + "_" + ax_los] map_disk = maps_disk[image + '_' + ax_los]
if image == "Q": if image == 'Q' :
im = P.imshow( im = P.imshow(map_disk,
map_Q,
extent=im_extent, extent=im_extent,
origin="lower", origin='lower',
cmap="RdBu", cmap='RdBu',
norm=mpl.colors.LogNorm(), norm=mpl.colors.LogNorm(),
vmin=0.01, vmin=0.01, vmax=100.)
vmax=100.0,
)
else: else:
im = P.imshow( im = P.imshow(
map_disk, map_disk,
@@ -348,46 +346,37 @@ def plot_maps(
cbar = P.colorbar(im) cbar = P.colorbar(im)
if image == "coldens": if image == 'coldens':
cbar.set_label(r"$log(N)$ (code)") cbar.set_label(r'$log(\Sigma)$ (code)')
if "levels" in images: if 'levels' in images:
map_level = maps_disk["levels_" + ax_los] map_level = maps_disk['levels_' + ax_los]
# Computing linewidths # Computing linewidths
levels_ar = np.arange(np.min(map_level), np.max(map_level) + 1)
lw = np.ones(levels_ar.size) * 2 lw = np.ones(levels_ar.size) * 2
lvl_th = 8 # Level threeshold for reducing linewidths lvl_th = 8 # Level threeshold for reducing linewidths
lw[levels_ar >= lvl_th] = lw[levels_ar >= lvl_th] ** ( lw[levels_ar >= lvl_th] = lw[levels_ar >= lvl_th]**(lvl_th - levels_ar[levels_ar >= lvl_th])
lvl_th - levels_ar[levels_ar >= lvl_th] lw[levels_ar < lvl_th] = 1.
)
lw[levels_ar < lvl_th] = 1.0
cont = P.contour( cont = P.contour(map_level,
map_level,
extent=im_extent, extent=im_extent,
origin="lower", origin='lower',
colors="k", colors='k',
linewidths=lw, linewidths=lw,
levels=levels_ar, levels=levels_ar)
)
cont.levels = cont.levels + 1 cont.levels = cont.levels + 1
P.clabel( P.clabel(cont,
cont,
levels_ar[levels_ar < lvl_th + 2][1::2], levels_ar[levels_ar < lvl_th + 2][1::2],
inline=1, inline=1, fontsize=8., fmt='%1d')
fontsize=8.0, elif image == 'rho':
fmt="%1d", cbar.set_label(r'$log(n)$ (code)')
)
elif image == "rho":
cbar.set_label(r"$log(n)$ (code)")
if "speed" in images: if 'speed' in images:
dmap_vh = maps_disk["v" + ax_h + "_" + ax_los] dmap_vh = maps_disk['v' + ax_h + '_' + ax_los]
dmap_vv = maps_disk["v" + ax_v + "_" + ax_los] dmap_vv = maps_disk['v' + ax_v + '_' + ax_los]
map_vh_red = dmap_vh[ map_vh_red = dmap_vh[::vel_red,::vel_red] # take only a subset of velocities
::vel_red, ::vel_red
] # take only a subset of velocities
map_vv_red = dmap_vv[::vel_red,::vel_red] map_vv_red = dmap_vv[::vel_red,::vel_red]
nh = map_vh_red.shape[0] nh = map_vh_red.shape[0]
nv = map_vv_red.shape[1] nv = map_vv_red.shape[1]
@@ -532,8 +521,9 @@ def disk_prop(
g_az = (pos[:, 0] * g[:, 1] - pos[:, 1] * g[:, 0]) / norm_pos g_az = (pos[:, 0] * g[:, 1] - pos[:, 1] * g[:, 0]) / norm_pos
# Select cells that are actually in the disk, ie within the scale height # Select cells that are actually in the disk, ie within the scale height
G = 1.0 G = 1.
cs = np.sqrt(cells["P"]/cells["rho"]) # sound velocity cs = np.sqrt(cells["P"]/cells["rho"]) # sound velocity
height = cs * np.sqrt(rc**3 / (G * mass_star)) height = cs * np.sqrt(rc**3 / (G * mass_star))
mask_pos = np.abs(pos[:, 2]) < height # condition on position mask_pos = np.abs(pos[:, 2]) < height # condition on position
mask_dens = cells["rho"] > 0.01 * np.mean(cells["rho"]) # condition on density mask_dens = cells["rho"] > 0.01 * np.mean(cells["rho"]) # condition on density
@@ -559,8 +549,6 @@ def disk_prop(
total_mass_disk = np.sum(rho_disk * dvol_disk) total_mass_disk = np.sum(rho_disk * dvol_disk)
total_mass = np.sum(cells["rho"] * dx ** 3) total_mass = np.sum(cells["rho"] * dx ** 3)
print("Mass disk", total_mass_disk)
print("Mass box", total_mass)
# Initialize binned quantities # Initialize binned quantities
cs_rad = np.zeros(nb_bin - 1) cs_rad = np.zeros(nb_bin - 1)
@@ -726,38 +714,33 @@ def plot_disk_prop(
for plot in plots: for plot in plots:
title = "t=" + str(time)[0:5] + " (code)" title = "t=" + str(time)[0:5] + " (code)"
P.grid() P.grid()
P.xlabel("disk radius") P.xlabel('disk radius')
if plot == "rho": if plot == 'rho':
P.xscale("log") P.xscale('log')
P.yscale("log") P.yscale('log')
P.plot(rad, prop_disk["rho"], color="k", linewidth=2) P.plot(rad, prop_disk['rho'], color='k', linewidth=2)
P.ylabel(r"$n \, (code)$") P.ylabel(r'$n \, (code)$')
elif plot == "T": elif plot == 'T':
P.xscale("log") P.xscale('log')
P.yscale("log") P.yscale('log')
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)$')
elif plot == "V": elif plot == 'V':
P.xscale("log") P.xscale('log')
P.yscale("symlog", linthreshy=0.01) P.yscale('symlog',linthreshy=0.01)
P.plot(rad, prop_disk["v_rad"], color="k", linewidth=2) P.plot(rad, prop_disk['v_rad'], color='k', linewidth=2)
P.plot(rad, prop_disk["v_kepl"], color="b", linewidth=2) P.plot(rad, prop_disk['v_kepl'], color='b', linewidth=2)
P.plot(rad, abs(prop_disk["v_az"]), color="r", linewidth=2) P.plot(rad, abs(prop_disk['v_az']), color='r', linewidth=2)
P.plot(rad, prop_disk["cs"], color="c", linewidth=2) P.plot(rad,prop_disk['cs'], color='c', linewidth=2)
P.legend( P.legend((r'$v_r$', r'$v_{kepl}$', r'$v_\phi$', r'$c_s$'), loc='upper right')
(r"$v_r$", r"$v_{kepl}$", r"$v_\phi$", r"$c_s$"), loc="upper right" P.ylabel(r'$V \, (km s^{-1})$')
) elif plot == 'coldens':
P.ylabel(r"$V \, (km s^{-1})$") P.xscale('log')
elif plot == "coldens": P.yscale('log')
P.xscale("log") P.plot(rad,prop_disk['coldens'],color='k',linewidth=2)
P.yscale("log") P.ylabel(r'$\Sigma\, (cm^{-2})$')
P.plot(rad, prop_disk["coldens"], color="k", linewidth=2) elif plot == 'alpha':
P.ylabel(r"$N\, (cm^{-2})$") alpha_rey_mean, alpha_grav_mean = prop_disk['alpha_rey_mean'], prop_disk['alpha_grav_mean']
elif plot == "alpha":
alpha_rey_mean, alpha_grav_mean = (
prop_disk["alpha_rey_mean"],
prop_disk["alpha_grav_mean"],
)
P.xlim([1e-2, 0.25]) P.xlim([1e-2, 0.25])
P.yscale("log") P.yscale("log")
P.ylim([1e-7, 1.0]) P.ylim([1e-7, 1.0])
@@ -950,10 +933,10 @@ def disk_pdf(
nb_cells = np.sum(mask_flat) nb_cells = np.sum(mask_flat)
P.grid() P.grid()
P.yscale("log") P.yscale('log')
P.ylim([0.5 / nb_cells, 1.0]) P.ylim([0.5 / nb_cells, 1.])
P.xlabel(r"$\log(N / \bar{N})$") P.xlabel(r'$\log(\Sigma / \bar{\Sigma})$')
P.ylabel(r"$\mathcal{P}_N$") P.ylabel(r'$\mathcal{P}_\Sigma$')
if put_title: if put_title:
P.title(title) P.title(title)
values, edges, _ = P.hist( values, edges, _ = P.hist(
@@ -999,14 +982,15 @@ def disk_pdf(
P.close() P.close()
# Derived quantities # Derived quantities
drho = fluct_maps["rho"].flatten() drho = fluct_maps['rho'].flatten()
dcs = fluct_maps["cs"].flatten() dcs = fluct_maps['cs'].flatten()
dv = fluct_maps["v"].flatten() dv = fluct_maps['v'].flatten()
dvaz_kepl = abs(maps["vaz"] - v_kepl) / v_kepl dvaz_kepl = abs(maps['vaz'] - v_kepl) / v_kepl
fluct_maps["vaz_kepl"] = dvaz_kepl fluct_maps['vaz_kepl'] = dvaz_kepl
dmach = abs(maps["v"] - avg_maps["v"]) / maps["cs"] dmach = abs(maps['v'] - avg_maps['v']) / maps['cs']
fluct_maps["mach"] = dmach dmach[dmach > 10.] = 10.
dmach_mean = np.mean(dmach[mask_map].flatten()) fluct_maps['mach'] = dmach
dmach_mean = np.mean(dmach[mask_map & (dmach < 5.)].flatten())
# Fluctuations plots # Fluctuations plots
f = open(name_prop, "w") f = open(name_prop, "w")
@@ -1056,52 +1040,51 @@ def disk_pdf(
for cur_map in fluct_maps: for cur_map in fluct_maps:
fluct_map = fluct_maps[cur_map] fluct_map = fluct_maps[cur_map]
if cur_map == "coldens": if cur_map == 'coldens':
im = P.imshow( im = P.imshow(fluct_map,
fluct_map,
norm=mpl.colors.LogNorm(), norm=mpl.colors.LogNorm(),
extent=im_extent, extent=im_extent,
origin="lower", origin='lower',
cmap="viridis", cmap='viridis')
) label = r'$log(\Sigma/\bar{\Sigma})$'
label = r"$log(N/\bar{N})$" elif cur_map == 'cs':
elif cur_map == "cs": im = P.imshow(np.log10(fluct_map),
im = P.imshow(
np.log10(fluct_map),
extent=im_extent, extent=im_extent,
origin="lower", origin='lower',
cmap="RdBu_r", cmap='RdBu_r',
vmin=-0.6, vmin=-0.6,
vmax=0.6, vmax=0.6)
) label = r'$log(c_s/\bar{c_s})$'
label = r"$log(c_s/\bar{c_s})$" elif cur_map == 'rho':
elif cur_map == "rho": im = P.imshow(np.log10(fluct_map),
im = P.imshow(
np.log10(fluct_map),
extent=im_extent, extent=im_extent,
origin="lower", origin='lower',
cmap="RdBu_r", cmap='RdBu_r',
vmin=-2.0, vmin=-2.,
vmax=2.0, vmax=2.)
) label = r'$log(\rho/\bar{\rho})$'
label = r"$log(\rho/\bar{\rho})$" elif cur_map == 'vaz_kepl':
elif cur_map == "vaz_kepl": im = P.imshow(fluct_map,
im = P.imshow(
fluct_map,
extent=im_extent, extent=im_extent,
origin="lower", origin='lower',
cmap="RdBu_r", cmap='RdBu_r',
norm=mpl.colors.LogNorm(), norm=mpl.colors.LogNorm(),
vmax=1.0, vmax=1.,
vmin=0.01, vmin=0.01)
) label = r'$|v_\varphi - v_{kepl}|/v_{kepl}$'
label = r"$|v_\varphi - v_{kepl}|/v_{kepl}$" elif cur_map == 'vaz':
elif cur_map == "vaz": im = P.imshow(fluct_map,
im = P.imshow(fluct_map, extent=im_extent, origin="lower", cmap="RdBu_r") extent=im_extent,
label = r"$v_\varphi / \bar{v_\varphi}$" origin='lower',
elif cur_map == "mach": cmap='RdBu_r')
im = P.imshow(fluct_map, extent=im_extent, origin="lower", cmap="RdBu_r") label = r'$v_\varphi / \bar{v_\varphi}$'
label = r"$|v - \bar{v}| / c_s$" elif cur_map == 'mach':
im = P.imshow(fluct_map,
extent=im_extent,
origin='lower',
cmap='RdBu_r')
label = r'$|v - \bar{v}| / c_s$'
if put_title: if put_title:
P.title(title) P.title(title)
@@ -1163,6 +1146,7 @@ def compare(
all_var = [] all_var = []
all_dmach = [] all_dmach = []
all_beta = []
for i, run in enumerate(runs): for i, run in enumerate(runs):
path_run = path + "/" + run path_run = path + "/" + run
@@ -1198,9 +1182,6 @@ def compare(
var_run.append(fit["var"]) var_run.append(fit["var"])
dmach_run.append(prop_disk["dmach_mean"]) dmach_run.append(prop_disk["dmach_mean"])
all_var = all_var + var_run
all_dmach = all_dmach + dmach_run
nb_outputs = nb_outputs + 1 nb_outputs = nb_outputs + 1
print(run, num, nb_outputs) print(run, num, nb_outputs)
@@ -1218,6 +1199,9 @@ def compare(
var_std[i] = np.std(var_run) var_std[i] = np.std(var_run)
dmach[i] = np.mean(dmach_run) dmach[i] = np.mean(dmach_run)
dmach_std[i] = np.std(dmach_run) dmach_std[i] = np.std(dmach_run)
all_var = all_var + var_run
all_dmach = all_dmach + dmach_run
all_beta = all_beta + [beta[i]]*len(var_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
@@ -1229,10 +1213,10 @@ def compare(
if Q_in_name: if Q_in_name:
Q0[i] = float(run.split("_")[2][1:]) Q0[i] = float(run.split("_")[2][1:])
# Check if the output file exists, and exit if it is the case if pdf:
name_save = path + "/alphaQ_" + nums_name + out_ext all_dmach = np.array(all_dmach)
# if (not force and len(glob.glob(name_save)) !=0): all_var = np.array(all_var)
# return all_beta = np.array(all_beta)
# alpha = f(Qmin) # alpha = f(Qmin)
P.yscale("log") P.yscale("log")
@@ -1279,8 +1263,8 @@ def compare(
P.errorbar(beta, slope, yerr=slope_std, fmt="o") P.errorbar(beta, slope, yerr=slope_std, fmt="o")
P.legend() P.legend()
P.ylabel(r"$d\log\mathcal{P}_N / d\logN$") P.ylabel(r'$d\log\mathcal{P}_\Sigma / d\log\Sigma$')
P.xlabel(r"$\beta$") P.xlabel(r'$\beta$')
(a, b, rho, _, stderr) = linregress(beta, slope) (a, b, rho, _, stderr) = linregress(beta, slope)
P.plot(beta, a * beta + b, "--", linewidth=1.5) P.plot(beta, a * beta + b, "--", linewidth=1.5)
@@ -1298,8 +1282,8 @@ def compare(
P.errorbar(beta, var, yerr=var_std, fmt="o") P.errorbar(beta, var, yerr=var_std, fmt="o")
P.legend() P.legend()
P.ylabel(r"$Var(\log(N / \bar(N))$") P.ylabel(r'$Var(\log(\Sigma / \bar{\Sigma})$')
P.xlabel(r"$\beta$") P.xlabel(r'$\beta$')
(a, b, rho, _, stderr) = linregress(beta, var) (a, b, rho, _, stderr) = linregress(beta, var)
P.plot(beta, a * beta + b, "--", linewidth=1.5) P.plot(beta, a * beta + b, "--", linewidth=1.5)
@@ -1313,17 +1297,33 @@ def compare(
P.close() P.close()
# var = f(log(dmach) # var = f(log(dmach)
mask = all_dmach < 1
all_var = all_var[mask]
all_beta = all_beta[mask]
all_dmach = all_dmach[mask]
P.grid() P.grid()
P.plot(all_dmach, all_var, "o") cmap = mpl.cm.get_cmap('RdYlBu', np.max(beta) - np.min(beta) + 1)
P.scatter(all_dmach, np.exp(all_var), c=all_beta,
vmin=np.min(beta)-0.5,
vmax=np.max(beta)+0.5,
cmap=cmap)
cbar = P.colorbar()
cbar.set_ticks(beta)
cbar.set_label(r'$\beta$')
# P.errorbar(dmach, np.exp(var), xerr=dmach_std, yerr=np.exp(var) * var_std, fmt='+')
P.legend() P.xlabel(r'$<(v - \bar{v}) / c_s>$')
P.xlabel(r"$<(v - \bar{v}) / c_s>$") P.ylabel(r'$\exp(Var(\log(\Sigma / \bar{\Sigma}))$')
P.ylabel(r"$Var(\log(N / \bar(N))$")
P.yscale("log") (a, b, rho, _, stderr) = linregress(all_dmach, np.exp(all_var))
#P.plot(all_dmach, a*all_dmach + b, '--', linewidth=1.5)
print("a=%e, b=%e, rho^2=%e"% (a,b,rho**2))
(a, b, rho, _, stderr) = linregress(dmach, np.exp(var))
# P.plot(all_dmach, a*all_dmach + b, '-.', linewidth=1.5)
print("a=%e, b=%e, rho^2=%e"% (a,b,rho**2))
# (a, b, rho, _, stderr) = linregress(var, log(dmach)
# P.plot(var, a*var + b, '--', linewidth=1.5)
# print("a=%e, b=%e, rho^2=%e"% (a,b,rho**2))
if interactive: if interactive:
P.figure() P.figure()
@@ -1467,11 +1467,12 @@ def evolution(path, nums, force=False, interactive=False, pdf=False):
print(time, slope) print(time, slope)
P.plot(time, slope, "o-.") P.plot(time, slope, "o-.")
P.legend() P.legend()
P.ylabel(r"$d\log\mathcal{P}_{N} / d\logN$") P.ylabel(r'$d\log\mathcal{P}_{\Sigma} / d\log\Sigma$')
P.xlabel(r"time (code)") P.xlabel(r'time (code)')
if interactive: if interactive:
P.figure() P.figure()
else: else:
P.tight_layout(pad=1) P.tight_layout(pad=1)
P.savefig(path + "/dcolslope_time" + out_ext) P.savefig(path + "/dcolslope_time" + out_ext)
P.close() P.close()
+1 -1
View File
@@ -246,7 +246,7 @@ for run in runs:
# If we are here, success ! # If we are here, success !
success = True success = True
run_succeded[run].append(i) run_succeded[run].append(i)
except (ValueError, IOError) as e: except (ValueError, IOError, KeyError) as e:
print(e) print(e)
if args.watch and failures < args.allowed_failures: if args.watch and failures < args.allowed_failures:
failures = failures + 1 failures = failures + 1