MCPcopy Create free account
hub / github.com/SeisSol/SeisSol / main

Function main

postprocessing/visualization/tools/animate_2d_output.py:11–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10
11def main():
12 description = '''Creates an animation of the velocity/displacement
13 wavefield from SeisSol free-surface XDMF output file.'''
14 parser = argparse.ArgumentParser(description=description)
15 parser.add_argument(
16 'fin', help='SeisSol surface (XDMF) output file.')
17 parser.add_argument(
18 'fout', help='Output animation file.', default='animation.gif')
19 parser.add_argument(
20 'dataid', help='Which data component to use', default='v1')
21 parser.add_argument(
22 '--cmap', help='Matplotlib colormap', default='bwr')
23 parser.add_argument(
24 '--dpi', default=200, type=int)
25 parser.add_argument(
26 '--bounds', nargs='+', help='xmin xmax ymin ymax', type=float)
27 args = parser.parse_args()
28
29 ds = sx(args.fin)
30 data = ds.ReadData(args.dataid)
31 geo = ds.ReadGeometry()
32 connect = ds.ReadConnect()
33 dt = ds.ReadTimeStep()
34 nt = data.shape[0]
35 tarr = np.arange(0.0, nt * dt, dt)
36
37 fig = plt.figure(figsize=(8, 7))
38 ax = plt.subplot(111)
39 dmax = abs(data).max()
40 im = ax.tripcolor(
41 geo.T[0], geo.T[1], connect, data[0], cmap=args.cmap, vmin=-dmax,
42 vmax=dmax)
43 ax.set_xlabel('x (m)')
44 ax.set_ylabel('y (m)')
45 ax.set_xlim(args.bounds[0], args.bounds[1])
46 ax.set_ylim(args.bounds[2], args.bounds[3])
47 fig.colorbar(im, label=args.dataid)
48
49 def animate(i):
50 im.set_array(data[i])
51 ax.set_title('$t=$%.1f' % tarr[i])
52
53 def progress_callback(i, n):
54 return print(f'Saving frame {i} of {n}')
55
56 anim = animation.FuncAnimation(
57 fig, animate, frames=data.shape[0],
58 interval=dt * 1000)
59 anim.save(args.fout, dpi=args.dpi, progress_callback=progress_callback)
60 plt.close('all')
61
62
63if __name__ == '__main__':

Callers 1

Calls 4

ReadDataMethod · 0.80
ReadTimeStepMethod · 0.80
maxMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected