Browse Source

Fixed plot doc import issue. Updated error messages for map related utility functions when xarray is not installed or is disabled.

lon0
Bill Ladwig 8 years ago
parent
commit
fa5bebe242
  1. 2
      doc/source/plot.rst
  2. 2
      src/wrf/computation.py
  3. 17
      src/wrf/util.py

2
doc/source/plot.rst

@ -40,7 +40,7 @@ Plotting a Two-dimensional Field
import cartopy.crs as crs import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature from cartopy.feature import NaturalEarthFeature
from wrf import to_np, getvar, smooth2d, get_cartopy, cartopy_xlim, cartopy_ylim from wrf import to_np, getvar, smooth2d, get_cartopy, cartopy_xlim, cartopy_ylim, latlon_coords
# Open the NetCDF file # Open the NetCDF file
ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00") ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")

2
src/wrf/computation.py

@ -26,7 +26,7 @@ def xy(field, pivot_point=None, angle=None, start_point=None, end_point=None,
Args: Args:
field3d (:class:`xarray.DataArray` or :class:`numpy.ndarray`): A field (:class:`xarray.DataArray` or :class:`numpy.ndarray`): A
field with at least two dimensions. field with at least two dimensions.
pivot_point (:obj:`tuple` or :obj:`list`, optional): A pivot_point (:obj:`tuple` or :obj:`list`, optional): A

17
src/wrf/util.py

@ -3021,6 +3021,9 @@ def geo_bounds(var=None, wrfin=None, varname=None, timeidx=0, method="cat",
# Getting lat/lon from xarray coordinates # Getting lat/lon from xarray coordinates
if var is not None: if var is not None:
if not xarray_enabled():
raise ValueError("xarray is not installed or is disabled")
is_moving = None is_moving = None
try: try:
var_coords = var.coords var_coords = var.coords
@ -3142,8 +3145,15 @@ def _get_wrf_proj_geobnds(var, wrfin, varname, timeidx, method, squeeze,
""" """
# Using a variable # Using a variable
if var is not None: if var is not None:
if not xarray_enabled():
raise ValueError("xarray is not installed or is disabled")
geobnds = geo_bounds(var) geobnds = geo_bounds(var)
wrf_proj = var.attrs["projection"] try:
wrf_proj = var.attrs["projection"]
except AttributeError:
raise ValueError("variable does not contain projection "
"information")
else: else:
geobnds = geo_bounds(wrfin=wrfin, varname=varname, timeidx=timeidx, geobnds = geo_bounds(wrfin=wrfin, varname=varname, timeidx=timeidx,
method=method, cache=cache) method=method, cache=cache)
@ -3260,6 +3270,9 @@ def latlon_coords(var, as_np=False):
""" """
if not xarray_enabled():
raise ValueError("xarray is not installed or is disabled")
try: try:
var_coords = var.coords var_coords = var.coords
except AttributeError: except AttributeError:
@ -3284,8 +3297,6 @@ def latlon_coords(var, as_np=False):
return lats, lons return lats, lons
def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat", def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat",
squeeze=True, cache=None): squeeze=True, cache=None):
"""Return a :class:`cartopy.crs.Projection` subclass for the """Return a :class:`cartopy.crs.Projection` subclass for the

Loading…
Cancel
Save