Browse Source

Now throws a warning if latlon is set to True, but there is no coordinate metadata for vertcross and interpline. Fixes #38.

lon0
Bill Ladwig 7 years ago
parent
commit
23520ac34f
  1. 18
      src/wrf/interp.py
  2. 13
      src/wrf/metadecorators.py

18
src/wrf/interp.py

@ -199,6 +199,15 @@ def vertcross(field3d, vert, levels=None, missing=default_fill(np.float64),
horizontal line and include this information in the metadata horizontal line and include this information in the metadata
(if enabled). This can be helpful for plotting. Default is False. (if enabled). This can be helpful for plotting. Default is False.
Note:
Currently, *field3d* must be of type :class:`xarray.DataArray`
and contain coordinate information in order to generate the
latitude and longitude coordinates along the line if
*latlon* is set to True. Otherwise, a warning will be issued,
and the latitude and longitude information will not be
present.
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) cache (:obj:`dict`, optional): A dictionary of (varname, ndarray)
that can be used to supply pre-extracted NetCDF variables to the that can be used to supply pre-extracted NetCDF variables to the
computational routines. It is primarily used for internal computational routines. It is primarily used for internal
@ -365,6 +374,15 @@ def interpline(field2d, pivot_point=None,
horizontal line and include this information in the metadata horizontal line and include this information in the metadata
(if enabled). This can be helpful for plotting. Default is False. (if enabled). This can be helpful for plotting. Default is False.
Note:
Currently, *field2d* must be of type :class:`xarray.DataArray`
and contain coordinate information in order to generate the
latitude and longitude coordinates along the line if
*latlon* is set to True. Otherwise, a warning will be issued,
and the latitude and longitude information will not be
present.
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) cache (:obj:`dict`, optional): A dictionary of (varname, ndarray)
that can be used to supply pre-extracted NetCDF variables to the that can be used to supply pre-extracted NetCDF variables to the
computational routines. It is primarily used for internal computational routines. It is primarily used for internal

13
src/wrf/metadecorators.py

@ -1,5 +1,6 @@
from __future__ import (absolute_import, division, print_function, from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
import warnings
import wrapt import wrapt
from collections import OrderedDict from collections import OrderedDict
@ -1022,6 +1023,8 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
outcoords["xy_loc"] = (loc_dimnames, latlon_loc) outcoords["xy_loc"] = (loc_dimnames, latlon_loc)
else: else:
warnings.warn("'latlon' is set to True, but 'field3d' "
" contains no coordinate information")
outcoords["xy_loc"] = ("cross_line_idx", np.asarray(tuple( outcoords["xy_loc"] = ("cross_line_idx", np.asarray(tuple(
CoordPair(xy[i,0], xy[i,1]) CoordPair(xy[i,0], xy[i,1])
for i in py3range(xy.shape[-2])))) for i in py3range(xy.shape[-2]))))
@ -1034,6 +1037,10 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
outcoords["vertical"] = z_var2d[:] outcoords["vertical"] = z_var2d[:]
else: else:
if inc_latlon:
warnings.warn("'latlon' is set to True, but 'field3d' is "
"not of type xarray.DataArray and contains no "
"coordinate information")
outname = "field3d_cross" outname = "field3d_cross"
outattrs = OrderedDict() outattrs = OrderedDict()
@ -1229,6 +1236,8 @@ def _set_line_meta(wrapped, instance, args, kwargs):
outcoords["xy_loc"] = (loc_dimnames, latlon_loc) outcoords["xy_loc"] = (loc_dimnames, latlon_loc)
else: else:
warnings.warn("'latlon' is set to True, but 'field2d' "
"contains no coordinate information")
outcoords["xy_loc"] = ("line_idx", np.asarray(tuple( outcoords["xy_loc"] = ("line_idx", np.asarray(tuple(
CoordPair(xy[i,0], xy[i,1]) CoordPair(xy[i,0], xy[i,1])
for i in py3range(xy.shape[-2])))) for i in py3range(xy.shape[-2]))))
@ -1239,6 +1248,10 @@ def _set_line_meta(wrapped, instance, args, kwargs):
for i in py3range(xy.shape[-2])))) for i in py3range(xy.shape[-2]))))
else: else:
if inc_latlon:
warnings.warn("'latlon' is set to True, but 'field2d' is "
"not of type xarray.DataArray and contains no "
"coordinate information")
outname = "field2d_line" outname = "field2d_line"
outattrs = OrderedDict() outattrs = OrderedDict()

Loading…
Cancel
Save