-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.plot_field.py
More file actions
executable file
·241 lines (215 loc) · 9.68 KB
/
06.plot_field.py
File metadata and controls
executable file
·241 lines (215 loc) · 9.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 15 15:54:16 2023
@author: chingchen
"""
import stagpy
import numpy as np
from stagpy import field
from stagpy import stagyydata
import matplotlib.pyplot as plt
model = 'kvar_a0101'
# model = 'h13'
path = '/Users/chingchen/Desktop/data/'
# path = '/lfs/jiching/ScalingLaw_model/23summer/'
#path = '/lfs/jiching/thermo_chemical/'
path = '/lfs/jiching/thermal_conductivity/'
# path = '/Users/chingchen/Desktop/model/'
# figpath = '/Users/chingchen/Desktop/figure/'
figpath = '/lfs/jiching/figure/'
data = stagyydata.StagyyData(path+model)
plotting_3field = 0
plotting_Tv = 0
plotting_T = 0
plotting_bs = 0
plotting_prim = 1
gif = 1
mp4 = 1
end = 300
if plotting_3field:
for shot in range(end-2,end):
kk1,kk2,kk3,kk4 = field.get_meshes_fld(data.snaps[shot],'T')
bs1,bs2,bs3,bs4 = field.get_meshes_fld(data.snaps[shot],'bs')
prim1,prim2,prim3,prim4 = field.get_meshes_fld(data.snaps[shot],'prim')
kk1 = np.concatenate((kk1, kk1[:1]), axis=0)
kk2 = np.concatenate((kk2, kk2[:1]), axis=0)
newline = (kk3[:1] + kk3[-1:]) / 2
kk3 = np.concatenate((kk3, newline), axis=0)
newline = (bs3[:1] + bs3[-1:]) / 2
bs3 = np.concatenate((bs3, newline), axis=0)
newline = (prim3[:1] + prim3[-1:]) / 2
prim3 = np.concatenate((prim3, newline), axis=0)
fig,(ax,ax2,ax3) = plt.subplots(1,3,figsize=(12,4))
ax.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax.pcolormesh(kk1,kk2,kk3,cmap = cmap, vmin = 0,vmax = 1)
ax.axis('off')
cax = plt.axes([0.165, 0.05, 0.15, 0.05])
cc1=fig.colorbar(colorbar, ax=ax,cax=cax,orientation='horizontal')
cc1.ax.tick_params(labelsize=20)
cc1.set_label(label='Temperature', size=25)
cc1.ax.yaxis.set_label_position('left')
ax.set_title(model+' at time '+str(shot/1000),fontsize = 26)
ax2.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax2.pcolormesh(kk1,kk2,bs3,cmap = cmap, vmin = 0,vmax = 1)
ax2.axis('off')
cax = plt.axes([0.445, 0.05, 0.15, 0.05])
cc2=fig.colorbar(colorbar, ax=ax2,cax=cax,orientation='horizontal')
cc2.ax.tick_params(labelsize=20)
cc2.set_label(label='Basalt', size=25)
ax3.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax3.pcolormesh(kk1,kk2,prim3,cmap = cmap, vmin = 0,vmax = 1)
ax3.axis('off')
cax = plt.axes([0.72, 0.05, 0.15, 0.05])
cc3=fig.colorbar(colorbar, ax=ax3,cax=cax,orientation='horizontal')
cc3.set_label(label='Primordial Material', size=25)
cc3.ax.tick_params(labelsize=20)
fig.savefig(figpath+model+'_'+'snapshot_'+str(shot)+'_3field.png')
fig.gca()
plt.close(fig)
if plotting_Tv:
print('plotting')
for shot in range(1,end):
kk1,kk2,kk3,kk4 = field.get_meshes_fld(data.snaps[shot],'T')
eta1,eta2,eta3,eta4 = field.get_meshes_fld(data.snaps[shot],'eta')
fig,(ax,ax2) = plt.subplots(1,2,figsize=(8,5))
ax.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax.pcolormesh(kk1,kk2,kk3,cmap = cmap, vmin = 0,vmax = 1)
ax.axis('off')
cax = plt.axes([0.157, 0.15, 0.3, 0.05])
cc1=fig.colorbar(colorbar, ax=ax,cax=cax,orientation='horizontal')
cc1.ax.tick_params(labelsize=15)
cc1.set_label(label='Temperature', size=15)
cc1.ax.yaxis.set_label_position('left')
ax.set_title(model+' at time '+str(shot/1000),fontsize = 26)
ax2.set_aspect('equal')
cmap = plt.cm.get_cmap('rainbow')
colorbar = ax2.pcolormesh(kk1,kk2,np.log10(eta3),cmap = cmap, vmin = -2.5,vmax = 2.5)
ax2.axis('off')
cax = plt.axes([0.585, 0.15, 0.30, 0.05])
cc2=fig.colorbar(colorbar, ax=ax2,cax=cax,orientation='horizontal')
cc2.ax.tick_params(labelsize=15)
cc2.set_label(label='Viscosity', size=15)
fig.savefig(figpath+model+'_'+'snapshot_'+str(shot)+'_field.png')
fig.gca()
plt.close(fig)
if plotting_T:
for shot in range(1,end):
kk1,kk2,kk3,kk4 = field.get_meshes_fld(data.snaps[shot],'T')
### Cause the mesh lack one column,
### need to concatenate it for xmesh, ymseh and field
kk1 = np.concatenate((kk1, kk1[:1]), axis=0)
kk2 = np.concatenate((kk2, kk2[:1]), axis=0)
newline = (kk3[:1] + kk3[-1:]) / 2
kk3 = np.concatenate((kk3, newline), axis=0)
# normalized the field to [0-1]
#nor_kk3=(kk3-np.min(kk3))/(np.max(kk3)-np.min(kk3))
### plot begin
fig,(ax) = plt.subplots(1,figsize=(13,13))
ax.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax.pcolormesh(kk1,kk2,kk3,cmap = cmap, vmin = 0,vmax = 1)
ax.axis('off')
ax.set_title(model+' at time '+str(shot/1000),fontsize = 12)
cax = plt.axes([0.93, 0.285, 0.01, 0.431])
cbar = plt.colorbar(colorbar, cax=cax)
cbar.set_label(label = 'Temperature',size=12)
fig.savefig(figpath+model+'_'+'temperature_snapshot_'+str(shot)+'_field.png')
print('save figure '+model+'_'+'temperature_snapshot_'+str(shot)+'_field.png')
fig.gca()
plt.close(fig)
if plotting_bs:
for shot in range(1,end):
kk1,kk2,kk3,kk4 = field.get_meshes_fld(data.snaps[shot],'bs')
### Cause the mesh lack one column,
### need to concatenate it for xmesh, ymseh and field
kk1 = np.concatenate((kk1, kk1[:1]), axis=0)
kk2 = np.concatenate((kk2, kk2[:1]), axis=0)
newline = (kk3[:1] + kk3[-1:]) / 2
kk3 = np.concatenate((kk3, newline), axis=0)
# normalized the field to [0-1]
nor_kk3=(kk3-np.min(kk3))/(np.max(kk3)-np.min(kk3))
### plot begin
fig,(ax) = plt.subplots(1,figsize=(13,13))
ax.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax.pcolormesh(kk1,kk2,nor_kk3,cmap = cmap, vmin = 0,vmax = 1)
ax.axis('off')
ax.set_title(model+' at time '+str(shot/1000),fontsize = 12)
cax = plt.axes([0.93, 0.285, 0.01, 0.431])
cbar = plt.colorbar(colorbar, cax=cax)
cbar.set_label(label = 'Basalt',size=12)
fig.savefig(figpath+model+'_'+'basalt_snapshot_'+str(shot)+'_field.png')
print('save figure '+model+'_'+'basalt_snapshot_'+str(shot)+'_field.png')
fig.gca()
plt.close(fig)
if plotting_prim:
for shot in range(1,end):
kk1,kk2,kk3,kk4 = field.get_meshes_fld(data.snaps[shot],'prim')
### Cause the mesh lack one column,
### need to concatenate it for xmesh, ymseh and field
kk1 = np.concatenate((kk1, kk1[:1]), axis=0)
kk2 = np.concatenate((kk2, kk2[:1]), axis=0)
newline = (kk3[:1] + kk3[-1:]) / 2
kk3 = np.concatenate((kk3, newline), axis=0)
# normalized the field to [0-1]
nor_kk3=(kk3-np.min(kk3))/(np.max(kk3)-np.min(kk3))
### plot begin
fig,(ax) = plt.subplots(1,figsize=(13,13))
ax.set_aspect('equal')
cmap = plt.cm.get_cmap('RdBu_r')
colorbar = ax.pcolormesh(kk1,kk2,nor_kk3,cmap = cmap, vmin = 0,vmax = 1)
ax.axis('off')
ax.set_title(model+' at time '+str(shot/1000),fontsize = 12)
cax = plt.axes([0.93, 0.285, 0.01, 0.431])
cbar = plt.colorbar(colorbar, cax=cax)
cbar.set_label(label = 'Primordial Material',size=12)
fig.savefig(figpath+model+'_'+'primordial_snapshot_'+str(shot)+'_field.png')
print('save figure '+model+'_'+'primordial_snapshot_'+str(shot)+'_field.png')
fig.gca()
plt.close(fig)
#-----------------------------creat GIF-----------------------------------------
if gif:
from PIL import Image
frames = []
for shot in range(1,end):
img=figpath+model+'_'+'temperature_snapshot_'+str(shot)+'_field.png'
new_frame = Image.open(img)
frames.append(new_frame)
frames[0].save(figpath+'temperature_png2gif.gif', format='GIF', append_images=frames[1:],
save_all=True, duration=40, loop=0)
# frames = []
# for shot in range(1,end):
# img=figpath+model+'_'+'basalt_snapshot_'+str(shot)+'_field.png'
# new_frame = Image.open(img)
# frames.append(new_frame)
# frames[0].save(figpath+'basalt_png2gif.gif', format='GIF', append_images=frames[1:],
# save_all=True, duration=40, loop=0)
frames = []
for shot in range(1,end):
img=figpath+model+'_'+'primordial_snapshot_'+str(shot)+'_field.png'
new_frame = Image.open(img)
frames.append(new_frame)
frames[0].save(figpath+'primordial_png2gif.gif', format='GIF', append_images=frames[1:],
save_all=True, duration=40, loop=0)
# for shot in range(1,2001,5):
# img=figpath+model+'_'+'snapshot_'+str(shot)+'_3field.png'
# new_frame = Image.open(img)
# frames.append(new_frame)
# frames[0].save(figpath+'png_to_gif4.gif', format='GIF', append_images=frames[1:],
# save_all=True, duration=40, loop=0)
#-----------------------------creat mp4-----------------------------------------
if mp4:
import moviepy.editor as mp
clip = mp.VideoFileClip(figpath+'temperature_png2gif.gif')
clip.write_videofile(figpath+'temperature_field_'+model+".mp4")
# clip = mp.VideoFileClip(figpath+'basalt_png2gif.gif')
# clip.write_videofile(figpath+'basalt_field_'+model+".mp4")
clip = mp.VideoFileClip(figpath+'primordial_png2gif.gif')
clip.write_videofile(figpath+'primordial_field_'+model+".mp4")
# clip = mp.VideoFileClip(figpath+'png_to_gif4.gif')
# clip.write_videofile(figpath+'3fieldStagYY'+model+".mp4")