MCPcopy Create free account
hub / github.com/NCAR/wrf-python / test

Function test

test/ci_tests/utests.py:28–77  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

26# http://eli.thegreenplace.net/2014/04/02/dynamically-generating-python-test-cases
27def make_test(varname, wrf_in, referent, multi=False, repeat=3, pynio=False):
28 def test(self):
29
30 from netCDF4 import Dataset as NetCDF
31 timeidx = 0
32 in_wrfnc = NetCDF(wrf_in)
33 refnc = NetCDF(referent)
34
35 # These have a left index that defines the product type
36 multiproduct = varname in ("uvmet", "uvmet10", "cape_2d", "cape_3d",
37 "cfrac")
38
39 ref_vals = refnc.variables[varname][:]
40
41 if (varname == "tc"):
42 my_vals = getvar(in_wrfnc, "temp", timeidx=timeidx, units="c")
43 tol = 1/100.
44 atol = .1 # Note: NCL uses 273.16 as conversion for some reason
45 nt.assert_allclose(to_np(my_vals), ref_vals, tol, atol)
46 elif (varname == "pw"):
47 my_vals = getvar(in_wrfnc, "pw", timeidx=timeidx)
48 tol = .5/100.0
49 atol = 0
50 nt.assert_allclose(to_np(my_vals), ref_vals, tol, atol)
51 elif (varname == "cape_2d"):
52 cape_2d = getvar(in_wrfnc, varname, timeidx=timeidx)
53 tol = 0/100.
54 atol = 200.0
55 # Let's only compare CAPE values until the F90 changes are
56 # merged back in to NCL. The modifications to the R and CP
57 # changes TK enough that non-lifting parcels could lift, thus
58 # causing wildly different values in LCL
59 nt.assert_allclose(to_np(cape_2d[0, :]), ref_vals[0, :], tol, atol)
60 elif (varname == "cape_3d"):
61 cape_3d = getvar(in_wrfnc, varname, timeidx=timeidx)
62 # Changing the R and CP constants, while keeping TK within
63 # 2%, can lead to some big changes in CAPE. Tolerances
64 # have been set wide when comparing the with the original
65 # NCL. Change back when the F90 code is merged back with
66 # NCL
67 tol = 0/100.
68 atol = 200.0
69
70 # print np.amax(np.abs(to_np(cape_3d[0,:]) - ref_vals[0,:]))
71 nt.assert_allclose(to_np(cape_3d), ref_vals, tol, atol)
72 else:
73 my_vals = getvar(in_wrfnc, varname, timeidx=timeidx)
74 tol = 2/100.
75 atol = 0.1
76 # print (np.amax(np.abs(to_np(my_vals) - ref_vals)))
77 nt.assert_allclose(to_np(my_vals), ref_vals, tol, atol)
78
79 return test
80

Callers

nothing calls this directly

Calls 10

getvarFunction · 0.90
to_npFunction · 0.90
interplevelFunction · 0.90
CoordPairClass · 0.90
vertcrossFunction · 0.90
interplineFunction · 0.90
vinterpFunction · 0.90
ll_to_xyFunction · 0.90
xy_to_llFunction · 0.90
_get_refvalsFunction · 0.70

Tested by

no test coverage detected