-
Notifications
You must be signed in to change notification settings - Fork 3
/
setplot.py
540 lines (449 loc) · 17 KB
/
setplot.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
"""
Set up the plot figures, axes, and items to be done for each frame.
This module is imported by the plotting routines and then the
function setplot is called to set the plot parameters.
"""
import numpy as np
import matplotlib.pyplot as plt
import cmocean
import matplotlib as mpl
from clawpack.visclaw import geoplot
from clawpack.visclaw import colormaps
from clawpack.visclaw import gridtools
import os,sys
sea_level = 50.
outdir2 = None
#outdir2 = '_output_SL50_order2_trans0'
#--------------------------
def setplot(plotdata=None):
#--------------------------
"""
Specify what is to be plotted at each frame.
Input: plotdata, an instance of pyclaw.plotters.data.ClawPlotData.
Output: a modified version of plotdata.
"""
import clawpack.dclaw.plot as dplot
from numpy import linspace
if plotdata is None:
from clawpack.visclaw.data import ClawPlotData
plotdata = ClawPlotData()
plotdata.clearfigures() # clear any old figures,axes,items data
plotdata.format = 'binary'
def timeformat(t):
from numpy import mod
hours = int(t/3600.)
tmin = mod(t,3600.)
min = int(tmin/60.)
sec = int(mod(tmin,60.))
timestr = '%s:%s:%s' % (hours,str(min).zfill(2),str(sec).zfill(2))
return timestr
def title_hours(current_data):
from pylab import title
t = current_data.t
timestr = timeformat(t)
title('t = %s' % timestr)
#-----------------------------------------
# Figure for surface
#-----------------------------------------
plotfigure = plotdata.new_plotfigure(name='Computational domain', figno=0)
plotfigure.kwargs = {'figsize':(8,7)}
plotfigure.show = False
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes('pcolor')
plotaxes.title = 'Surface'
plotaxes.scaled = True
def aa(current_data):
from pylab import ticklabel_format, xticks, gca, cos, pi, savefig
gca().set_aspect(1.)
title_hours(current_data)
ticklabel_format(useOffset=False)
xticks(rotation=20)
plotaxes.afteraxes = aa
# Hillshade
plotitem = plotaxes.new_plotitem(plot_type="2d_hillshade")
plotitem.show = False
plotitem.plot_var = dplot.eta
plotitem.add_colorbar = False
# Surface
plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
plotitem.plot_var = dplot.surface_solid_frac_lt03
plotitem.add_colorbar = True
plotitem.colorbar_kwargs = {
"shrink": 0.9,
"location": "bottom",
"orientation": "horizontal",
}
plotitem.colorbar_label = "Surface (m)"
plotitem.imshow_cmap = cmocean.cm.curl
plotitem.imshow_cmin = 90
plotitem.imshow_cmax = 110
# Debris
plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
plotitem.plot_var = dplot.solid_frac_gt03
plotitem.imshow_cmap = cmocean.cm.turbid
plotitem.imshow_cmin = 0.3
plotitem.imshow_cmax = 1
plotitem.add_colorbar = False
#-----------------------------------------
# Figure for water / landslide separately
#-----------------------------------------
plotfigure = plotdata.new_plotfigure(name='Landslide/water surface', figno=1)
plotfigure.figsize=(8,8)
plotfigure.facecolor='w'
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes('pcolor')
plotaxes.axescmd = 'axes([.15,.5,.7,.45])'
plotaxes.title = 'Landslide / Water'
plotaxes.scaled = True
plotaxes.xlimits = [-3e3,3e3]
plotaxes.ylimits = [-3e3,3e3]
def pure_water(current_data):
q = current_data.q
h = q[0,:,:]
hm = q[3,:,:]
eta = dplot.eta(current_data)
with np.errstate(divide="ignore", invalid="ignore"):
m = hm / h
water = np.where(np.logical_and(h>1e-3, m<0.1),
eta, np.nan)
#import pdb; pdb.set_trace()
return water
# Water
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
#plotitem.plot_var = geoplot.surface
#plotitem.plot_var = geoplot.surface_or_depth
#plotitem.show = False
plotitem.plot_var = pure_water
plotitem.pcolor_cmap = geoplot.tsunami_colormap
plotitem.pcolor_cmin = sea_level - 20.
plotitem.pcolor_cmax = sea_level + 20.
plotitem.add_colorbar = True
plotitem.amr_celledges_show = [0,0,0]
plotitem.patchedges_show = 0
def landslide(current_data):
q = current_data.q
h = q[0,:,:]
hm = q[3,:,:]
eta = dplot.eta(current_data)
with np.errstate(divide="ignore", invalid="ignore"):
m = hm / h
landslide = np.where(np.logical_and(h>1e-3, m>0.1),
h, np.nan)
#import pdb; pdb.set_trace()
return landslide
# Landslide
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
#plotitem.plot_var = geoplot.surface
#plotitem.plot_var = geoplot.surface_or_depth
#plotitem.show = False
plotitem.plot_var = landslide
cmap_mass = colormaps.make_colormap({0.:'w', 1.:'brown'})
plotitem.pcolor_cmap = cmap_mass
plotitem.pcolor_cmin = 0.
plotitem.pcolor_cmax = 80.
plotitem.add_colorbar = True
plotitem.amr_celledges_show = [0,0,0]
plotitem.patchedges_show = 0
def land(current_data):
"""
Return a masked array containing the surface elevation only in dry cells.
"""
drytol = 1e-3
q = current_data.q
h = q[0,...]
eta = q[-1,...]
land = np.ma.masked_where(h>drytol, eta)
#import pdb; pdb.set_trace()
#land = eta - h # everywhere
return land
# Land
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
#plotitem.show = False
plotitem.plot_var = land
plotitem.pcolor_cmap = geoplot.land_colors
plotitem.pcolor_cmin = 0.0
plotitem.pcolor_cmax = 400.0
plotitem.add_colorbar = False
plotitem.amr_celledges_show = [0]
plotitem.patchedges_show = 0
#-----------------------------------------
# Figure for cross section compared to 1d_radial
#-----------------------------------------
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes('radial slice')
plotaxes.axescmd = 'axes([.1,.1,.8,.3])'
plotaxes.title = 'Diagonal Transect'
#plotaxes.scaled = True
def plot_xsec(current_data):
from pylab import plot,linspace,zeros,ones,legend,xlabel,\
sqrt,grid,xlim,fill_between,logical_and
from pylab import nan,where,ylim,loadtxt,arange
from clawpack.pyclaw import Solution
pd = current_data.plotdata
frameno = current_data.frameno
framesoln = Solution(frameno, path=pd.outdir, file_format=pd.format)
#xout = linspace(-3e3,3e3,1000)
#yout = ones(xout.shape) # near x-axis
#rout = xout
xout = linspace(-3e3,3e3,1000)
yout = xout
rout = xout * sqrt(2)
etaout = gridtools.grid_output_2d(framesoln, -1, xout, yout)
hout = gridtools.grid_output_2d(framesoln, 0, xout, yout)
zetaout = where(hout>0.001, etaout, nan)
Bout = etaout - hout
hmout = gridtools.grid_output_2d(framesoln, 3, xout, yout)
with np.errstate(divide="ignore", invalid="ignore"):
mout = hmout / hout
water = where(mout<0.1, etaout, nan)
landslide = where(mout>0.5, etaout, nan)
mixed = where(logical_and(0.1<mout,mout<0.5), etaout, nan)
#plot(xout, etaout, 'm')
fill_between(rout,Bout,water,color=[.4,.4,1])
fill_between(rout,Bout,landslide,color='brown')
fill_between(rout,Bout,mixed,color='orange')
#plot(xout, Bout, 'g')
fill_between(rout,Bout,0,color='lightgreen')
plot(rout, etaout, 'k')
plotaxes.afteraxes = plot_xsec
#-----------------------------------------
# Figure for depth
#-----------------------------------------
plotfigure = plotdata.new_plotfigure(name='Depth', figno=2)
#plotfigure.show = False
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes('pcolor')
#plotaxes.title = 'Water or landslide depth'
mq = 5
plotaxes.title = 'q[%i+1]' % mq
plotaxes.scaled = True
plotaxes.xlimits = [-3e3,3e3]
plotaxes.ylimits = [-3e3,3e3]
def water_or_landslide_depth(current_data):
q = current_data.q
h = q[0,:,:]
hm = q[3,:,:]
with np.errstate(divide="ignore", invalid="ignore"):
m = hm / h
water = np.where(np.logical_and(h>1e-3, m<0.1),
h, np.nan)
import pdb; pdb.set_trace()
return water
# Water
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
#plotitem.plot_var = geoplot.surface
#plotitem.plot_var = geoplot.surface_or_depth
#plotitem.show = False
plotitem.plot_var = mq
plotitem.pcolor_cmap = colormaps.white_red
#plotitem.pcolor_cmin = 0.
#plotitem.pcolor_cmax = 100.
plotitem.add_colorbar = True
plotitem.amr_celledges_show = [0,0,0]
plotitem.patchedges_show = 0
def land(current_data):
"""
Return a masked array containing the surface elevation only in dry cells.
"""
drytol = 1e-3
q = current_data.q
h = q[0,...]
eta = q[-1,...]
land = np.ma.masked_where(h>drytol, eta)
#import pdb; pdb.set_trace()
#land = eta - h # everywhere
return land
# Land
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
#plotitem.show = False
plotitem.plot_var = land
plotitem.pcolor_cmap = geoplot.land_colors
plotitem.pcolor_cmin = 0.0
plotitem.pcolor_cmax = 400.0
plotitem.add_colorbar = False
plotitem.amr_celledges_show = [0]
plotitem.patchedges_show = 0
#-----------------------------------------
# Figure for mass fraction
#-----------------------------------------
plotfigure = plotdata.new_plotfigure(name='Mass Fraction', figno=6)
plotfigure.kwargs = {'figsize':(8,7)}
#plotfigure.show = False
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes('pcolor')
plotaxes.title = 'mass fraction'
plotaxes.scaled = True
plotaxes.scaled = True
plotaxes.xlimits = [-3e3,3e3]
plotaxes.ylimits = [-3e3,3e3]
def mass_frac(current_data):
q = current_data.q
h = q[0,:,:]
hm = q[3,:,:]
with np.errstate(divide="ignore", invalid="ignore"):
m = hm / h
mwet = np.where(h > 0.01, m, np.nan)
mmax = np.nanmax(mwet)
print('mmax = %.3e' % mmax)
q3max = abs(q[3,:,:]).max()
q4max = abs(q[4,:,:]).max()
q5max = abs(q[5,:,:]).max()
print('q3max = %.3e' % q3max, 'q4max = %.3e' % q4max,
'q5max = %.3e' % q5max)
return mwet
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
plotitem.plot_var = mass_frac
plotitem.pcolor_cmap = colormaps.blue_yellow_red
plotitem.pcolor_cmin = 0.
plotitem.pcolor_cmax = 0.65
plotitem.add_colorbar = True
plotitem.amr_celledges_show = [0,0,0]
plotitem.patchedges_show = 0
# Land
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
#plotitem.show = False
plotitem.plot_var = land
plotitem.pcolor_cmap = geoplot.land_colors
plotitem.pcolor_cmin = 0.0
plotitem.pcolor_cmax = 400.0
plotitem.add_colorbar = False
plotitem.amr_celledges_show = [0]
plotitem.patchedges_show = 0
# -----------------------
# Figure for scatter plot
# -----------------------
plotfigure = plotdata.new_plotfigure(name='scatter', figno=3)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = [0, 3e3*np.sqrt(2)]
plotaxes.ylimits = 'auto'
plotaxes.title = 'Scatter plot'
plotaxes.grid = True
def h_vs_r(current_data):
# Return radius of each grid cell and p value in the cell
from pylab import sqrt
x = current_data.x
y = current_data.y
r = np.sqrt(x**2 + y**2)
q = current_data.q
h = q[0,:,:]
return r,h
plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
plotitem.map_2d_to_1d = h_vs_r
plotitem.plot_var = 0
plotitem.plotstyle = '.'
plotitem.color = 'b'
plotitem.kwargs = {'markersize':1}
plotitem.show = True # show on plot?
if outdir2:
plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
plotitem.outdir = outdir2
plotitem.map_2d_to_1d = h_vs_r
plotitem.plot_var = 0
plotitem.plotstyle = '.'
plotitem.color = 'r'
plotitem.kwargs = {'markersize':1}
# -----------------------
# Figure for scatter plot of pressure
# -----------------------
plotfigure = plotdata.new_plotfigure(name='scatter_pressure', figno=7)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = [0, 3e3*np.sqrt(2)]
plotaxes.ylimits = 'auto'
plotaxes.title = 'pressure'
plotaxes.grid = True
def p_vs_r(current_data):
# Return radius of each grid cell and p value in the cell
from pylab import sqrt
x = current_data.x
y = current_data.y
r = np.sqrt(x**2 + y**2)
q = current_data.q
p = q[4,:,:]
return r,p
plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
plotitem.map_2d_to_1d = p_vs_r
#plotitem.plot_var = 0
plotitem.plotstyle = '+'
plotitem.color = 'r'
plotitem.kwargs = {'markersize':1}
plotitem.show = True # show on plot?
def hydrostatic_vs_r(current_data):
# Return radius of each grid cell and hydrostatic p value in the cell
from pylab import sqrt
x = current_data.x
y = current_data.y
r = np.sqrt(x**2 + y**2)
q = current_data.q
h = q[0,:,:]
p = 1000.*9.81*h
return r,p
plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
plotitem.map_2d_to_1d = hydrostatic_vs_r
#plotitem.plot_var = 0
plotitem.plotstyle = '.'
plotitem.color = 'b'
plotitem.kwargs = {'markersize':1}
plotitem.show = True # show on plot?
# -----------------------
# Figure for scatter plot of speed
# -----------------------
plotfigure = plotdata.new_plotfigure(name='scatter_speed', figno=9)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = [0, 3e3*np.sqrt(2)]
plotaxes.ylimits = 'auto'
plotaxes.title = 'speed'
plotaxes.grid = True
def s_vs_r(current_data):
# Return radius of each grid cell and p value in the cell
from pylab import sqrt,nan,where
x = current_data.x
y = current_data.y
r = np.sqrt(x**2 + y**2)
q = current_data.q
s = sqrt(q[1,:,:]**2 + q[2,:,:]**2)
h = where(q[0,:,:]>1e-2, q[0,:,:], nan)
s = s/h
return r,s
plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
plotitem.map_2d_to_1d = s_vs_r
#plotitem.plot_var = 0
plotitem.plotstyle = '+'
plotitem.color = 'r'
#plotitem.kwargs = {'markersize':1}
plotitem.show = True # show on plot?
#-------------------------------------
# Plots of timing (CPU and wall time):
def make_timing_plots(plotdata):
import os
from clawpack.visclaw import plot_timing_stats
try:
timing_plotdir = plotdata.plotdir + '/_timing_figures'
os.system('mkdir -p %s' % timing_plotdir)
units = {'comptime':'minutes', 'simtime':'minutes', 'cell':'millions'}
plot_timing_stats.make_plots(outdir=plotdata.outdir, make_pngs=True,
plotdir=timing_plotdir, units=units)
os.system('cp %s/timing.* %s' % (plotdata.outdir, timing_plotdir))
except:
print('*** Error making timing plots')
otherfigure = plotdata.new_otherfigure(name='timing',
fname='_timing_figures/timing.html')
otherfigure.makefig = make_timing_plots
#-----------------------------------------
# Parameters used only when creating html and/or latex hardcopy
# e.g., via pyclaw.plotters.frametools.printframes:
plotdata.printfigs = True # print figures
plotdata.print_format = 'png' # file format
plotdata.print_framenos = 'all' # list of frames to print
plotdata.print_gaugenos = 'all' # list of gauges to print
plotdata.print_fignos = 'all' # list of figures to print
plotdata.html = True # create html files of plots?
plotdata.html_homelink = '../README.html' # pointer for top of index
plotdata.latex = True # create latex file of plots?
plotdata.latex_figsperline = 2 # layout of plots
plotdata.latex_framesperline = 1 # layout of plots
plotdata.latex_makepdf = False # also run pdflatex?
plotdata.parallel = True # make multiple frame png's at once
return plotdata