Browse Source

Merge branch 'bugfix/proj_globe' into develop

lon0
Bill Ladwig 6 years ago
parent
commit
bd3c6161c0
  1. 11
      src/wrf/projection.py
  2. BIN
      test/plot_tests/d01/avo.png
  3. BIN
      test/plot_tests/d01/cape_2d.png
  4. BIN
      test/plot_tests/d01/cape_3d.png
  5. BIN
      test/plot_tests/d01/cfrac.png
  6. BIN
      test/plot_tests/d01/ctt.png
  7. BIN
      test/plot_tests/d01/dbz.png
  8. BIN
      test/plot_tests/d01/eth.png
  9. BIN
      test/plot_tests/d01/geopt.png
  10. BIN
      test/plot_tests/d01/helicity.png
  11. BIN
      test/plot_tests/d01/lat.png
  12. BIN
      test/plot_tests/d01/lon.png
  13. BIN
      test/plot_tests/d01/mdbz.png
  14. BIN
      test/plot_tests/d01/omg.png
  15. BIN
      test/plot_tests/d01/p.png
  16. BIN
      test/plot_tests/d01/pressure.png
  17. BIN
      test/plot_tests/d01/pvo.png
  18. BIN
      test/plot_tests/d01/pw.png
  19. BIN
      test/plot_tests/d01/rh.png
  20. BIN
      test/plot_tests/d01/rh2.png
  21. BIN
      test/plot_tests/d01/slp.png
  22. BIN
      test/plot_tests/d01/tc.png
  23. BIN
      test/plot_tests/d01/td.png
  24. BIN
      test/plot_tests/d01/td2.png
  25. BIN
      test/plot_tests/d01/ter.png
  26. BIN
      test/plot_tests/d01/theta.png
  27. BIN
      test/plot_tests/d01/tk.png
  28. BIN
      test/plot_tests/d01/tv.png
  29. BIN
      test/plot_tests/d01/twb.png
  30. BIN
      test/plot_tests/d01/ua.png
  31. BIN
      test/plot_tests/d01/updraft_helicity.png
  32. BIN
      test/plot_tests/d01/uvmet.png
  33. BIN
      test/plot_tests/d01/uvmet10.png
  34. BIN
      test/plot_tests/d01/uvmet10_wspd_wdir.png
  35. BIN
      test/plot_tests/d01/uvmet_wspd_wdir.png
  36. BIN
      test/plot_tests/d01/va.png
  37. BIN
      test/plot_tests/d01/wa.png
  38. BIN
      test/plot_tests/d01/wspd_wdir.png
  39. BIN
      test/plot_tests/d01/wspd_wdir10.png
  40. BIN
      test/plot_tests/d01/z.png
  41. BIN
      test/plot_tests/d02/avo.png
  42. BIN
      test/plot_tests/d02/cape_2d.png
  43. BIN
      test/plot_tests/d02/cape_3d.png
  44. BIN
      test/plot_tests/d02/cfrac.png
  45. BIN
      test/plot_tests/d02/ctt.png
  46. BIN
      test/plot_tests/d02/dbz.png
  47. BIN
      test/plot_tests/d02/eth.png
  48. BIN
      test/plot_tests/d02/geopt.png
  49. BIN
      test/plot_tests/d02/helicity.png
  50. BIN
      test/plot_tests/d02/lat.png
  51. BIN
      test/plot_tests/d02/lon.png
  52. BIN
      test/plot_tests/d02/mdbz.png
  53. BIN
      test/plot_tests/d02/omg.png
  54. BIN
      test/plot_tests/d02/p.png
  55. BIN
      test/plot_tests/d02/pressure.png
  56. BIN
      test/plot_tests/d02/pvo.png
  57. BIN
      test/plot_tests/d02/pw.png
  58. BIN
      test/plot_tests/d02/rh.png
  59. BIN
      test/plot_tests/d02/rh2.png
  60. BIN
      test/plot_tests/d02/slp.png
  61. BIN
      test/plot_tests/d02/tc.png
  62. BIN
      test/plot_tests/d02/td.png
  63. BIN
      test/plot_tests/d02/td2.png
  64. BIN
      test/plot_tests/d02/ter.png
  65. BIN
      test/plot_tests/d02/theta.png
  66. BIN
      test/plot_tests/d02/tk.png
  67. BIN
      test/plot_tests/d02/tv.png
  68. BIN
      test/plot_tests/d02/twb.png
  69. BIN
      test/plot_tests/d02/ua.png
  70. BIN
      test/plot_tests/d02/updraft_helicity.png
  71. BIN
      test/plot_tests/d02/uvmet.png
  72. BIN
      test/plot_tests/d02/uvmet10.png
  73. BIN
      test/plot_tests/d02/uvmet10_wspd_wdir.png
  74. BIN
      test/plot_tests/d02/uvmet_wspd_wdir.png
  75. BIN
      test/plot_tests/d02/va.png
  76. BIN
      test/plot_tests/d02/wa.png
  77. BIN
      test/plot_tests/d02/wspd_wdir.png
  78. BIN
      test/plot_tests/d02/wspd_wdir10.png
  79. BIN
      test/plot_tests/d02/z.png
  80. 325
      test/plot_tests/plot_all.ipynb

