-
Notifications
You must be signed in to change notification settings - Fork 0
/
stability_check.py
executable file
·100 lines (83 loc) · 2.19 KB
/
stability_check.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
#!/usr/bin/env python
import sys
import os
import argparse
import glob
import numpy as np
import matplotlib.pyplot as plt
from loadmodules import *
import gadget_snap
from const import rsol, msol
def statility_check(
snapbase="snapshot",
snappath="output",
save="plots",
):
files = glob.glob(os.path.join(snappath, "%s_*.hdf5" % snapbase))
files = np.array([os.path.basename(x) for x in files])
files.sort()
densities = []
times = []
for i, file in enumerate(files):
print("[%d/%d] Processing snapshot %s" % (i, len(files), file))
s = gadget_snap.gadget_snapshot(
os.path.join(snappath, file),
hdf5=True,
quiet=True,
lazy_load=True,
)
times.append(s.time)
densities.append(max(s.data["rho"]))
plt.plot(times, densities)
plt.xlabel("Time(s)")
plt.ylabel("Densitiy (g/ccm)")
plt.grid()
plt.tight_layout()
if not os.path.exists(save):
print("Creating save directory...")
os.mkdir(save)
savefile = os.path.join(save, "statility_check.png")
saved = False
tryed = 0
while not saved:
if os.path.exists(savefile):
tryed += 1
savefile = os.path.join(
save,
"statility_check-(%d).png" % tryed,
)
else:
plt.savefig(
savefile,
dpi=600,
bbox_inches="tight",
)
saved = True
return
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-b",
"--base",
help="Snapshot base name. Default: snapshot",
default="snapshot",
)
parser.add_argument(
"-p",
"--path",
help="Snapshot directory. Default: output",
default="output",
)
parser.add_argument(
"-s",
"--save",
help="Path to directory where plots are saved to. Default: plots",
default="plots",
)
args = parser.parse_args()
statility_check(
snapbase=args.base,
snappath=args.path,
save=args.save,
)
print("Finished creating stability check plot")