From 9e66ea139e8613b82ed31d6679b8c78d1983662d Mon Sep 17 00:00:00 2001 From: Bill Ladwig Date: Wed, 19 Apr 2017 16:56:17 -0600 Subject: [PATCH] numpy 1.11 does not properly set the flags for 1D arrays that are expanded via np.newaxis. This was allowing the 1D cape to work in numpy 1.11 but not in numpy 1.12. Fortran arrays are now directly created to ensure it works across numpy versions. Fixes #9. --- src/wrf/specialdec.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wrf/specialdec.py b/src/wrf/specialdec.py index 656fcd2..3957f73 100644 --- a/src/wrf/specialdec.py +++ b/src/wrf/specialdec.py @@ -244,7 +244,6 @@ def cape_left_iter(alg_dtype=np.float64): flip = False if p_hpa[0] > p_hpa[-1]: - flip = True p_hpa = np.ascontiguousarray(p_hpa[::-1]) tk = np.ascontiguousarray(tk[::-1]) @@ -252,10 +251,13 @@ def cape_left_iter(alg_dtype=np.float64): ht = np.ascontiguousarray(ht[::-1]) # Need to make 3D views for the fortran code. - new_args[0] = p_hpa[:, np.newaxis, np.newaxis] - new_args[1] = tk[:, np.newaxis, np.newaxis] - new_args[2] = qv[:, np.newaxis, np.newaxis] - new_args[3] = ht[:, np.newaxis, np.newaxis] + # Going to make these fortran ordered, since the f_contiguous and + # c_contiguous flags are broken in numpy 1.11 (always false). This + # should work across all numpy versions. + new_args[0] = p_hpa.reshape((1, 1, p_hpa.shape[0]), order='F') + new_args[1] = tk.reshape((1, 1, tk.shape[0]), order='F') + new_args[2] = qv.reshape((1, 1, qv.shape[0]), order='F') + new_args[3] = ht.reshape((1, 1, ht.shape[0]), order='F') new_args[4] = np.full((1,1), ter, orig_dtype) new_args[5] = np.full((1,1), sfp, orig_dtype)