-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_snapshots.py
107 lines (81 loc) · 2.85 KB
/
draw_snapshots.py
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
def plot_single(in_file, zfunc, zname, out_file):
import pylab
import numpy
import h5py
from matplotlib.collections import PolyCollection
import matplotlib as mpl
import matplotlib.pyplot as plt
import os
if os.path.isfile(out_file):
return
print(out_file)
with h5py.File(in_file,'r+') as f:
vert_idx_list = numpy.concatenate(([0],
numpy.cumsum(f['Number of vertices in cell'])))
verts = []
for i in range(len(f['density'])):
lowbound = int(vert_idx_list[i])
upbound = int(vert_idx_list[i+1])
verts.append([[x,y] for x,y
in zip(f['x position of vertices'][lowbound:upbound],
f['y position of vertices'][lowbound:upbound])])
coll = PolyCollection(verts,
array=zfunc(f),
cmap = mpl.cm.jet,
edgecolors = 'none')
fig, ax = plt.subplots()
fig.suptitle(zname+' @ t = '+str(numpy.array(f['time'])[0]))
ax.add_collection(coll)
ax.autoscale_view()
ax.set_aspect('equal')
fig.colorbar(coll,ax=ax)
print(out_file)
if out_file==None:
plt.show()
else:
plt.savefig(out_file)
plt.clf()
fig.clf()
def plot_all(zfunc, zname):
import glob
import numpy
import joblib
flist = glob.glob('snapshot_*.h5')
joblib.Parallel(n_jobs=8)(joblib.delayed(plot_single)
(fname,
zfunc,
zname,
fname.replace('snapshot',zname).replace('.h5','.png')) for fname in flist)
#[plot_single(fname,zfunc,zname,
# fname.replace('snapshot',zname).replace('.h5','.png'))
# for fname in flist]
def log10_number_density_cgs(f):
import numpy
parsec2cm = 3.08e18
solar_mass2g = 1.9891e33
density_scale = solar_mass2g/parsec2cm**3
proton_mass_g = 1.67e-24
return numpy.log10(numpy.array(f['density'])*density_scale/proton_mass_g)
def log10_temperature(f):
import numpy
return numpy.log10(f['temperature'])
def x_velocity(f):
import numpy
return numpy.array(f['x_velocity'])
def y_velocity(f):
import numpy
return numpy.array(f['y_velocity'])
def main():
import matplotlib
matplotlib.use('Agg')
import numpy
#plot_single('snapshot_405.h5',
# log10_temperature,
# 'log10_temperature',
# 'log10_temperature_405.png')
plot_all(log10_number_density_cgs, 'log10_number_density')
plot_all(log10_temperature, 'log10_temperature')
plot_all(x_velocity, 'x_velocity')
plot_all(y_velocity, 'y_velocity')
if __name__ == '__main__':
main()