diff --git a/postproc/time_series_chiralmhd.py b/postproc/time_series_chiralmhd.py index 6710201..1f85ec1 100644 --- a/postproc/time_series_chiralmhd.py +++ b/postproc/time_series_chiralmhd.py @@ -1,285 +1,293 @@ ################### # plotting script # ################### # import modules import pencil as pc import numpy as np import pylab as plt import matplotlib from matplotlib import rc import matplotlib.text as mtext import matplotlib.transforms as mtransforms import os import sys # latex fonts: from matplotlib import rc from matplotlib import rcParams from mpl_toolkits.axes_grid1 import make_axes_locatable rcParams['text.usetex'] = True rcParams['text.latex.preamble'] = [r'\usepackage{amssymb}'] # colors colors = ['#000075', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf', '#B8B8B8', '#eeeeee'] linestyles = ["-","--","-.",":"] fig, ax = plt.subplots() ax = plt.subplot(111) ######################### # read in time series and parameters: ts_rel = pc.read_ts(filename='time_series.dat', datadir='../chiral_mhd_rel/magnetic_decay/64_3D_kf10_eta1e-2_lambda51e6/data') ts_nonrel = pc.read_ts(filename='time_series.dat', datadir='../chiral_mhd_nonrel/magnetic_decay/64_3D_kf10_eta1e-2_lambda51e6/data') ######################### eta = 1e-2 tteta = 1./eta # ######################### # # read in spectra # os.chdir("../") # pmag = pc.read_power("data/power_mag.dat") # # this are the power spectra at different times # tspecteta = pmag[0]/g.teta # p = pmag[1] # minspec = 0 # maxspec = len(tspecteta) # #incrementspec = round(maxspec/10.,0) # number of spectra we want to plot in equi-distant steps # # reduce timeseries array to spectra # j=0 # jspec = 0 # jspectmp = 0 # urmsspec = [] # urmsspec.append(ts.urms[0]) # for i in range(len(ts.t)): # loop over all elements in time series # jspec = int(round(j*len(tspecteta)/len(tteta))) # corresponding index in spectral array # jspectmpm1 = jspectmp # save the previous jspectmp # # if round(tteta[j],3) == round(tspecteta[jspec],3): # only write something if simulation times are equal (order of 3) # if ((tteta[j]-tspecteta[jspec])**2<0.01): # only write something if simulation times are very equal # jspectmp = jspec # safe the current spectral index # print "index in spectral array =", jspectmp # if jspectmp == jspectmpm1 : # trick to avoid double entries # print "double entry" # else: # urmsspec.append(ts.urms[j]) # write urms # j = j+1 # # if i == len(ts.t) # # ormsspec.append(0) # # urmsspec.append(0) # # find maximum wavenumber # j=0 # kmax = [] # kmax2Olambda = [] # for i in range(maxspec): #Why do I need to substract 1??? # kmax2Olambda.append(2*np.argmax(p[j])/g.lambda5) # kmax.append(np.argmax(p[j])) # j = j+1 # # calculate Rm # j=0 # Rm = [] # for i in range(maxspec): #Why do I need to substract 1??? # if urmsspec[j] == 0. : # Rm.append(0) # else: # Rm.append(urmsspec[j]/(g.eta*kmax[j])) # j = j+1 # os.chdir("postproc") # ######################### # ######################### # # find time when kpeak becomes k1: # jkpk1 = 0 # i=0 # j=0 # for i in range(maxspec): # if kmax[j]-1 == 0: # jkpk1 = j # break # j = j+1 # tspectetakp1 = tspecteta[jkpk1] # # find time when kpeak becomes k1: # jabmin = np.argmin(ts.abm) # ttetaabmin = tteta[jabmin] # ######################### fig, ax = plt.subplots() ax = plt.subplot(111) -plt.axis([1e-10, max([max(ts_nonrel.t),max(ts_rel.t)])/tteta, 1e-10, 1e-1]) +plt.axis([1e-10, max([max(ts_nonrel.t),max(ts_rel.t)])/tteta, 1e-10, 1e2]) plt.ylabel('time series') plt.xlabel('$t/t_\eta$') plt.yscale('log') plt.xscale('log') # plt.axvline(x=tspectetakp1, linestyle="-", color='grey') # plt.axvline(x=ttetaabmin, linestyle=":", color='grey') # x1 = np.logspace(-3.8, -3.2, 100) # plt.plot(x1, 2.05e-7*x1**(-2./3), color='grey') # plt.text(0.000315, 4e-5, '$\propto (t/t_\eta)^{-2/3}$', color='grey') plt.plot(ts_nonrel.t/tteta, ts_nonrel.abm, label="$\langle\mathbf{A}\cdot\mathbf{B} \\rangle$", linestyle=linestyles[0], color=colors[0]) - plt.plot(ts_nonrel.t/tteta, ts_nonrel.brms, label="$\\mathbf{B}_\\mathrm{rms}$", linestyle=linestyles[0], color=colors[1]) plt.plot(ts_nonrel.t/tteta, ts_nonrel.urms, label="$\\mathbf{u}_\\mathrm{rms}$", linestyle=linestyles[0], color=colors[2]) +plt.plot(ts_nonrel.t/tteta, ts_nonrel.mu5rms, + label="$\\mu_\\mathrm{5,rms}$", + linestyle=linestyles[0], color=colors[3]) + plt.plot(ts_rel.t/tteta, ts_rel.abm, # label="$\langle\mathbf{A}\cdot\mathbf{B} \\rangle$", linestyle=linestyles[1], color=colors[0]) plt.plot(ts_rel.t/tteta, ts_rel.brms, # label="$\\mathbf{B}_\\mathrm{rms}$", linestyle=linestyles[1], color=colors[1]) plt.plot(ts_rel.t/tteta, ts_rel.urms, # label="$\\mathbf{u}_\\mathrm{rms}$", linestyle=linestyles[1], color=colors[2]) +plt.plot(ts_rel.t/tteta, ts_rel.mu5rms, +# label="$\\mathbf{u}_\\mathrm{rms}$", + linestyle=linestyles[1], color=colors[3]) + + # plt.scatter(tspecteta, kmax2Olambda, # label='$2 k_\mathrm{p}/\lambda$', # linestyle=linestyles[1], color=colors[1]) # plt.plot(ts.t/g.teta, 2*g.ki/g.lambda5 + ts.t/g.teta*0, # label="$2 k_\mathrm{p,0}/\lambda$", # linestyle=linestyles[0], color=colors[1]) #plt.plot(ts.t/g.teta, 2*ts.mu5m/g.lambda5, # label="$2 \langle\mu_5\\rangle/\lambda$", # linestyle=linestyles[1], color=colors[2]) # plt.plot(ts.t/g.teta, 8*g.eta*ts.brms[0]**2*g.ki*tI*(1-3./4.*(ts.t/tI)**(-1/3)), # label="$8 \\eta B_\\mathrm{rms,0}^2 k_\mathrm{I} (1 - 3 (t/t_\mathrm{I})^{-1/3}/4)$", # linestyle=linestyles[1], color=colors[2]) # plt.scatter(ts.t/g.teta, ts.abm + 2*ts.mu5m/g.lambda5, # label="$\langle\mathbf{A}\cdot\mathbf{B} \\rangle + 2 \langle\mu_5\\rangle/\lambda$", # linestyle=linestyles[1], color=colors[3]) props = dict(boxstyle='round', facecolor=colors[11],edgecolor=colors[10]) # plt.axhline(y=1e-5, xmin=5e-4, xmax=3e-2, color=colors[10], linestyle='-') # plt.annotate( " ", xy = (5e-4, 1e-5), \ # xytext = (4e-3, 1e-5), fontsize = 7, \ # color = colors[10], arrowprops=dict(facecolor=colors[10], edgecolor=colors[10], lw=1.5, arrowstyle = '<|-|>, head_length = 1, head_width = .4')) # plt.annotate( " ", xy = (4e-3, 1e-5), \ # xytext = (3e-2, 1e-5), fontsize = 7, \ # color = colors[10], arrowprops=dict(edgecolor=colors[10], lw=1.5, arrowstyle = '|-|')) # plt.text(2.5e-3, 1e-5, "phase (i)", fontsize=11, # verticalalignment='center', bbox=props) # plt.annotate( " ", xy = (4e-2, 1e-5), \ # xytext = (0.35, 1e-5), fontsize = 7, \ # color = colors[10], arrowprops=dict(edgecolor=colors[10], lw=1.5, arrowstyle = '|-|')) # plt.text(6.7e-2, 1e-5, "phase (ii)", fontsize=11, # verticalalignment='center', bbox=props) # plt.annotate( " ", xy = (0.4, 1e-5), \ # xytext = (1, 1e-5), fontsize = 7, \ # color = colors[10], arrowprops=dict(edgecolor=colors[10], lw=1.5, arrowstyle = '|-|')) # plt.annotate( " ", xy = (1, 1e-5), \ # xytext = (5, 1e-5), fontsize = 7, \ # color = colors[10], arrowprops=dict(facecolor=colors[10], lw=1.5, edgecolor=colors[10], arrowstyle = '<|-|>, head_length = 1, head_width = .4')) # plt.text(6.3e-1, 1e-5, "phase (iii)", fontsize=11, # verticalalignment='center', bbox=props) ######### # # add scaling bar: # class RotationAwareAnnotation2(mtext.Annotation): # def __init__(self, s, xy, p, pa=None, ax=None, **kwargs): # self.ax = ax or plt.gca() # self.p = p # if not pa: # self.pa = xy # kwargs.update(rotation_mode=kwargs.get("rotation_mode", "anchor")) # mtext.Annotation.__init__(self, s, xy, **kwargs) # self.set_transform(mtransforms.IdentityTransform()) # if 'clip_on' in kwargs: # self.set_clip_path(self.ax.patch) # self.ax._add_text(self) # def calc_angle(self): # p = self.ax.transData.transform_point(self.p) # pa = self.ax.transData.transform_point(self.pa) # ang = np.arctan2(p[1]-pa[1], p[0]-pa[0]) # return np.rad2deg(ang) # def _get_rotation(self): # return self.calc_angle() # def _set_rotation(self, rotation): # pass # _rotation = property(_get_rotation, _set_rotation) # tsarray = np.logspace(-3.6, -2.6, 100) # scaling_function = lambda tsarray: 1.9e-7*tsarray**(-2./3) # y = scaling_function(tsarray) # ax.plot(tsarray, y, color='grey', linewidth=0.75) # #ax.set(yscale = 'log', xscale = 'log', ylim=(1e-6, 1e-4), xlim=(1e-5, 0.02), xlabel=r'$x$') # annots= [] # xi=tsarray[len(tsarray)/2] # an = RotationAwareAnnotation2("$\propto (t/t_\eta)^{-2/3}$", # xy=(xi,scaling_function(xi)), p=(xi+.01,scaling_function(xi+.01)), ax=ax, # xytext=(-1,1), textcoords="offset points", # ha="center", va="bottom", color='grey') # annots.append(an) # ######### # rect = patches.Rectangle((1e-3,4e-2),1e-5,2e-5,linewidth=1,edgecolor='r',facecolor='red') # ax.add_patch(rect) # ax.add_patch( # patches.Rectangle( # (1e-3,4e-2), # 1e-5,2e-5, # fill=False # remove background # ) ) plt.legend(loc='lower right') # save figure fig.savefig("time_series_chiralmhd.pdf", bbox_inches='tight')