Browse Source

Fixed typo in api.py and changed missingval to missing in raw computation routines. Modified a test notebook to work with API changes.

main 1.0a3
Bill Ladwig 8 years ago
parent
commit
2bc9d929c3
  1. 2
      src/wrf/api.py
  2. 22
      src/wrf/computation.py
  3. 22
      test/ipynb/nocopy_test.ipynb

2
src/wrf/api.py

@ -33,7 +33,7 @@ from .projection import (WrfProj, NullProjection, LambertConformal, Mercator,
getproj) getproj)
from .coordpair import CoordPair from .coordpair import CoordPair
from .interputils import to_xy_coords from .interputils import to_xy_coords
from cache import cache_item, get_cached_item from .cache import cache_item, get_cached_item
from .version import __version__ from .version import __version__
__all__ = [] __all__ = []

22
src/wrf/computation.py

@ -104,7 +104,7 @@ def xy(field, pivot_point=None, angle=None, start_point=None, end_point=None,
@set_interp_metadata("1d") @set_interp_metadata("1d")
def interp1d(field, z_in, z_out, missingval=Constants.DEFAULT_FILL, def interp1d(field, z_in, z_out, missing=Constants.DEFAULT_FILL,
meta=True): meta=True):
"""Return the linear interpolation of a one-dimensional variable. """Return the linear interpolation of a one-dimensional variable.
@ -127,7 +127,7 @@ def interp1d(field, z_in, z_out, missingval=Constants.DEFAULT_FILL,
one-dimensional array of *z_in* coordinate points to interpolate one-dimensional array of *z_in* coordinate points to interpolate
to. Must be the same type as *z_in*. to. Must be the same type as *z_in*.
missingval (:obj:`float`, optional): The fill value to use for the missing (:obj:`float`, optional): The fill value to use for the
output. Default is :data:`wrf.Constants.DEFAULT_FILL`. output. Default is :data:`wrf.Constants.DEFAULT_FILL`.
meta (:obj:`bool`, optional): Set to False to disable metadata and meta (:obj:`bool`, optional): Set to False to disable metadata and
@ -174,7 +174,7 @@ def interp1d(field, z_in, z_out, missingval=Constants.DEFAULT_FILL,
interp_vals = interp1d(p_1d, ht_1d, levels) interp_vals = interp1d(p_1d, ht_1d, levels)
""" """
return _interp1d(field, z_in, z_out, missingval) return _interp1d(field, z_in, z_out, missing)
@set_interp_metadata("2dxy") @set_interp_metadata("2dxy")
@ -713,7 +713,7 @@ def smooth2d(field, passes, meta=True):
@set_cape_alg_metadata(is2d=True, copyarg="pres_hpa") @set_cape_alg_metadata(is2d=True, copyarg="pres_hpa")
def cape_2d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow, def cape_2d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
missingval=Constants.DEFAULT_FILL, meta=True): missing=Constants.DEFAULT_FILL, meta=True):
"""Return the two-dimensional CAPE, CIN, LCL, and LFC. """Return the two-dimensional CAPE, CIN, LCL, and LFC.
This function calculates the maximum convective available potential This function calculates the maximum convective available potential
@ -789,7 +789,7 @@ def cape_2d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
data uses terrain following coordinates (WRF data). Set to data uses terrain following coordinates (WRF data). Set to
False for pressure level data. False for pressure level data.
missingval (:obj:`float`, optional): The fill value to use for the missing (:obj:`float`, optional): The fill value to use for the
output. Default is :data:`wrf.Constants.DEFAULT_FILL`. output. Default is :data:`wrf.Constants.DEFAULT_FILL`.
meta (:obj:`bool`): Set to False to disable metadata and return meta (:obj:`bool`): Set to False to disable metadata and return
@ -821,7 +821,7 @@ def cape_2d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
i3dflag = 0 i3dflag = 0
cape_cin = _cape(pres_hpa, tkel, qv, height, terrain, psfc_hpa, cape_cin = _cape(pres_hpa, tkel, qv, height, terrain, psfc_hpa,
missingval, i3dflag, ter_follow) missing, i3dflag, ter_follow)
left_dims = cape_cin.shape[1:-3] left_dims = cape_cin.shape[1:-3]
right_dims = cape_cin.shape[-2:] right_dims = cape_cin.shape[-2:]
@ -838,12 +838,12 @@ def cape_2d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
result[2,...,:,:] = cape_cin[1,...,-2,:,:] result[2,...,:,:] = cape_cin[1,...,-2,:,:]
result[3,...,:,:] = cape_cin[1,...,-3,:,:] result[3,...,:,:] = cape_cin[1,...,-3,:,:]
return ma.masked_values(result, missingval) return ma.masked_values(result, missing)
@set_cape_alg_metadata(is2d=False, copyarg="pres_hpa") @set_cape_alg_metadata(is2d=False, copyarg="pres_hpa")
def cape_3d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow, def cape_3d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
missingval=Constants.DEFAULT_FILL, meta=True): missing=Constants.DEFAULT_FILL, meta=True):
"""Return the three-dimensional CAPE and CIN. """Return the three-dimensional CAPE and CIN.
This function calculates the maximum convective available potential This function calculates the maximum convective available potential
@ -911,7 +911,7 @@ def cape_3d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
data uses terrain following coordinates (WRF data). Set to data uses terrain following coordinates (WRF data). Set to
False for pressure level data. False for pressure level data.
missingval (:obj:`float`, optional): The fill value to use for the missing (:obj:`float`, optional): The fill value to use for the
output. Default is :data:`wrf.Constants.DEFAULT_FILL`. output. Default is :data:`wrf.Constants.DEFAULT_FILL`.
meta (:obj:`bool`): Set to False to disable metadata and return meta (:obj:`bool`): Set to False to disable metadata and return
@ -943,9 +943,9 @@ def cape_3d(pres_hpa, tkel, qv, height, terrain, psfc_hpa, ter_follow,
i3dflag = 1 i3dflag = 1
cape_cin = _cape(pres_hpa, tkel, qv, height, terrain, psfc_hpa, cape_cin = _cape(pres_hpa, tkel, qv, height, terrain, psfc_hpa,
missingval, i3dflag, ter_follow) missing, i3dflag, ter_follow)
return ma.masked_values(cape_cin, missingval) return ma.masked_values(cape_cin, missing)
@set_cloudfrac_alg_metadata(copyarg="pres") @set_cloudfrac_alg_metadata(copyarg="pres")

22
test/ipynb/nocopy_test.ipynb

@ -130,11 +130,11 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# Pressure using pivot and angle\n", "# Pressure using pivot and angle\n",
"from wrf import getvar, vertcross\n", "from wrf import getvar, vertcross, CoordPair\n",
"\n", "\n",
"z = getvar(ncfile, \"z\", timeidx=None)\n", "z = getvar(ncfile, \"z\", timeidx=None)\n",
"p = getvar(ncfile, \"pressure\", timeidx=None)\n", "p = getvar(ncfile, \"pressure\", timeidx=None)\n",
"pivot_point = (z.shape[-2] / 2, z.shape[-1] / 2) \n", "pivot_point = CoordPair(z.shape[-2] / 2, z.shape[-1] / 2) \n",
"angle = 90.0\n", "angle = 90.0\n",
"\n", "\n",
"p_vert = vertcross(p, z, pivot_point=pivot_point, angle=angle)\n", "p_vert = vertcross(p, z, pivot_point=pivot_point, angle=angle)\n",
@ -142,8 +142,8 @@
"del p_vert\n", "del p_vert\n",
"\n", "\n",
"# Pressure using start_point and end_point\n", "# Pressure using start_point and end_point\n",
"start_point = (z.shape[-2]/2, 0)\n", "start_point = CoordPair(z.shape[-2]/2, 0)\n",
"end_point = (z.shape[-2]/2, -1)\n", "end_point = CoordPair(z.shape[-2]/2, -1)\n",
"\n", "\n",
"p_vert = vertcross(p, z, start_point=start_point, end_point=end_point)\n", "p_vert = vertcross(p, z, start_point=start_point, end_point=end_point)\n",
"print(p_vert)\n", "print(p_vert)\n",
@ -164,10 +164,10 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# T2 using pivot and angle\n", "# T2 using pivot and angle\n",
"from wrf import interpline, getvar\n", "from wrf import interpline, getvar, CoordPair\n",
"\n", "\n",
"t2 = getvar([ncfile,ncfile,ncfile], \"T2\", timeidx=None)\n", "t2 = getvar([ncfile,ncfile,ncfile], \"T2\", timeidx=None)\n",
"pivot_point = (t2.shape[-2] / 2, t2.shape[-1] / 2) \n", "pivot_point = CoordPair(t2.shape[-2] / 2, t2.shape[-1] / 2) \n",
"angle = 90.0\n", "angle = 90.0\n",
"\n", "\n",
"t2_line = interpline(t2, pivot_point=pivot_point, angle=angle)\n", "t2_line = interpline(t2, pivot_point=pivot_point, angle=angle)\n",
@ -176,8 +176,8 @@
"del t2_line\n", "del t2_line\n",
"\n", "\n",
"# T2 using start_point and end_point\n", "# T2 using start_point and end_point\n",
"start_point = (t2.shape[-2]/2, 0)\n", "start_point = CoordPair(t2.shape[-2]/2, 0)\n",
"end_point = (t2.shape[-2]/2, -1)\n", "end_point = CoordPair(t2.shape[-2]/2, -1)\n",
"\n", "\n",
"t2_line = interpline(t2, start_point=start_point, end_point=end_point)\n", "t2_line = interpline(t2, start_point=start_point, end_point=end_point)\n",
"print(t2_line)\n", "print(t2_line)\n",
@ -430,7 +430,7 @@
"import numpy as np\n", "import numpy as np\n",
"from wrf import (ALL_TIMES, to_np, Constants, getvar, extract_vars, destagger, \n", "from wrf import (ALL_TIMES, to_np, Constants, getvar, extract_vars, destagger, \n",
" interp1d, interp2dxy, interpz3d, \n", " interp1d, interp2dxy, interpz3d, \n",
" slp, tk, td, rh, uvmet, smooth2d, extract_global_attrs, xy)\n", " slp, tk, td, rh, uvmet, smooth2d, extract_global_attrs, xy, CoordPair)\n",
"from math import fabs, log, tan, sin, cos\n", "from math import fabs, log, tan, sin, cos\n",
"from wrf.util import either\n", "from wrf.util import either\n",
"from netCDF4 import Dataset as nc\n", "from netCDF4 import Dataset as nc\n",
@ -443,7 +443,7 @@
"\n", "\n",
"z = getvar(wrfnc, \"z\", timeidx)\n", "z = getvar(wrfnc, \"z\", timeidx)\n",
"\n", "\n",
"interp = interpz3d(field3d, z, 500, missingval=Constants.DEFAULT_FILL, meta=True)\n", "interp = interpz3d(field3d, z, 500, missing=Constants.DEFAULT_FILL, meta=True)\n",
"print (interp)\n", "print (interp)\n",
"print (\"\\n\")\n", "print (\"\\n\")\n",
"\n", "\n",
@ -479,7 +479,7 @@
"z_in = z[only_height]\n", "z_in = z[only_height]\n",
"z_out = np.asarray([100.,200.,300.,500.,1000.,5000.], field3d.dtype)\n", "z_out = np.asarray([100.,200.,300.,500.,1000.,5000.], field3d.dtype)\n",
"\n", "\n",
"int1d = interp1d(v_in, z_in, z_out, missingval=Constants.DEFAULT_FILL, meta=True)\n", "int1d = interp1d(v_in, z_in, z_out, missing=Constants.DEFAULT_FILL, meta=True)\n",
"print(int1d)\n", "print(int1d)\n",
"print (\"\\n\")\n" "print (\"\\n\")\n"
] ]

Loading…
Cancel
Save