[183] | 1 | from viz.utils import peek |
---|
| 2 | from viz.utils import cardinal_2_month |
---|
| 3 | from viz.utils import set_default_basemap |
---|
| 4 | import pylab as p |
---|
| 5 | import matplotlib.numerix.ma as ma |
---|
| 6 | import numpy as n |
---|
| 7 | from string import zfill |
---|
| 8 | |
---|
| 9 | a_small_number = 1e-8 |
---|
| 10 | |
---|
| 11 | def plot_soilw(file_name, cntr_lvl=None): |
---|
| 12 | file, vars = peek(file_name, show_vars=False) |
---|
| 13 | lon = vars['lon'].get_value() |
---|
| 14 | lat = vars['lat'].get_value() |
---|
| 15 | soilw_var = vars['soil_mois'] |
---|
| 16 | soilw = soilw_var.get_value()[0] |
---|
| 17 | mask = n.zeros(soilw.shape, dtype=int) |
---|
| 18 | for lvl_idx in range(len(soilw)): |
---|
| 19 | mask[lvl_idx] = vars['sea_lnd_ice_mask'].get_value() |
---|
| 20 | soilw_m = ma.masked_where(mask == 0 , soilw) |
---|
| 21 | lvl_bounds = vars['soil_lvl'].get_value() |
---|
| 22 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 23 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 24 | valid_when = valid_date[6:] + ' ' \ |
---|
| 25 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 26 | + valid_date[0:4] \ |
---|
| 27 | + ' ' + valid_time[:2] + ':' \ |
---|
| 28 | + valid_time[2:] + ' UTC' |
---|
| 29 | m = set_default_basemap(lon,lat) |
---|
| 30 | # must plot using 2d lon and lat |
---|
| 31 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 32 | #for lvl_idx in range(1): |
---|
| 33 | for lvl_idx in range(len(soilw)): |
---|
| 34 | p.figure() |
---|
| 35 | if cntr_lvl is not None: |
---|
| 36 | # let's not forget the scaling by the layer depth |
---|
| 37 | m.contourf(LON,LAT,soilw_m[lvl_idx]/lvl_bounds[lvl_idx], cntr_lvl) |
---|
| 38 | else: |
---|
| 39 | # let's not forget the scaling by the layer depth |
---|
| 40 | m.contourf(LON,LAT,soilw_m[lvl_idx]/lvl_bounds[lvl_idx]) |
---|
| 41 | m.drawcoastlines() |
---|
| 42 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 43 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 44 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=50) |
---|
| 45 | if lvl_idx == 0: |
---|
| 46 | title_string = 'Volumetric soil moisture (fraction) valid at ' \ |
---|
| 47 | + '\n' + valid_when + ' ' \ |
---|
| 48 | + '0' \ |
---|
| 49 | + '-' + str(int(round(lvl_bounds[lvl_idx]*100))) + ' cm' \ |
---|
| 50 | + ' from LAPS' |
---|
| 51 | else: |
---|
| 52 | title_string = 'Volumetric soil moisture (fraction) valid at ' \ |
---|
| 53 | + '\n' + valid_when + ' ' \ |
---|
| 54 | + str(int(round(lvl_bounds[lvl_idx-1]*100))) \ |
---|
| 55 | + '-' + str(int(round(lvl_bounds[lvl_idx]*100))) + ' cm' \ |
---|
| 56 | + ' from LAPS' |
---|
| 57 | p.title(title_string) |
---|
| 58 | return |
---|
| 59 | |
---|
| 60 | def plot_soilt(file_name, cntr_lvl=None): |
---|
| 61 | file, vars = peek(file_name, show_vars=False) |
---|
| 62 | lon = vars['lon'].get_value() |
---|
| 63 | lat = vars['lat'].get_value() |
---|
| 64 | soilt_var = vars['soil_temp'] |
---|
| 65 | soilt = soilt_var.get_value()[0] |
---|
| 66 | mask = n.zeros(soilt.shape, dtype=int) |
---|
| 67 | for lvl_idx in range(len(soilt)): |
---|
| 68 | mask[lvl_idx] = vars['sea_lnd_ice_mask'].get_value() |
---|
| 69 | soilt_m = ma.masked_where(mask == 0 , soilt) |
---|
| 70 | lvl_bounds = vars['soil_lvl'].get_value() |
---|
| 71 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 72 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 73 | valid_when = valid_date[6:] + ' ' \ |
---|
| 74 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 75 | + valid_date[0:4] \ |
---|
| 76 | + ' ' + valid_time[:2] + ':' \ |
---|
| 77 | + valid_time[2:] + ' UTC' |
---|
| 78 | m = set_default_basemap(lon,lat) |
---|
| 79 | # must plot using 2d lon and lat |
---|
| 80 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 81 | #for lvl_idx in range(1): |
---|
| 82 | for lvl_idx in range(len(soilt)): |
---|
| 83 | p.figure() |
---|
| 84 | if cntr_lvl is not None: |
---|
| 85 | m.contourf(LON,LAT,soilt_m[lvl_idx], cntr_lvl) |
---|
| 86 | else: |
---|
| 87 | m.contourf(LON,LAT,soilt_m[lvl_idx]) |
---|
| 88 | m.drawcoastlines() |
---|
| 89 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 90 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 91 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=50) |
---|
| 92 | if lvl_idx == 0: |
---|
| 93 | title_string = 'Soil temperature (K) valid at ' \ |
---|
| 94 | + '\n' + valid_when + ' ' \ |
---|
| 95 | + '0' \ |
---|
| 96 | + '-' + str(int(round(lvl_bounds[lvl_idx]*100))) + ' cm' \ |
---|
| 97 | + ' from LAPS' |
---|
| 98 | else: |
---|
| 99 | title_string = 'Soil temperature (K) valid at ' \ |
---|
| 100 | + '\n' + valid_when + ' ' \ |
---|
| 101 | + str(int(round(lvl_bounds[lvl_idx-1]*100))) \ |
---|
| 102 | + '-' + str(int(round(lvl_bounds[lvl_idx]*100))) + ' cm' \ |
---|
| 103 | + ' from LAPS' |
---|
| 104 | p.title(title_string) |
---|
| 105 | return |
---|
| 106 | |
---|
| 107 | def plot_temp(file_name, cntr_lvl=None, save_frames=False): |
---|
| 108 | file, vars = peek(file_name, show_vars=False) |
---|
| 109 | lon = vars['lon'].get_value() |
---|
| 110 | lat = vars['lat'].get_value() |
---|
| 111 | air_temp_var = vars['air_temp'] |
---|
| 112 | air_temp = air_temp_var.get_value()[0] |
---|
| 113 | lvl = vars['lvl'].get_value() |
---|
| 114 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 115 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 116 | valid_when = valid_date[6:] + ' ' \ |
---|
| 117 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 118 | + valid_date[0:4] \ |
---|
| 119 | + ' ' + valid_time[:2] + ':' \ |
---|
| 120 | + valid_time[2:] + ' UTC' |
---|
| 121 | if save_frames: |
---|
| 122 | frame_number = 0 |
---|
| 123 | m = set_default_basemap(lon,lat) |
---|
| 124 | # must plot using 2d lon and lat |
---|
| 125 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 126 | #for lvl_idx in range(1): |
---|
| 127 | for lvl_idx in range(len(lvl)): |
---|
| 128 | p.figure() |
---|
| 129 | if cntr_lvl is not None: |
---|
| 130 | #p.contourf(lon,lat,air_temp_m[lvl_idx], cntr_lvl) |
---|
| 131 | #p.contourf(lon,lat,air_temp[lvl_idx], cntr_lvl) |
---|
| 132 | m.contourf(LON,LAT,air_temp[lvl_idx], cntr_lvl) |
---|
| 133 | else: |
---|
| 134 | #p.contourf(lon,lat,air_temp_m[lvl_idx]) |
---|
| 135 | #p.contourf(lon,lat,air_temp[lvl_idx]) |
---|
| 136 | m.contourf(LON,LAT,air_temp[lvl_idx]) |
---|
| 137 | m.drawcoastlines() |
---|
| 138 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 139 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 140 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=50) |
---|
| 141 | title_string = 'Air temperature (K) valid at ' \ |
---|
| 142 | + '\n' + valid_when + ' ' \ |
---|
| 143 | + str(int(round(lvl[lvl_idx]))) + ' mb' \ |
---|
| 144 | + ' from LAPS' |
---|
| 145 | p.title(title_string) |
---|
| 146 | if save_frames: |
---|
| 147 | p.savefig('frames/frame_' + zfill(str(frame_number),3) +'_air_temp_' + str(int(lvl[lvl_idx])) + '_mb.png') |
---|
| 148 | frame_number += 1 |
---|
| 149 | return |
---|
| 150 | |
---|
| 151 | # plot_wind |
---|
| 152 | # plot_mr |
---|
| 153 | def plot_mr(file_name, cntr_lvl=None, save_frames=False): |
---|
| 154 | file, vars = peek(file_name, show_vars=False) |
---|
| 155 | lon = vars['lon'].get_value() |
---|
| 156 | lat = vars['lat'].get_value() |
---|
| 157 | mr_var = vars['mix_rto'] |
---|
| 158 | # to change between kg/kg to g/kg |
---|
| 159 | mr = mr_var.get_value()[0]*1000. |
---|
| 160 | lvl = vars['lvl'].get_value() |
---|
| 161 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 162 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 163 | valid_when = valid_date[6:] + ' ' \ |
---|
| 164 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 165 | + valid_date[0:4] \ |
---|
| 166 | + ' ' + valid_time[:2] + ':' \ |
---|
| 167 | + valid_time[2:] + ' UTC' |
---|
| 168 | if save_frames: |
---|
| 169 | frame_number = 0 |
---|
| 170 | m = set_default_basemap(lon,lat) |
---|
| 171 | # must plot using 2d lon and lat |
---|
| 172 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 173 | #for lvl_idx in range(2): |
---|
| 174 | for lvl_idx in range(len(lvl)): |
---|
| 175 | p.figure() |
---|
| 176 | if cntr_lvl is not None: |
---|
| 177 | m.contourf(LON,LAT,mr[lvl_idx], cntr_lvl) |
---|
| 178 | else: |
---|
| 179 | m.contourf(LON,LAT,mr[lvl_idx]) |
---|
| 180 | m.drawcoastlines() |
---|
| 181 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 182 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 183 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=50) |
---|
| 184 | title_string = 'Mixing ration (g/kg)' \ |
---|
| 185 | + '\n' + valid_when + ' ' \ |
---|
| 186 | + str(int(round(lvl[lvl_idx]))) + ' mb' \ |
---|
| 187 | + ' from LAPS' |
---|
| 188 | p.title(title_string) |
---|
| 189 | if save_frames: |
---|
| 190 | p.savefig('frames/frame_' + zfill(str(frame_number),3) +'_mr_' + str(int(lvl[lvl_idx])) + '_mb.png') |
---|
| 191 | frame_number += 1 |
---|
| 192 | return |
---|
| 193 | |
---|
| 194 | # plot_ght |
---|
| 195 | def plot_ght(file_name, cntr_lvl=None, save_frames=False): |
---|
| 196 | file, vars = peek(file_name, show_vars=False) |
---|
| 197 | lon = vars['lon'].get_value() |
---|
| 198 | lat = vars['lat'].get_value() |
---|
| 199 | ght_var = vars['geop_ht'] |
---|
| 200 | ght = ght_var.get_value()[0] |
---|
| 201 | lvl = vars['lvl'].get_value() |
---|
| 202 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 203 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 204 | valid_when = valid_date[6:] + ' ' \ |
---|
| 205 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 206 | + valid_date[0:4] \ |
---|
| 207 | + ' ' + valid_time[:2] + ':' \ |
---|
| 208 | + valid_time[2:] + ' UTC' |
---|
| 209 | if save_frames: |
---|
| 210 | frame_number = 0 |
---|
| 211 | m = set_default_basemap(lon,lat) |
---|
| 212 | # must plot using 2d lon and lat |
---|
| 213 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 214 | #for lvl_idx in range(2): |
---|
| 215 | for lvl_idx in range(len(lvl)): |
---|
| 216 | p.figure() |
---|
| 217 | if cntr_lvl is not None: |
---|
| 218 | m.contourf(LON,LAT,ght[lvl_idx], cntr_lvl) |
---|
| 219 | else: |
---|
| 220 | m.contourf(LON,LAT,ght[lvl_idx]) |
---|
| 221 | m.drawcoastlines() |
---|
| 222 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 223 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 224 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=70) |
---|
| 225 | title_string = 'Geopotential height (m)' \ |
---|
| 226 | + '\n' + valid_when + ' ' \ |
---|
| 227 | + str(int(round(lvl[lvl_idx]))) + ' mb' \ |
---|
| 228 | + ' from LAPS' |
---|
| 229 | p.title(title_string) |
---|
| 230 | if save_frames: |
---|
| 231 | p.savefig('frames/frame_' + zfill(str(frame_number),3) +'_ght_' + str(int(lvl[lvl_idx])) + '_mb.png') |
---|
| 232 | frame_number += 1 |
---|
| 233 | return |
---|
| 234 | |
---|
| 235 | def plot_sfc_temp(file_name, cntr_lvl=None, save_frames=False): |
---|
| 236 | file, vars = peek(file_name, show_vars=False) |
---|
| 237 | lon = vars['lon'].get_value() |
---|
| 238 | lat = vars['lat'].get_value() |
---|
| 239 | sfc_temp_var = vars['sfc_temp'] |
---|
| 240 | sfc_temp = sfc_temp_var.get_value()[0] |
---|
| 241 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 242 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 243 | valid_when = valid_date[6:] + ' ' \ |
---|
| 244 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 245 | + valid_date[0:4] \ |
---|
| 246 | + ' ' + valid_time[:2] + ':' \ |
---|
| 247 | + valid_time[2:] + ' UTC' |
---|
| 248 | m = set_default_basemap(lon,lat) |
---|
| 249 | # must plot using 2d lon and lat |
---|
| 250 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 251 | p.figure() |
---|
| 252 | if cntr_lvl is not None: |
---|
| 253 | m.contourf(LON,LAT,sfc_temp, cntr_lvl) |
---|
| 254 | else: |
---|
| 255 | m.contourf(LON,LAT,sfc_temp) |
---|
| 256 | m.drawcoastlines() |
---|
| 257 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 258 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 259 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=70) |
---|
| 260 | title_string = 'Surface temperature (K) valid at' \ |
---|
| 261 | + '\n' + valid_when + ' ' \ |
---|
| 262 | + ' from LAPS' |
---|
| 263 | p.title(title_string) |
---|
| 264 | if save_frames: |
---|
| 265 | p.savefig('frames/frame_' + zfill(str(frame_number),3) +'_sfc_temp_' + str(int(lvl[lvl_idx])) + '.png') |
---|
| 266 | return |
---|
| 267 | |
---|
| 268 | def plot_sfc_pres(file_name, cntr_lvl=None, save_frames=False): |
---|
| 269 | file, vars = peek(file_name, show_vars=False) |
---|
| 270 | lon = vars['lon'].get_value() |
---|
| 271 | lat = vars['lat'].get_value() |
---|
| 272 | sfc_pres_var = vars['sfc_pres'] |
---|
| 273 | sfc_pres = sfc_pres_var.get_value()[0]/100. |
---|
| 274 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 275 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 276 | valid_when = valid_date[6:] + ' ' \ |
---|
| 277 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 278 | + valid_date[0:4] \ |
---|
| 279 | + ' ' + valid_time[:2] + ':' \ |
---|
| 280 | + valid_time[2:] + ' UTC' |
---|
| 281 | m = set_default_basemap(lon,lat) |
---|
| 282 | # must plot using 2d lon and lat |
---|
| 283 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 284 | p.figure() |
---|
| 285 | if cntr_lvl is not None: |
---|
| 286 | m.contourf(LON,LAT,sfc_pres, cntr_lvl) |
---|
| 287 | else: |
---|
| 288 | m.contourf(LON,LAT,sfc_pres) |
---|
| 289 | m.drawcoastlines() |
---|
| 290 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 291 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 292 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=70) |
---|
| 293 | title_string = 'Surface pressure (K) valid at' \ |
---|
| 294 | + '\n' + valid_when + ' ' \ |
---|
| 295 | + ' from LAPS' |
---|
| 296 | p.title(title_string) |
---|
| 297 | if save_frames: |
---|
| 298 | p.savefig('frames/frame_' + zfill(str(0),3) +'_sfc_pres.png') |
---|
| 299 | return |
---|
| 300 | |
---|
| 301 | # plot_sfc_wind |
---|
| 302 | # plot_mslp |
---|
| 303 | # plot_land |
---|
| 304 | # plot_terrain |
---|
| 305 | def plot_skin_temp(file_name, cntr_lvl=None, save_frames=False): |
---|
| 306 | file, vars = peek(file_name, show_vars=False) |
---|
| 307 | lon = vars['lon'].get_value() |
---|
| 308 | lat = vars['lat'].get_value() |
---|
| 309 | skin_temp = vars['skin_temp'] |
---|
| 310 | skin_temp = skin_temp_var.get_value()[0] |
---|
| 311 | valid_date = str(vars['valid_date'].get_value()[0]) |
---|
| 312 | valid_time = zfill(str(vars['valid_time'].get_value()[0]), 4) |
---|
| 313 | valid_when = valid_date[6:] + ' ' \ |
---|
| 314 | + cardinal_2_month(int(valid_date[4:6])) + ' ' \ |
---|
| 315 | + valid_date[0:4] \ |
---|
| 316 | + ' ' + valid_time[:2] + ':' \ |
---|
| 317 | + valid_time[2:] + ' UTC' |
---|
| 318 | m = set_default_basemap(lon,lat) |
---|
| 319 | # must plot using 2d lon and lat |
---|
| 320 | LON, LAT = p.meshgrid(lon,lat) |
---|
| 321 | p.figure() |
---|
| 322 | if cntr_lvl is not None: |
---|
| 323 | m.contourf(LON,LAT,skin_temp, cntr_lvl) |
---|
| 324 | else: |
---|
| 325 | m.contourf(LON,LAT,skin_temp) |
---|
| 326 | m.drawcoastlines() |
---|
| 327 | m.drawmeridians(n.array(n.arange(lon.min(), lon.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 328 | m.drawparallels(n.array(n.arange(lat.min(), lat.max() + a_small_number, 15.)), labels=[1,0,0,1]) |
---|
| 329 | p.colorbar(orientation='horizontal', shrink=0.7, fraction=0.02, pad=0.07, aspect=70) |
---|
| 330 | title_string = 'Surface pressure (K) valid at' \ |
---|
| 331 | + '\n' + valid_when + ' ' \ |
---|
| 332 | + ' from LAPS' |
---|
| 333 | p.title(title_string) |
---|
| 334 | if save_frames: |
---|
| 335 | p.savefig('frames/frame_' + zfill(str(frame_number),3) +'_skin_temp_' + str(int(lvl[lvl_idx])) + '.png') |
---|
| 336 | return |
---|
| 337 | |
---|
| 338 | # plot_skin_temp |
---|
| 339 | |
---|
| 340 | |
---|