2import matplotlib.pyplot
as plt
14rho_c0_value=1.8788*10**(-26)
18 with open(fname)
as f:
19 for i, l
in enumerate(f):
27parser = argparse.ArgumentParser(description=
'Tracer_conversion')
28parser.add_argument(
"-if",
"--input-file", dest=
"file_name", required=
"True", type=str, help=
"input csv file name from paraview(and directory)" )
29parser.add_argument(
"-pq",
"--plot-quantity", dest=
"pq", default=
"rho", type=str, choices=[
"rho",
"v_x",
"v_y",
"v_z",
"E_t",
"P"], help=
"choose the quantity you want to plot" )
30parser.add_argument(
"-rescale",
"--rescale", dest=
"IfRescale", action=
"store_true", default=
False, help=
"if you need the rescaling using turnaround quantites" )
31parser.add_argument(
"-ylog",
"--yscale-log", dest=
"Ifylog", action=
"store_true", default=
False, help=
"if you need the plot with y axis in log scale" )
32parser.add_argument(
"-XUcode",
"--x-code-unit", dest=
"IfXunitInCode", action=
"store_true", default=
False, help=
"enable this option, if you want the plot in code unit for distance (the default one is in physical unit)" )
33parser.add_argument(
"-Xrescale",
"--x-rescale", dest=
"IfXRescale", action=
"store_true", default=
False, help=
"enable this option, if you want the x axis also get rescaled to lambda in Bertschinger, 1985. conflict with XUcode" )
34parser.add_argument(
"-RawD",
"--raw-data", dest=
"IfRawData", action=
"store_true", default=
False, help=
"enable this option, if you want the plot of the raw data (in code unit)" )
35args = parser.parse_args()
37IfXunitInCode=args.IfXunitInCode
50m_1 = [[]]; m_2 = [[]]; m_3 = [[]];
54 f=open(
"para_"+
str(snap)+
".csv")
55 print(
"Read in datafile: "+
"para_"+
str(snap)+
".csv")
62 tem=list(map(float,line.split(
',')))
63 if math.isnan(tem[1]):
65 coor[snapshot].append(tem[7]); rho[snapshot].append(tem[1]);
66 m_1[snapshot].append(tem[2]); m_2[snapshot].append(tem[3]); m_3[snapshot].append(tem[4]);
67 E_t[snapshot].append(tem[5]);
69 print(
"sample points received:", len(rho[snapshot]),
"for snapshot code time t=", snap)
71 rho.append([]);coor.append([])
72 m_1.append([]);m_2.append([]);m_3.append([])
78sample_point=len(rho[0])
79origin_point=int(sample_point/2)+1
83for snapshot
in range(len(snapshots)):
92 coor_data=np.array(coor[snapshot])
94 e_data = np.array(E_t[snapshot])
95 m1_data = np.array(m_1[snapshot])
96 m2_data = np.array(m_2[snapshot])
97 m3_data = np.array(m_3[snapshot])
98 rho_data = np.array(rho[snapshot])
100 q_data=np.array(rho[snapshot])
102 q_data=np.array(m_1[snapshot])
104 q_data=np.array(m_2[snapshot])
106 q_data=np.array(m_3[snapshot])
108 q_data=np.array(E_t[snapshot])
109 if q_id
in [
"v_x",
"v_y",
"v_z"]:
110 rho_data=np.array(rho[snapshot])
116 if not args.IfRawData:
117 t_code=snapshots[snapshot]
118 t_real=(0.1694*a_i**(-0.5)-t_code/11.8)**(-3)*10**15
119 a_scale=0.0287*(0.1694*a_i**(-0.5)-t_code/11.8)**(-2)
120 print(
"cosmological time:", t_real)
121 print(
"a_scale:", a_scale)
123 coor_data_physical=100*a_scale*coor_data
125 if q_id
in [
"v_x",
"v_y",
"v_z"]:
126 q_id_show=
"$"+q_id+
"/(km/s)$"
127 q_data=np.array(q_data)/np.array(rho_data)
128 q_data=q_data*10**4/a_scale
129 v_hubble=100*(2.057*10**17/t_real)*coor_data_physical
130 q_data=q_data+v_hubble
132 q_id_show=
r"$\rho/\rho_c $"
133 q_data=q_data/(a_scale**3)
136 q_data=(5/3-1)*(e_data-0.5*(m1_data**2+m2_data**2+m3_data**2)/rho_data)
137 q_data=q_data*10**(8+6)*rho_c0_value/(a_scale**5)
139 q_id_show=
"$"+q_id+
"/(Code Unit)"
144 r_ta=a_i*100*3.086*1e19*((3*M)/(4*pi*rho_c_ini))**(1/3)*(4/3/pi)**(8/9)*(t_real/6.505/1e12)**(8/9)
147 q_data=q_data*rho_c0_value
148 rho_scaling=1/(6*pi*G*t_real**2)
149 q_data=q_data/rho_scaling
150 q_id_show=
r"$\rho/\rho_{ta}(t) $"
151 if q_id
in [
"v_x",
"v_y",
"v_z"]:
153 v_scaling=r_ta/t_real
154 q_data=q_data/v_scaling
155 q_id_show=
r"$u/u_{ta}(t) $"
156 print(
"scaling velocity (km/s):", v_scaling)
158 rho_scaling=1/(6*pi*G*t_real**2)
159 P_scaling=rho_scaling*r_ta**2*1e6/(t_real**2)
160 q_data=q_data/P_scaling
161 q_id_show=
r"$P/P_{ta}(t) $"
164 plt.plot(coor_data[origin_point:],q_data[origin_point:],label=
"t= "+
str(t_code)+
" a= "+
str(a_scale))
165 elif args.IfXRescale:
166 plt.plot(np.log10(coor_data_physical[origin_point:]*3.086*1e19/r_ta),q_data[origin_point:],label=
"t= "+
str(t_code)+
" a= "+
str(a_scale))
168 plt.plot(coor_data_physical[origin_point:],q_data[origin_point:],label=
"t= "+
str(t_code)+
" a= "+
str(a_scale))
174 t_code=snapshots[snapshot]
175 a_scale=0.0287*(0.1694*a_i**(-0.5)-t_code/11.8)**(-2)
176 if q_id
in [
"v_x",
"v_y",
"v_z"]:
177 q_data=np.array(q_data)/np.array(rho_data)
179 q_data=(5/3-1)*(e_data-0.5*(m1_data**2+m2_data**2+m3_data**2)/rho_data)
181 q_id_show=
"$"+q_id+
"/(Code Unit)$"
182 plt.plot(coor_data[origin_point:],q_data[origin_point:],label=
"t= "+
str(t_code)+
" a= "+
str(a_scale))
187 plt.xlabel(
"$x/(Code Unit)$")
189 plt.xlabel(
r"$Log_{10}\lambda$")
191 plt.xlabel(
"$x/(h^{-1}Mpc)$")