diff --git a/src/wrf/g_cape.py b/src/wrf/g_cape.py index 697ca0d..062d28f 100755 --- a/src/wrf/g_cape.py +++ b/src/wrf/g_cape.py @@ -223,6 +223,80 @@ def get_3dcape(wrfin, timeidx=0, method="cat", return ma.masked_values(cape_cin, missing) + + +def get_cape2d_only(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, + meta=True, _key=None, missing=default_fill(np.float64)): + result = get_2dcape(wrfin, timeidx, method, squeeze, cache, + meta, _key, missing)[0,:] + + if meta: + result.attrs["description"] = "mcape" + result.attrs["units"] = "J kg-1" + + return result + + +def get_cin2d_only(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, + meta=True, _key=None, missing=default_fill(np.float64)): + result = get_2dcape(wrfin, timeidx, method, squeeze, cache, + meta, _key, missing)[1,:] + + if meta: + result.attrs["description"] = "mcin" + result.attrs["units"] = "J kg-1" + + return result + + +def get_lcl(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, + meta=True, _key=None, missing=default_fill(np.float64)): + result = get_2dcape(wrfin, timeidx, method, squeeze, cache, + meta, _key, missing)[2,:] + + if meta: + result.attrs["description"] = "lcl" + result.attrs["units"] = "m" + + return result + + +def get_lfc(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, + meta=True, _key=None, missing=default_fill(np.float64)): + result = get_2dcape(wrfin, timeidx, method, squeeze, cache, + meta, _key, missing)[3,:] + + if meta: + result.attrs["description"] = "lfc" + result.attrs["units"] = "m" + + return result + + +def get_3dcape_only(wrfin, timeidx=0, method="cat", + squeeze=True, cache=None, meta=True, + _key=None, missing=default_fill(np.float64)): + result = get_3dcape(wrfin, timeidx, method, squeeze, cache, meta, + _key, missing)[0,:] + + if meta: + result.attrs["description"] = "cape" + result.attrs["units"] = "J kg-1" + + return result + + +def get_3dcin_only(wrfin, timeidx=0, method="cat", + squeeze=True, cache=None, meta=True, + _key=None, missing=default_fill(np.float64)): + result = get_3dcape(wrfin, timeidx, method, squeeze, cache, meta, + _key, missing)[1,:] + + if meta: + result.attrs["description"] = "cin" + result.attrs["units"] = "J kg-1" + + return result \ No newline at end of file diff --git a/src/wrf/g_cloudfrac.py b/src/wrf/g_cloudfrac.py index bb9368d..a0458f6 100644 --- a/src/wrf/g_cloudfrac.py +++ b/src/wrf/g_cloudfrac.py @@ -161,3 +161,47 @@ def get_cloudfrac(wrfin, timeidx=0, method="cat", squeeze=True, return ma.masked_values(cfrac, missing) + +def get_low_cloudfrac(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + vert_type="height_agl", low_thresh=None, mid_thresh=None, + high_thresh=None, missing=default_fill(np.float64)): + result = get_cloudfrac(wrfin, timeidx, method, squeeze, + cache, meta, _key, + vert_type, low_thresh, mid_thresh, + high_thresh, missing)[0,:] + + if meta: + result.attrs["description"] = "low clouds" + + return result + + +def get_mid_cloudfrac(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + vert_type="height_agl", low_thresh=None, mid_thresh=None, + high_thresh=None, missing=default_fill(np.float64)): + result = get_cloudfrac(wrfin, timeidx, method, squeeze, + cache, meta, _key, + vert_type, low_thresh, mid_thresh, + high_thresh, missing)[1,:] + + if meta: + result.attrs["description"] = "mid clouds" + + return result + + +def get_high_cloudfrac(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + vert_type="height_agl", low_thresh=None, mid_thresh=None, + high_thresh=None, missing=default_fill(np.float64)): + result = get_cloudfrac(wrfin, timeidx, method, squeeze, + cache, meta, _key, + vert_type, low_thresh, mid_thresh, + high_thresh, missing)[2,:] + + if meta: + result.attrs["description"] = "high clouds" + + return result diff --git a/src/wrf/g_uvmet.py b/src/wrf/g_uvmet.py index e1d7108..9a058be 100755 --- a/src/wrf/g_uvmet.py +++ b/src/wrf/g_uvmet.py @@ -520,7 +520,51 @@ def get_uvmet10_wspd_wdir(wrfin, timeidx=0, method="cat", squeeze=True, return _calc_wspd_wdir(uvmet10[0,...,:,:], uvmet10[1,...,:,:], True, units) - +def get_uvmet_wspd(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + units="m s-1"): + result = get_uvmet_wspd_wdir(wrfin, timeidx, method, squeeze, + cache, meta, _key, units)[0,:] + + if meta: + result.attrs["description"] = "earth rotated wspd" + + return result + + +def get_uvmet_wdir(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + units="m s-1"): + result = get_uvmet_wspd_wdir(wrfin, timeidx, method, squeeze, + cache, meta, _key, units)[1,:] + + if meta: + result.attrs["description"] = "earth rotated wdir" + + return result + + +def get_uvmet10_wspd(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + units="m s-1"): + result = get_uvmet10_wspd_wdir(wrfin, timeidx, method, squeeze, + cache, meta, _key, units)[0,:] + if meta: + result.attrs["description"] = "10m earth rotated wspd" + + return result + + +def get_uvmet10_wdir(wrfin, timeidx=0, method="cat", squeeze=True, + cache=None, meta=True, _key=None, + units="m s-1"): + result = get_uvmet10_wspd_wdir(wrfin, timeidx, method, squeeze, + cache, meta, _key, units)[1,:] + + if meta: + result.attrs["description"] = "10m earth rotated wdir" + + return result \ No newline at end of file diff --git a/src/wrf/g_wind.py b/src/wrf/g_wind.py index 40f6fec..f91ead8 100755 --- a/src/wrf/g_wind.py +++ b/src/wrf/g_wind.py @@ -507,3 +507,50 @@ def get_destag_wspd_wdir10(wrfin, timeidx=0, method="cat", return _calc_wspd_wdir(u, v, True, units) + +def get_destag_wspd(wrfin, timeidx=0, method="cat", + squeeze=True, cache=None, meta=True, _key=None, + units="m s-1"): + result = get_destag_wspd_wdir(wrfin, timeidx, method, squeeze, cache, + meta, _key, units)[0,:] + + if meta: + result.attrs["description"] = "wspd in projection space" + + return result + +def get_destag_wdir(wrfin, timeidx=0, method="cat", + squeeze=True, cache=None, meta=True, _key=None, + units="m s-1"): + result = get_destag_wspd_wdir(wrfin, timeidx, method, squeeze, cache, + meta, _key, units)[1,:] + + if meta: + result.attrs["description"] = "wdir in projection space" + + return result + + +def get_destag_wspd10(wrfin, timeidx=0, method="cat", + squeeze=True, cache=None, meta=True, _key=None, + units="m s-1"): + result = get_destag_wspd_wdir10(wrfin, timeidx, method, + squeeze, cache, meta, _key, units)[0,:] + + if meta: + result.attrs["description"] = "10m wspd in projection space" + + return result + + +def get_destag_wdir10(wrfin, timeidx=0, method="cat", + squeeze=True, cache=None, meta=True, _key=None, + units="m s-1"): + result = get_destag_wspd_wdir10(wrfin, timeidx, method, + squeeze, cache, meta, _key, units)[1,:] + + if meta: + result.attrs["description"] = "10m wdir in projection space" + + return result + diff --git a/src/wrf/routines.py b/src/wrf/routines.py index d687a1e..aef3697 100644 --- a/src/wrf/routines.py +++ b/src/wrf/routines.py @@ -2,7 +2,9 @@ from __future__ import (absolute_import, division, print_function) from .util import (get_iterable, is_standard_wrf_var, extract_vars, viewkeys, get_id) -from .g_cape import get_2dcape, get_3dcape +from .g_cape import (get_2dcape, get_3dcape, get_cape2d_only, + get_cin2d_only, get_lcl, get_lfc, get_3dcape_only, + get_3dcin_only) from .g_ctt import get_ctt from .g_dbz import get_dbz, get_max_dbz from .g_dewpoint import get_dp, get_dp_2m @@ -17,12 +19,16 @@ from .g_slp import get_slp from .g_temp import get_tc, get_eth, get_temp, get_theta, get_tk, get_tv, get_tw from .g_terrain import get_terrain from .g_uvmet import (get_uvmet, get_uvmet10, get_uvmet10_wspd_wdir, - get_uvmet_wspd_wdir) + get_uvmet_wspd_wdir, get_uvmet_wspd, get_uvmet_wdir, + get_uvmet10_wspd, get_uvmet10_wdir) from .g_vorticity import get_avo, get_pvo from .g_wind import (get_destag_wspd_wdir, get_destag_wspd_wdir10, - get_u_destag, get_v_destag, get_w_destag) + get_u_destag, get_v_destag, get_w_destag, + get_destag_wspd, get_destag_wdir, get_destag_wspd10, + get_destag_wdir10) from .g_times import get_times, get_xtimes -from .g_cloudfrac import get_cloudfrac +from .g_cloudfrac import (get_cloudfrac, get_low_cloudfrac, get_mid_cloudfrac, + get_high_cloudfrac) # func is the function to call. kargs are required arguments that should @@ -70,7 +76,25 @@ _FUNC_MAP = {"cape2d" : get_2dcape, "ctt" : get_ctt, "cloudfrac" : get_cloudfrac, "geopt_stag" : get_stag_geopt, - "zstag" : get_stag_height + "zstag" : get_stag_height, + # Diagnostics below are extracted from multi-product diagnostics + "cape2d_only" : get_cape2d_only, + "cin2d_only" : get_cin2d_only, + "lcl" : get_lcl, + "lfc" : get_lfc, + "cape3d_only" : get_3dcape_only, + "cin3d_only": get_3dcin_only, + "uvmet_wspd" : get_uvmet_wspd, + "uvmet_wdir" : get_uvmet_wdir, + "uvmet10_wspd" : get_uvmet10_wspd, + "uvmet10_wdir" : get_uvmet10_wdir, + "wspd" : get_destag_wspd, + "wdir" : get_destag_wdir, + "wspd10" : get_destag_wspd10, + "wdir10" : get_destag_wdir10, + "low_cloudfrac" : get_low_cloudfrac, + "mid_cloudfrac" : get_mid_cloudfrac, + "high_cloudfrac" : get_high_cloudfrac } _VALID_KARGS = {"cape2d" : ["missing"], @@ -118,6 +142,26 @@ _VALID_KARGS = {"cape2d" : ["missing"], "mid_thresh", "high_thresh"], "geopt_stag" : [], "zstag" : ["msl", "units"], + "cape2d_only" : ["missing"], + "cin2d_only" : ["missing"], + "lcl" : ["missing"], + "lfc" : ["missing"], + "cape3d_only" : ["missing"], + "cin3d_only": ["missing"], + "uvmet_wspd" : ["units"], + "uvmet_wdir" : ["units"], + "uvmet10_wspd" : ["units"], + "uvmet10_wdir" : ["units"], + "wspd" : ["units"], + "wdir" : ["units"], + "wspd10" : ["units"], + "wdir10" : ["units"], + "low_cloudfrac" : ["vert_type", "low_thresh", + "mid_thresh", "high_thresh"], + "mid_cloudfrac" : ["vert_type", "low_thresh", + "mid_thresh", "high_thresh"], + "high_cloudfrac" : ["vert_type", "low_thresh", + "mid_thresh", "high_thresh"], "default" : [] } @@ -140,7 +184,14 @@ _ALIASES = {"cape_2d" : "cape2d", "cfrac" : "cloudfrac", "wspd_wdir_uvmet" : "uvmet_wspd_wdir", "wspd_wdir_uvmet10" : "uvmet10_wspd_wdir", - "th" : "theta" + "th" : "theta", + "low_cfrac" : "low_cloudfrac", + "mid_cfrac" : "mid_cloudfrac", + "high_cfrac" : "high_cloudfrac", + "wspd_uvmet" : "uvmet_wspd" , + "wdir_uvmet" : "uvmet_wdir" , + "wspd_uvmet10" : "uvmet10_wspd" , + "wdir_uvmet10" : "uvmet10_wdir" , } class ArgumentError(Exception): diff --git a/test/plot_tests/d01/cape2d_only.png b/test/plot_tests/d01/cape2d_only.png new file mode 100644 index 0000000..32e5d66 Binary files /dev/null and b/test/plot_tests/d01/cape2d_only.png differ diff --git a/test/plot_tests/d01/cape3d_only.png b/test/plot_tests/d01/cape3d_only.png new file mode 100644 index 0000000..e75f5a4 Binary files /dev/null and b/test/plot_tests/d01/cape3d_only.png differ diff --git a/test/plot_tests/d01/cin2d_only.png b/test/plot_tests/d01/cin2d_only.png new file mode 100644 index 0000000..dab42c2 Binary files /dev/null and b/test/plot_tests/d01/cin2d_only.png differ diff --git a/test/plot_tests/d01/cin3d_only.png b/test/plot_tests/d01/cin3d_only.png new file mode 100644 index 0000000..4762554 Binary files /dev/null and b/test/plot_tests/d01/cin3d_only.png differ diff --git a/test/plot_tests/d01/high_cfrac.png b/test/plot_tests/d01/high_cfrac.png new file mode 100644 index 0000000..0a89b18 Binary files /dev/null and b/test/plot_tests/d01/high_cfrac.png differ diff --git a/test/plot_tests/d01/lcl.png b/test/plot_tests/d01/lcl.png new file mode 100644 index 0000000..6a7d334 Binary files /dev/null and b/test/plot_tests/d01/lcl.png differ diff --git a/test/plot_tests/d01/lfc.png b/test/plot_tests/d01/lfc.png new file mode 100644 index 0000000..7c8e29c Binary files /dev/null and b/test/plot_tests/d01/lfc.png differ diff --git a/test/plot_tests/d01/low_cfrac.png b/test/plot_tests/d01/low_cfrac.png new file mode 100644 index 0000000..a434292 Binary files /dev/null and b/test/plot_tests/d01/low_cfrac.png differ diff --git a/test/plot_tests/d01/mid_cfrac.png b/test/plot_tests/d01/mid_cfrac.png new file mode 100644 index 0000000..7596ccf Binary files /dev/null and b/test/plot_tests/d01/mid_cfrac.png differ diff --git a/test/plot_tests/d01/uvmet10_wdir.png b/test/plot_tests/d01/uvmet10_wdir.png new file mode 100644 index 0000000..ee38ca0 Binary files /dev/null and b/test/plot_tests/d01/uvmet10_wdir.png differ diff --git a/test/plot_tests/d01/uvmet10_wspd.png b/test/plot_tests/d01/uvmet10_wspd.png new file mode 100644 index 0000000..31a0487 Binary files /dev/null and b/test/plot_tests/d01/uvmet10_wspd.png differ diff --git a/test/plot_tests/d01/uvmet_wdir.png b/test/plot_tests/d01/uvmet_wdir.png new file mode 100644 index 0000000..98e7796 Binary files /dev/null and b/test/plot_tests/d01/uvmet_wdir.png differ diff --git a/test/plot_tests/d01/uvmet_wspd.png b/test/plot_tests/d01/uvmet_wspd.png new file mode 100644 index 0000000..d5ba724 Binary files /dev/null and b/test/plot_tests/d01/uvmet_wspd.png differ diff --git a/test/plot_tests/d01/wdir.png b/test/plot_tests/d01/wdir.png new file mode 100644 index 0000000..adaaf5c Binary files /dev/null and b/test/plot_tests/d01/wdir.png differ diff --git a/test/plot_tests/d01/wdir10.png b/test/plot_tests/d01/wdir10.png new file mode 100644 index 0000000..892a299 Binary files /dev/null and b/test/plot_tests/d01/wdir10.png differ diff --git a/test/plot_tests/d01/wspd.png b/test/plot_tests/d01/wspd.png new file mode 100644 index 0000000..86c2e66 Binary files /dev/null and b/test/plot_tests/d01/wspd.png differ diff --git a/test/plot_tests/d01/wspd10.png b/test/plot_tests/d01/wspd10.png new file mode 100644 index 0000000..74b24d6 Binary files /dev/null and b/test/plot_tests/d01/wspd10.png differ diff --git a/test/plot_tests/d02/cape2d_only.png b/test/plot_tests/d02/cape2d_only.png new file mode 100644 index 0000000..f0b43ab Binary files /dev/null and b/test/plot_tests/d02/cape2d_only.png differ diff --git a/test/plot_tests/d02/cape3d_only.png b/test/plot_tests/d02/cape3d_only.png new file mode 100644 index 0000000..fc0c178 Binary files /dev/null and b/test/plot_tests/d02/cape3d_only.png differ diff --git a/test/plot_tests/d02/cin2d_only.png b/test/plot_tests/d02/cin2d_only.png new file mode 100644 index 0000000..c5cb133 Binary files /dev/null and b/test/plot_tests/d02/cin2d_only.png differ diff --git a/test/plot_tests/d02/cin3d_only.png b/test/plot_tests/d02/cin3d_only.png new file mode 100644 index 0000000..4f5e771 Binary files /dev/null and b/test/plot_tests/d02/cin3d_only.png differ diff --git a/test/plot_tests/d02/high_cfrac.png b/test/plot_tests/d02/high_cfrac.png new file mode 100644 index 0000000..ef92109 Binary files /dev/null and b/test/plot_tests/d02/high_cfrac.png differ diff --git a/test/plot_tests/d02/lcl.png b/test/plot_tests/d02/lcl.png new file mode 100644 index 0000000..a2efe53 Binary files /dev/null and b/test/plot_tests/d02/lcl.png differ diff --git a/test/plot_tests/d02/lfc.png b/test/plot_tests/d02/lfc.png new file mode 100644 index 0000000..0a41fe8 Binary files /dev/null and b/test/plot_tests/d02/lfc.png differ diff --git a/test/plot_tests/d02/low_cfrac.png b/test/plot_tests/d02/low_cfrac.png new file mode 100644 index 0000000..e2d3a88 Binary files /dev/null and b/test/plot_tests/d02/low_cfrac.png differ diff --git a/test/plot_tests/d02/mid_cfrac.png b/test/plot_tests/d02/mid_cfrac.png new file mode 100644 index 0000000..628524a Binary files /dev/null and b/test/plot_tests/d02/mid_cfrac.png differ diff --git a/test/plot_tests/d02/uvmet10_wdir.png b/test/plot_tests/d02/uvmet10_wdir.png new file mode 100644 index 0000000..32ff17c Binary files /dev/null and b/test/plot_tests/d02/uvmet10_wdir.png differ diff --git a/test/plot_tests/d02/uvmet10_wspd.png b/test/plot_tests/d02/uvmet10_wspd.png new file mode 100644 index 0000000..f014caf Binary files /dev/null and b/test/plot_tests/d02/uvmet10_wspd.png differ diff --git a/test/plot_tests/d02/uvmet_wdir.png b/test/plot_tests/d02/uvmet_wdir.png new file mode 100644 index 0000000..ae44362 Binary files /dev/null and b/test/plot_tests/d02/uvmet_wdir.png differ diff --git a/test/plot_tests/d02/uvmet_wspd.png b/test/plot_tests/d02/uvmet_wspd.png new file mode 100644 index 0000000..85dd630 Binary files /dev/null and b/test/plot_tests/d02/uvmet_wspd.png differ diff --git a/test/plot_tests/d02/wdir.png b/test/plot_tests/d02/wdir.png new file mode 100644 index 0000000..c1039f3 Binary files /dev/null and b/test/plot_tests/d02/wdir.png differ diff --git a/test/plot_tests/d02/wdir10.png b/test/plot_tests/d02/wdir10.png new file mode 100644 index 0000000..18c9ddd Binary files /dev/null and b/test/plot_tests/d02/wdir10.png differ diff --git a/test/plot_tests/d02/wspd.png b/test/plot_tests/d02/wspd.png new file mode 100644 index 0000000..3600356 Binary files /dev/null and b/test/plot_tests/d02/wspd.png differ diff --git a/test/plot_tests/d02/wspd10.png b/test/plot_tests/d02/wspd10.png new file mode 100644 index 0000000..ed8c32a Binary files /dev/null and b/test/plot_tests/d02/wspd10.png differ diff --git a/test/plot_tests/plot_all.ipynb b/test/plot_tests/plot_all.ipynb index a47f1e5..75ef2f8 100644 --- a/test/plot_tests/plot_all.ipynb +++ b/test/plot_tests/plot_all.ipynb @@ -210,6 +210,50 @@ " elif diagname == \"uvmet10_wspd_wdir\":\n", " levels = numpy.arange(-40,40,5)\n", " extend = \"both\"\n", + " elif diagname ==\"cape2d_only\":\n", + " levels = numpy.arange(200.,4000.,250.)\n", + " extend = \"max\"\n", + " elif diagname ==\"cin2d_only\": \n", + " levels = numpy.arange(10.,200.,10.)\n", + " extend = \"max\"\n", + " elif diagname ==\"lcl\":\n", + " levels = numpy.arange(50.,2000.,50.)\n", + " extend = \"max\"\n", + " elif diagname ==\"lfc\": \n", + " levels = numpy.arange(100.,5000.,100.)\n", + " extend = \"max\"\n", + " elif diagname ==\"cape3d_only\": \n", + " levels = numpy.arange(200.,4000.,250.)\n", + " extend = \"max\"\n", + " elif diagname ==\"cin3d_only\": \n", + " levels = levels = numpy.arange(10.,200.,10.)\n", + " extend = \"max\"\n", + " elif diagname ==\"uvmet_wspd\": \n", + " levels = numpy.arange(-40,40,5)\n", + " extend = \"both\"\n", + " elif diagname ==\"uvmet_wdir\": \n", + " levels = numpy.arange(0,370,10)\n", + " elif diagname ==\"uvmet10_wspd\": \n", + " levels = numpy.arange(-40,40,5)\n", + " extend = \"both\"\n", + " elif diagname ==\"uvmet10_wdir\": \n", + " levels = numpy.arange(0,370,10)\n", + " elif diagname ==\"wspd\": \n", + " levels = numpy.arange(-40,40,5)\n", + " extend = \"both\"\n", + " elif diagname ==\"wdir\": \n", + " levels = numpy.arange(0,370,10)\n", + " elif diagname ==\"wspd10\": \n", + " levels = numpy.arange(-40,40,5)\n", + " extend = \"both\"\n", + " elif diagname ==\"wdir10\": \n", + " levels = numpy.arange(0,370,10)\n", + " elif diagname ==\"low_cfrac\":\n", + " levels = numpy.arange(0.0,1.1,.2)\n", + " elif diagname ==\"mid_cfrac\": \n", + " levels = numpy.arange(0.0,1.1,.2)\n", + " elif diagname ==\"high_cfrac\":\n", + " levels = numpy.arange(0.0,1.1,.2)\n", " \n", " return levels, extend" ] @@ -238,7 +282,10 @@ " \"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", + " \"uvmet_wspd_wdir\", \"uvmet10_wspd_wdir\", \"cfrac\",\n", + " \"cape2d_only\",\"cin2d_only\", \"lcl\", \"lfc\", \"cape3d_only\", \"cin3d_only\",\"uvmet_wspd\", \n", + " \"uvmet_wdir\",\"uvmet10_wspd\", \"uvmet10_wdir\",\"wspd\", \"wdir\", \"wspd10\", \"wdir10\",\n", + " \"low_cfrac\", \"mid_cfrac\", \"high_cfrac\"):\n", " \n", " # Get the terrain height\n", " print(diagname)\n",