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

Function main

postprocessing/visualization/tools/plot_imt_map.py:8–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7
8def main():
9 description = '''Plots a map view of the ground motion intensity.'''
10 parser = argparse.ArgumentParser(description=description)
11 parser.add_argument(
12 'fin', help='XDMF input file name.')
13 parser.add_argument(
14 'fout', help='Output image file name.')
15 parser.add_argument(
16 'dataid', help='Which intensity metric to use', default='PGV')
17 parser.add_argument(
18 '--cmap', help='Matplotlib colormap', default='viridis')
19 parser.add_argument(
20 '--dpi', default=200)
21 parser.add_argument(
22 '--log', help='Plot log of intensity', action='store_true',
23 default=False)
24 parser.add_argument(
25 '--bounds', nargs='+', help='xmin xmax ymin ymax', type=float)
26 parser.add_argument(
27 '--contour', action='store_true', default=False)
28 args = parser.parse_args()
29
30 ds = sx(args.fin)
31 geo = ds.ReadGeometry()
32 connect = ds.ReadConnect()
33 coords = geo[connect].mean(axis=1)
34 x, y = coords.T[0], coords.T[1]
35 imt = ds.ReadData(args.dataid)
36 clabel = args.dataid
37 if args.log:
38 imt = np.log(imt)
39 clabel = 'log(%s)' % clabel
40
41 if args.bounds:
42 idx = ((x > args.bounds[0]) & (x < args.bounds[1]) &
43 (y > args.bounds[2]) & (y < args.bounds[3]))
44 vmin = imt[idx].min()
45 vmax = imt[idx].max()
46 else:
47 vmin, vmax = None, None
48
49 plt.figure(figsize=(6, 5))
50
51 if args.contour:
52 plt.tricontourf(x, y, imt, vmin=vmin, vmax=vmax)
53 else:
54 plt.tripcolor(geo.T[0], geo.T[1], connect, imt, vmin=vmin, vmax=vmax)
55 if args.bounds:
56 plt.xlim(args.bounds[0], args.bounds[1])
57 plt.ylim(args.bounds[2], args.bounds[3])
58 plt.colorbar(label=clabel)
59 plt.xlabel('x (m)')
60 plt.ylabel('y (m)')
61 plt.savefig(args.fout, dpi=int(args.dpi))
62 print('Image file saved to %s' % args.fout)
63 plt.close('all')
64
65

Callers 1

plot_imt_map.pyFile · 0.70

Calls 6

printFunction · 0.85
ReadDataMethod · 0.80
logMethod · 0.80
minMethod · 0.45
maxMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected