/
surface_panels_quick_dirty.py
217 lines (188 loc) · 8.85 KB
/
surface_panels_quick_dirty.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
"""quick workaround for comparing variables from different WRF runs
To do this right (TM) I need to figure out if/how I can generate
panel.depends decorators dynamically. I haven't figured out the
syntax for that yet and I need these plots for the group meeting this
afternoon, so I'm going with copy/paste for the moment.
"""
import panel as pn
import geoviews_tools as gt
def three_panel_quadmesh_compare_vertical_var(ds, varname, cmap='RdBu'):
"""three-panel WRF variable comparison with sliders for z, time
Create a three-panel plot showing values for W vertical wind
velocity (W) with sliders to select vertical level and time stamp.
Display a contour plot to show height above ground of the
currently displayed vertical level.
The three panels show values for the control run, Yatir run, and
control - yatir difference.
"""
hour_select = pn.widgets.IntSlider(start=0, end=2, value=0, name='Hour',
orientation='vertical',
direction='rtl')
var_varies_vertically = len(gt.get_vdim(ds, varname)) > 0
vdim = gt.get_vdim(ds, varname)
if 'stag' in vdim:
agl_var = 'height_agl_stag'
zmax = ds[vdim].size
elif vdim == []: # this variable does not vary vertically
zmax = 0
else:
agl_var = 'height_agl'
zmax = ds[vdim].size
z_select = pn.widgets.IntSlider(start=0, end=zmax, value=1,
name='vertical level',
orientation='vertical',
direction='rtl',
disabled=(var_varies_vertically is False))
# bounds for the figures in fraction of the panel,
fig_bounds = (0.2, 0.2, 0.8, 0.8)
@pn.depends(hour_select, z_select)
def get_contour_agl(hour_select, z_select):
"""create contours of height above ground level
"""
# zstag: height of staggered Z levels, calucated by wrf-python
# ter: height of terrain (meters above sea level)
# calculate staggered Z level height above ground level (agl)
agl_contour = ds[agl_var].sel({'WRFrun': 'yatir dry',
'hour': hour_select,
vdim: z_select}).hvplot.contour(
x='XLONG',
y='XLAT',
z=agl_var,
title='WRF height AGL').opts(
frame_width=200,
frame_height=200)
return(agl_contour)
@pn.depends(hour_select, z_select)
def get_quadmesh_control(hour_select, z_select):
"""
"""
# if var_varies_vertically:
# idx = {'WRFrun': 'control',
# 'hour': hour_select,
# vdim: z_select}
# else:
# idx = {'WRFrun': 'control',
# 'hour': hour_select}
vdim = gt.get_vdim(ds, varname)
vmin, vmax = gt.get_min_max(ds, varname, hour_select, z_select)
qm = ds[varname].sel({'WRFrun': 'yatir dry',
'hour': hour_select,
vdim: z_select}).hvplot.quadmesh(
x='XLONG',
y='XLAT',
z=varname,
title='Yatir dry',
clim=(vmin, vmax),
cmap=cmap).opts(frame_width=200,
frame_height=200)
return(qm)
@pn.depends(hour_select, z_select)
def get_quadmesh_yatir(hour_select, z_select):
"""
"""
vdim = gt.get_vdim(ds, varname)
vmin, vmax = gt.get_min_max(ds, varname, hour_select, z_select)
qm = ds[varname].sel({'WRFrun': 'yatir wet',
'hour': hour_select,
vdim: z_select}).hvplot.quadmesh(
x='XLONG',
y='XLAT',
z=varname,
title='Yatir wet',
cmap=cmap,
clim=(vmin, vmax)).opts(frame_width=200,
frame_height=200)
return(qm)
@pn.depends(hour_select, z_select)
def get_quadmesh_diff(hour_select, z_select):
"""
"""
vdim = gt.get_vdim(ds, varname)
vmin, vmax = gt.get_min_max(ds, varname, hour_select, z_select)
qm = ds[varname].sel({'WRFrun': 'Yatir dry - Yatir wet',
'hour': hour_select,
vdim: z_select}).hvplot.quadmesh(
x='XLONG',
y='XLAT',
z=varname,
#clim=(vmin, vmax),
symmetric=True,
cmap='RdBu',
title='Yatir dry - Yatir wet').opts(
frame_width=200,
frame_height=200)
return(qm)
#main_title = '## ' + ds[varname].long_name
main_title = '## ' + varname
the_plot = pn.Column(pn.Row(pn.pane.Markdown(main_title)),
pn.Row(get_quadmesh_control, get_quadmesh_yatir,
hour_select, z_select),
pn.Row(get_quadmesh_diff, get_contour_agl))
return(the_plot)
def three_panel_quadmesh_compare_surface_var(ds, varname, cmap='RdBu'):
"""three-panel WRF variable comparison with slider for time
Create a three-panel plot showing values for a WRF variable) with
one slider to select time stamp.
The three panels show values for the control run, Yatir run, and
control - yatir difference.
"""
hour_select = pn.widgets.IntSlider(start=0, end=2, value=0, name='Hour',
orientation='vertical',
direction='rtl')
z_select = None # this is a surface variable
# bounds for the figures in fraction of the panel,
fig_bounds = (0.2, 0.2, 0.8, 0.8)
@pn.depends(hour_select)
def get_quadmesh_control(hour_select):
"""
"""
vmin, vmax = gt.get_min_max(ds, varname, hour_select, z_select)
qm = ds[varname].sel({'WRFrun': 'yatir dry',
'hour': hour_select}).hvplot.quadmesh(
x='XLONG',
y='XLAT',
z=varname,
title='Yatir Dry',
clim=(vmin, vmax),
cmap=cmap).opts(frame_width=200,
frame_height=200)
return(qm)
@pn.depends(hour_select)
def get_quadmesh_yatir(hour_select):
"""
"""
vmin, vmax = gt.get_min_max(ds, varname, hour_select, z_select)
qm = ds[varname].sel({'WRFrun': 'yatir wet',
'hour': hour_select}).hvplot.quadmesh(
x='XLONG',
y='XLAT',
z=varname,
title='Yatir wet',
cmap=cmap,
clim=(vmin, vmax)).opts(frame_width=200,
frame_height=200)
return(qm)
@pn.depends(hour_select)
def get_quadmesh_diff(hour_select):
"""
"""
vmin, vmax = gt.get_min_max(ds, varname, hour_select, z_select)
qm = ds[varname].sel({'WRFrun': 'Yatir dry - Yatir wet',
'hour': hour_select}).hvplot.quadmesh(
x='XLONG',
y='XLAT',
z=varname,
#clim=(vmin, vmax),
symmetric=True,
cmap='RdBu',
title='Yatir dry - Yatir wet').opts(
frame_width=200,
frame_height=200)
return(qm)
# main_title = '## ' + ds[varname].long_name
main_title = '## ' + varname
the_plot = pn.Column(pn.Row(pn.pane.Markdown(main_title)),
pn.Row(get_quadmesh_control, get_quadmesh_yatir,
hour_select),
pn.Row(get_quadmesh_diff))
return(the_plot)