-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[original]_plot_rb.py
More file actions
78 lines (63 loc) · 2.37 KB
/
[original]_plot_rb.py
File metadata and controls
78 lines (63 loc) · 2.37 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
"""
Plot 2D cartesian snapshots.
Usage:
plot_snapshots.py <files>... [--output=<dir>]
Options:
--output=<dir> Output directory [default: ./frames]
"""
import h5py
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from dedalus.extras import plot_tools
def main(filename, start, count, output):
"""Save plot of specified tasks for given range of analysis writes."""
# Plot settings
tasks = ['buoyancy', 'vorticity']
scale = 1.5
dpi = 200
title_func = lambda sim_time: 't = {:.3f}'.format(sim_time)
savename_func = lambda write: 'write_{:06}.png'.format(write)
# Layout
nrows, ncols = 2, 1
image = plot_tools.Box(4, 1)
pad = plot_tools.Frame(0.3, 0, 0, 0)
margin = plot_tools.Frame(0.2, 0.1, 0, 0)
# Create multifigure
mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale)
fig = mfig.figure
# Plot writes
with h5py.File(filename, mode='r') as file:
for index in range(start, start+count):
for n, task in enumerate(tasks):
# Build subfigure axes
i, j = divmod(n, ncols)
axes = mfig.add_axes(i, j, [0, 0, 1, 1])
# Call 3D plotting helper, slicing in time
dset = file['tasks'][task]
plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True, visible_axes=False)
# Add time title
title = title_func(file['scales/sim_time'][index])
title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y
fig.suptitle(title, x=0.44, y=title_height, ha='left')
# Save figure
savename = savename_func(file['scales/write_number'][index])
savepath = output.joinpath(savename)
fig.savefig(str(savepath), dpi=dpi)
fig.clear()
plt.close(fig)
if __name__ == "__main__":
import pathlib
from docopt import docopt
from dedalus.tools import logging
from dedalus.tools import post
from dedalus.tools.parallel import Sync
args = docopt(__doc__)
output_path = pathlib.Path(args['--output']).absolute()
# Create output directory if needed
with Sync() as sync:
if sync.comm.rank == 0:
if not output_path.exists():
output_path.mkdir()
post.visit_writes(args['<files>'], main, output=output_path)