diff --git a/MANIFEST.in b/MANIFEST.in index d83672c..6654fc5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,8 @@ include requirements.txt include fortran/*.f90 include fortran/*.pyf +include build_scripts/*.sh +include build_scripts/*.bat include setup.py recursive-include doc/source * diff --git a/build_scripts/gnu_no_omp.sh b/build_scripts/gnu_no_omp.sh index 6f73784..b87b529 100755 --- a/build_scripts/gnu_no_omp.sh +++ b/build_scripts/gnu_no_omp.sh @@ -4,5 +4,7 @@ cd ../fortran gfortran -E ompgen.F90 -cpp -o omp.f90 f2py *.f90 -m _wrffortran -h wrffortran.pyf --overwrite-signature cd .. + python setup.py clean --all python setup.py config_fc --f90flags="-mtune=generic" build_ext build +pip install . diff --git a/build_scripts/gnu_omp.sh b/build_scripts/gnu_omp.sh index cf66f27..09644ad 100755 --- a/build_scripts/gnu_omp.sh +++ b/build_scripts/gnu_omp.sh @@ -2,8 +2,10 @@ cd ../fortran gfortran -E ompgen.F90 -fopenmp -cpp -o omp.f90 -f2py *.f90 -m _wrffortran -h wrffortran.pyf --overwrite-signature --no-wrap-functions +f2py *.f90 -m _wrffortran -h wrffortran.pyf --overwrite-signature cd .. + python setup.py clean --all python setup.py config_fc --f90flags="-mtune=generic -fopenmp" build_ext --libraries="gomp" build +pip install . diff --git a/build_scripts/win_mingw_no_omp.bat b/build_scripts/win_mingw_no_omp.bat new file mode 100644 index 0000000..9e1223c --- /dev/null +++ b/build_scripts/win_mingw_no_omp.bat @@ -0,0 +1,15 @@ +cd ../fortran +CALL gfortran -E ompgen.F90 -cpp -o omp.f90 +REM Wildcards not working on Windows for some reason +CALL f2py -m _wrffortran -h wrffortran.pyf --overwrite-signature wrf_constants.f90 wrf_testfunc.f90 wrf_user.f90 rip_cape.f90 wrf_cloud_fracf.f90 wrf_fctt.f90 wrf_user_dbz.f90 wrf_relhl.f90 calc_uh.f90 wrf_user_latlon_routines.f90 wrf_pvo.f90 eqthecalc.f90 wrf_rip_phys_routines.f90 wrf_pw.f90 wrf_vinterp.f90 wrf_wind.f90 omp.f90 +cd .. + +CALL python setup.py clean --all + +IF %PROCESSOR_ARCHITECTURE% == AMD64 ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic" build --compiler=mingw32 --fcompiler=gnu95 +) ELSE ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic -mincoming-stack-boundary=2" build --compiler=mingw32 --fcompiler=gnu95 +) + +CALL pip install . diff --git a/build_scripts/win_mingw_omp.bat b/build_scripts/win_mingw_omp.bat new file mode 100644 index 0000000..b412e96 --- /dev/null +++ b/build_scripts/win_mingw_omp.bat @@ -0,0 +1,17 @@ +cd ../fortran +CALL gfortran -E ompgen.F90 -cpp -fopenmp -o omp.f90 +REM Wildcards not working on Windows for some reason +CALLf2py -m _wrffortran -h wrffortran.pyf --overwrite-signature wrf_constants.f90 wrf_testfunc.f90 wrf_user.f90 rip_cape.f90 wrf_cloud_fracf.f90 wrf_fctt.f90 wrf_user_dbz.f90 wrf_relhl.f90 calc_uh.f90 wrf_user_latlon_routines.f90 wrf_pvo.f90 eqthecalc.f90 wrf_rip_phys_routines.f90 wrf_pw.f90 wrf_vinterp.f90 wrf_wind.f90 omp.f90 +cd .. + +CALL python setup.py clean --all + +IF %PROCESSOR_ARCHITECTURE% == AMD64 ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic -fopenmp" build_ext --libraries="gomp" build --compiler=mingw32 --fcompiler=gnu95 +) ELSE ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic -fopenmp -mincoming-stack-boundary=2" build_ext --libraries="gomp" build --compiler=mingw32 --fcompiler=gnu95 +) + +CALL pip install . + + diff --git a/build_scripts/win_msvc_mingw_no_omp.bat b/build_scripts/win_msvc_mingw_no_omp.bat new file mode 100644 index 0000000..6fa132b --- /dev/null +++ b/build_scripts/win_msvc_mingw_no_omp.bat @@ -0,0 +1,14 @@ +cd ../fortran +CALL gfortran -E ompgen.F90 -cpp -o omp.f90 +REM Wildcards not working on Windows for some reason +CALL f2py -m _wrffortran -h wrffortran.pyf --overwrite-signature wrf_constants.f90 wrf_testfunc.f90 wrf_user.f90 rip_cape.f90 wrf_cloud_fracf.f90 wrf_fctt.f90 wrf_user_dbz.f90 wrf_relhl.f90 calc_uh.f90 wrf_user_latlon_routines.f90 wrf_pvo.f90 eqthecalc.f90 wrf_rip_phys_routines.f90 wrf_pw.f90 wrf_vinterp.f90 wrf_wind.f90 omp.f90 +cd .. + +CALL python setup.py clean --all + +IF %PROCESSOR_ARCHITECTURE% == AMD64 ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic" build --compiler=mingw32 --fcompiler=gnu95 +) ELSE ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic -mincoming-stack-boundary=2" build --compiler=msvc --fcompiler=gnu95 +) + CALL pip install . diff --git a/build_scripts/win_msvc_mingw_omp.bat b/build_scripts/win_msvc_mingw_omp.bat new file mode 100644 index 0000000..95a13a7 --- /dev/null +++ b/build_scripts/win_msvc_mingw_omp.bat @@ -0,0 +1,16 @@ +cd ../fortran +CALL gfortran -E ompgen.F90 -cpp -fopenmp -o omp.f90 +REM Wildcards not working on Windows for some reason +CALL f2py -m _wrffortran -h wrffortran.pyf --overwrite-signature wrf_constants.f90 wrf_testfunc.f90 wrf_user.f90 rip_cape.f90 wrf_cloud_fracf.f90 wrf_fctt.f90 wrf_user_dbz.f90 wrf_relhl.f90 calc_uh.f90 wrf_user_latlon_routines.f90 wrf_pvo.f90 eqthecalc.f90 wrf_rip_phys_routines.f90 wrf_pw.f90 wrf_vinterp.f90 wrf_wind.f90 omp.f90 +cd .. + +CALL python setup.py clean --all + +IF %PROCESSOR_ARCHITECTURE% == AMD64 ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic -fopenmp" build_ext --libraries="gomp" build --compiler=msvc --fcompiler=gnu95 +) ELSE ( + CALL python setup.py config_fc --f90flags="-O2 -mtune=generic -fopenmp -mincoming-stack-boundary=2" build_ext --libraries="gomp" build --compiler=msvc --fcompiler=gnu95 +) + +CALL pip install . + diff --git a/conda_recipe/bld.bat b/conda_recipe/bld.bat index cedde2c..d1bb7f0 100644 --- a/conda_recipe/bld.bat +++ b/conda_recipe/bld.bat @@ -1,8 +1,15 @@ +cd ./fortran +CALL gfortran -E ompgen.F90 -cpp -fopenmp -o omp.f90 +REM Wildcards not working on Windows for some reason +CALL f2py -m _wrffortran -h wrffortran.pyf --overwrite-signature wrf_constants.f90 wrf_testfunc.f90 wrf_user.f90 rip_cape.f90 wrf_cloud_fracf.f90 wrf_fctt.f90 wrf_user_dbz.f90 wrf_relhl.f90 calc_uh.f90 wrf_user_latlon_routines.f90 wrf_pvo.f90 eqthecalc.f90 wrf_rip_phys_routines.f90 wrf_pw.f90 wrf_vinterp.f90 wrf_wind.f90 omp.f90 +cd .. -%ARCH% == 64 ( - %PYTHON% setup.py config_fc --f90flags="-O2 -mtune=generic -mfpmath=sse -msse2" build --compiler=mingw32 --fcompiler=gnu95 -) else ( - %PYTHON% setup.py config_fc --f90flags="-O2 -mtune=generic -mfpmath=sse -msse2 -mincoming-stack-boundary=2" build --compiler=mingw32 --fcompiler=gnu95 +IF %ARCH% == 64 ( + CALL %PYTHON% setup.py config_fc --f90flags="-O2 -mtune=generic -fopenmp" build_ext --libraries="gomp" build --compiler=msvc --fcompiler=gnu95 +) ELSE ( + CALL %PYTHON% setup.py config_fc --f90flags="-O2 -mtune=generic -fopenmp -mincoming-stack-boundary=2" build_ext --libraries="gomp" build --compiler=msvc --fcompiler=gnu95 ) -%PYTHON% setup.py install --single-version-externally-managed --record=record.txt + +CALL %PYTHON% setup.py install --single-version-externally-managed --record=record.txt + diff --git a/conda_recipe/build.sh b/conda_recipe/build.sh index 9ae7b95..ec01ebb 100644 --- a/conda_recipe/build.sh +++ b/conda_recipe/build.sh @@ -1,10 +1,16 @@ #!/bin/bash +cd ./fortran +gfortran -E ompgen.F90 -fopenmp -cpp -o omp.f90 +f2py *.f90 -m _wrffortran -h wrffortran.pyf --overwrite-signature +cd .. + if [ `uname` == Darwin ]; then LDFLAGS="$LDFLAGS -undefined dynamic_lookup -bundle" fi -$PYTHON setup.py config_fc --f90flags="-mtune=generic -mfpmath=sse" build +$PYTHON setup.py config_fc --f90flags="-mtune=generic -fopenmp" build_ext --libraries="gomp" build + $PYTHON setup.py install --single-version-externally-managed --record=record.txt diff --git a/conda_recipe/meta.yaml b/conda_recipe/meta.yaml index 6fbe7d0..b912d3a 100644 --- a/conda_recipe/meta.yaml +++ b/conda_recipe/meta.yaml @@ -1,38 +1,40 @@ -{% set version = "1.0.5" %} +{% set version = "1.1.0" %} package: name: wrf-python version: {{ version }} source: - fn: wrf-python-{{ version }}.tar.gz - url: https://github.com/NCAR/wrf-python/archive/{{ version }}.tar.gz - sha256: ea2202e1d8237c65b9d77a91f00da0f2e7a37ed6214ddd976872b619b9647b33 + git_url: https://github.com/NCAR/wrf-python + git_branch: develop + build: number: 0 detect_binary_files_with_prefix: true - skip: True # [(win and py>=35)] requirements: build: - setuptools - - numpy x.x - - wrapt - - mingwpy # [win] - - gcc # [unix] - python + - numpy 1.11.* # [unix] + - numpy 1.14.* # [win] + - wrapt + - m2w64-toolchain # [win] + - gcc # [unix] run: - - numpy x.x + - setuptools + - numpy >=1.11 - python - wrapt - - mingwpy # [win] + - m2w64-gcc-libs # [win] - libgfortran # [unix] - libgcc # [unix] - xarray test: requires: + - setuptools - netcdf4 - xarray source_files: diff --git a/conda_recipe/meta.yaml.develop b/conda_recipe/meta.yaml.develop new file mode 100644 index 0000000..ee75ff1 --- /dev/null +++ b/conda_recipe/meta.yaml.develop @@ -0,0 +1,58 @@ +{% set version = "1.1.0" %} + +package: + name: wrf-python + version: {{ version }} + +source: + git_url: https://github.com/NCAR/wrf-python + git_branch: develop + + +build: + number: 0 + detect_binary_files_with_prefix: true + +requirements: + build: + - setuptools + - numpy 1.11.* # [unix] + - numpy 1.14.* # [win] + - wrapt + - m2w64-toolchain # [win] + - gcc # [unix] + - python + run: + - setuptools + - numpy >=1.11 + - python + - wrapt + - m2w64-gcc-libs # [win] + - libgfortran # [unix] + - libgcc # [unix] + - xarray + +test: + requires: + - setuptools + - netcdf4 + - xarray + source_files: + - test/ci_tests + imports: + - wrf + commands: + - cd test/ci_tests && python utests.py + +about: + home: https://github.com/NCAR/wrf-python + license: "UCAR" + license_file: '{{ environ["RECIPE_DIR"] }}/LICENSE' + summary: "Diagnostic and interpolation routines for WRF-ARW data." + +extra: + recipe-maintainers: + - bladwig1 + - marylhaley + - david-ian-brown + - khallock diff --git a/conda_recipe/meta.yaml.release b/conda_recipe/meta.yaml.release new file mode 100644 index 0000000..51c2ee0 --- /dev/null +++ b/conda_recipe/meta.yaml.release @@ -0,0 +1,58 @@ +{% set version = "1.1.0" %} + +package: + name: wrf-python + version: {{ version }} + +source: + fn: wrf-python-{{ version }}.tar.gz + url: https://github.com/NCAR/wrf-python/archive/{{ version }}.tar.gz + sha256: ea2202e1d8237c65b9d77a91f00da0f2e7a37ed6214ddd976872b619b9647b33 + +build: + number: 0 + detect_binary_files_with_prefix: true + +requirements: + build: + - setuptools + - numpy 1.11.* # [unix] + - numpy 1.14.* # [win] + - wrapt + - m2w64-toolchain # [win] + - gcc # [unix] + - python + run: + - setuptools + - numpy >=1.11 + - python + - wrapt + - m2w64-gcc-libs # [win] + - libgfortran # [unix] + - libgcc # [unix] + - xarray + +test: + requires: + - setuptools + - netcdf4 + - xarray + source_files: + - test/ci_tests + imports: + - wrf + commands: + - cd test/ci_tests && python utests.py + +about: + home: https://github.com/NCAR/wrf-python + license: "UCAR" + license_file: '{{ environ["RECIPE_DIR"] }}/LICENSE' + summary: "Diagnostic and interpolation routines for WRF-ARW data." + +extra: + recipe-maintainers: + - bladwig1 + - marylhaley + - david-ian-brown + - khallock diff --git a/doc/source/installation.rst b/doc/source/installation.rst index 15b0cc4..bd5cb18 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -4,9 +4,10 @@ Installation Required Dependencies ---------------------- - - Python 2.7, 3.4, or 3.5 - - numpy (1.9 or later) + - Python 2.7, 3.4, or 3.5+ + - numpy (1.11 or later; 1.14 required to build on Windows) - wrapt (1.10 or later) + - setuptools (38.0 or later) Highly Recommended Packages @@ -81,13 +82,52 @@ The source code is available via github: https://github.com/NCAR/wrf-python -To install, change to the wrf-python directory and run:: +Or PyPI: + +https://pypi.python.org/pypi/wrf-python + +To install, if you do not need OpenMP support, change your working directory +to the wrf-python source directory and run:: $ pip install . + +Beginning with wrf-python 1.1, OpenMP is supported, but preprocessing the +ompgen.F90 file is required, which also requires running f2py to +build the .pyf file. To simplify this process, you can use the build scripts in +the *build_scripts* directory as a guide, or just call the script directly. + +Below is a sample from a build script for GNU compiler with OpenMP enabled: + +.. code-block:: none + + cd ../fortran + + gfortran -E ompgen.F90 -fopenmp -cpp -o omp.f90 + + f2py *.f90 -m _wrffortran -h wrffortran.pyf --overwrite-signature + + cd .. + + python setup.py clean --all + + python setup.py config_fc --f90flags="-mtune=generic -fopenmp" build_ext --libraries="gomp" build + + pip install . + +Beginning with numpy 1.14, f2py extensions can now be built using the MSVC +compiler and mingw gfortran compiler. Numpy 1.14 is required to build +wrf-python for Python 3.5+. + +.. note:: + + If you are building on a supercomputer and receiving linker related + errors (e.g. missing symbols, undefined references, etc), you probably + need to unset the LDFLAGS environment variable. System administrators on + supercomputing systems often define LDFLAGS for you so that you don't need + to worry about where libraries like NetCDF are installed. Unfortunately, + this can cause problems with the numpy.distutils build system. To fix, + using the build command from above:: + + $ unset LDFLAGS python setup.py config_fc --f90flags="-mtune=generic -fopenmp" build_ext --libraries="gomp" build + -Note that building on Win64 with Python 3.5+ and the mingw-64 compiler -is very difficult, due to incompatibilities with the runtime libraries and -lack of support from numpy's distutils. Improved support for these -configurations, along with numpy distutils support, should take place this -year. But for now, visual studio and the intel compiler may be required. -Otherwise, Python 2.7 or Python 3.4 is recommended. diff --git a/requirements.txt b/requirements.txt index 83c125c..b044c9f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -numpy>=1.10 +numpy>=1.11 wrapt>=1.10 +setuptools>=38.0 diff --git a/src/wrf/__init__.py b/src/wrf/__init__.py index 2365ac4..25f0762 100755 --- a/src/wrf/__init__.py +++ b/src/wrf/__init__.py @@ -4,12 +4,13 @@ import os import pkg_resources # For gfortran+msvc combination, extra shared libraries may exist (stored by numpy.distutils) -if os.name == 'nt': +if os.name == "nt": try: - req = pkg_resources.Requirement.parse('wrf-python') - extra_dll_dir = pkg_resources.resource_filename(req, 'wrf-python/extra-dll') + req = pkg_resources.Requirement.parse("wrf-python") + extra_dll_dir = pkg_resources.resource_filename(req, + "wrf-python/.libs") if os.path.isdir(extra_dll_dir): - os.environ['PATH'] += os.pathsep + extra_dll_dir + os.environ["PATH"] += os.pathsep + extra_dll_dir except ImportError: pass diff --git a/src/wrf/metadecorators.py b/src/wrf/metadecorators.py index 0549220..228c857 100644 --- a/src/wrf/metadecorators.py +++ b/src/wrf/metadecorators.py @@ -805,7 +805,7 @@ def _set_horiz_meta(wrapped, instance, args, kwargs): outname = None outdimnames = None outcoords = None - outattrs = None + outattrs = OrderedDict() # Get the vertical level units vert_units = None @@ -823,7 +823,6 @@ def _set_horiz_meta(wrapped, instance, args, kwargs): if isinstance(field3d, DataArray): outcoords = OrderedDict() - outattrs = OrderedDict() outdimnames = list(field3d.dims) outcoords.update(field3d.coords) outdimnames.remove(field3d.dims[-3]) @@ -836,7 +835,6 @@ def _set_horiz_meta(wrapped, instance, args, kwargs): else: outname = "field3d_{0}".format(name_levelstr) - outattrs = OrderedDict() outattrs["level"] = levelstr outattrs["missing_value"] = missingval @@ -959,7 +957,7 @@ def _set_cross_meta(wrapped, instance, args, kwargs): outname = None outdimnames = None outcoords = None - outattrs = None + outattrs = OrderedDict() # Use XY to set the cross-section metadata st_x = xy[0,0] @@ -974,7 +972,6 @@ def _set_cross_meta(wrapped, instance, args, kwargs): if isinstance(field3d, DataArray): outcoords = OrderedDict() - outattrs = OrderedDict() outdimnames = list(field3d.dims) outcoords.update(field3d.coords) for i in py3range(-3,0,1): @@ -1062,7 +1059,6 @@ def _set_cross_meta(wrapped, instance, args, kwargs): "not of type xarray.DataArray and contains no " "coordinate information") outname = "field3d_cross" - outattrs = OrderedDict() outattrs["orientation"] = cross_str outattrs["missing_value"] = missingval @@ -1173,7 +1169,7 @@ def _set_line_meta(wrapped, instance, args, kwargs): outname = None outdimnames = None outcoords = None - outattrs = None + outattrs = OrderedDict() # Use XY to set the cross-section metadata st_x = xy[0,0] @@ -1188,7 +1184,6 @@ def _set_line_meta(wrapped, instance, args, kwargs): if isinstance(field2d, DataArray): outcoords = OrderedDict() - outattrs = OrderedDict() outdimnames = list(field2d.dims) outcoords.update(field2d.coords) for i in py3range(-2,0,1): @@ -1273,7 +1268,6 @@ def _set_line_meta(wrapped, instance, args, kwargs): "not of type xarray.DataArray and contains no " "coordinate information") outname = "field2d_line" - outattrs = OrderedDict() outattrs["orientation"] = cross_str @@ -1334,12 +1328,11 @@ def _set_vinterp_meta(wrapped, instance, args, kwargs): outname = None outdimnames = None outcoords = None - outattrs = None + outattrs = OrderedDict() if isinstance(field, DataArray): outcoords = OrderedDict() - outattrs = OrderedDict() outdimnames = list(field.dims) outcoords.update(field.coords) @@ -1352,13 +1345,14 @@ def _set_vinterp_meta(wrapped, instance, args, kwargs): outdimnames.insert(-2, "interp_level") outcoords["interp_level"] = interp_levels outattrs.update(field.attrs) - outattrs["vert_interp_type"] = vert_coord + outname = field.name else: outname = field_type + outattrs["vert_interp_type"] = vert_coord return DataArray(result, name=outname, dims=outdimnames, coords=outcoords, attrs=outattrs) @@ -1402,8 +1396,7 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs): argvars = from_args(wrapped, ("field3d", "xy"), *args, **kwargs) field3d = argvars["field3d"] - xy = argvars["xy"] - xy = to_np(xy) + xy = to_np(argvars["xy"]) result = wrapped(*args, **kwargs) @@ -1419,12 +1412,11 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs): outname = None outdimnames = None outcoords = None - outattrs = None + outattrs = OrderedDict() # Dims are (...,xy,z) if isinstance(field3d, DataArray): outcoords = OrderedDict() - outattrs = OrderedDict() outdimnames = list(field3d.dims) outcoords.update(field3d.coords) @@ -1520,12 +1512,11 @@ def _set_1d_meta(wrapped, instance, args, kwargs): outname = None outdimnames = None outcoords = None - outattrs = None + outattrs = OrderedDict() # Dims are (...,xy,z) if isinstance(field, DataArray): outcoords = OrderedDict() - outattrs = OrderedDict() outdimnames = list(field.dims) outdimnames.pop(-1) @@ -1540,9 +1531,6 @@ def _set_1d_meta(wrapped, instance, args, kwargs): outname = "{0}_z".format(field.name) outcoords["z"] = z_out - outattrs["_FillValue"] = missingval - outattrs["missing_value"] = missingval - desc = field.attrs.get("description", None) if desc is not None: outattrs["description"] = desc @@ -1554,6 +1542,8 @@ def _set_1d_meta(wrapped, instance, args, kwargs): else: outname = "field_z" + outattrs["_FillValue"] = missingval + outattrs["missing_value"] = missingval return DataArray(result, name=outname, dims=outdimnames, coords=outcoords, attrs=outattrs) diff --git a/test/ci_tests/ci_test_file.nc b/test/ci_tests/ci_test_file.nc index ad5a3f6..b0f8945 100644 Binary files a/test/ci_tests/ci_test_file.nc and b/test/ci_tests/ci_test_file.nc differ diff --git a/test/ci_tests/make_test_file.py b/test/ci_tests/make_test_file.py index 5f76b5d..e6ec29b 100644 --- a/test/ci_tests/make_test_file.py +++ b/test/ci_tests/make_test_file.py @@ -9,9 +9,9 @@ from netCDF4 import Dataset from wrf import (getvar, interplevel, interpline, vertcross, vinterp, py2round, CoordPair, ll_to_xy, xy_to_ll, to_np) -VARS_TO_KEEP = ("XLAT", "XLONG", "XLAT_U", "XLAT_V", "XLONG_U", "XLONG_V", - "U", "V", "W", "PH", "PHB", "T", "P", "PB", "Q2", "T2", - "PSFC", "U10", "V10", "XTIME", "QVAPOR", "QCLOUD", +VARS_TO_KEEP = ("Times", "XLAT", "XLONG", "XLAT_U", "XLAT_V", "XLONG_U", + "XLONG_V", "U", "V", "W", "PH", "PHB", "T", "P", "PB", "Q2", + "T2", "PSFC", "U10", "V10", "XTIME", "QVAPOR", "QCLOUD", "QGRAUP", "QRAIN", "QSNOW", "MAPFAC_M", "MAPFAC_U", "MAPFAC_V", "F", "HGT", "RAINC", "RAINSH", "RAINNC") diff --git a/test/ci_tests/utests.py b/test/ci_tests/utests.py index 0a1535f..a61cf5c 100644 --- a/test/ci_tests/utests.py +++ b/test/ci_tests/utests.py @@ -100,6 +100,10 @@ def make_interp_test(varname, wrf_in, referent, multi=False, ref_ht_850 = _get_refvals(referent, "interplevel", repeat, multi) hts = getvar(in_wrfnc, "z", timeidx=timeidx) p = getvar(in_wrfnc, "pressure", timeidx=timeidx) + + # Check that it works with numpy arrays + hts_850 = interplevel(to_np(hts), p, 850) + #print (hts_850) hts_850 = interplevel(hts, p, 850) nt.assert_allclose(to_np(hts_850), ref_ht_850) @@ -111,6 +115,10 @@ def make_interp_test(varname, wrf_in, referent, multi=False, p = getvar(in_wrfnc, "pressure", timeidx=timeidx) pivot_point = CoordPair(hts.shape[-1] // 2, hts.shape[-2] // 2) + # Check that it works with numpy arrays + ht_cross = vertcross(to_np(hts), to_np(p), + pivot_point=pivot_point, angle=90.) + #print (ht_cross) ht_cross = vertcross(hts, p, pivot_point=pivot_point, angle=90.) nt.assert_allclose(to_np(ht_cross), ref_ht_cross, rtol=.01) @@ -123,6 +131,10 @@ def make_interp_test(varname, wrf_in, referent, multi=False, t2 = getvar(in_wrfnc, "T2", timeidx=timeidx) pivot_point = CoordPair(t2.shape[-1] // 2, t2.shape[-2] // 2) + # Check that it works with numpy arrays + t2_line1 = interpline(to_np(t2), pivot_point=pivot_point, + angle=90.0) + #print (t2_line1) t2_line1 = interpline(t2, pivot_point=pivot_point, angle=90.0) nt.assert_allclose(to_np(t2_line1), ref_t2_line) @@ -136,6 +148,17 @@ def make_interp_test(varname, wrf_in, referent, multi=False, interp_levels = [200,300,500,1000] + # Check that it works with numpy arrays + field = vinterp(in_wrfnc, + field=to_np(tk), + vert_coord="theta", + interp_levels=interp_levels, + extrapolate=True, + field_type="tk", + timeidx=timeidx, + log_p=True) + #print (field) + field = vinterp(in_wrfnc, field=tk, vert_coord="theta", diff --git a/test/utests.py b/test/utests.py index 9c9ba12..75cf254 100644 --- a/test/utests.py +++ b/test/utests.py @@ -269,6 +269,9 @@ def make_interp_test(varname, wrf_in, referent, multi=False, ref_ht_500 = _get_refvals(referent, "z_500", repeat, multi) hts = getvar(in_wrfnc, "z", timeidx=timeidx) p = getvar(in_wrfnc, "pressure", timeidx=timeidx) + + # Make sure the numpy versions work first + hts_500 = interplevel(to_np(hts), to_np(p), 500) hts_500 = interplevel(hts, p, 500) nt.assert_allclose(to_np(hts_500), ref_ht_500) @@ -283,6 +286,9 @@ def make_interp_test(varname, wrf_in, referent, multi=False, pivot_point = CoordPair(hts.shape[-1] / 2, hts.shape[-2] / 2) #ht_cross = vertcross(to_np(hts), p, pivot_point=pivot_point, # angle=90., latlon=True) + # Make sure the numpy versions work first + ht_cross = vertcross(to_np(hts), to_np(p), + pivot_point=pivot_point, angle=90.) ht_cross = vertcross(hts, p, pivot_point=pivot_point, angle=90.) # Note: Until the bug is fixed in NCL, the wrf-python cross @@ -315,6 +321,9 @@ def make_interp_test(varname, wrf_in, referent, multi=False, #t2_line1 = interpline(to_np(t2), pivot_point=pivot_point, # angle=90.0, latlon=True) + # Make sure the numpy version works + t2_line1 = interpline(to_np(t2), pivot_point=pivot_point, + angle=90.0) t2_line1 = interpline(t2, pivot_point=pivot_point, angle=90.0) # Note: After NCL is fixed, remove the slice. @@ -337,6 +346,16 @@ def make_interp_test(varname, wrf_in, referent, multi=False, interp_levels = [200,300,500,1000] + # Make sure the numpy version works + field = vinterp(in_wrfnc, + field=to_np(tk), + vert_coord="theta", + interp_levels=interp_levels, + extrapolate=True, + field_type="tk", + timeidx=timeidx, + log_p=True) + field = vinterp(in_wrfnc, field=tk, vert_coord="theta", @@ -630,8 +649,8 @@ class WRFLatLonTest(ut.TestCase): if __name__ == "__main__": from wrf import (omp_set_num_threads, omp_set_schedule, omp_get_schedule, - omp_set_dynamic, OMP_SCHED_STATIC) - omp_set_num_threads(8) + omp_set_dynamic, omp_get_num_procs, OMP_SCHED_STATIC) + omp_set_num_threads(omp_get_num_procs()-1) omp_set_schedule(OMP_SCHED_STATIC, 0) omp_set_dynamic(False)