From 23520ac34fc7f7d98ce8a7495566b0a8245529f3 Mon Sep 17 00:00:00 2001 From: Bill Ladwig Date: Tue, 19 Dec 2017 15:01:45 -0700 Subject: [PATCH] Now throws a warning if latlon is set to True, but there is no coordinate metadata for vertcross and interpline. Fixes #38. --- src/wrf/interp.py | 20 +++++++++++++++++++- src/wrf/metadecorators.py | 13 +++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/wrf/interp.py b/src/wrf/interp.py index 403abd6..fcd3a8e 100755 --- a/src/wrf/interp.py +++ b/src/wrf/interp.py @@ -197,7 +197,16 @@ def vertcross(field3d, vert, levels=None, missing=default_fill(np.float64), latlon (:obj:`bool`, optional): Set to True to also interpolate the two-dimensional latitude and longitude coordinates along the same 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) that can be used to supply pre-extracted NetCDF variables to the @@ -365,6 +374,15 @@ def interpline(field2d, pivot_point=None, horizontal line and include this information in the metadata (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) that can be used to supply pre-extracted NetCDF variables to the computational routines. It is primarily used for internal diff --git a/src/wrf/metadecorators.py b/src/wrf/metadecorators.py index 0fe6b35..c397ba1 100644 --- a/src/wrf/metadecorators.py +++ b/src/wrf/metadecorators.py @@ -1,5 +1,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) +import warnings import wrapt from collections import OrderedDict @@ -1022,6 +1023,8 @@ def _set_cross_meta(wrapped, instance, args, kwargs): outcoords["xy_loc"] = (loc_dimnames, latlon_loc) else: + warnings.warn("'latlon' is set to True, but 'field3d' " + " contains no coordinate information") outcoords["xy_loc"] = ("cross_line_idx", np.asarray(tuple( CoordPair(xy[i,0], xy[i,1]) for i in py3range(xy.shape[-2])))) @@ -1034,6 +1037,10 @@ def _set_cross_meta(wrapped, instance, args, kwargs): outcoords["vertical"] = z_var2d[:] 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" outattrs = OrderedDict() @@ -1229,6 +1236,8 @@ def _set_line_meta(wrapped, instance, args, kwargs): outcoords["xy_loc"] = (loc_dimnames, latlon_loc) else: + warnings.warn("'latlon' is set to True, but 'field2d' " + "contains no coordinate information") outcoords["xy_loc"] = ("line_idx", np.asarray(tuple( CoordPair(xy[i,0], xy[i,1]) 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])))) 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" outattrs = OrderedDict()