def fig2_seb(path, fig=None, ax=None, t_start=None): sim = fls.load_sim_for_plot(path, merge_missing_params=True) path_file = os.path.join(path, "spect_energy_budg.h5") f = h5py.File(path_file, "r") k_f = _k_f(sim.params) # eps = _eps(sim, t_start) eps, E, ts, tmax = epsetstmax(path) if t_start is None: t_start = ts imin_plot = _index_where(f["times"][...], t_start) khE = (f["khE"][...] + 0.1) / k_f transfers = 0 for key in ("Tq_AAA", "Tq_GAAs", "Tq_GAAd", "Tq_AGG", "Tq_GGG"): transfers += f[key][imin_plot:].mean(0) / eps Pi_tot = cumsum_inv(transfers) * sim.oper.deltak print(eps) ax.axhline(1.0, color="k", ls=":") ax.set_xlabel("$k/k_f$") ax.set_ylabel(r"$\Pi(k)/\epsilon$") ax.set_xscale("log") ax.set_yscale("linear") ax.plot(khE, Pi_tot, "k", linewidth=2, label=r"$\Pi$") ax.set_ylim([-0.1, 1.1])
def init_df(path): with stdout_redirected(): sim = load_sim(str(path)) # dico_sp = sim.output.spatial_means.load() dico = sim.output.spectra.load2d_mean() kmax = dico["kh"].max() dealias = sim.params.oper.coef_dealiasing ratio = sim.params.preprocess.viscosity_const * np.pi kdiss = kmax / ratio # last_file = sorted(path.glob("state_phys*"))[-1].name kf = _k_f(sim.params) Lf = np.pi / kf eps, E, ts, tmax = epsetstmax(path) c = sim.params.c2**0.5 # Fr = (eps / kf) ** (1./3) / c Fr = (eps * Lf)**(1.0 / 3) / c return { "short name": os.path.basename(path), "kmax": kmax, "kmax_resolved": kmax * dealias, "k_d": kdiss, "kmax_by_kdiss": ratio, "c": c, "$n$": sim.params.oper.nx, "nu": sim.params.nu_2, "visc_const": sim.params.preprocess.viscosity_const, "dealias": dealias, "tmax": float(tmax), "$F_f$": float(Fr), "E": float(E), "$\epsilon$": float(eps), }
def fig_struct_order( path, fig, ax, eps, Fr, order=[2, 4, 6], tmin=10, tmax=1000, delta_t=0.5, key="ux", run_nb=0, label_func=None, coeff=1, ylabel=True, test=False, n_colors=10, ): sim = fls.load_sim_for_plot(path, merge_missing_params=True) rxs, So_var_dict, deltax = _rxs_str_func( sim, order, tmin, tmax, delta_t, [key], cache=test ) for ax1 in ax: ax1.set_xlabel("$r/L_f$") ax1.set_xscale("log") ax1.set_yscale("log") if label_func is None: label_func = _label L_f = np.pi / _k_f(sim.params) # color_list = ['r', 'b', 'g', 'c', 'm', 'y', 'k'] color_list = sns.color_palette(n_colors=n_colors) if coeff == "1/c": coeff = 1 / sim.params.c2 ** 0.5 elif coeff == "c": coeff = sim.params.c2 ** 0.5 for i, (o, ax1) in enumerate(zip(order, ax)): ax1.set_ylabel(label_func(key, o)) key_order = "{0}_{1:.0f}".format(key, o) norm = ( (L_f * Fr ** 0.5) ** (o / 3 - 1) * eps ** (o / 3) * rxs * coeff ** o ) So_var = So_var_dict[key_order] / norm ax1.plot( rxs / L_f, So_var, c=color_list[run_nb], linewidth=1, label=label_func(key, o), ) if o == 2: ax1.set_ylim([1e-1, 8]) ax1.set_xlim([1e-3, 2])
def fig11_ratio_struct(path, fig, ax1, order=[2, 3, 4, 5], tmin=0, tmax=1000, delta_t=0.5): sim = fls.load_sim_for_plot(path, merge_missing_params=True) key_var = ["ux", "uy"] rxs, So_var_dict, deltax = _rxs_str_func(sim, order, tmin, tmax, delta_t, key_var, force_absolute=True) ax1.set_xlabel("$r/L_f$") ax1.set_ylabel("$R_p(r)$") # ax1.set_title('Ratio of longitundinal and transverse struct. functions') ax1.set_xscale("log") ones = pl.ones(rxs.shape) shock_model = { 0: 1.0, 1: pl.pi / 4, 2: 2, 3: 6 * pl.pi / 8, 4: 8.0 / 3, 5: 15.0 * pl.pi / 16, 6: 16.0 / 5, } L_f = pl.pi / _k_f(sim.params) # color_list = ['r', 'b', 'g', 'c', 'm', 'y', 'k'] color_list = iter(sns.color_palette()) for o in order: color1 = next(color_list) # color2 = ':' + color1 So_ux = So_var_dict["{0}_{1:.0f}".format("ux", o)] So_uy = So_var_dict["{0}_{1:.0f}".format("uy", o)] ax1.plot( rxs / L_f, abs(So_ux) / abs(So_uy), c=color1, linewidth=1, label="$R_{:.0f}$".format(o), ) ax1.plot(rxs / L_f, ones * shock_model[int(o)], linestyle=":", c=color1) ax1.set_xlim([0.001, 3]) ax1.set_ylim([0.0, 11]) rev_legend(ax, loc=1, fontsize=9)
def pandas_from_path(p, key, as_df=False): init_field, c, nh, Bu, init_field_const = keyparams_from_path(p) params_xml_path = os.path.join(p, "params_simul.xml") params = ParamContainer(path_file=params_xml_path) # sim = fls.load_sim_for_plot(p, merge_missing_params=True) c = int(c) kf = _k_f(params) Lf = np.pi / kf kd_kf = _k_diss(params) / kf # ts = _t_stationary(path=p) # eps = _eps(t_start=ts, path=p) eps, E, ts, tmax = epsetstmax(p) efr = params.preprocess.init_field_const if params.nu_2 > 0: Re = eps**(1 / 3) * Lf**(4 / 3) / params.nu_2 else: Re = np.nan # defined differently Fr = (eps * Lf)**(1.0 / 3) / c try: Ro = (eps / Lf**2)**(1.0 / 3) / params.f except ZeroDivisionError: Ro = np.inf minh = 0 maxuc = 0 # del sim gc.collect() data = [ nh, c, params.nu_8, params.nu_2, params.f, eps, kd_kf, Fr, Ro, Re, Re * Fr**(2 / 3), Bu, # minh, maxuc, efr, E, ts, tmax, key, ] if as_df: return pd.DataFrame(data, columns=pd_columns) else: return pd.Series(data, index=pd_columns)
def fig_phys_subplot( sim, fig, ax, key_field, x_slice=None, y_slice=None, cmap="inferno", vmin=None, vmax=None, ): kf = _k_f(sim.params) Lf = np.pi / kf X = sim.oper.x_seq / Lf Y = sim.oper.y_seq / Lf def slice_where(R, r1, r2): i1 = _index_where(R, r1) i2 = _index_where(R, r2) return slice(i1, i2) if x_slice is not None: x_slice = slice_where(X, *x_slice) X = X[x_slice] if y_slice is not None: y_slice = slice_where(Y, *y_slice) Y = Y[y_slice] try: field = sim.state.get_var(key_field) except ValueError: field = sim.oper.ifft(sim.state.get_var(key_field + "_fft")) field = field[y_slice, x_slice] cmap = plt.get_cmap(cmap) ax.set_xlabel("$x/L_f$") ax.set_ylabel("$y/L_f$") ax.set_rasterization_zorder(1) norm = None contours = ax.pcolormesh(X, Y, field, norm=norm, vmin=vmin, vmax=vmax, cmap=cmap, zorder=0) cbar = fig.colorbar(contours, ax=ax) cbar.solids.set_rasterized(True)
def fig7_spectra(path, fig, ax, Fr, c, t_start, run_nb, n_colors=10): sim = fls.load_sim_for_plot(path, merge_missing_params=True) kh, E_tot, EK, EA = _mean_spectra(sim, t_start) eps = _eps(sim, t_start) k_f = _k_f(sim.params) # norm = (kh ** (-2) * # sim.params.c2 ** (1. / 6) * # eps ** (5. / 9) * # k_f ** (4. / 9)) o = 2 L_f = pl.pi / k_f norm = (L_f * Fr**0.5)**(o / 3 - 1) * eps**(o / 3) * kh**-2 color_list = sns.color_palette(n_colors=n_colors) kh_f = kh / k_f ax.plot( kh_f, E_tot / norm, # "k", c=color_list[run_nb], # c="k", # linestyle=next(style), linewidth=1, label=f"$c = {c}$", ) # ax.plot(kh_f, EK / norm, 'r', linewidth=2, label='$E_K$') # ax.plot(kh_f, EA / norm, 'b', linewidth=2, label='$E_A$') if run_nb == 0: s1 = slice(_index_where(kh_f, 3), _index_where(kh_f, 80)) s2 = slice(_index_where(kh_f, 30), _index_where(kh_f, 200)) ax.plot((kh_f)[s1], 0.7 * (kh_f**-2 / norm)[s1], "k-", linewidth=1) ax.text(10, 0.2, "$k^{-2}$") # ax.plot((kh_f)[s2], (kh_f ** -1.5 / norm)[s2], 'k-', linewidth=1) # ax.text(70, 1.5, '$k^{-3/2}$') ax.set_xscale("log") ax.set_yscale("log") ax.set_xlabel("$k/k_f$") ax.set_ylabel(_label()) # ax.legend() rev_legend(ax, loc=1, fontsize=8) fig.tight_layout()
def fig2_seb(path, fig=None, ax=None, t_start=None): sim = fls.load_sim_for_plot(path, merge_missing_params=True) path_file = os.path.join(path, "spect_energy_budg.h5") f = h5py.File(path_file, "r") k_f = _k_f(sim.params) # eps = _eps(sim, t_start) eps, E, ts, tmax = epsetstmax(path) if t_start is None: t_start = ts imin_plot = _index_where(f["times"][...], t_start) khE = (f["khE"][...] + 0.1) / k_f transferEKr = f["transfer2D_EKr"][imin_plot:].mean(0) / eps transferEKd = f["transfer2D_EKd"][imin_plot:].mean(0) / eps transferEAr = f["transfer2D_EAr"][imin_plot:].mean(0) / eps transferEAd = f["transfer2D_EAd"][imin_plot:].mean(0) / eps # transferEPd = f['transfer2D_EPd'][imin_plot:].mean(0) / eps PiEKr = cumsum_inv(transferEKr) * sim.oper.deltak PiEKd = cumsum_inv(transferEKd) * sim.oper.deltak PiEAr = cumsum_inv(transferEAr) * sim.oper.deltak PiEAd = cumsum_inv(transferEAd) * sim.oper.deltak # PiEPd = cumsum_inv(transferEPd) * sim.oper.deltak print(eps) ax.axhline(1.0, color="k", ls=":") PiEK = PiEKr + PiEKd PiEA = PiEAr + PiEAd PiE = PiEK + PiEA ax.set_xlabel("$k/k_f$") ax.set_ylabel(r"$\Pi(k)/\epsilon$") ax.set_xscale("log") ax.set_yscale("linear") ax.plot(khE, PiE, "k", linewidth=2, label=r"$\Pi$") ax.plot(khE, PiEK, "r:", linewidth=2, label=r"$\Pi_K$") ax.plot(khE, PiEA, "b--", linewidth=2, label=r"$\Pi_A$") ax.set_ylim([-0.1, 1.1]) ax.legend()
def fig1_energy( paths, fig=None, ax=None, t_start=0.0, legend=None, linestyle=None, normalized=False, ): # fig.subplots_adjust(right=0.78) if legend is None: legend = [os.path.basename(p) for p in paths] for i, path in enumerate(paths): # with stdout_redirected(): sim = fls.load_sim_for_plot(path, merge_missing_params=True) P0 = _eps(sim, t_start) k_f = _k_f(sim.params) # path + '/params_simul.xml') L_f = pl.pi / k_f dico = sim.output.spatial_means.load() E = dico["E"] t = dico["t"] if normalized: E_f = (P0 * L_f) ** (2.0 / 3) T_f = (P0 / L_f ** 2) ** (-1.0 / 3) E = E / E_f t = t / T_f print( "{}\teps={}\tk_f={}\tE_f={}\tT_f={}".format( label, P0, k_f, E_f, T_f ) ) label = legend[i] ax.plot(t, E, linestyle, linewidth=1.0, label=label)
def fig12_flatness( path, fig, ax, tmin=0, tmax=1000, delta_t=0.5, key_var=("uy", "ux"), run_nb=0, ax_inset=None, cache=False, n_colors=10, ): sim = fls.load_sim_for_plot(path, merge_missing_params=True) order = [2, 4] rxs, So_var_dict, deltax = _rxs_str_func( sim, order, tmin, tmax, delta_t, key_var, cache=cache ) ax.set_xlabel("$r/L_f$") # ax.set_ylabel('$F_T, F_L$') # ax.set_title('Flatness of longitundinal and transverse increments') # ax.hold(True) ax.set_xscale("log") ax.set_yscale("log") _label = {"ux": "F_L", "uy": "F_T"} L_f = pl.pi / _k_f(sim.params) # color_list = ['r', 'b', 'g', 'c', 'm', 'r', 'b'] color_list = sns.color_palette(n_colors=n_colors) def get_F(key): So_4 = So_var_dict["{0}_{1:.0f}".format(key, 4)] So_2 = So_var_dict["{0}_{1:.0f}".format(key, 2)] return So_4 / So_2 ** 2 if len(key_var) == 1: key = key_var[0] F = get_F(key) label = _label[key] # r^-1 line cond = pl.logical_and(rxs > 0.015 * L_f, rxs < 0.17 * L_f) fac = 12 ax.plot(rxs[cond] / L_f, fac / rxs[cond], "k", linewidth=0.5) x_text = rxs[cond].mean() / 2 / L_f + 0.02 y_text = fac / rxs[cond].mean() * 2 ax.text(x_text, y_text, "$r^{-1}$") else: F = np.divide(*map(get_F, key_var)) print("F=", F.shape) label = f"{_label[key_var[0]]}/{_label[key_var[1]]}" label = f"${label}$" color1 = color_list[run_nb] ax.plot(rxs / L_f, F, c=color1, linewidth=1, label=label) if ax_inset is not None: ax_inset.semilogx( rxs / L_f, get_F("uy") / get_F("ux"), color_list[run_nb], linewidth=1 )
for t in range(10, 26): _df = pd.read_csv( # "dataframes/shock_sep_laplacian_nupt1.csv", f"dataframes/shock_sep_laplacian_nupt1_by_counting_t{t}.csv", comment="#", ) _dfs.append(_df.set_index("short_name")) _df_concat = pd.concat(_dfs, keys=range(10, 26)) df_shock_sep = _df_concat.groupby(level=1).mean() df_shock_sep df_shock_sep.to_csv("dataframes/shock_sep_laplacian_nupt1_by_counting_mean.csv") sim = fs.load_sim_for_plot(paths_sim[df_shock_sep.iloc[0].name]) Lf = np.pi / _k_f(sim.params) df["shock separation"] = df_shock_sep["mean"] / Lf df.head() df["shock separation"] = df_shock_sep["mean"] / Lf df.head() matplotlib_rc(11) fig, ax = plt.subplots(figsize=(5, 3)) mark = markers() for n, grp in df.groupby("$n$"): ax.scatter( r"$F_f$", "shock separation",
def fig3_struct(path, fig, ax1, tmin=0, tmax=1000): sim = fls.load_sim_for_plot(path, merge_missing_params=True) path_file = os.path.join(path, "increments.h5") f = h5py.File(path_file, "r") dset_times = f["times"] times = dset_times[...] if tmax is None: tmax = times.max() rxs = f["rxs"][...] oper = f["/info_simul/params/oper"] nx = oper.attrs["nx"] Lx = oper.attrs["Lx"] deltax = Lx / nx rxs = pl.array(rxs, dtype=pl.float64) * deltax imin_plot = pl.argmin(abs(times - tmin)) imax_plot = pl.argmin(abs(times - tmax)) S_uL2JL = f["struc_func_uL2JL"][imin_plot:imax_plot + 1].mean(0) S_uT2JL = f["struc_func_uT2JL"][imin_plot:imax_plot + 1].mean(0) S_c2h2uL = f["struc_func_c2h2uL"][imin_plot:imax_plot + 1].mean(0) S_Kolmo = f["struc_func_Kolmo"][imin_plot:imax_plot + 1].mean(0) # S_uT2uL = f['struc_func_uT2uL'][imin_plot:imax_plot + 1].mean(0) eps = _eps(sim, tmin) S_Kolmo_theo = -4 * eps * rxs Lf = pl.pi / _k_f(sim.params) ax1.set_xscale("log") ax1.set_yscale("linear") # ax1.plot(rxs / Lf, # (S_uL2JL+S_uT2JL+S_c2h2uL)/S_Kolmo_theo, # 'y', linewidth=1, label='sum check') def _label(x, y): pre = "" if y == "uu": y = r"\mathbf{u}" y2 = r"|\delta {}|^2".format(y) else: if y == "h": pre = "c ^ 2" y2 = r"(\delta {})^2".format(y) return "$ -\langle {} \delta {} {} \\rangle $".format(pre, x, y2) ax1.set_xlabel("$r/L_f$") label1 = _label("J_L", "uu") label2 = _label("u_L", "h") label3 = label1[:-10] + " + " + label2[10:] def label_norm(label): str_norm = " / (4\epsilon r)$" return label.rstrip(" $") + str_norm ax1.set_ylabel(label_norm(label3)) ax1.plot(rxs / Lf, S_Kolmo / S_Kolmo_theo, "k", linewidth=2, label=(label3)) ax1.plot( rxs / Lf, (S_uL2JL + S_uT2JL) / S_Kolmo_theo, "r:", linewidth=2, label=(label1), ) ax1.plot(rxs / Lf, S_c2h2uL / S_Kolmo_theo, "b--", linewidth=2, label=(label2)) # ax1.plot(rxs / Lf, S_uL2JL / S_Kolmo_theo, # 'r--', linewidth=2, label=_label('J_L', 'u_L')) # ax1.plot(rxs / Lf, S_uT2JL / S_Kolmo_theo, # 'r-.', linewidth=2, label=_label('J_L', 'u_T')) # cond = rxs < 6 * deltax # ax1.plot(rxs[cond] / Lf, 1.e0 * rxs[cond] ** 3 / S_Kolmo_theo[cond], # 'y', linewidth=2, label='$r^3/S; r<6dx$') ax1.axhline(1.0, color="k", ls=":") # ax1.plot(rxs, pl.ones(rxs.shape), 'k:', linewidth=1) ax1.set_xlim([None, 2]) ax1.set_ylim([-0.1, 1.1]) ax1.legend(loc=8)