11
src/wrf/projection.py

@ -309,7 +309,8 @@ class WrfProj(object):
return (None if not cartopy_enabled() return (None if not cartopy_enabled()
else crs.Globe(ellipse=None, else crs.Globe(ellipse=None,
semimajor_axis=Constants.WRF_EARTH_RADIUS, semimajor_axis=Constants.WRF_EARTH_RADIUS,
semiminor_axis=Constants.WRF_EARTH_RADIUS)) semiminor_axis=Constants.WRF_EARTH_RADIUS,
nadgrids="@null"))
def cartopy_xlim(self, geobounds): def cartopy_xlim(self, geobounds):
"""Return the x extents in projected coordinates for cartopy. """Return the x extents in projected coordinates for cartopy.
@ -610,7 +611,7 @@ class LambertConformal(WrfProj):
else self.truelat2) else self.truelat2)
_proj4 = ("+proj=lcc +units=meters +a={} +b={} +lat_1={} " _proj4 = ("+proj=lcc +units=meters +a={} +b={} +lat_1={} "
"+lat_2={} +lat_0={} +lon_0={}".format( "+lat_2={} +lat_0={} +lon_0={} +nadgrids=@null".format(
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
self.truelat1, self.truelat1,
@ -731,7 +732,7 @@ class Mercator(WrfProj):
def _proj4(self): def _proj4(self):
_proj4 = ("+proj=merc +units=meters +a={} +b={} " _proj4 = ("+proj=merc +units=meters +a={} +b={} "
"+lon_0={} +lat_ts={}".format( "+lon_0={} +lat_ts={} +nadgrids=@null".format(
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
self._stand_lon, self._stand_lon,
@ -845,7 +846,7 @@ class PolarStereographic(WrfProj):
def _proj4(self): def _proj4(self):
_proj4 = ("+proj=stere +units=meters +a={} +b={} " _proj4 = ("+proj=stere +units=meters +a={} +b={} "
"+lat0={} +lon_0={} +lat_ts={}".format( "+lat0={} +lon_0={} +lat_ts={} +nadgrids=@null".format(
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
self._hemi, self._hemi,
@ -951,7 +952,7 @@ class LatLon(WrfProj):
def _proj4(self): def _proj4(self):
_proj4 = ("+proj=eqc +units=meters +a={} +b={} " _proj4 = ("+proj=eqc +units=meters +a={} +b={} "
"+lon_0={}".format(Constants.WRF_EARTH_RADIUS, "+lon_0={} +nadgrids=@null".format(Constants.WRF_EARTH_RADIUS,
Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS,
self.stand_lon)) self.stand_lon))
return _proj4 return _proj4

BIN
test/plot_tests/d01/avo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

BIN
test/plot_tests/d01/cape_2d.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

BIN
test/plot_tests/d01/cape_3d.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

BIN
test/plot_tests/d01/cfrac.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

BIN
test/plot_tests/d01/ctt.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

BIN
test/plot_tests/d01/dbz.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
test/plot_tests/d01/eth.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
test/plot_tests/d01/geopt.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
test/plot_tests/d01/helicity.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
test/plot_tests/d01/lat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
test/plot_tests/d01/lon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
test/plot_tests/d01/mdbz.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
test/plot_tests/d01/omg.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

BIN
test/plot_tests/d01/p.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

BIN
test/plot_tests/d01/pressure.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

BIN
test/plot_tests/d01/pvo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

BIN
test/plot_tests/d01/pw.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

BIN
test/plot_tests/d01/rh.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

BIN
test/plot_tests/d01/rh2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

BIN
test/plot_tests/d01/slp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

BIN
test/plot_tests/d01/tc.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
test/plot_tests/d01/td.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
test/plot_tests/d01/td2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
test/plot_tests/d01/ter.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
test/plot_tests/d01/theta.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

BIN
test/plot_tests/d01/tk.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
test/plot_tests/d01/tv.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
test/plot_tests/d01/twb.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
test/plot_tests/d01/ua.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
test/plot_tests/d01/updraft_helicity.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
test/plot_tests/d01/uvmet.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
test/plot_tests/d01/uvmet10.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
test/plot_tests/d01/uvmet10_wspd_wdir.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
test/plot_tests/d01/uvmet_wspd_wdir.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

BIN
test/plot_tests/d01/va.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
test/plot_tests/d01/wa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

BIN
test/plot_tests/d01/wspd_wdir.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

BIN
test/plot_tests/d01/wspd_wdir10.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
test/plot_tests/d01/z.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

BIN
test/plot_tests/d02/avo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
test/plot_tests/d02/cape_2d.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

BIN
test/plot_tests/d02/cape_3d.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

BIN
test/plot_tests/d02/cfrac.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
test/plot_tests/d02/ctt.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

BIN
test/plot_tests/d02/dbz.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
test/plot_tests/d02/eth.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
test/plot_tests/d02/geopt.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
test/plot_tests/d02/helicity.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

BIN
test/plot_tests/d02/lat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
test/plot_tests/d02/lon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
test/plot_tests/d02/mdbz.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

BIN
test/plot_tests/d02/omg.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

BIN
test/plot_tests/d02/p.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
test/plot_tests/d02/pressure.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

BIN
test/plot_tests/d02/pvo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
test/plot_tests/d02/pw.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
test/plot_tests/d02/rh.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
test/plot_tests/d02/rh2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
test/plot_tests/d02/slp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
test/plot_tests/d02/tc.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
test/plot_tests/d02/td.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
test/plot_tests/d02/td2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
test/plot_tests/d02/ter.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
test/plot_tests/d02/theta.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
test/plot_tests/d02/tk.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
test/plot_tests/d02/tv.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
test/plot_tests/d02/twb.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
test/plot_tests/d02/ua.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
test/plot_tests/d02/updraft_helicity.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

BIN
test/plot_tests/d02/uvmet.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
test/plot_tests/d02/uvmet10.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
test/plot_tests/d02/uvmet10_wspd_wdir.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
test/plot_tests/d02/uvmet_wspd_wdir.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
test/plot_tests/d02/va.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
test/plot_tests/d02/wa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

BIN
test/plot_tests/d02/wspd_wdir.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
test/plot_tests/d02/wspd_wdir10.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
test/plot_tests/d02/z.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

325
test/plot_tests/plot_all.ipynb

@ -0,0 +1,325 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"\n",
"# This jupyter notebook command inserts matplotlib graphics in \n",
"# to the workbook\n",
"%matplotlib inline\n",
"\n",
"# Modify these to point to your own files\n",
"WRF_DIRECTORY = \"/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest\"\n",
"\n",
"WRF_FILES = [\"wrfout_d02_2005-08-28_00:00:00\",\n",
" \"wrfout_d02_2005-08-28_12:00:00\",\n",
" \"wrfout_d02_2005-08-29_00:00:00\"]\n",
"\n",
"\n",
"# Do not modify the code below this line\n",
"#------------------------------------------------------\n",
"# Turn off annoying warnings\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"# Make sure the environment is good\n",
"import numpy\n",
"import cartopy\n",
"import matplotlib\n",
"from netCDF4 import Dataset\n",
"from xarray import DataArray\n",
"from wrf import (getvar, interplevel, vertcross, \n",
" vinterp, ALL_TIMES)\n",
"import os\n",
"\n",
"_WRF_FILES = [os.path.abspath(os.path.expanduser(\n",
" os.path.join(WRF_DIRECTORY, f))) for f in WRF_FILES]\n",
"\n",
"# Check that the WRF files exist\n",
"try:\n",
" for f in _WRF_FILES:\n",
" if not os.path.exists(f):\n",
" raise ValueError(\"{} does not exist. \"\n",
" \"Check for typos or incorrect directory.\".format(f))\n",
"except ValueError:\n",
" # If the directory ended up in the zip file, then \n",
" # another 'wrf_tutorial_data' directory might be \n",
" # used.\n",
" WRF_DIRECTORY = os.path.join(WRF_DIRECTORY, \"wrf_tutorial_data\")\n",
" _WRF_FILES = [os.path.abspath(os.path.expanduser(\n",
" os.path.join(WRF_DIRECTORY, f))) for f in WRF_FILES]\n",
" for f in _WRF_FILES:\n",
" if not os.path.exists(f):\n",
" raise\n",
"\n",
" \n",
"# Create functions so that the WRF files only need\n",
"# to be specified using the WRF_FILES global above\n",
"def single_wrf_file():\n",
" global _WRF_FILES\n",
" return _WRF_FILES[0]\n",
"\n",
"def multiple_wrf_files():\n",
" global _WRF_FILES\n",
" return _WRF_FILES\n",
"\n",
"def save_fig(diagname):\n",
" f = single_wrf_file()\n",
" if f.find(\"_d01_\") > 0:\n",
" fout = \"{}.png\".format(os.path.join(os.path.abspath(\".\"), \"d01\", diagname))\n",
" else:\n",
" fout = \"{}.png\".format(os.path.join(os.path.abspath(\".\"), \"d02\", diagname))\n",
" \n",
" matplotlib.pyplot.savefig(fout)\n",
" \n",
"\n",
"print(\"All tests passed!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_kwargs(diagname):\n",
" kwargs = {}\n",
" if diagname == \"ctt\":\n",
" kwargs = {\"fill_nocloud\" : True}\n",
" \n",
" return kwargs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def contour_levels(diagname, diag, numlevels=15):\n",
" levels = numlevels\n",
" extend = \"neither\"\n",
" if diagname == \"ter\":\n",
" levels = numpy.arange(10.,4000.,250.)\n",
" elif diagname == \"avo\":\n",
" levels = numpy.arange(10.,75.,5.)\n",
" extend=\"max\"\n",
" elif diagname == \"eth\":\n",
" levels = numpy.arange(270.,400.,10.)\n",
" elif diagname == \"cape_2d\":\n",
" levels = numpy.arange(200.,4000.,250.)\n",
" extend = \"max\"\n",
" elif diagname == \"cape_3d\":\n",
" levels = numpy.arange(200.,4000.,250.)\n",
" extend = \"max\"\n",
" elif diagname == \"ctt\":\n",
" # Note: The MP scheme doesn't produce cloud water so this\n",
" # is just surface temperature\n",
" levels = numpy.arange(-100, 20., 5.0)\n",
" extend = \"both\"\n",
" elif diagname == \"dbz\":\n",
" #pass\n",
" levels = numpy.arange(15.,75.,5.)\n",
" extend = \"max\"\n",
" elif diagname == \"mdbz\":\n",
" levels = numpy.arange(15.,75.,5.)\n",
" extend = \"max\"\n",
" elif diagname == \"geopt\":\n",
" pass\n",
" elif diagname == \"helicity\":\n",
" levels = numpy.arange(100,500,25)\n",
" extend=\"max\"\n",
" elif diagname == \"lat\":\n",
" pass\n",
" elif diagname == \"lon\":\n",
" pass\n",
" elif diagname == \"omg\":\n",
" pass\n",
" elif diagname == \"p\":\n",
" levels = numpy.arange(95000.,103000.,250.)\n",
" extend = \"min\"\n",
" elif diagname == \"pressure\":\n",
" levels = numpy.arange(950.,1030.,2.5)\n",
" extend = \"min\"\n",
" elif diagname == \"pvo\":\n",
" levels = numpy.arange(.5,5.,.25)\n",
" elif diagname == \"pw\":\n",
" #pass\n",
" levels = numpy.arange(0.1,100,10)\n",
" elif diagname == \"rh2\":\n",
" levels = numpy.arange(50,101,5)\n",
" elif diagname == \"rh\":\n",
" levels = numpy.arange(50.,101.,5)\n",
" elif diagname == \"slp\":\n",
" levels = numpy.arange(950.,1030.,2.5)\n",
" extend = \"min\"\n",
" elif diagname == \"td2\":\n",
" levels = numpy.arange(10,40,5)\n",
" extend = \"max\"\n",
" elif diagname == \"td\":\n",
" levels = numpy.arange(10,40,5)\n",
" extend = \"max\"\n",
" elif diagname == \"tc\":\n",
" levels = numpy.arange(10,40,5)\n",
" extend = \"max\"\n",
" elif diagname == \"theta\":\n",
" levels = numpy.arange(270.,350.,2.5)\n",
" elif diagname == \"tk\":\n",
" levels = numpy.arange(270.,350.,5.)\n",
" elif diagname == \"tv\":\n",
" levels = numpy.arange(270.,350.,5.)\n",
" #levels = numpy.arange(10,40,5)\n",
" elif diagname == \"twb\":\n",
" levels = numpy.arange(270.,350.,5.) \n",
" elif diagname == \"updraft_helicity\":\n",
" pass\n",
" #levels = numpy.arange(1,100,5)\n",
" elif diagname == \"ua\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"va\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"wa\":\n",
" pass\n",
" #levels = numpy.arange(0.1,40,5)\n",
" elif diagname == \"uvmet10\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"uvmet\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"z\":\n",
" levels = numpy.arange(0,200,10)\n",
" extend=\"max\"\n",
" elif diagname == \"cfrac\":\n",
" levels = numpy.arange(0.0,1.1,.2)\n",
" elif diagname == \"wspd_wdir\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"wspd_wdir10\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"uvmet_wspd_wdir\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" elif diagname == \"uvmet10_wspd_wdir\":\n",
" levels = numpy.arange(-40,40,5)\n",
" extend = \"both\"\n",
" \n",
" return levels, extend"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"import numpy\n",
"from matplotlib import pyplot\n",
"from matplotlib.cm import get_cmap\n",
"from cartopy import crs\n",
"from cartopy.feature import NaturalEarthFeature\n",
"from netCDF4 import Dataset\n",
"from wrf import getvar, to_np, get_cartopy, latlon_coords, cartopy_xlim, cartopy_ylim, Constants\n",
"\n",
"file_path = single_wrf_file()\n",
"wrf_file = Dataset(file_path)\n",
"\n",
"for diagname in (\"ter\",\"avo\", \"eth\", \"cape_2d\", \"cape_3d\", \"ctt\", \"dbz\", \"mdbz\", \n",
" \"geopt\", \"helicity\", \"lat\", \"lon\", \"omg\", \"p\", \"pressure\", \n",
" \"pvo\", \"pw\", \"rh2\", \"rh\", \"slp\", \"td2\", \"td\", \"tc\",\n",
" \"theta\", \"tk\", \"tv\", \"twb\", \"updraft_helicity\", \"ua\", \"va\", \n",
" \"wa\", \"uvmet10\", \"uvmet\", \"z\", \"wspd_wdir\", \"wspd_wdir10\",\n",
" \"uvmet_wspd_wdir\", \"uvmet10_wspd_wdir\", \"cfrac\"):\n",
" \n",
" # Get the terrain height\n",
" print(diagname)\n",
" kwargs = get_kwargs(diagname)\n",
" diag = getvar(wrf_file, diagname, timeidx=3, **kwargs)\n",
"\n",
" if diag.ndim == 3:\n",
" diag = diag[0,:]\n",
" elif diag.ndim == 4:\n",
" diag = diag[0,0,:]\n",
"\n",
" # Get the cartopy object and the lat,lon coords\n",
" cart_proj = get_cartopy(diag)\n",
" lats, lons = latlon_coords(diag)\n",
" \n",
"\n",
" # Create a figure and get the GetAxes object\n",
" fig = pyplot.figure(figsize=(10, 7.5))\n",
" ax = pyplot.axes(projection=cart_proj)\n",
"\n",
" # Download and add the states and coastlines\n",
" # See the cartopy documentation for more on this.\n",
" states = NaturalEarthFeature(category='cultural', \n",
" scale='50m', \n",
" facecolor='none',\n",
" name='admin_1_states_provinces_shp')\n",
"\n",
" ax.add_feature(states, linewidth=.5, edgecolor='black', zorder=3)\n",
" ax.coastlines('50m', linewidth=.8, color='black', zorder=4)\n",
"\n",
" # Set the contour levels\n",
" levels, extend = contour_levels(diagname, diag, numlevels=15)\n",
"\n",
" # Make the contour lines and fill them.\n",
" pyplot.contour(to_np(lons), to_np(lats), \n",
" to_np(diag), levels=levels, \n",
" colors=\"black\",\n",
" transform=crs.PlateCarree())\n",
" pyplot.contourf(to_np(lons), to_np(lats), \n",
" to_np(diag), levels=levels,\n",
" transform=crs.PlateCarree(),\n",
" extend=extend,\n",
" cmap=get_cmap(\"jet\"))\n",
"\n",
" ax.set_xlim(cartopy_xlim(diag))\n",
" ax.set_ylim(cartopy_ylim(diag))\n",
" \n",
" # Add a color bar. The shrink often needs to be set \n",
" # by trial and error.\n",
" cb = pyplot.colorbar(ax=ax, shrink=.99)\n",
" \n",
" pyplot.title(diagname)\n",
" \n",
" # Uncomment this to build the sample images\n",
" #save_fig(diagname)\n",
" \n",
" pyplot.show()\n",
"\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading…
Cancel
Save