-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathplotall.py
More file actions
executable file
·65 lines (53 loc) · 1.78 KB
/
Copy pathplotall.py
File metadata and controls
executable file
·65 lines (53 loc) · 1.78 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
#!/usr/bin/env python3
"""
plots simulation output--a simple example
"""
from argparse import ArgumentParser
from pathlib import Path
import gemini3d
def main():
p = ArgumentParser()
p.add_argument("direc", help="directory to plot")
p.add_argument("--mayavi", help="do 3D Mayavi plots", action="store_true")
p.add_argument("-s", "--saveplots", help="save plots to data directory", action="store_true")
p.add_argument("--only", help="only plot these quantities", nargs="+")
p = p.parse_args()
if p.mayavi:
import gemini3d.vis3d as vis3d
from mayavi.mlab import show
else:
import gemini3d.vis as vis
from matplotlib.pyplot import show
direc = Path(p.direc).expanduser().resolve(strict=True)
if p.saveplots:
from matplotlib.figure import Figure
fg = Figure(constrained_layout=True)
save_dir = direc / "plots"
save_dir.mkdir(parents=True, exist_ok=True)
else:
fg = None
save_dir = None
grid = gemini3d.readgrid(direc)
flist = sorted(direc.glob("*.h5"))
if len(flist) == 0:
flist = sorted(direc.glob("*.dat"))
# %% loop over files / time
for file in flist:
try:
dat = gemini3d.readdata(file)
except Exception as e:
print(f"SKIP: {file} {e}")
continue
if "mlon" in dat and "mlon" not in grid:
grid["mlon"] = dat["mlon"]
grid["mlat"] = dat["mlat"]
if p.mayavi:
vis3d.plotframe(grid, dat, params=p.only, save_dir=save_dir)
else:
vis.plotframe(grid, dat, params=p.only, save_dir=save_dir, fg=fg)
if p.saveplots:
print(f"{dat['time']} => {save_dir}")
else:
show()
if __name__ == "__main__":
main()