From 9629bf121a1c0bf920dbc33fd4746646517ae216 Mon Sep 17 00:00:00 2001 From: Bill Ladwig Date: Fri, 2 Dec 2016 12:08:07 -0700 Subject: [PATCH] Renamed npvalues to to_np. Fixed issue with generator expressions crashing. --- src/wrf/api.py | 4 +- src/wrf/decorators.py | 6 +-- src/wrf/interp.py | 4 +- src/wrf/latlonutils.py | 3 +- src/wrf/metadecorators.py | 24 ++++++------ src/wrf/specialdec.py | 6 +-- src/wrf/util.py | 32 +++++++++++----- test/comp_utest.py | 8 ++-- test/utests.py | 78 +++++++++++++++++++-------------------- 9 files changed, 89 insertions(+), 76 deletions(-) diff --git a/src/wrf/api.py b/src/wrf/api.py index 6ef5ec9..831bd45 100644 --- a/src/wrf/api.py +++ b/src/wrf/api.py @@ -15,7 +15,7 @@ from .interp import (interplevel, vertcross, interpline, vinterp) from .latlon import (xy_to_ll, ll_to_xy, xy_to_ll_proj, ll_to_xy_proj) from .py3compat import (viewitems, viewkeys, viewvalues, isstr, py2round, py3range, ucode) -from .util import (npvalues, extract_global_attrs, is_standard_wrf_var, +from .util import (to_np, extract_global_attrs, is_standard_wrf_var, extract_dim, extract_vars, extract_times, combine_files, extract_times, npbytes_to_str, is_moving_domain, is_staggered, get_left_indexes, iter_left_indexes, @@ -51,7 +51,7 @@ __all__ += ["interplevel", "vertcross", "interpline", "vinterp"] __all__ += ["xy_to_ll", "ll_to_xy", "xy_to_ll_proj", "ll_to_xy_proj"] __all__ += ["viewitems", "viewkeys", "viewvalues", "isstr", "py2round", "py3range", "ucode"] -__all__ += ["npvalues", "extract_global_attrs", "is_standard_wrf_var", +__all__ += ["to_np", "extract_global_attrs", "is_standard_wrf_var", "extract_dim", "extract_vars", "extract_times", "combine_files", "extract_times", "npbytes_to_str", "is_moving_domain", "is_staggered", "get_left_indexes", "iter_left_indexes", diff --git a/src/wrf/decorators.py b/src/wrf/decorators.py index 7add8b2..399bc94 100644 --- a/src/wrf/decorators.py +++ b/src/wrf/decorators.py @@ -8,7 +8,7 @@ import numpy as np import numpy.ma as ma from .units import do_conversion, check_units, dealias_and_clean_unit -from .util import iter_left_indexes, from_args, npvalues, combine_dims +from .util import iter_left_indexes, from_args, to_np, combine_dims from .py3compat import viewitems, viewvalues, isstr from .config import xarray_enabled from .constants import Constants @@ -187,7 +187,7 @@ def left_iteration(ref_var_expected_dims, skip_missing = False for arg in new_args: if isinstance(arg, DataArray): - arr = npvalues(arg) + arr = to_np(arg) elif isinstance(arg, np.ndarray): arr = arg else: @@ -352,7 +352,7 @@ def _extract_and_transpose(arg, do_transpose): if xarray_enabled(): if isinstance(arg, DataArray): - arg = npvalues(arg) + arg = to_np(arg) if do_transpose: if isinstance(arg, np.ndarray): diff --git a/src/wrf/interp.py b/src/wrf/interp.py index e69787b..e610631 100755 --- a/src/wrf/interp.py +++ b/src/wrf/interp.py @@ -8,7 +8,7 @@ from .extension import (_interpz3d, _vertcross, _interpline, _smooth2d, _monotonic, _vintrp) from .metadecorators import set_interp_metadata -from .util import extract_vars, is_staggered, get_id, npvalues +from .util import extract_vars, is_staggered, get_id, to_np from .py3compat import py3range from .interputils import get_xy, get_xy_z_params, to_xy_coords from .constants import Constants, ConversionFactors @@ -262,7 +262,7 @@ def vertcross(field3d, vert, levels=None, missing=Constants.DEFAULT_FILL, else: end_point_xy = (end_point.x, end_point.y) - xy, var2dz, z_var2d = get_xy_z_params(npvalues(vert), pivot_point_xy, + xy, var2dz, z_var2d = get_xy_z_params(to_np(vert), pivot_point_xy, angle, start_point_xy, end_point_xy, levels) diff --git a/src/wrf/latlonutils.py b/src/wrf/latlonutils.py index b21bbd6..530d8c1 100644 --- a/src/wrf/latlonutils.py +++ b/src/wrf/latlonutils.py @@ -9,8 +9,7 @@ from .constants import Constants, ProjectionTypes from .extension import _lltoxy, _xytoll from .util import (extract_vars, extract_global_attrs, either, is_moving_domain, is_multi_time_req, - iter_left_indexes, is_mapping, is_multi_file, - npvalues) + iter_left_indexes, is_mapping, is_multi_file) from .py3compat import viewkeys, viewitems from .projutils import dict_keys_to_upper diff --git a/src/wrf/metadecorators.py b/src/wrf/metadecorators.py index 3e8cce1..82ae075 100644 --- a/src/wrf/metadecorators.py +++ b/src/wrf/metadecorators.py @@ -8,7 +8,7 @@ import numpy.ma as ma from .extension import _interpline from .util import (extract_vars, either, from_args, arg_location, - is_coordvar, latlon_coordvars, npvalues, + is_coordvar, latlon_coordvars, to_np, from_var, iter_left_indexes) from .coordpair import CoordPair from .py3compat import viewkeys, viewitems, py3range, ucode @@ -308,11 +308,11 @@ def set_wind_metadata(copy_varname, name, description, if not wind_ncvar: for key,dataarray in viewitems(copy_var.coords): if is_coordvar(key): - outcoords[key] = dataarray.dims, npvalues(dataarray) + outcoords[key] = dataarray.dims, to_np(dataarray) elif key == "XTIME": - outcoords[key] = dataarray.dims, npvalues(dataarray) + outcoords[key] = dataarray.dims, to_np(dataarray) elif key == "Time": - outcoords[key] = npvalues(dataarray) + outcoords[key] = to_np(dataarray) outname = name outattrs["description"] = description @@ -420,11 +420,11 @@ def set_cape_metadata(is2d): for key,dataarray in viewitems(copy_var.coords): if is_coordvar(key): - outcoords[key] = dataarray.dims, npvalues(dataarray) + outcoords[key] = dataarray.dims, to_np(dataarray) elif key == "XTIME": - outcoords[key] = dataarray.dims, npvalues(dataarray) + outcoords[key] = dataarray.dims, to_np(dataarray) elif key == "Time": - outcoords[key] = npvalues(dataarray) + outcoords[key] = to_np(dataarray) if is2d: outcoords["mcape_mcin_lcl_lfc"] = ["mcape", "mcin", "lcl", "lfc"] @@ -516,11 +516,11 @@ def set_cloudfrac_metadata(): for key,dataarray in viewitems(copy_var.coords): if is_coordvar(key): - outcoords[key] = dataarray.dims, npvalues(dataarray) + outcoords[key] = dataarray.dims, to_np(dataarray) elif key == "XTIME": - outcoords[key] = dataarray.dims, npvalues(dataarray) + outcoords[key] = dataarray.dims, to_np(dataarray) elif key == "Time": - outcoords[key] = npvalues(dataarray) + outcoords[key] = to_np(dataarray) outcoords["low_mid_high"] = ["low", "mid", "high"] @@ -880,7 +880,7 @@ def _set_cross_meta(wrapped, instance, args, kwargs): else: end_point_xy = (end_point.x, end_point.y) - xy, var2dz, z_var2d = get_xy_z_params(npvalues(z), pivot_point_xy, angle, + xy, var2dz, z_var2d = get_xy_z_params(to_np(z), pivot_point_xy, angle, start_point_xy, end_point_xy, levels) # Make a copy so we don't modify a user supplied cache @@ -1327,7 +1327,7 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs): field3d = argvars["field3d"] xy = argvars["xy"] - xy = npvalues(xy) + xy = to_np(xy) result = wrapped(*args, **kwargs) diff --git a/src/wrf/specialdec.py b/src/wrf/specialdec.py index 15536aa..77f6161 100644 --- a/src/wrf/specialdec.py +++ b/src/wrf/specialdec.py @@ -5,7 +5,7 @@ import numpy as np import wrapt -from .util import iter_left_indexes, npvalues +from .util import iter_left_indexes, to_np from .config import xarray_enabled from .constants import Constants @@ -72,11 +72,11 @@ def uvmet_left_iter(alg_dtype=np.float64): has_missing = False u_arr = u if isinstance(u, DataArray): - u_arr = npvalues(u) + u_arr = to_np(u) v_arr = v if isinstance(v, DataArray): - v_arr = npvalues(v) + v_arr = to_np(v) umissing = Constants.DEFAULT_FILL if isinstance(u_arr, np.ma.MaskedArray): diff --git a/src/wrf/util.py b/src/wrf/util.py index 061a76a..50f7949 100644 --- a/src/wrf/util.py +++ b/src/wrf/util.py @@ -5,7 +5,7 @@ import os from sys import version_info from copy import copy from collections import Iterable, Mapping, OrderedDict -from itertools import product +from itertools import product, tee from types import GeneratorType import datetime as dt from inspect import getmodule @@ -190,6 +190,12 @@ def _generator_copy(gen): """ funcname = gen.__name__ + + # This is for generator comprehensions. Only solution is to tee the + # original generator. + if funcname == "": + return tee(gen) + try: argvals = getargvalues(gen.gi_frame) except NameError: @@ -319,7 +325,15 @@ class IterWrapper(Iterable): """ if isinstance(self._wrapped, GeneratorType): - return _generator_copy(self._wrapped) + + gen_copy = _generator_copy(self._wrapped) + # If a tuple comes back, then this is a generator comprehension, + # so store the first tee'd item, then return the other + if isinstance(gen_copy, tuple): + self._wrapped = gen_copy[0] + return gen_copy[1] + + return gen_copy else: obj_copy = copy(self._wrapped) return obj_copy.__iter__() @@ -360,7 +374,7 @@ def get_iterable(wrfseq): # Helper to extract masked arrays from DataArrays that convert to NaN -def npvalues(array): +def to_np(array): """Return the :class:`numpy.ndarray` contained in an :class:`xarray.DataArray` instance. @@ -947,7 +961,7 @@ def _combine_dict(wrfdict, varname, timeidx, method, meta, _key): if outdata.shape[1:] != vardata.shape: raise ValueError("data sequences must have the " "same size for all dictionary keys") - outdata[idx,:] = npvalues(vardata)[:] + outdata[idx,:] = to_np(vardata)[:] idx += 1 if xarray_enabled() and meta: @@ -967,7 +981,7 @@ def _combine_dict(wrfdict, varname, timeidx, method, meta, _key): break key_coordnames.append(key_coord_name) - coord_vals.append(npvalues(first_array.coords[key_coord_name])) + coord_vals.append(to_np(first_array.coords[key_coord_name])) existing_cnt += 1 @@ -1533,7 +1547,7 @@ def _cat_files(wrfseq, varname, timeidx, is_moving, squeeze, meta, _key): outxtimes = get_cached_item(_key, timekey) if outxtimes is None: outxtimes = np.empty(outdims[0]) - outxtimes[startidx:endidx] = npvalues(first_var.coords[timename][:]) + outxtimes[startidx:endidx] = to_np(first_var.coords[timename][:]) else: timecached = True @@ -1545,7 +1559,7 @@ def _cat_files(wrfseq, varname, timeidx, is_moving, squeeze, meta, _key): outlats = get_cached_item(_key, latkey) if outlats is None: outlats = np.empty(outcoorddims, first_var.dtype) - outlats[startidx:endidx, :] = npvalues(first_var.coords[latname][:]) + outlats[startidx:endidx, :] = to_np(first_var.coords[latname][:]) else: latcached = True @@ -1553,7 +1567,7 @@ def _cat_files(wrfseq, varname, timeidx, is_moving, squeeze, meta, _key): outlons = get_cached_item(_key, lonkey) if outlons is None: outlons = np.empty(outcoorddims, first_var.dtype) - outlons[startidx:endidx, :] = npvalues(first_var.coords[lonname][:]) + outlons[startidx:endidx, :] = to_np(first_var.coords[lonname][:]) else: loncached = True @@ -2114,7 +2128,7 @@ def _extract_var(wrfin, varname, timeidx, is_moving, pass else: if not meta: - return npvalues(cache_var) + return to_np(cache_var) return cache_var diff --git a/test/comp_utest.py b/test/comp_utest.py index 2ba98bf..4cb4e5a 100644 --- a/test/comp_utest.py +++ b/test/comp_utest.py @@ -341,7 +341,7 @@ def get_args(varname, wrfnc, timeidx, method, squeeze): t = ncvars["T"] p = ncvars["P"] pb = ncvars["PB"] - qvapor = npvalues(ncvars["QVAPOR"]) + qvapor = to_np(ncvars["QVAPOR"]) full_t = t + Constants.T_BASE full_p = p + pb @@ -358,7 +358,7 @@ def get_args(varname, wrfnc, timeidx, method, squeeze): t = ncvars["T"] p = ncvars["P"] pb = ncvars["PB"] - qvapor = npvalues(ncvars["QVAPOR"]) + qvapor = to_np(ncvars["QVAPOR"]) ph = ncvars["PH"] phb = ncvars["PHB"] @@ -381,7 +381,7 @@ def get_args(varname, wrfnc, timeidx, method, squeeze): p = ncvars["P"] pb = ncvars["PB"] - qvapor = npvalues(ncvars["QVAPOR"]) + qvapor = to_np(ncvars["QVAPOR"]) # Algorithm requires hPa full_p = .01*(p + pb) @@ -535,7 +535,7 @@ def make_func(varname, wrfnc, timeidx, method, squeeze, meta): ref = getvar(wrfnc, varname, timeidx, method, squeeze, cache=None, meta=meta) - nt.assert_allclose(npvalues(result), npvalues(ref)) + nt.assert_allclose(to_np(result), to_np(ref)) if meta: self.assertEqual(result.dims, ref.dims) diff --git a/test/utests.py b/test/utests.py index ce502bf..234239a 100644 --- a/test/utests.py +++ b/test/utests.py @@ -6,7 +6,7 @@ import os, sys import subprocess from wrf import (getvar, interplevel, interpline, vertcross, vinterp, - disable_xarray, xarray_enabled, npvalues, + disable_xarray, xarray_enabled, to_np, xy_to_ll, ll_to_xy, xy_to_ll_proj, ll_to_xy_proj, extract_global_attrs, viewitems, CoordPair) from wrf.util import is_multi_file @@ -137,13 +137,13 @@ def make_test(varname, wrf_in, referent, multi=False, repeat=3, pynio=False): my_vals = getvar(in_wrfnc, "temp", timeidx=timeidx, units="c") tol = 1/100. atol = .1 # Note: NCL uses 273.16 as conversion for some reason - nt.assert_allclose(npvalues(my_vals), ref_vals, tol, atol) + nt.assert_allclose(to_np(my_vals), ref_vals, tol, atol) elif (varname == "pw"): my_vals = getvar(in_wrfnc, "pw", timeidx=timeidx) tol = .5/100.0 atol = 0 # NCL uses different constants and doesn't use same # handrolled virtual temp in method - nt.assert_allclose(npvalues(my_vals), ref_vals, tol, atol) + nt.assert_allclose(to_np(my_vals), ref_vals, tol, atol) elif (varname == "cape_2d"): cape_2d = getvar(in_wrfnc, varname, timeidx=timeidx) tol = 0/100. @@ -152,7 +152,7 @@ def make_test(varname, wrf_in, referent, multi=False, repeat=3, pynio=False): # merged back in to NCL. The modifications to the R and CP # changes TK enough that non-lifting parcels could lift, thus # causing wildly different values in LCL - nt.assert_allclose(npvalues(cape_2d[0,:]), ref_vals[0,:], tol, atol) + nt.assert_allclose(to_np(cape_2d[0,:]), ref_vals[0,:], tol, atol) elif (varname == "cape_3d"): cape_3d = getvar(in_wrfnc, varname, timeidx=timeidx) # Changing the R and CP constants, while keeping TK within @@ -163,14 +163,14 @@ def make_test(varname, wrf_in, referent, multi=False, repeat=3, pynio=False): tol = 0/100. atol = 200.0 - #print np.amax(np.abs(npvalues(cape_3d[0,:]) - ref_vals[0,:])) - nt.assert_allclose(npvalues(cape_3d), ref_vals, tol, atol) + #print np.amax(np.abs(to_np(cape_3d[0,:]) - ref_vals[0,:])) + nt.assert_allclose(to_np(cape_3d), ref_vals, tol, atol) else: my_vals = getvar(in_wrfnc, varname, timeidx=timeidx) tol = 2/100. atol = 0.1 - #print (np.amax(np.abs(npvalues(my_vals) - ref_vals))) - nt.assert_allclose(npvalues(my_vals), ref_vals, tol, atol) + #print (np.amax(np.abs(to_np(my_vals) - ref_vals))) + nt.assert_allclose(to_np(my_vals), ref_vals, tol, atol) return test @@ -249,7 +249,7 @@ def make_interp_test(varname, wrf_in, referent, multi=False, p = getvar(in_wrfnc, "pressure", timeidx=timeidx) hts_500 = interplevel(hts, p, 500) - nt.assert_allclose(npvalues(hts_500), ref_ht_500) + nt.assert_allclose(to_np(hts_500), ref_ht_500) elif (varname == "vertcross"): ref_ht_cross = _get_refvals(referent, "ht_cross", repeat, multi) @@ -261,12 +261,12 @@ def make_interp_test(varname, wrf_in, referent, multi=False, pivot_point = CoordPair(hts.shape[-1] / 2, hts.shape[-2] / 2) ht_cross = vertcross(hts, p, pivot_point=pivot_point, angle=90.) - nt.assert_allclose(npvalues(ht_cross), ref_ht_cross, rtol=.01) + nt.assert_allclose(to_np(ht_cross), ref_ht_cross, rtol=.01) # Test opposite p_cross1 = vertcross(p,hts,pivot_point=pivot_point, angle=90.0) - nt.assert_allclose(npvalues(p_cross1), + nt.assert_allclose(to_np(p_cross1), ref_p_cross, rtol=.01) # Test point to point @@ -276,8 +276,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, p_cross2 = vertcross(p,hts,start_point=start_point, end_point=end_point) - nt.assert_allclose(npvalues(p_cross1), - npvalues(p_cross2)) + nt.assert_allclose(to_np(p_cross1), + to_np(p_cross2)) elif (varname == "interpline"): @@ -288,7 +288,7 @@ def make_interp_test(varname, wrf_in, referent, multi=False, t2_line1 = interpline(t2, pivot_point=pivot_point, angle=90.0) - nt.assert_allclose(npvalues(t2_line1), ref_t2_line) + nt.assert_allclose(to_np(t2_line1), ref_t2_line) # Test point to point start_point = CoordPair(0, t2.shape[-2]/2) @@ -297,7 +297,7 @@ def make_interp_test(varname, wrf_in, referent, multi=False, t2_line2 = interpline(t2, start_point=start_point, end_point=end_point) - nt.assert_allclose(npvalues(t2_line1), npvalues(t2_line2)) + nt.assert_allclose(to_np(t2_line1), to_np(t2_line2)) elif (varname == "vinterp"): # Tk to theta fld_tk_theta = _get_refvals(referent, "fld_tk_theta", repeat, multi) @@ -320,8 +320,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, atol = 0.0001 field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_tk_theta))) - nt.assert_allclose(npvalues(field), fld_tk_theta, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_tk_theta))) + nt.assert_allclose(to_np(field), fld_tk_theta, tol, atol) # Tk to theta-e fld_tk_theta_e = _get_refvals(referent, "fld_tk_theta_e", repeat, multi) @@ -342,8 +342,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, atol = 50.0001 field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_tk_theta_e)/fld_tk_theta_e)*100) - nt.assert_allclose(npvalues(field), fld_tk_theta_e, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_tk_theta_e)/fld_tk_theta_e)*100) + nt.assert_allclose(to_np(field), fld_tk_theta_e, tol, atol) # Tk to pressure fld_tk_pres = _get_refvals(referent, "fld_tk_pres", repeat, multi) @@ -362,8 +362,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_tk_pres))) - nt.assert_allclose(npvalues(field), fld_tk_pres, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_tk_pres))) + nt.assert_allclose(to_np(field), fld_tk_pres, tol, atol) # Tk to geoht_msl fld_tk_ght_msl = _get_refvals(referent, "fld_tk_ght_msl", repeat, multi) @@ -380,8 +380,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, log_p=True) field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_tk_ght_msl))) - nt.assert_allclose(npvalues(field), fld_tk_ght_msl, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_tk_ght_msl))) + nt.assert_allclose(to_np(field), fld_tk_ght_msl, tol, atol) # Tk to geoht_agl fld_tk_ght_agl = _get_refvals(referent, "fld_tk_ght_agl", repeat, multi) @@ -398,8 +398,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, log_p=True) field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_tk_ght_agl))) - nt.assert_allclose(npvalues(field), fld_tk_ght_agl, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_tk_ght_agl))) + nt.assert_allclose(to_np(field), fld_tk_ght_agl, tol, atol) # Hgt to pressure fld_ht_pres = _get_refvals(referent, "fld_ht_pres", repeat, multi) @@ -417,8 +417,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, log_p=True) field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_ht_pres))) - nt.assert_allclose(npvalues(field), fld_ht_pres, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_ht_pres))) + nt.assert_allclose(to_np(field), fld_ht_pres, tol, atol) # Pressure to theta fld_pres_theta = _get_refvals(referent, "fld_pres_theta", repeat, multi) @@ -436,8 +436,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, log_p=True) field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_pres_theta))) - nt.assert_allclose(npvalues(field), fld_pres_theta, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_pres_theta))) + nt.assert_allclose(to_np(field), fld_pres_theta, tol, atol) # Theta-e to pres fld_thetae_pres = _get_refvals(referent, "fld_thetae_pres", repeat, multi) @@ -455,8 +455,8 @@ def make_interp_test(varname, wrf_in, referent, multi=False, log_p=True) field = np.squeeze(field) - #print (np.amax(np.abs(npvalues(field) - fld_thetae_pres))) - nt.assert_allclose(npvalues(field), fld_thetae_pres, tol, atol) + #print (np.amax(np.abs(to_np(field) - fld_thetae_pres))) + nt.assert_allclose(to_np(field), fld_thetae_pres, tol, atol) return test @@ -531,13 +531,13 @@ def make_latlon_test(testid, wrf_in, referent, single, multi=False, repeat=3, xy = xy + 1 # NCL uses fortran indexing ref = ref_vals[:,0] - nt.assert_allclose(npvalues(xy), ref) + nt.assert_allclose(to_np(xy), ref) # Next make sure the 'proj' version works projparams = extract_proj_params(in_wrfnc) xy_proj = ll_to_xy_proj(lats[0], lons[0], **projparams) - nt.assert_allclose(npvalues(xy_proj), npvalues(xy-1)) + nt.assert_allclose(to_np(xy_proj), to_np(xy-1)) else: @@ -545,13 +545,13 @@ def make_latlon_test(testid, wrf_in, referent, single, multi=False, repeat=3, xy = xy + 1 # NCL uses fortran indexing ref = ref_vals[:] - nt.assert_allclose(npvalues(xy), ref) + nt.assert_allclose(to_np(xy), ref) # Next make sure the 'proj' version works projparams = extract_proj_params(in_wrfnc) xy_proj = ll_to_xy_proj(lats, lons, **projparams) - nt.assert_allclose(npvalues(xy_proj), npvalues(xy-1)) + nt.assert_allclose(to_np(xy_proj), to_np(xy-1)) else: # Since this domain is not moving, the reference values are the @@ -567,24 +567,24 @@ def make_latlon_test(testid, wrf_in, referent, single, multi=False, repeat=3, ll = xy_to_ll(in_wrfnc, i_s[0], j_s[0]) ref = ref_vals[::-1,0] - nt.assert_allclose(npvalues(ll), ref) + nt.assert_allclose(to_np(ll), ref) # Next make sure the 'proj' version works projparams = extract_proj_params(in_wrfnc) ll_proj = xy_to_ll_proj(i_s[0], j_s[0], **projparams) - nt.assert_allclose(npvalues(ll_proj), npvalues(ll)) + nt.assert_allclose(to_np(ll_proj), to_np(ll)) else: ll = xy_to_ll(in_wrfnc, i_s, j_s) ref = ref_vals[::-1,:] - nt.assert_allclose(npvalues(ll), ref) + nt.assert_allclose(to_np(ll), ref) # Next make sure the 'proj' version works projparams = extract_proj_params(in_wrfnc) ll_proj = xy_to_ll_proj(i_s, j_s, **projparams) - nt.assert_allclose(npvalues(ll_proj), npvalues(ll)) + nt.assert_allclose(to_np(ll_proj), to_np(ll)) return test