diff --git a/doc/source/plot.rst b/doc/source/plot.rst index 49ed55f..13f229d 100644 --- a/doc/source/plot.rst +++ b/doc/source/plot.rst @@ -40,7 +40,7 @@ Plotting a Two-dimensional Field import cartopy.crs as crs 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 ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00") diff --git a/src/wrf/computation.py b/src/wrf/computation.py index d01e1ab..1d2d050 100644 --- a/src/wrf/computation.py +++ b/src/wrf/computation.py @@ -26,7 +26,7 @@ def xy(field, pivot_point=None, angle=None, start_point=None, end_point=None, 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. pivot_point (:obj:`tuple` or :obj:`list`, optional): A diff --git a/src/wrf/util.py b/src/wrf/util.py index d5985e5..6ac841f 100644 --- a/src/wrf/util.py +++ b/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 if var is not None: + if not xarray_enabled(): + raise ValueError("xarray is not installed or is disabled") + is_moving = None try: var_coords = var.coords @@ -3142,8 +3145,15 @@ def _get_wrf_proj_geobnds(var, wrfin, varname, timeidx, method, squeeze, """ # Using a variable if var is not None: + if not xarray_enabled(): + raise ValueError("xarray is not installed or is disabled") + 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: geobnds = geo_bounds(wrfin=wrfin, varname=varname, timeidx=timeidx, 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: var_coords = var.coords except AttributeError: @@ -3284,8 +3297,6 @@ def latlon_coords(var, as_np=False): return lats, lons - - def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat", squeeze=True, cache=None): """Return a :class:`cartopy.crs.Projection` subclass for the