Browse Source

PEP 8.

Also reorganized the test directory. Various snippets that may or may not be of
use anymore added the the misc directory. Misc. NCL scripts used
during development added to ncl directory.
lon0
Bill Ladwig 6 years ago
parent
commit
d1a4651c23
  1. 10
      doc/source/_templates/product_table.txt
  2. 3
      doc/source/internal_api/index.rst
  3. 68
      src/wrf/g_geoht.py
  4. 5
      src/wrf/routines.py
  5. 17
      test/ctt_test.py
  6. 8
      test/generator_test.py
  7. 40
      test/misc/extract_one_time.py
  8. 70
      test/misc/loop_and_fill_meta.py
  9. 35
      test/misc/mocktest.py
  10. 124
      test/misc/projtest.py
  11. 58
      test/misc/quiver_test.py
  12. 31
      test/misc/snippet.py
  13. 18
      test/misc/varcache.py
  14. 19
      test/misc/viewtest.py
  15. 230
      test/misc/wps.py
  16. 0
      test/ncl/listBug.ncl
  17. 0
      test/ncl/ncl_get_var.ncl
  18. 92
      test/ncl/ncl_vertcross.ncl
  19. 81
      test/ncl/refl10_cross.ncl
  20. 26
      test/ncl/rotated_test.ncl
  21. 21
      test/ncl/test_this.ncl
  22. 0
      test/ncl/test_vinterp.ncl
  23. 416
      test/ncl/wrf_user_vertcross.ncl
  24. 52
      test/test_filevars.py
  25. 41
      test/test_inputs.py
  26. 42
      test/test_multi_cache.py
  27. 29
      test/test_omp.py
  28. 120
      test/test_proj_params.py
  29. 1
      test/test_units.py
  30. 2
      test/utests.py

10
doc/source/_templates/product_table.txt

@ -245,6 +245,16 @@
| | | | | | | | | |
| | | mi | | | | | mi | |
+--------------------+---------------------------------------------------------------+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ +--------------------+---------------------------------------------------------------+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| height_agl | Model Height for Mass Grid (AGL) | m | **units** (str) : Set to desired units. Default is *'m'*. |
| | | | |
| | | km | |
| | | | |
| | | dm | |
| | | | |
| | | ft | |
| | | | |
| | | mi | |
+--------------------+---------------------------------------------------------------+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| zstag | Model Height for Vertically Staggered Grid | m | **msl** (boolean): Set to False to return AGL values. True is for MSL. Default is *True*. | | zstag | Model Height for Vertically Staggered Grid | m | **msl** (boolean): Set to False to return AGL values. True is for MSL. Default is *True*. |
| | | | | | | | | |
| | | km | **units** (str) : Set to desired units. Default is *'m'*. | | | | km | **units** (str) : Set to desired units. Default is *'m'*. |

3
doc/source/internal_api/index.rst

@ -23,6 +23,9 @@ The routines below are called internally by :meth:`wrf.getvar`.
wrf.g_dewpoint.get_dp_2m wrf.g_dewpoint.get_dp_2m
wrf.g_geoht.get_geopt wrf.g_geoht.get_geopt
wrf.g_geoht.get_height wrf.g_geoht.get_height
wrf.g_geoht.get_height_agl
wrf.g_geoht.get_stag_geopt
wrf.g_geoht.get_stag_height
wrf.g_helicity.get_srh wrf.g_helicity.get_srh
wrf.g_helicity.get_uh wrf.g_helicity.get_uh
wrf.g_omega.get_omega wrf.g_omega.get_omega

68
src/wrf/g_geoht.py

@ -391,3 +391,71 @@ def get_stag_height(wrfin, timeidx=0, method="cat", squeeze=True,
return _get_geoht(wrfin, timeidx, method, squeeze, cache, meta, _key, return _get_geoht(wrfin, timeidx, method, squeeze, cache, meta, _key,
True, msl, stag=True) True, msl, stag=True)
@set_height_metadata(geopt=False, stag=False)
@convert_units("height", "m")
def get_height_agl(wrfin, timeidx=0, method="cat", squeeze=True,
cache=None, meta=True, _key=None, units="m"):
"""Return the geopotential height (AGL).
The geopotential height is returned as Above Ground Level (AGL) by
subtracting the terrain height.
This functions extracts the necessary variables from the NetCDF file
object in order to perform the calculation.
Args:
wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \
iterable): WRF-ARW NetCDF
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile`
or an iterable sequence of the aforementioned types.
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The
desired time index. This value can be a positive integer,
negative integer, or
:data:`wrf.ALL_TIMES` (an alias for None) to return
all times in the file or sequence. The default is 0.
method (:obj:`str`, optional): The aggregation method to use for
sequences. Must be either 'cat' or 'join'.
'cat' combines the data along the Time dimension.
'join' creates a new dimension for the file index.
The default is 'cat'.
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions
with a size of 1 from being automatically removed from the shape
of the output. Default is True.
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray)
that can be used to supply pre-extracted NetCDF variables to the
computational routines. It is primarily used for internal
purposes, but can also be used to improve performance by
eliminating the need to repeatedly extract the same variables
used in multiple diagnostics calculations, particularly when using
large sequences of files.
Default is None.
meta (:obj:`bool`, optional): Set to False to disable metadata and
return :class:`numpy.ndarray` instead of
:class:`xarray.DataArray`. Default is True.
_key (:obj:`int`, optional): A caching key. This is used for internal
purposes only. Default is None.
units (:obj:`str`): The desired units. Refer to the :meth:`getvar`
product table for a list of available units for 'height_agl'.
Default is 'm'.
Returns:
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The
geopotential height.
If xarray is enabled and the *meta* parameter is True, then the result
will be a :class:`xarray.DataArray` object. Otherwise, the result will
be a :class:`numpy.ndarray` object with no metadata.
"""
return _get_geoht(wrfin, timeidx, method, squeeze, cache, meta, _key,
True, False)

5
src/wrf/routines.py

@ -8,7 +8,8 @@ from .g_cape import (get_2dcape, get_3dcape, get_cape2d_only,
from .g_ctt import get_ctt from .g_ctt import get_ctt
from .g_dbz import get_dbz, get_max_dbz from .g_dbz import get_dbz, get_max_dbz
from .g_dewpoint import get_dp, get_dp_2m from .g_dewpoint import get_dp, get_dp_2m
from .g_geoht import get_geopt, get_height, get_stag_geopt, get_stag_height from .g_geoht import (get_geopt, get_height, get_stag_geopt, get_stag_height,
get_height_agl)
from .g_helicity import get_srh, get_uh from .g_helicity import get_srh, get_uh
from .g_latlon import get_lat, get_lon from .g_latlon import get_lat, get_lon
from .g_omega import get_omega from .g_omega import get_omega
@ -78,6 +79,7 @@ _FUNC_MAP = {"cape2d": get_2dcape,
"cloudfrac": get_cloudfrac, "cloudfrac": get_cloudfrac,
"geopt_stag": get_stag_geopt, "geopt_stag": get_stag_geopt,
"zstag": get_stag_height, "zstag": get_stag_height,
"height_agl": get_height_agl,
# Diagnostics below are extracted from multi-product diagnostics # Diagnostics below are extracted from multi-product diagnostics
"cape2d_only": get_cape2d_only, "cape2d_only": get_cape2d_only,
"cin2d_only": get_cin2d_only, "cin2d_only": get_cin2d_only,
@ -143,6 +145,7 @@ _VALID_KARGS = {"cape2d": ["missing"],
"mid_thresh", "high_thresh"], "mid_thresh", "high_thresh"],
"geopt_stag": [], "geopt_stag": [],
"zstag": ["msl", "units"], "zstag": ["msl", "units"],
"height_agl": ["units"],
"cape2d_only": ["missing"], "cape2d_only": ["missing"],
"cin2d_only": ["missing"], "cin2d_only": ["missing"],
"lcl": ["missing"], "lcl": ["missing"],

17
test/ctt_test.py

@ -4,10 +4,12 @@ from matplotlib.cm import get_cmap
import cartopy.crs as crs import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature from cartopy.feature import NaturalEarthFeature
from wrf import to_np, getvar, smooth2d, get_cartopy, cartopy_xlim, cartopy_ylim, latlon_coords from wrf import (to_np, getvar, smooth2d, get_cartopy, cartopy_xlim,
cartopy_ylim, latlon_coords)
# Open the NetCDF file # Open the NetCDF file
ncfile = Dataset("/Users/ladwig/Documents/wrf_files/problem_files/cfrac_bug/wrfout_d02_1987-10-01_00:00:00") ncfile = Dataset("/Users/ladwig/Documents/wrf_files/"
"problem_files/cfrac_bug/wrfout_d02_1987-10-01_00:00:00")
# Get the sea level pressure # Get the sea level pressure
ctt = getvar(ncfile, "ctt") ctt = getvar(ncfile, "ctt")
@ -19,20 +21,23 @@ lats, lons = latlon_coords(ctt)
cart_proj = get_cartopy(ctt) cart_proj = get_cartopy(ctt)
# Create a figure # Create a figure
fig = plt.figure(figsize=(12,9)) fig = plt.figure(figsize=(12, 9))
# Set the GeoAxes to the projection used by WRF # Set the GeoAxes to the projection used by WRF
ax = plt.axes(projection=cart_proj) ax = plt.axes(projection=cart_proj)
# Download and add the states and coastlines # Download and add the states and coastlines
states = NaturalEarthFeature(category='cultural', scale='50m', facecolor='none', states = NaturalEarthFeature(category='cultural', scale='50m',
facecolor='none',
name='admin_1_states_provinces_shp') name='admin_1_states_provinces_shp')
ax.add_feature(states, linewidth=.5) ax.add_feature(states, linewidth=.5)
ax.coastlines('50m', linewidth=0.8) ax.coastlines('50m', linewidth=0.8)
# Make the contour outlines and filled contours for the smoothed sea level pressure. # Make the contour outlines and filled contours for the smoothed sea level
# pressure.
plt.contour(to_np(lons), to_np(lats), to_np(ctt), 10, colors="black", plt.contour(to_np(lons), to_np(lats), to_np(ctt), 10, colors="black",
transform=crs.PlateCarree()) transform=crs.PlateCarree())
plt.contourf(to_np(lons), to_np(lats), to_np(ctt), 10, transform=crs.PlateCarree(), plt.contourf(to_np(lons), to_np(lats), to_np(ctt), 10,
transform=crs.PlateCarree(),
cmap=get_cmap("jet")) cmap=get_cmap("jet"))
# Add a color bar # Add a color bar

8
test/generator_test.py

@ -1,17 +1,19 @@
from __future__ import (absolute_import, division, print_function, unicode_literals) from __future__ import (absolute_import, division, print_function,
unicode_literals)
from wrf import getvar from wrf import getvar
from netCDF4 import Dataset as nc from netCDF4 import Dataset as nc
#ncfile = nc("/Users/ladwig/Documents/wrf_files/wrfout_d01_2016-02-25_18_00_00")
ncfile = nc("/Users/ladwig/Documents/wrf_files/wrfout_d01_2016-10-07_00_00_00") ncfile = nc("/Users/ladwig/Documents/wrf_files/wrfout_d01_2016-10-07_00_00_00")
def gen_seq(): def gen_seq():
wrfseq = [ncfile, ncfile, ncfile] wrfseq = [ncfile, ncfile, ncfile]
for wrf in wrfseq: for wrf in wrfseq:
yield wrf yield wrf
p_gen = getvar(gen_seq(), "P", method="join") p_gen = getvar(gen_seq(), "P", method="join")
print(p_gen) print(p_gen)
del p_gen del p_gen

40
test/misc/extract_one_time.py

@ -0,0 +1,40 @@
from netCDF4 import Dataset
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", "QICE", "MAPFAC_M", "MAPFAC_U",
"MAPFAC_V", "F", "HGT", "RAINC", "RAINSH", "RAINNC",
"I_RAINC", "I_RAINNC")
INPUT_FILE = "wrfout_d02_2005-08-28_00:00:00"
OUTPUT_FILE = "wrfout_problem_file"
DESIRED_TIME_INDEX = 0
with Dataset(INPUT_FILE) as infile, Dataset(OUTPUT_FILE, mode="w") as outfile:
# Copy the global attributes
outfile.setncatts(infile.__dict__)
# Copy Dimensions
for name, dimension in infile.dimensions.items():
if name != "Time":
dimsize = len(dimension)
outfile.createDimension(name, dimsize)
else:
outfile.createDimension(name, 1)
# Copy Variables
for name, variable in infile.variables.iteritems():
if name not in VARS_TO_KEEP:
continue
outvar = outfile.createVariable(name, variable.datatype,
variable.dimensions, zlib=True)
if len(variable.dimensions) > 1:
outvar[:] = variable[DESIRED_TIME_INDEX, :]
else:
outvar[:] = variable[DESIRED_TIME_INDEX]
outvar.setncatts(variable.__dict__)

70
test/misc/loop_and_fill_meta.py

@ -0,0 +1,70 @@
from __future__ import print_function, division
import os
import numpy as np
from netCDF4 import Dataset
from wrf import getvar, ALL_TIMES, to_np
import xarray
filename_list = ["/Users/ladwig/Documents/wrf_files/"
"wrf_vortex_single/wrfout_d02_2005-08-28_00:00:00",
"/Users/ladwig/Documents/wrf_files/wrf_vortex_single/"
"wrfout_d02_2005-08-28_03:00:00",
"/Users/ladwig/Documents/wrf_files/wrf_vortex_single/"
"wrfout_d02_2005-08-28_06:00:00",
"/Users/ladwig/Documents/wrf_files/wrf_vortex_single/"
"wrfout_d02_2005-08-28_09:00:00"]
result_shape = (4, 1, 96, 96)
# Let's get the first time so we can copy the metadata later
f = Dataset(filename_list[0])
# By setting squeeze to False, you'll get all the dimension names.
z1 = getvar(f, "T2", 0, squeeze=False)
xlat = getvar(f, "XLAT", 0)
xlong = getvar(f, "XLONG", 0)
z_final = np.empty(result_shape, np.float32)
# Modify this number if using more than 1 time per file
times_per_file = 1
data_times = []
xtimes = []
for timeidx in range(result_shape[0]):
# Compute the file index and the time index inside the file
fileidx = timeidx // times_per_file
file_timeidx = timeidx % times_per_file
f = Dataset(filename_list[fileidx])
z = getvar(f, "T2", file_timeidx)
t = getvar(f, "Times", file_timeidx)
xt = getvar(f, "xtimes", file_timeidx)
data_times.append(to_np(t))
xtimes.append(to_np(xt))
z_final[timeidx, :] = z[:]
f.close()
# Let's make the metadata. Dimension names should copy easily if you set
# sqeeze to False, otherwise you can just set them yourself is a tuple of
# dimension names. Since you wanted
# to keep the bottom_top dimension for this 2D variable (which is normally
# removed), I'm doing this manually.
z_dims = ["Time", "bottom_top", "south_north", "west_east"]
# Xarray doesn't copy coordinates easily (it always complains about shape
# mismatches), so do this manually
z_coords = {}
z_coords["Time"] = data_times
z_coords["XTIME"] = ("Time",), xtimes
z_coords["XLAT"] = ("south_north", "west_east"), xlat
z_coords["XLONG"] = ("south_north", "west_east"), xlong
z_name = "T2"
# Attributes copy nicely
z_attrs = {}
z_attrs.update(z1.attrs)
z_with_meta = xarray.DataArray(z_final, coords=z_coords, dims=z_dims,
attrs=z_attrs, name=z_name)

35
test/misc/mocktest.py

@ -6,39 +6,48 @@ try:
except ImportError: except ImportError:
from mock import Mock as MagicMock from mock import Mock as MagicMock
class Mock(MagicMock): class Mock(MagicMock):
@classmethod @classmethod
def __getattr__(cls, name): def __getattr__(cls, name):
return Mock() return Mock()
MOCK_MODULES = ["numpy", "numpy.ma", "xarray", "cartopy", MOCK_MODULES = ["numpy", "numpy.ma", "xarray", "cartopy",
"pandas", "matplotlib", "netCDF4", "mpl_toolkits.basemap", "pandas", "matplotlib", "netCDF4", "mpl_toolkits.basemap",
"wrf._wrffortran"] "wrf._wrffortran"]
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
consts = {"DEFAULT_FILL" : 9.9692099683868690E36, consts = {"DEFAULT_FILL": 9.9692099683868690E36,
"DEFAULT_FILL_INT8" : -127, "DEFAULT_FILL_INT8": -127,
"DEFAULT_FILL_INT16" : -32767, "DEFAULT_FILL_INT16": -32767,
"DEFAULT_FILL_INT32" : -2147483647, "DEFAULT_FILL_INT32": -2147483647,
"DEFAULT_FILL_INT64" : -9223372036854775806, "DEFAULT_FILL_INT64": -9223372036854775806,
"DEFAULT_FILL_FLOAT" : 9.9692099683868690E36, "DEFAULT_FILL_FLOAT": 9.9692099683868690E36,
"DEFAULT_FILL_DOUBLE" : 9.9692099683868690E36, "DEFAULT_FILL_DOUBLE": 9.9692099683868690E36,
"fomp_sched_static" : 1, "fomp_sched_static": 1,
"fomp_sched_dynamic" : 2, "fomp_sched_dynamic": 2,
"fomp_sched_guided" : 3, "fomp_sched_guided": 3,
"fomp_sched_auto" : 4} "fomp_sched_auto": 4}
class MockWrfConstants(object): class MockWrfConstants(object):
def __init__(self): def __init__(self):
self.__dict__ = consts self.__dict__ = consts
def mock_asscalar(val): def mock_asscalar(val):
return float(val) return float(val)
sys.modules["wrf._wrffortran"].wrf_constants = MockWrfConstants() sys.modules["wrf._wrffortran"].wrf_constants = MockWrfConstants()
sys.modules["wrf._wrffortran"].omp_constants = MockWrfConstants() sys.modules["wrf._wrffortran"].omp_constants = MockWrfConstants()
sys.modules["numpy"].asscalar = mock_asscalar sys.modules["numpy"].asscalar = mock_asscalar
import wrf try:
print (wrf.get_coord_pairs.__doc__) import wrf
except ImportError:
pass
print(wrf.get_coord_pairs.__doc__)

124
test/misc/projtest.py

@ -7,6 +7,8 @@ import matplotlib.cm as cm
from netCDF4 import Dataset as NetCDF from netCDF4 import Dataset as NetCDF
from wrf import get_proj_params
from wrf.projection import getproj, RotatedLatLon, PolarStereographic
PYNGL = True PYNGL = True
try: try:
@ -27,15 +29,11 @@ except ImportError:
CARTOPY = False CARTOPY = False
from wrf import get_proj_params
from wrf.projection import getproj, RotatedLatLon, PolarStereographic
FILE_DIR = "/Users/ladwig/Documents/wrf_files/" FILE_DIR = "/Users/ladwig/Documents/wrf_files/"
WRF_FILES = [ WRF_FILES = [join(FILE_DIR, "norway", "geo_em.d01.nc"),
join(FILE_DIR, "norway", "geo_em.d01.nc"),
join(FILE_DIR, "rotated_pole", "EAS_geo_em.d01.nc"), join(FILE_DIR, "rotated_pole", "EAS_geo_em.d01.nc"),
join(FILE_DIR, "rotated_pole", "EUR_geo_em.d01.nc"), join(FILE_DIR, "rotated_pole", "EUR_geo_em.d01.nc"),
join(FILE_DIR,"wrfout_d01_2016-02-25_18_00_00"), join(FILE_DIR, "wrfout_d01_2016-02-25_18_00_00"),
join(FILE_DIR, "wrfout_d01_2008-09-29_23-30-00"), join(FILE_DIR, "wrfout_d01_2008-09-29_23-30-00"),
join(FILE_DIR, "wrfout_d01_2010-06-13_21:00:00")] join(FILE_DIR, "wrfout_d01_2010-06-13_21:00:00")]
@ -46,63 +44,66 @@ def nz_proj():
lons = np.array([[163.839595, -179.693502], lons = np.array([[163.839595, -179.693502],
[163.839595, -179.693502]]) [163.839595, -179.693502]])
params = {"MAP_PROJ" : 6, params = {"MAP_PROJ": 6,
"CEN_LAT" : -41.814869, "CEN_LAT": -41.814869,
"CEN_LON" : 179.693502, "CEN_LON": 179.693502,
"TRUELAT1" : 0, "TRUELAT1": 0,
"TRUELAT2": 0, "TRUELAT2": 0,
"MOAD_CEN_LAT" : -41.814869, "MOAD_CEN_LAT": -41.814869,
"STAND_LON" : 180.0 - 179.693502, "STAND_LON": 180.0 - 179.693502,
"POLE_LAT" : 48.185131, "POLE_LAT": 48.185131,
"POLE_LON" : 0.0} "POLE_LON": 0.0}
return lats, lons, RotatedLatLon(lats=lats, lons=lons, **params) return lats, lons, RotatedLatLon(lats=lats, lons=lons, **params)
def argentina_proj(): def argentina_proj():
lats = np.array([[-57.144064, -57.144064], lats = np.array([[-57.144064, -57.144064],
[-21.154470, -21.154470]]) [-21.154470, -21.154470]])
lons = np.array([[-86.893797, -37.089724], lons = np.array([[-86.893797, -37.089724],
[-86.893797, -37.089724]]) [-86.893797, -37.089724]])
params = {"MAP_PROJ" : 6, params = {"MAP_PROJ": 6,
"CEN_LAT" : -39.222954, "CEN_LAT": -39.222954,
"CEN_LON" : -65.980109, "CEN_LON": -65.980109,
"TRUELAT1" : 0, "TRUELAT1": 0,
"TRUELAT2": 0, "TRUELAT2": 0,
"MOAD_CEN_LAT" : -39.222954, "MOAD_CEN_LAT": -39.222954,
"STAND_LON" : 180.0 - -65.980109, "STAND_LON": 180.0 - -65.980109,
"POLE_LAT" : 90 + -39.222954, "POLE_LAT": 90 + -39.222954,
"POLE_LON" : 0.0} "POLE_LON": 0.0}
return lats, lons, RotatedLatLon(lats=lats, lons=lons, **params) return lats, lons, RotatedLatLon(lats=lats, lons=lons, **params)
def south_polar_proj(): def south_polar_proj():
lats = np.array([[-30.0,-30.0], lats = np.array([[-30.0, -30.0],
[-30.0,-30.0]]) [-30.0, -30.0]])
lons = np.array([[-120, 60], lons = np.array([[-120, 60],
[-120, 60]]) [-120, 60]])
params = {"MAP_PROJ" : 2, params = {"MAP_PROJ": 2,
"CEN_LAT" : -90.0, "CEN_LAT": -90.0,
"CEN_LON" : 0, "CEN_LON": 0,
"TRUELAT1" : -10.0, "TRUELAT1": -10.0,
"MOAD_CEN_LAT" : -90.0, "MOAD_CEN_LAT": -90.0,
"STAND_LON" : 0} "STAND_LON": 0}
return lats, lons, PolarStereographic(lats=lats, lons=lons, **params) return lats, lons, PolarStereographic(lats=lats, lons=lons, **params)
def north_polar_proj(): def north_polar_proj():
lats = np.array([[30.0,30.0], lats = np.array([[30.0, 30.0],
[30.0,30.0]]) [30.0, 30.0]])
lons = np.array([[-45, 140], lons = np.array([[-45, 140],
[-45, 140]]) [-45, 140]])
params = {"MAP_PROJ" : 2, params = {"MAP_PROJ": 2,
"CEN_LAT" : 90.0, "CEN_LAT": 90.0,
"CEN_LON" : 10, "CEN_LON": 10,
"TRUELAT1" : 10.0, "TRUELAT1": 10.0,
"MOAD_CEN_LAT" : 90.0, "MOAD_CEN_LAT": 90.0,
"STAND_LON" : 10} "STAND_LON": 10}
return lats, lons, PolarStereographic(lats=lats, lons=lons, **params) return lats, lons, PolarStereographic(lats=lats, lons=lons, **params)
@ -113,20 +114,22 @@ def dateline_rot_proj():
lons = np.array([[170.332771, -153.456292], lons = np.array([[170.332771, -153.456292],
[170.332771, -153.456292]]) [170.332771, -153.456292]])
params = {"MAP_PROJ" : 6, params = {"MAP_PROJ": 6,
"CEN_LAT" : 66.335764, "CEN_LAT": 66.335764,
"CEN_LON" : -173.143792, "CEN_LON": -173.143792,
"TRUELAT1" : 0, "TRUELAT1": 0,
"TRUELAT2": 0, "TRUELAT2": 0,
"MOAD_CEN_LAT" : 66.335764, "MOAD_CEN_LAT": 66.335764,
"STAND_LON" : 173.143792, "STAND_LON": 173.143792,
"POLE_LAT" : 90.0 - 66.335764, "POLE_LAT": 90.0 - 66.335764,
"POLE_LON" : 180.0} "POLE_LON": 180.0}
return lats, lons, RotatedLatLon(lats=lats, lons=lons, **params) return lats, lons, RotatedLatLon(lats=lats, lons=lons, **params)
class WRFProjTest(ut.TestCase): class WRFProjTest(ut.TestCase):
longMessage = True longMessage = True
def make_test(wrf_file=None, fixed_case=None): def make_test(wrf_file=None, fixed_case=None):
if wrf_file is not None: if wrf_file is not None:
ncfile = NetCDF(wrf_file) ncfile = NetCDF(wrf_file)
@ -144,22 +147,22 @@ def make_test(wrf_file=None, fixed_case=None):
elif fixed_case == "north_polar": elif fixed_case == "north_polar":
lats, lons, proj = north_polar_proj() lats, lons, proj = north_polar_proj()
elif fixed_case == "dateline_rot": elif fixed_case == "dateline_rot":
lats,lons,proj = dateline_rot_proj() lats, lons, proj = dateline_rot_proj()
print ("wrf proj4: {}".format(proj.proj4())) print("wrf proj4: {}".format(proj.proj4()))
if PYNGL: if PYNGL:
# PyNGL plotting # PyNGL plotting
wks_type = bytes("png") wks_type = bytes("png")
wks = Ngl.open_wks(wks_type,bytes("pyngl_{}".format(name_suffix))) wks = Ngl.open_wks(wks_type, bytes("pyngl_{}".format(name_suffix)))
mpres = proj.pyngl() mpres = proj.pyngl()
map = Ngl.map(wks,mpres) map = Ngl.map(wks, mpres)
Ngl.delete_wks(wks) Ngl.delete_wks(wks)
if BASEMAP: if BASEMAP:
# Basemap plotting # Basemap plotting
fig = plt.figure(figsize=(10,10)) fig = plt.figure(figsize=(10, 10))
ax = fig.add_axes([0.1,0.1,0.8,0.8]) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
# Define and plot the meridians and parallels # Define and plot the meridians and parallels
min_lat = np.amin(lats) min_lat = np.amin(lats)
@ -174,27 +177,28 @@ def make_test(wrf_file=None, fixed_case=None):
bm = proj.basemap() bm = proj.basemap()
bm.drawcoastlines(linewidth=.5) bm.drawcoastlines(linewidth=.5)
#bm.drawparallels(parallels,labels=[1,1,1,1],fontsize=10) # bm.drawparallels(parallels,labels=[1,1,1,1],fontsize=10)
#bm.drawmeridians(meridians,labels=[1,1,1,1],fontsize=10) # bm.drawmeridians(meridians,labels=[1,1,1,1],fontsize=10)
print ("basemap proj4: {}".format(bm.proj4string)) print("basemap proj4: {}".format(bm.proj4string))
plt.savefig("basemap_{}.png".format(name_suffix)) plt.savefig("basemap_{}.png".format(name_suffix))
plt.close(fig) plt.close(fig)
if CARTOPY: if CARTOPY:
# Cartopy plotting # Cartopy plotting
fig = plt.figure(figsize=(10,10)) fig = plt.figure(figsize=(10, 10))
ax = plt.axes([0.1,0.1,0.8,0.8], projection=proj.cartopy()) ax = plt.axes([0.1, 0.1, 0.8, 0.8], projection=proj.cartopy())
print ("cartopy proj4: {}".format(proj.cartopy().proj4_params)) print("cartopy proj4: {}".format(proj.cartopy().proj4_params))
ax.coastlines('50m', linewidth=0.8) ax.coastlines('50m', linewidth=0.8)
#print proj.x_extents() # print proj.x_extents()
#print proj.y_extents() # print proj.y_extents()
ax.set_xlim(proj.cartopy_xlim()) ax.set_xlim(proj.cartopy_xlim())
ax.set_ylim(proj.cartopy_ylim()) ax.set_ylim(proj.cartopy_ylim())
ax.gridlines() ax.gridlines()
plt.savefig("cartopy_{}.png".format(name_suffix)) plt.savefig("cartopy_{}.png".format(name_suffix))
plt.close(fig) plt.close(fig)
if __name__ == "__main__": if __name__ == "__main__":
for wrf_file in WRF_FILES: for wrf_file in WRF_FILES:
test_func = make_test(wrf_file=wrf_file) test_func = make_test(wrf_file=wrf_file)

58
test/misc/quiver_test.py

@ -0,0 +1,58 @@
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature
from wrf import (getvar, interplevel, to_np, latlon_coords, get_cartopy,
cartopy_xlim, cartopy_ylim)
# Open the NetCDF file
ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00")
# Extract the pressure and wind variables
p = getvar(ncfile, "pressure")
# Note: This is m/s.
ua = getvar(ncfile, "ua")
va = getvar(ncfile, "va")
# Interpolate u, and v winds to 950 hPa
u_950 = interplevel(ua, p, 950)
v_950 = interplevel(va, p, 950)
# Get the lat/lon coordinates
lats, lons = latlon_coords(u_950)
# Get the map projection information
cart_proj = get_cartopy(u_950)
# Create the figure
fig = plt.figure(figsize=(12, 9))
ax = plt.axes(projection=cart_proj)
# Download and add the states and coastlines
states = NaturalEarthFeature(category='cultural', scale='50m',
facecolor='none',
name='admin_1_states_provinces_shp')
ax.add_feature(states, linewidth=0.5)
ax.coastlines('50m', linewidth=0.8)
# Add the 950 hPa wind barbs, only plotting every 'thin'ed barb. Adjust thin
# as needed. Also, no scaling is done for the arrows, so you might need to
# mess with the scale argument.
thin = 50
plt.quiver(to_np(lons[::thin, ::thin]), to_np(lats[::thin, ::thin]),
to_np(u_950[::thin, ::thin]), to_np(v_950[::thin, ::thin]),
transform=crs.PlateCarree())
# Set the map bounds
ax.set_xlim(cartopy_xlim(u_950))
ax.set_ylim(cartopy_ylim(v_950))
ax.gridlines()
plt.title("Arrows")
plt.show()

31
test/misc/snippet.py

@ -1,30 +1,29 @@
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap from mpl_toolkits.basemap import Basemap
def main(): def main():
bm = Basemap(projection = "rotpole", bm = Basemap(projection="rotpole",
o_lat_p = 36.0, o_lat_p=36.0,
o_lon_p = 180.0, o_lon_p=180.0,
llcrnrlat = -10.590603, llcrnrlat=-10.590603,
urcrnrlat = 46.591976, urcrnrlat=46.591976,
llcrnrlon = -139.08585, llcrnrlon=-139.08585,
urcrnrlon = 22.661009, urcrnrlon=22.661009,
lon_0 = -106.0, lon_0=-106.0,
rsphere = 6370000, rsphere=6370000,
resolution = 'l') resolution='l')
fig = plt.figure(figsize=(8,8)) fig = plt.figure(figsize=(8, 8))
ax = fig.add_axes([0.1,0.1,0.8,0.8]) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
bm.drawcoastlines(linewidth=.5) bm.drawcoastlines(linewidth=.5)
print bm.proj4string print(bm.proj4string)
plt.savefig("basemap_map.png") plt.savefig("basemap_map.png")
plt.close(fig) plt.close(fig)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

18
test/varcache.py → test/misc/varcache.py

@ -4,13 +4,18 @@ import time
from netCDF4 import Dataset from netCDF4 import Dataset
from wrf import getvar, ALL_TIMES, extract_vars from wrf import getvar, ALL_TIMES, extract_vars
wrf_filenames = ["/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/wrfout_d02_2005-08-28_00:00:00", wrf_filenames = ["/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/"
"/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/wrfout_d02_2005-08-28_12:00:00", "moving_nest/wrfout_d02_2005-08-28_00:00:00",
"/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/wrfout_d02_2005-08-29_00:00:00"] "/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/"
"moving_nest/wrfout_d02_2005-08-28_12:00:00",
"/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/"
"moving_nest/wrfout_d02_2005-08-29_00:00:00"]
wrfin = [Dataset(x) for x in wrf_filenames] wrfin = [Dataset(x) for x in wrf_filenames]
my_cache = extract_vars(wrfin, ALL_TIMES, ("P", "PB", "PH", "PHB", "T", "QVAPOR", "HGT", "U", "V", "W", "PSFC")) my_cache = extract_vars(wrfin, ALL_TIMES,
("P", "PB", "PH", "PHB", "T", "QVAPOR", "HGT", "U",
"V", "W", "PSFC"))
start = time.time() start = time.time()
for var in ("avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz", for var in ("avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz",
@ -21,7 +26,7 @@ for var in ("avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz",
v = getvar(wrfin, var, ALL_TIMES) v = getvar(wrfin, var, ALL_TIMES)
end = time.time() end = time.time()
print ("Time taken without variable cache: ", (end-start)) print("Time taken without variable cache: ", (end-start))
start = time.time() start = time.time()
for var in ("avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz", for var in ("avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz",
@ -32,5 +37,4 @@ for var in ("avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz",
v = getvar(wrfin, var, ALL_TIMES, cache=my_cache) v = getvar(wrfin, var, ALL_TIMES, cache=my_cache)
end = time.time() end = time.time()
print ("Time taken with variable cache: ", (end-start)) print("Time taken with variable cache: ", (end-start))

19
test/viewtest.py → test/misc/viewtest.py

@ -1,26 +1,25 @@
# Test snippet for f2py
import numpy as np import numpy as np
import wrf._wrffortran import wrf._wrffortran
errlen = int(wrf._wrffortran.constants.errlen) errlen = int(wrf._wrffortran.constants.errlen)
a = np.ones((3, 3, 3))
a = np.ones((3,3,3)) b = np.zeros((3, 3, 3, 3))
b = np.zeros((3,3,3,3))
c = np.zeros(errlen, "c") c = np.zeros(errlen, "c")
errstat = np.array(0) errstat = np.array(0)
errmsg = np.zeros(errlen, "c") errmsg = np.zeros(errlen, "c")
c[:] = "Test String" c[:] = "Test String"
for i in xrange(2): for i in xrange(2):
outview = b[i,:] outview = b[i, :]
outview = outview.T outview = outview.T
q = wrf._wrffortran.testfunc(a,outview,c,errstat=errstat,errmsg=errmsg) q = wrf._wrffortran.testfunc(a, outview, c, errstat=errstat,
print errstat errmsg=errmsg)
print(errstat)
str_bytes = (bytes(char).decode("utf-8") for char in errmsg[:]) str_bytes = (bytes(char).decode("utf-8") for char in errmsg[:])
print repr(errmsg) print(repr(errmsg))
print "".join(str_bytes).strip() print("".join(str_bytes).strip())

230
test/misc/wps.py

@ -0,0 +1,230 @@
# Hastily made script to read WPS intermediate files
from __future__ import print_function
import struct
import numpy as np
# Number of bytes used at the start and end of a fortran record to
# indicate the record size
SIZE_BYTES = 4
class WPSData(object):
def __init__(self, ifv=None, hdate=None, xfcst=None, map_source=None,
field=None, units=None, desc=None, xlvl=None, nx=None,
ny=None, iproj=None, startloc=None, startlat=None,
startlon=None, deltalat=None, deltalon=None, nlats=None,
dx=None, dy=None, xlonc=None, truelat1=None, truelat2=None,
earth_radius=None, is_wind_earth_rel=None, slab=None):
self.ifv = ifv
self.hdate = hdate
self.xfcst = xfcst
self.map_source = map_source
self.field = field
self.units = units
self.desc = desc
self.xlvl = xlvl
self.nx = nx
self.ny = ny
self.iproj = iproj
self.startloc = startloc
self.startlat = startlat
self.startlon = startlon
self.deltalat = deltalat
self.deltalon = deltalon
self.nlats = nlats
self.dx = dx
self.dy = dy
self.xlonc = xlonc
self.truelat1 = truelat1
self.truelat2 = truelat2
self.earth_radius = earth_radius
self.is_wind_earth_rel = is_wind_earth_rel
self.slab = slab
def _parse_record1(data):
result = {}
result["ifv"] = struct.unpack(">i", data)
return result
def _parse_record2(data):
result = {}
parsed = struct.unpack(">24sf32s9s25s46sfiii", data)
result["hdate"] = parsed[0]
result["xfcst"] = parsed[1]
result["map_source"] = parsed[2]
result["field"] = parsed[3]
result["units"] = parsed[4]
result["desc"] = parsed[5]
result["xlvl"] = parsed[6]
result["nx"] = parsed[7]
result["ny"] = parsed[8]
result["iproj"] = parsed[9]
return result
def _parse_record3(data, iproj):
result = {}
if iproj == 0:
fmt = ">8sfffff"
parsed = struct.unpack(fmt, data)
result["startloc"] = parsed[0]
result["startlat"] = parsed[1]
result["startlon"] = parsed[2]
result["deltalat"] = parsed[3]
result["deltalon"] = parsed[4]
result["earth_radius"] = parsed[5]
elif iproj == 1:
fmt = ">8sffffff"
parsed = struct.unpack(fmt, data)
result["startloc"] = parsed[0]
result["startlat"] = parsed[1]
result["startlon"] = parsed[2]
result["dx"] = parsed[3]
result["dy"] = parsed[4]
result["truelat1"] = parsed[5]
result["earth_radius"] = parsed[6]
elif iproj == 3:
fmt = ">8sffffffff"
parsed = struct.unpack(fmt, data)
result["startloc"] = parsed[0]
result["startlat"] = parsed[1]
result["startlon"] = parsed[2]
result["dx"] = parsed[3]
result["dy"] = parsed[4]
result["xlonc"] = parsed[5]
result["truelat1"] = parsed[6]
result["truelat2"] = parsed[7]
result["earth_radius"] = parsed[8]
elif iproj == 4:
fmt = ">8sfffff"
parsed = struct.unpack(fmt, data)
result["startloc"] = parsed[0]
result["startlat"] = parsed[1]
result["startlon"] = parsed[2]
result["nlats"] = parsed[3]
result["deltalon"] = parsed[4]
result["earth_radius"] = parsed[5]
elif iproj == 5:
fmt = ">8sfffffff"
parsed = struct.unpack(fmt, data)
result["startloc"] = parsed[0]
result["startlat"] = parsed[1]
result["startlon"] = parsed[2]
result["dx"] = parsed[3]
result["dy"] = parsed[4]
result["xlonc"] = parsed[5]
result["truelat1"] = parsed[6]
result["earth_radius"] = parsed[7]
return result
def _parse_record4(data):
result = {}
result["is_wind_earth_rel"] = struct.unpack(">i", data)
return result
def _parse_record5(data, nx, ny):
result = {}
size = nx * ny
fmt = ">{}f".format(size)
parsed = struct.unpack(fmt, data)
arr = np.array(parsed, dtype=np.float32)
result["slab"] = arr.reshape((nx, ny), order="F")
return result
_PARSE_MAP = {0: _parse_record1,
1: _parse_record2,
2: _parse_record3,
3: _parse_record4,
4: _parse_record5}
def parse_record(record_idx, data, iproj=None, nx=None, ny=None):
if record_idx == 0 or record_idx == 1 or record_idx == 3:
return _PARSE_MAP[record_idx](data)
elif record_idx == 2:
return _PARSE_MAP[record_idx](data, iproj)
elif record_idx == 4:
return _PARSE_MAP[record_idx](data, nx, ny)
def read_wps(wps_file, field=None):
with open(wps_file, "rb") as f:
wps_params = {}
record_list = []
raw_data = f.read()
record_size_idx = 0
end_of_file_idx = len(raw_data) - 1
while True:
iproj = None
nx = None
ny = None
keep_record = True
for record_idx in range(5):
# Each record has the size (in SIZE_BYTES bytes) at the
# start and end of each record. This might be compiler
# dependent though, so this might need to be modified.
# Also, the WPS files are stored big endian.
record_size = struct.unpack(
">i",
raw_data[record_size_idx: record_size_idx + SIZE_BYTES])
record_start = record_size_idx + SIZE_BYTES
record_end = record_start + record_size[0]
record_data = raw_data[record_start:record_end]
parsed_record = parse_record(record_idx, record_data, iproj,
nx, ny)
try:
field_name = parsed_record["field"].strip()
except KeyError:
pass
else:
if field is not None:
if field_name != field:
keep_record = False
try:
iproj = parsed_record["iproj"]
except KeyError:
pass
try:
nx = parsed_record["nx"]
except KeyError:
pass
try:
ny = parsed_record["ny"]
except KeyError:
pass
wps_params.update(parsed_record)
record_size_idx = record_end + SIZE_BYTES
if keep_record:
record_list.append(WPSData(**wps_params))
# Repeat for all record slabs
if record_end + SIZE_BYTES > end_of_file_idx:
break
return record_list

0
test/listBug.ncl → test/ncl/listBug.ncl

0
test/ncl_get_var.ncl → test/ncl/ncl_get_var.ncl

92
test/ncl/ncl_vertcross.ncl

@ -0,0 +1,92 @@
input_file = addfile("/Users/ladwig/Documents/wrf_files/wrfout_d02_2010-06-13_21:00:00.nc", "r")
z = wrf_user_getvar(input_file, "z", 0) ; grid point height
p = wrf_user_getvar(input_file, "pressure", 0) ; total pressure
dimsz = dimsizes(z)
pivot = (/ (dimsz(2)-1)/2, (dimsz(1)-1)/2 /) ; pivot point is center of domain
; For the new cross section routine
xopt = True
xopt@use_pivot = True
xopt@angle = 45.0
;xopt@levels =
;xopt@latlon =
xopt@file_handle = input_file
;xopt@timeidx =
xopt@linecoords = True
ht_vertcross = wrf_user_vertcross(z, p, pivot, xopt)
printVarSummary(ht_vertcross)
print(min(ht_vertcross@lats))
print(min(ht_vertcross@lons))
print(max(ht_vertcross@lats))
print(max(ht_vertcross@lons))
xopt@use_pivot = False
xopt@angle = 0.0
;xopt@levels =
xopt@latlon = True
xopt@file_handle = input_file
xopt@timeidx = 0
xopt@linecoords = True
loc_param = (/-104.3632, 32.8562, -95.15308, 40.06575 /) ; pivot point is center of domain
ht_vertcross2 = wrf_user_vertcross(z, p, loc_param, xopt)
printVarSummary(ht_vertcross2)
print(min(ht_vertcross2@lats))
print(min(ht_vertcross2@lons))
print(max(ht_vertcross2@lats))
print(max(ht_vertcross2@lons))
print(ht_vertcross2@lats(190))
print(ht_vertcross2@lons(190))
xopt@use_pivot = True
xopt@angle = 45.0
;xopt@levels =
xopt@latlon = True
xopt@file_handle = input_file
xopt@timeidx = 0
xopt@linecoords = True
loc_param := (/-99.98572, 36.54949 /) ; pivot point is center of domain
ht_vertcross3 = wrf_user_vertcross(z, p, loc_param, xopt)
printVarSummary(ht_vertcross3)
print(min(ht_vertcross3@lats))
print(min(ht_vertcross3@lons))
print(max(ht_vertcross3@lats))
print(max(ht_vertcross3@lons))
xopt@use_pivot = True
xopt@angle = 45.0
xopt@levels = (/1000., 850., 700., 500., 250. /)
xopt@latlon = True
xopt@file_handle = input_file
xopt@timeidx = 0
xopt@linecoords = True
loc_param := (/-99.98572, 36.54949 /) ; pivot point is center of domain
ht_vertcross4 = wrf_user_vertcross(z, p, loc_param, xopt)
printVarSummary(ht_vertcross4)
print(min(ht_vertcross4@lats))
print(min(ht_vertcross4@lons))
print(max(ht_vertcross4@lats))
print(max(ht_vertcross4@lons))
o = True
o@returnInt = False
o@useTime = 0
l = wrf_user_ll_to_xy(input_file, -99.98572, 36.54949, o)
print(l)
l1 = wrf_user_xy_to_ll(input_file, l(1), l(0), o)
print(l1)

81
test/ncl/refl10_cross.ncl

@ -0,0 +1,81 @@
a = addfile("wrfout_d03_2017-04-03_06:00:00_ctrl","r")
time = 0
refl_10cm = wrf_user_getvar(a,"REFL_10CM",time)
z = wrf_user_getvar(a, "z", time)
lat = wrf_user_getvar(a, "lat", time)
lon = wrf_user_getvar(a, "lon", time)
; convert the lat/lon to x,y
start_lat = 20.9
start_lon = 92.5
end_lat = 29.2
end_lon = 92.5
opt = True
start_ij = wrf_user_ll_to_ij(a, start_lon, start_lat, opt)
start_ij = start_ij - 1
end_ij = wrf_user_ll_to_ij(a, end_lon, end_lat, opt)
end_ij = end_ij - 1
start_end = (/start_ij(0), start_ij(1), end_ij(0), end_ij(1)/)
lat_line = wrf_user_intrp2d(lat,start_end,0.0,True)
nlat = dimsizes(lat_line)
lon_line = wrf_user_intrp2d(lon,start_end,0.0,True)
refl_cross = wrf_user_intrp3d(refl_10cm,z,"v",start_end,0.,True)
; Need to make a vertical coordinate by using the same code as the
; cross section
; Currently, the vertical coordinate is not set, so let's do it
; manually. This will be fixed in the next version of NCL.
; If you want to set these levels yourself, you'll need to copy the
; code I sent before and manually set the levels in the cross section
; routine, then do it again here.
z_max = max(z)
z_min = 0.
dz = 0.01 * z_max
nlevels = tointeger( z_max/dz )
z_var2d = new( (/nlevels/), typeof(z))
z_var2d(0) = z_min
do i=1, nlevels-1
z_var2d(i) = z_var2d(0)+i*dz
end do
refl_cross&Vertical = z_var2d
wks = gsn_open_wks("png","cross")
cmap := read_colormap_file("BlAqGrYeOrReVi200")
cmap(0,:) = (/0,0,0,0/) ; make first color fully transparent
resx = True
resx@gsnMaximize = True
resx@lbLabelAutoStride = True ; default v6.1.0
resx@cnFillOn = True ; turn on color fill
resx@cnLinesOn = False ; turn lines on/off ; True is default
resx@cnLineLabelsOn = False ; turn line labels on/off ; True is default
resx@cnFillPalette = cmap
nLabels = 8 ; arbitrary
resx@tmXBLabels = new(nLabels,"string")
resx@tmXBMode = "Explicit"
resx@tmXBValues := toint(fspan(0,nlat-1,nLabels))
do i=0,nLabels-1
x = lon_line(i)
y = lat_line(i)
resx@tmXBLabels(i) = sprintf("%5.1f", y)+"~C~"+sprintf("%5.1f", x)
end do
resx@tiMainString = "Full South-North Grid Line X-Section"
plot1 = gsn_csm_contour(wks, refl_cross, resx )

26
test/ncl/rotated_test.ncl

@ -0,0 +1,26 @@
;---Open file and calculate slp.
a = addfile("/Users/ladwig/Documents/wrf_files/rotated_pole_test.nc","r")
t2 = wrf_user_getvar(a,"T2",0)
;---Start the graphics
wks = gsn_open_wks("x11","wrf")
;---Set some graphical resources
res = True
res@gsnMaximize = True
res@cnFillOn = True
res@tfDoNDCOverlay = True ; This is necessary if you don't
; set sfXArray/sfYArray
;---Add additional map resources
res = wrf_map_resources(a,res)
;---Change some of the resources that were set (these were set to "gray")
res@mpGeophysicalLineColor = "black"
res@mpNationalLineColor = "black"
res@mpUSStateLineColor = "black"
plot = gsn_csm_contour_map(wks,t2,res)

21
test/ncl/test_this.ncl

@ -0,0 +1,21 @@
ifils = systemfunc ("ls /Users/ladwig/Documents/wrf_files/wrf_vortex_single/wrfout_d02_*")
print(ifils)
a = addfiles(ifils, "r")
;a = addfile("/Users/ladwig/Documents/wrf_files/wrfout_d01_2010-06-13_21:00:00.nc", "r")
lats := (/22.0, 25.0, 27.0 /)
lons := (/-90.0, -87.5, -83.75 /)
opt = True
opt@useTime = -1
opt@returnI = False
xy = wrf_user_ll_to_xy(a, lons, lats, opt)
print(xy)
x_s = (/10, 50, 90 /)
y_s = (/10, 50, 90 /)
ll = wrf_user_xy_to_ll(a, x_s, y_s, opt)
print(ll)

0
test/test_vinterp.ncl → test/ncl/test_vinterp.ncl

416
test/ncl/wrf_user_vertcross.ncl

@ -0,0 +1,416 @@
;--------------------------------------------------------------------------------
undef("wrf_user_ll_to_xy")
function wrf_user_ll_to_xy( file_handle, longitude:numeric, latitude:numeric, \
opts_args:logical )
; This is the same as wrf_user_ll_to_ij, but returns 0-based indexes
begin
;
; As of NCL V6.0.0, wrf_user_ll_to_ij can now handle a file
; or a list of files.
;
if(typeof(file_handle).eq."file") then
ISFILE = True
nc_file = file_handle
elseif(typeof(file_handle).eq."list") then
ISFILE = False
nc_file = file_handle[0]
else
print("wrf_user_ll_to_xy: Error: the first argument must be a file or a list of files opened with addfile or addfiles")
return
end if
opts = opts_args
useT = get_res_value(opts,"useTime",0)
returnI= get_res_value(opts,"returnInt",True)
res = True
res@MAP_PROJ = nc_file@MAP_PROJ
res@TRUELAT1 = nc_file@TRUELAT1
res@TRUELAT2 = nc_file@TRUELAT2
res@STAND_LON = nc_file@STAND_LON
res@DX = nc_file@DX
res@DY = nc_file@DY
if (res@MAP_PROJ .eq. 6) then
res@POLE_LAT = nc_file@POLE_LAT
res@POLE_LON = nc_file@POLE_LON
res@LATINC = (res@DY*360.)/2.0/3.141592653589793/6370000.
res@LONINC = (res@DX*360.)/2.0/3.141592653589793/6370000.
else
res@POLE_LAT = 90.0
res@POLE_LON = 0.0
res@LATINC = 0.0
res@LONINC = 0.0
end if
if(isfilevar(nc_file,"XLAT"))
if(ISFILE) then
XLAT = nc_file->XLAT(useT,:,:)
XLONG = nc_file->XLONG(useT,:,:)
else
XLAT = file_handle[:]->XLAT
XLONG = file_handle[:]->XLONG
end if
else
if(ISFILE) then
XLAT = nc_file->XLAT_M(useT,:,:)
XLONG = nc_file->XLONG_M(useT,:,:)
else
XLAT = file_handle[:]->XLAT_M
XLONG = file_handle[:]->XLONG_M
end if
end if
if(dimsizes(dimsizes(XLAT)).eq.2) then
; Rank 2
res@REF_LAT = XLAT(0,0)
res@REF_LON = XLONG(0,0)
else
; Rank 3
res@REF_LAT = XLAT(useT,0,0)
res@REF_LON = XLONG(useT,0,0)
end if
res@KNOWNI = 1.0
res@KNOWNJ = 1.0
loc = wrf_ll_to_ij (longitude, latitude, res)
loc = loc - 1
if (dimsizes(dimsizes(loc)) .eq. 1) then
loc!0 = "x_y"
elseif (dimsizes(dimsizes(loc)) .eq. 2) then
loc!0 = "x_y"
loc!1 = "idx"
else ; Not currently supported
loc!0 = "x_y"
loc!1 = "domain_idx"
loc!2 = "idx"
end if
if ( returnI ) then
loci = new(dimsizes(loc),integer)
;loci@_FillValue = default_fillvalue("integer") ; was -999
loci = tointeger(loc + .5)
loci!0 = loc!0
return(loci)
else
return(loc)
end if
end
;--------------------------------------------------------------------------------
undef("wrf_user_xy_to_ll")
function wrf_user_xy_to_ll( file_handle, x:numeric, y:numeric, \
opts_args:logical )
begin
;
; As of NCL V6.0.0, wrf_user_ll_to_ij can now handle a file
; or a list of files.
;
if(typeof(file_handle).eq."file") then
ISFILE = True
nc_file = file_handle
elseif(typeof(file_handle).eq."list") then
ISFILE = False
nc_file = file_handle[0]
else
print("wrf_user_xy_to_ll: Error: the first argument must be a file or a list of files opened with addfile or addfiles")
return
end if
opts = opts_args
useT = get_res_value(opts,"useTime",0)
res = True
res@MAP_PROJ = nc_file@MAP_PROJ
res@TRUELAT1 = nc_file@TRUELAT1
res@TRUELAT2 = nc_file@TRUELAT2
res@STAND_LON = nc_file@STAND_LON
res@DX = nc_file@DX
res@DY = nc_file@DY
if (res@MAP_PROJ .eq. 6) then
res@POLE_LAT = nc_file@POLE_LAT
res@POLE_LON = nc_file@POLE_LON
res@LATINC = (res@DY*360.)/2.0/3.141592653589793/6370000.
res@LONINC = (res@DX*360.)/2.0/3.141592653589793/6370000.
else
res@POLE_LAT = 90.0
res@POLE_LON = 0.0
res@LATINC = 0.0
res@LONINC = 0.0
end if
if(isfilevar(nc_file,"XLAT")) then
if(ISFILE) then
XLAT = nc_file->XLAT(useT,:,:)
XLONG = nc_file->XLONG(useT,:,:)
else
XLAT = file_handle[:]->XLAT
XLONG = file_handle[:]->XLONG
end if
else
if(ISFILE) then
XLAT = nc_file->XLAT_M(useT,:,:)
XLONG = nc_file->XLONG_M(useT,:,:)
else
XLAT = file_handle[:]->XLAT_M
XLONG = file_handle[:]->XLONG_M
end if
end if
if(dimsizes(dimsizes(XLAT)).eq.2) then
; Rank 2
res@REF_LAT = XLAT(0,0)
res@REF_LON = XLONG(0,0)
else
; Rank 3
res@REF_LAT = XLAT(useT,0,0)
res@REF_LON = XLONG(useT,0,0)
end if
res@KNOWNI = 1.0
res@KNOWNJ = 1.0
; Convert to 1-based indexes for Fortran
new_x = x + 1
new_y = y + 1
loc = wrf_ij_to_ll (new_x,new_y,res)
if (dimsizes(dimsizes(loc)) .eq. 1) then
loc!0 = "lon_lat"
elseif (dimsizes(dimsizes(loc)) .eq. 2) then
loc!0 = "lon_lat"
loc!1 = "idx"
else ; Not currently supported
loc!0 = "lon_lat"
loc!1 = "domain_idx"
loc!2 = "idx"
end if
return(loc)
end
;--------------------------------------------------------------------------------
undef("wrf_user_vertcross")
function wrf_user_vertcross(var3d:numeric, z_in:numeric, \
loc_param:numeric, opts:logical )
; var3d - 3d field to interpolate (all input fields must be unstaggered)
; z_in - interpolate to this field (either p/z)
; loc_param - an array of 4 values representing the start point and end point
; for the cross section (start_x, start_y, end_x, end_y) OR a single
; point when opt@use_pivot is True representing the pivot point.
; The values can be in grid coordinates or lat/lon coordinates
; (start_x = start_lon, start_y = start_lat, ...). If using
; lat/lon coordinates, then opt@latlon must be True.
; opts - optional arguments
; use_pivot - set to True to indicate that loc_param and angle are used,
; otherwise loc_param is set to 4 values to indicate a start and
; end point
; angle - an angle for vertical plots - 90 represent a WE cross section,
; ignored if use_pivot is False.
; levels - the vertical levels to use in the same units as z_in. Set to
; False to automatically generate the number of levels specified
; by autolevels.
; latlon - set to True if the values in loc_param are latitude and longitude
; values rather than grid values
; file_handle - must be set to a file handle when latlon is True or
; linecoords is True, otherwise this is ignored.
; timeidx - the time index to use for moving nests when latlon is True. Set
; to 0 if the nest is not moving.
; linecoords - set to True to include the latitude and longitude coordinates
; for the cross section line in the output attributes.
; autolevels - set to the desired number of levels when levels are
; selected automatically (default 100).
begin
use_pivot = get_res_value(opts, "use_pivot", False)
angle = get_res_value(opts, "angle", 0.0)
levels = get_res_value(opts, "levels", new(1,integer))
latlon = get_res_value(opts, "latlon", False)
file_handle = get_res_value(opts, "file_handle", 0)
timeidx = get_res_value(opts, "timeidx", 0)
linecoords = get_res_value(opts, "linecoords", False)
nlevels = get_res_value(opts, "autolevels", 100)
dims = dimsizes(var3d)
nd = dimsizes(dims)
dimX = dims(nd-1)
dimY = dims(nd-2)
dimZ = dims(nd-3)
if ( nd .eq. 4 ) then
z = z_in(0,:,:,:)
else
z = z_in
end if
; Convert latlon to xy coordinates
if (use_pivot) then
if (latlon) then
opt = True
opt@returnInt = True
opt@useTime = timeidx
ij := wrf_user_ll_to_xy(file_handle, loc_param(0), loc_param(1), opt)
start_x = ij(0)
start_y = ij(1)
else
start_x = loc_param(0)
start_y = loc_param(1)
end if
else
if (latlon) then
opt = True
opt@returnInt = True
opt@useTime = timeidx
ij := wrf_user_ll_to_xy(file_handle, (/ loc_param(0), loc_param(2) /), (/ loc_param(1), loc_param(3) /), opt)
start_x = ij(0,0)
start_y = ij(1,0)
end_x = ij(0,1)
end_y = ij(1,1)
else
start_x = loc_param(0)
start_y = loc_param(1)
end_x = loc_param(2)
end_y = loc_param(3)
end if
end if
; get the lat/lons along the cross section line if requested
; set the cross section line coordinates if requested
if (linecoords) then
latname = "XLAT"
lonname = "XLONG"
if(.not. isfilevar(file_handle,"XLAT")) then
if(isfilevar(file_handle,"XLAT_M")) then
latname = "XLAT_M"
lonname = "XLONG_M"
end if
end if
latvar = _get_wrf_var(file_handle, latname, timeidx)
lonvar = _get_wrf_var(file_handle, lonname, timeidx)
if (use_pivot) then
loc := (/start_x, start_y/)
linelats = wrf_user_intrp2d(latvar, loc, angle, False)
linelons = wrf_user_intrp2d(lonvar, loc, angle, False)
else
loc := (/start_x, start_y, end_x, end_y /)
linelats = wrf_user_intrp2d(latvar, loc, angle, True)
linelons = wrf_user_intrp2d(lonvar, loc, angle, True)
end if
end if
; set vertical cross section
; Note for wrf_user_set_xy, opt is False when pivot and angle used.
if (use_pivot) then
xy = wrf_user_set_xy( z, start_x, start_y, \ ; assumes 0-based indexing in v6.5.0
0.0, 0.0, angle, False )
else
xy = wrf_user_set_xy( z, start_x, start_y, \ ; assumes 0-based indexing in v6.5.0
end_x, end_y, \
angle, True)
end if
xp = dimsizes(xy)
; first we interp z
var2dz = wrf_interp_2d_xy( z, xy)
; interp to constant z grid
if (all(ismissing(levels))) then
if(var2dz(0,0) .gt. var2dz(1,0) ) then ; monotonically decreasing coordinate
z_max = floor(max(z)/10)*10 ; bottom value
z_min = ceil(min(z)/10)*10 ; top value
dz = (1.0/nlevels) * (z_max - z_min)
;nlevels = tointeger( (z_max-z_min)/dz)
z_var2d = new( (/nlevels/), typeof(z))
z_var2d(0) = z_max
dz = -dz
else
z_max = max(z)
z_min = 0.
dz = (1.0/nlevels) * z_max
;nlevels = tointeger( z_max/dz )
z_var2d = new( (/nlevels/), typeof(z))
z_var2d(0) = z_min
end if
do i=1, nlevels-1
z_var2d(i) = z_var2d(0)+i*dz
end do
else
z_var2d = levels
nlevels = dimsizes(z_var2d)
end if
; interp the variable
if ( dimsizes(dims) .eq. 4 ) then
var2d = new( (/dims(0), nlevels, xp(0)/), typeof(var2dz))
do it = 0,dims(0)-1
var2dtmp = wrf_interp_2d_xy( var3d(it,:,:,:), xy)
do i=0,xp(0)-1
var2d(it,:,i) = wrf_interp_1d( var2dtmp(:,i), var2dz(:,i), z_var2d)
end do
end do
var2d!0 = var3d!0
var2d!1 = "vertical"
var2d!2 = "cross_line_idx"
else
var2d = new( (/nlevels, xp(0)/), typeof(var2dz))
var2dtmp = wrf_interp_2d_xy( var3d, xy)
do i=0,xp(0)-1
var2d(:,i) = wrf_interp_1d( var2dtmp(:,i), var2dz(:,i), z_var2d)
end do
var2d!0 = "vertical"
var2d!1 = "cross_line_idx"
end if
st_x = tointeger(xy(0,0)) ; + 1 (removed 1-based indexing in 6.5.0)
st_y = tointeger(xy(0,1)) ; + 1
ed_x = tointeger(xy(xp(0)-1,0)) ; + 1
ed_y = tointeger(xy(xp(0)-1,1)) ; + 1
if (.not. use_pivot) then
var2d@Orientation = "Cross-Section: (" + \
st_x + "," + st_y + ") to (" + \
ed_x + "," + ed_y + ")"
else
var2d@Orientation = "Cross-Section: (" + \
st_x + "," + st_y + ") to (" + \
ed_x + "," + ed_y + ") ; center=(" + \
start_x + "," + start_y + \
") ; angle=" + angle
end if
if (linecoords) then
var2d@lats = linelats
var2d@lons = linelons
end if
var2d&vertical = z_var2d
return(var2d)
end

52
test/test_filevars.py

@ -2,7 +2,8 @@ import unittest as ut
import numpy.testing as nt import numpy.testing as nt
import numpy as np import numpy as np
import numpy.ma as ma import numpy.ma as ma
import os, sys import os
import sys
import subprocess import subprocess
from wrf import getvar, ALL_TIMES from wrf import getvar, ALL_TIMES
@ -21,38 +22,39 @@ if sys.version_info > (3,):
class WRFFileVarsTest(ut.TestCase): class WRFFileVarsTest(ut.TestCase):
longMessage = True longMessage = True
def make_test(ncfiles, varname): def make_test(ncfiles, varname):
def test(self): def test(self):
#import time # import time
#very_start = time.time() # very_start = time.time()
#start = time.time() # start = time.time()
t1 = getvar(ncfiles, varname, 0) t1 = getvar(ncfiles, varname, 0)
#end = time.time() # end = time.time()
#print ("t1: ", start-end) # print("t1: ", start-end)
#start = time.time() # start = time.time()
t2 = getvar(ncfiles, varname, 0, meta=False) t2 = getvar(ncfiles, varname, 0, meta=False)
#end = time.time() # end = time.time()
#print ("t2: ", start-end) # print("t2: ", start-end)
#start = time.time() # start = time.time()
t3 = getvar(ncfiles, varname, ALL_TIMES) t3 = getvar(ncfiles, varname, ALL_TIMES)
#end = time.time() # end = time.time()
#print ("t3: ", start-end) # print("t3: ", start-end)
#start = time.time() # start = time.time()
t4 = getvar(ncfiles, varname, ALL_TIMES, meta=False) t4 = getvar(ncfiles, varname, ALL_TIMES, meta=False)
#end = time.time() # end = time.time()
#print ("t4: ", start-end) # print("t4: ", start-end)
#start = time.time() # start = time.time()
t5 = getvar(ncfiles, varname, ALL_TIMES, method="join") t5 = getvar(ncfiles, varname, ALL_TIMES, method="join")
#end = time.time() # end = time.time()
#print ("t5: ", start-end) # print("t5: ", start-end)
#start = time.time() # start = time.time()
t6 = getvar(ncfiles, varname, ALL_TIMES, method="join", meta=False) t6 = getvar(ncfiles, varname, ALL_TIMES, method="join", meta=False)
#end = time.time() # end = time.time()
#print ("t6: ", start-end) # print("t6: ", start-end)
#start = time.time() # start = time.time()
#print ("Total Time: ", (end-start)) # print("Total Time: ", (end-start))
return test return test
@ -60,8 +62,8 @@ if __name__ == "__main__":
from netCDF4 import Dataset from netCDF4 import Dataset
ncfiles = [Dataset(x) for x in TEST_FILES] ncfiles = [Dataset(x) for x in TEST_FILES]
#import scipy.io # import scipy.io
#ncfiles = [scipy.io.netcdf.netcdf_file(x) for x in TEST_FILES] # ncfiles = [scipy.io.netcdf.netcdf_file(x) for x in TEST_FILES]
file_vars = ncfiles[0].variables.keys() file_vars = ncfiles[0].variables.keys()

41
test/test_inputs.py

@ -17,6 +17,7 @@ TEST_FILES = [os.path.join(IN_DIR, "wrfout_d02_2005-08-28_00:00:00"),
os.path.join(IN_DIR, "wrfout_d02_2005-08-28_12:00:00"), os.path.join(IN_DIR, "wrfout_d02_2005-08-28_12:00:00"),
os.path.join(IN_DIR, "wrfout_d02_2005-08-29_00:00:00")] os.path.join(IN_DIR, "wrfout_d02_2005-08-29_00:00:00")]
def wrfin_gen(wrf_in): def wrfin_gen(wrf_in):
for x in wrf_in: for x in wrf_in:
yield x yield x
@ -51,6 +52,7 @@ def make_test(varname, wrf_in):
return test return test
def make_interp_test(varname, wrf_in): def make_interp_test(varname, wrf_in):
def test(self): def test(self):
@ -58,7 +60,7 @@ def make_interp_test(varname, wrf_in):
if (varname == "vinterp"): if (varname == "vinterp"):
for timeidx in (0, None): for timeidx in (0, None):
eth = getvar(wrf_in, "eth", timeidx=timeidx) eth = getvar(wrf_in, "eth", timeidx=timeidx)
interp_levels = [850,500,5] interp_levels = [850, 500, 5]
field = vinterp(wrf_in, field = vinterp(wrf_in,
field=eth, field=eth,
vert_coord="pressure", vert_coord="pressure",
@ -70,7 +72,6 @@ def make_interp_test(varname, wrf_in):
else: else:
pass pass
return test return test
@ -94,12 +95,15 @@ def make_latlon_test(testid, wrf_in):
class WRFVarsTest(ut.TestCase): class WRFVarsTest(ut.TestCase):
longMessage = True longMessage = True
class WRFInterpTest(ut.TestCase): class WRFInterpTest(ut.TestCase):
longMessage = True longMessage = True
class WRFLatLonTest(ut.TestCase): class WRFLatLonTest(ut.TestCase):
longMessage = True longMessage = True
if __name__ == "__main__": if __name__ == "__main__":
from wrf import (omp_set_num_threads, omp_set_schedule, omp_get_schedule, from wrf import (omp_set_num_threads, omp_set_schedule, omp_get_schedule,
omp_set_dynamic, omp_get_num_procs, OMP_SCHED_STATIC) omp_set_dynamic, omp_get_num_procs, OMP_SCHED_STATIC)
@ -116,13 +120,12 @@ if __name__ == "__main__":
interp_methods = ["interplevel", "vertcross", "interpline", "vinterp"] interp_methods = ["interplevel", "vertcross", "interpline", "vinterp"]
latlon_tests = ["xy_out", "ll_out"] latlon_tests = ["xy_out", "ll_out"]
for nc_lib in ("netcdf4", "pynio", "scipy"): for nc_lib in ("netcdf4", "pynio", "scipy"):
if nc_lib == "netcdf4": if nc_lib == "netcdf4":
try: try:
from netCDF4 import Dataset from netCDF4 import Dataset
except ImportError: except ImportError:
print ("netcdf4-python not installed") print("netcdf4-python not installed")
continue continue
else: else:
test_in = [Dataset(x) for x in TEST_FILES] test_in = [Dataset(x) for x in TEST_FILES]
@ -130,15 +133,15 @@ if __name__ == "__main__":
try: try:
from Nio import open_file from Nio import open_file
except ImportError: except ImportError:
print ("PyNIO not installed") print("PyNIO not installed")
continue continue
else: else:
test_in = [open_file(x +".nc", "r") for x in TEST_FILES] test_in = [open_file(x + ".nc", "r") for x in TEST_FILES]
elif nc_lib == "scipy": elif nc_lib == "scipy":
try: try:
from scipy.io.netcdf import netcdf_file from scipy.io.netcdf import netcdf_file
except ImportError: except ImportError:
print ("scipy.io.netcdf not installed") print("scipy.io.netcdf not installed")
else: else:
test_in = [netcdf_file(x, mmap=False) for x in TEST_FILES] test_in = [netcdf_file(x, mmap=False) for x in TEST_FILES]
@ -147,29 +150,25 @@ if __name__ == "__main__":
input2 = tuple(input1) input2 = tuple(input1)
input3 = wrfin_gen(test_in) input3 = wrfin_gen(test_in)
input4 = wrf_in_iter_class(test_in) input4 = wrf_in_iter_class(test_in)
input5 = {"A" : input1, input5 = {"A": input1,
"B" : input2} "B": input2}
input6 = {"A" : {"AA" : input1}, input6 = {"A": {"AA": input1},
"B" : {"BB" : input2}} "B": {"BB": input2}}
for i,input in enumerate((input0, input1, input2, for i, input in enumerate((input0, input1, input2,
input3, input4, input5, input6)): input3, input4, input5, input6)):
for var in wrf_vars: for var in wrf_vars:
if var in ignore_vars: if var in ignore_vars:
continue continue
test_func1 = make_test(var, input) test_func1 = make_test(var, input)
setattr(WRFVarsTest, "test_{0}_input{1}_{2}".format(nc_lib, setattr(WRFVarsTest, "test_{0}_input{1}_{2}".format(
i, var), nc_lib, i, var), test_func1)
test_func1)
for method in interp_methods: for method in interp_methods:
test_interp_func1 = make_interp_test(method, input) test_interp_func1 = make_interp_test(method, input)
setattr(WRFInterpTest, setattr(WRFInterpTest, "test_{0}_input{1}_{2}".format(
"test_{0}_input{1}_{2}".format(nc_lib, nc_lib, i, method), test_interp_func1)
i, method),
test_interp_func1)
for testid in latlon_tests: for testid in latlon_tests:
test_ll_func = make_latlon_test(testid, input) test_ll_func = make_latlon_test(testid, input)
@ -177,5 +176,3 @@ if __name__ == "__main__":
setattr(WRFLatLonTest, test_name, test_ll_func) setattr(WRFLatLonTest, test_name, test_ll_func)
ut.main() ut.main()

42
test/test_multi_cache.py

@ -3,56 +3,60 @@ from wrf.cache import _get_cache
from wrf import getvar from wrf import getvar
from netCDF4 import Dataset as nc from netCDF4 import Dataset as nc
#a = nc("/Users/ladwig/Documents/wrf_files/wrf_vortex_single/wrfout_d02_2005-08-28_00:00:00") a = nc("/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/"
#b = nc("/Users/ladwig/Documents/wrf_files/wrf_vortex_single/wrfout_d02_2005-08-28_03:00:00") "wrfout_d02_2005-08-28_00:00:00")
a = nc("/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/wrfout_d02_2005-08-28_00:00:00") b = nc("/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/"
b = nc("/Users/ladwig/Documents/wrf_files/wrf_vortex_multi/moving_nest/wrfout_d02_2005-08-28_12:00:00") "wrfout_d02_2005-08-28_12:00:00")
q = {"outoutoutout" : {"outoutout" : {"outout" : {"out1" : {"blah" : [a,b], "blah2" : [a,b]}, "out2" : {"blah" : [a,b], "blah2" : [a,b]} } } } } q = {"outoutoutout":
{"outoutout":
{"outout":
{"out1": {"blah": [a, b], "blah2": [a, b]},
"out2": {"blah": [a, b], "blah2": [a, b]}}}}}
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="cat", timeidx=None, squeeze=True) c = getvar(q, "rh", method="cat", timeidx=None, squeeze=True)
t2 = time.time() t2 = time.time()
print (c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="cat", timeidx=None, squeeze=False) c = getvar(q, "rh", method="cat", timeidx=None, squeeze=False)
t2 = time.time() t2 = time.time()
print (c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="cat", timeidx=1, squeeze=True) c = getvar(q, "rh", method="cat", timeidx=1, squeeze=True)
t2 = time.time() t2 = time.time()
print (c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="cat", timeidx=1, squeeze=False) c = getvar(q, "rh", method="cat", timeidx=1, squeeze=False)
t2 = time.time() t2 = time.time()
print(c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="join", timeidx=None, squeeze=True) c = getvar(q, "rh", method="join", timeidx=None, squeeze=True)
t2 = time.time() t2 = time.time()
print (c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="join", timeidx=None, squeeze=False) c = getvar(q, "rh", method="join", timeidx=None, squeeze=False)
t2 = time.time() t2 = time.time()
print(c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="join", timeidx=1, squeeze=True) c = getvar(q, "rh", method="join", timeidx=1, squeeze=True)
t2 = time.time() t2 = time.time()
print (c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))
t1 = time.time() t1 = time.time()
c = getvar(q, "rh", method="join", timeidx=1, squeeze=False) c = getvar(q, "rh", method="join", timeidx=1, squeeze=False)
t2 = time.time() t2 = time.time()
print (c) print(c)
print ("time taken: {}".format((t2-t1)*1000.)) print("time taken: {}".format((t2-t1)*1000.))

29
test/test_omp.py

@ -28,11 +28,11 @@ class OmpTest(ut.TestCase):
longMessage = True longMessage = True
def test_locks(self): def test_locks(self):
l = omp_init_lock() lk = omp_init_lock()
omp_set_lock(l) omp_set_lock(lk)
omp_unset_lock(l) omp_unset_lock(lk)
omp_test_lock(l) omp_test_lock(lk)
omp_destroy_lock(l) omp_destroy_lock(lk)
nl = omp_init_nest_lock() nl = omp_init_nest_lock()
omp_set_nest_lock(nl) omp_set_nest_lock(nl)
@ -40,24 +40,25 @@ class OmpTest(ut.TestCase):
omp_test_nest_lock(nl) omp_test_nest_lock(nl)
omp_destroy_nest_lock(nl) omp_destroy_nest_lock(nl)
def test_thread_set(self): def test_thread_set(self):
omp_set_num_threads(4) omp_set_num_threads(4)
max_threads = omp_get_max_threads() max_threads = omp_get_max_threads()
self.assertEqual(max_threads, 4) self.assertEqual(max_threads, 4)
num_threads = omp_get_num_threads() num_threads = omp_get_num_threads()
self.assertEqual(num_threads, 1) # Always 1 outside of parallel region # Always 1 outside of parallel region
self.assertEqual(num_threads, 1)
thread_num = omp_get_thread_num() thread_num = omp_get_thread_num()
self.assertEqual(thread_num, 0) # Always 0 outside of parallel region # Always 0 outside of parallel region
self.assertEqual(thread_num, 0)
num_procs = omp_get_num_procs() num_procs = omp_get_num_procs()
in_parallel = omp_in_parallel() in_parallel = omp_in_parallel()
self.assertFalse(in_parallel) # Always False outside of parallel region # Always False outside of parallel region
self.assertFalse(in_parallel)
limit = omp_get_thread_limit() limit = omp_get_thread_limit()
def test_dynamic(self): def test_dynamic(self):
omp_set_dynamic(True) omp_set_dynamic(True)
dynamic = omp_get_dynamic() dynamic = omp_get_dynamic()
@ -76,7 +77,6 @@ class OmpTest(ut.TestCase):
nested = omp_get_nested() nested = omp_get_nested()
self.assertFalse(nested) self.assertFalse(nested)
def test_schedule(self): def test_schedule(self):
omp_set_schedule(OMP_SCHED_STATIC, 100000) omp_set_schedule(OMP_SCHED_STATIC, 100000)
kind, modifier = omp_get_schedule() kind, modifier = omp_get_schedule()
@ -96,10 +96,10 @@ class OmpTest(ut.TestCase):
omp_set_schedule(OMP_SCHED_AUTO, 10) omp_set_schedule(OMP_SCHED_AUTO, 10)
kind, modifier = omp_get_schedule() kind, modifier = omp_get_schedule()
self.assertEqual(kind, OMP_SCHED_AUTO) self.assertEqual(kind, OMP_SCHED_AUTO)
self.assertNotEqual(modifier, 10) # The modifier argument is ignored, # The modifier argument is ignored,
# so it will be set to the previous # so it will be set to the previous
# value of 100. # value of 100.
self.assertNotEqual(modifier, 10)
def test_team_level(self): def test_team_level(self):
omp_set_max_active_levels(10) omp_set_max_active_levels(10)
@ -112,11 +112,10 @@ class OmpTest(ut.TestCase):
active_level = omp_get_active_level() active_level = omp_get_active_level()
in_final = omp_in_final() in_final = omp_in_final()
def test_time(self): def test_time(self):
wtime = omp_get_wtime() wtime = omp_get_wtime()
wtick = omp_get_wtick() wtick = omp_get_wtick()
if __name__ == "__main__": if __name__ == "__main__":
ut.main() ut.main()

120
test/test_proj_params.py

@ -2,7 +2,8 @@ import unittest as ut
import numpy.testing as nt import numpy.testing as nt
import numpy as np import numpy as np
import numpy.ma as ma import numpy.ma as ma
import os, sys import os
import sys
import subprocess import subprocess
from wrf import xy_to_ll_proj, ll_to_xy_proj, to_np from wrf import xy_to_ll_proj, ll_to_xy_proj, to_np
@ -11,11 +12,12 @@ from wrf import xy_to_ll_proj, ll_to_xy_proj, to_np
class WRFLatLonProjTest(ut.TestCase): class WRFLatLonProjTest(ut.TestCase):
longMessage = True longMessage = True
def make_test(xy_or_ll_out): def make_test(xy_or_ll_out):
def test(self): def test(self):
# Python 3 # Python 3
if sys.version_info > (3,): if sys.version_info > (3, ):
assert_raises_regex = self.assertRaisesRegex assert_raises_regex = self.assertRaisesRegex
xrange = range xrange = range
else: else:
@ -23,37 +25,37 @@ def make_test(xy_or_ll_out):
if xy_or_ll_out == "xy": if xy_or_ll_out == "xy":
# Test the required failures # Test the required failures
with assert_raises_regex(ValueError, ".*map_proj.*" ): with assert_raises_regex(ValueError, ".*map_proj.*"):
ll_to_xy_proj(30,-110) ll_to_xy_proj(30, -110)
with assert_raises_regex(ValueError, ".*ref_lat.*" ): with assert_raises_regex(ValueError, ".*ref_lat.*"):
ll_to_xy_proj(30,-110, map_proj=1) ll_to_xy_proj(30, -110, map_proj=1)
with assert_raises_regex(ValueError, ".*ref_lon.*" ): with assert_raises_regex(ValueError, ".*ref_lon.*"):
ll_to_xy_proj(30,-110, map_proj=1, ref_lat=45) ll_to_xy_proj(30, -110, map_proj=1, ref_lat=45)
with assert_raises_regex(ValueError, ".*known_x.*" ): with assert_raises_regex(ValueError, ".*known_x.*"):
ll_to_xy_proj(30,-110, map_proj=1, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=1, ref_lat=45.0,
ref_lon=-120.) ref_lon=-120.)
with assert_raises_regex(ValueError, ".*known_y.*" ): with assert_raises_regex(ValueError, ".*known_y.*"):
ll_to_xy_proj(30,-110, map_proj=1, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=1) ref_lon=-120., known_x=1)
with assert_raises_regex(ValueError, ".*dx.*" ): with assert_raises_regex(ValueError, ".*dx.*"):
ll_to_xy_proj(30,-110, map_proj=1, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0) ref_lon=-120., known_x=0, known_y=0)
####### Now test the projections # Now test the projections
# Lambert Conformal - truelat1, stand_lon required # Lambert Conformal - truelat1, stand_lon required
with assert_raises_regex(ValueError, ".*truelat1.*" ): with assert_raises_regex(ValueError, ".*truelat1.*"):
ll_to_xy_proj(30,-110, map_proj=1, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000.) dx=3000.)
with assert_raises_regex(ValueError, ".*stand_lon.*" ): with assert_raises_regex(ValueError, ".*stand_lon.*"):
ll_to_xy_proj(30,-110, map_proj=1, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000., dx=3000.,
truelat1=60.) truelat1=60.)
@ -64,23 +66,21 @@ def make_test(xy_or_ll_out):
dx=30000., truelat1=30., truelat2=30., dx=30000., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=90., pole_lon=0.) stand_lon=-89., pole_lat=90., pole_lon=0.)
p_def = ll_to_xy_proj(28., -89., map_proj=1, ref_lat=17.803, p_def = ll_to_xy_proj(28., -89., map_proj=1, ref_lat=17.803,
ref_lon=-100.7747, known_x=0, known_y=0, ref_lon=-100.7747, known_x=0, known_y=0,
dx=30000., truelat1=30., dx=30000., truelat1=30., stand_lon=-89.)
stand_lon=-89.)
nt.assert_allclose(to_np(p_all), to_np(p_def)) nt.assert_allclose(to_np(p_all), to_np(p_def))
# Polar Stereographic - truelat1, stand_lon # Polar Stereographic - truelat1, stand_lon
with assert_raises_regex(ValueError, ".*truelat1.*" ): with assert_raises_regex(ValueError, ".*truelat1.*"):
ll_to_xy_proj(30,-110, map_proj=2, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=2, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000.) dx=3000.)
with assert_raises_regex(ValueError, ".*stand_lon.*" ): with assert_raises_regex(ValueError, ".*stand_lon.*"):
ll_to_xy_proj(30,-110, map_proj=2, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=2, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000., dx=3000.,
truelat1=60.) truelat1=60.)
@ -90,19 +90,16 @@ def make_test(xy_or_ll_out):
dx=30000., truelat1=30., truelat2=30., dx=30000., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=90., pole_lon=0.) stand_lon=-89., pole_lat=90., pole_lon=0.)
p_def = ll_to_xy_proj(28., -89., map_proj=2, ref_lat=17.933, p_def = ll_to_xy_proj(28., -89., map_proj=2, ref_lat=17.933,
ref_lon=-100.0735, known_x=0, known_y=0, ref_lon=-100.0735, known_x=0, known_y=0,
dx=30000., truelat1=30., dx=30000., truelat1=30., stand_lon=-89.)
stand_lon=-89.)
nt.assert_allclose(to_np(p_all), to_np(p_def)) nt.assert_allclose(to_np(p_all), to_np(p_def))
# Mercator - truelat1 # Mercator - truelat1
with assert_raises_regex(ValueError, ".*truelat1.*" ): with assert_raises_regex(ValueError, ".*truelat1.*"):
ll_to_xy_proj(30,-110, map_proj=2, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=2, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000.) dx=3000.)
@ -111,7 +108,6 @@ def make_test(xy_or_ll_out):
dx=30000., truelat1=30., truelat2=30., dx=30000., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=90., pole_lon=0.) stand_lon=-89., pole_lat=90., pole_lon=0.)
p_def = ll_to_xy_proj(28., -89., map_proj=3, ref_lat=19.1075, p_def = ll_to_xy_proj(28., -89., map_proj=3, ref_lat=19.1075,
ref_lon=-101.008, known_x=0, known_y=0, ref_lon=-101.008, known_x=0, known_y=0,
dx=30000., truelat1=30.) dx=30000., truelat1=30.)
@ -120,38 +116,37 @@ def make_test(xy_or_ll_out):
# Lat/lon - stand_lon, dy, pole_lat, pole_lon # Lat/lon - stand_lon, dy, pole_lat, pole_lon
with assert_raises_regex(ValueError, ".*stand_lon.*" ): with assert_raises_regex(ValueError, ".*stand_lon.*"):
ll_to_xy_proj(30,-110, map_proj=6, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=.2698388) dx=.2698388)
with assert_raises_regex(ValueError, ".*dy.*" ): with assert_raises_regex(ValueError, ".*dy.*"):
ll_to_xy_proj(30,-110, map_proj=6, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
stand_lon=89.0, stand_lon=89.0,
dx=.2698388) dx=.2698388)
with assert_raises_regex(ValueError, ".*pole_lat.*" ): with assert_raises_regex(ValueError, ".*pole_lat.*"):
ll_to_xy_proj(30,-110, map_proj=6, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
stand_lon=89.0, stand_lon=89.0,
dx=.2698388, dy=.2698388) dx=.2698388, dy=.2698388)
with assert_raises_regex(ValueError, ".*pole_lon.*" ): with assert_raises_regex(ValueError, ".*pole_lon.*"):
ll_to_xy_proj(30,-110, map_proj=6, ref_lat=45.0, ll_to_xy_proj(30, -110, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
stand_lon=89.0, stand_lon=89.0,
dx=.2698388, dy=.2698388, dx=.2698388, dy=.2698388,
pole_lat=62.0) pole_lat=62.0)
p_all = ll_to_xy_proj(28.,-89., map_proj=6, ref_lat=17.6759, p_all = ll_to_xy_proj(28., -89., map_proj=6, ref_lat=17.6759,
ref_lon=-101.4286, known_x=0, known_y=0, ref_lon=-101.4286, known_x=0, known_y=0,
dx=30000, dy=30000, dx=30000, dy=30000,
truelat1=30., truelat2=30., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=62.0, stand_lon=-89., pole_lat=62.0,
pole_lon=180.) pole_lon=180.)
p_def = ll_to_xy_proj(28., -89., map_proj=6, ref_lat=17.6759, p_def = ll_to_xy_proj(28., -89., map_proj=6, ref_lat=17.6759,
ref_lon=-101.4286, known_x=0, known_y=0, ref_lon=-101.4286, known_x=0, known_y=0,
stand_lon=-89., stand_lon=-89.,
@ -160,40 +155,39 @@ def make_test(xy_or_ll_out):
nt.assert_allclose(to_np(p_all), to_np(p_def)) nt.assert_allclose(to_np(p_all), to_np(p_def))
if xy_or_ll_out == "ll": if xy_or_ll_out == "ll":
# Test the required failures # Test the required failures
with assert_raises_regex(ValueError, ".*map_proj.*" ): with assert_raises_regex(ValueError, ".*map_proj.*"):
xy_to_ll_proj(45, 50) xy_to_ll_proj(45, 50)
with assert_raises_regex(ValueError, ".*ref_lat.*" ): with assert_raises_regex(ValueError, ".*ref_lat.*"):
xy_to_ll_proj(45, 50, map_proj=1) xy_to_ll_proj(45, 50, map_proj=1)
with assert_raises_regex(ValueError, ".*ref_lon.*" ): with assert_raises_regex(ValueError, ".*ref_lon.*"):
xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45) xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45)
with assert_raises_regex(ValueError, ".*known_x.*" ): with assert_raises_regex(ValueError, ".*known_x.*"):
xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0,
ref_lon=-120.) ref_lon=-120.)
with assert_raises_regex(ValueError, ".*known_y.*" ): with assert_raises_regex(ValueError, ".*known_y.*"):
xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=1) ref_lon=-120., known_x=1)
with assert_raises_regex(ValueError, ".*dx.*" ): with assert_raises_regex(ValueError, ".*dx.*"):
xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0) ref_lon=-120., known_x=0, known_y=0)
####### Now test the projections # Now test the projections
# Lambert Conformal - truelat1, stand_lon required # Lambert Conformal - truelat1, stand_lon required
with assert_raises_regex(ValueError, ".*truelat1.*" ): with assert_raises_regex(ValueError, ".*truelat1.*"):
xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000.) dx=3000.)
with assert_raises_regex(ValueError, ".*stand_lon.*" ): with assert_raises_regex(ValueError, ".*stand_lon.*"):
xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=1, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000., dx=3000.,
@ -205,7 +199,6 @@ def make_test(xy_or_ll_out):
dx=30000., truelat1=30., truelat2=30., dx=30000., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=90., pole_lon=0.) stand_lon=-89., pole_lat=90., pole_lon=0.)
p_def = xy_to_ll_proj(45, 50, map_proj=1, ref_lat=17.803, p_def = xy_to_ll_proj(45, 50, map_proj=1, ref_lat=17.803,
ref_lon=-100.7747, known_x=0, known_y=0, ref_lon=-100.7747, known_x=0, known_y=0,
dx=30000., truelat1=30., dx=30000., truelat1=30.,
@ -215,12 +208,12 @@ def make_test(xy_or_ll_out):
# Polar Stereographic - truelat1, stand_lon # Polar Stereographic - truelat1, stand_lon
with assert_raises_regex(ValueError, ".*truelat1.*" ): with assert_raises_regex(ValueError, ".*truelat1.*"):
xy_to_ll_proj(45, 50, map_proj=2, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=2, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000.) dx=3000.)
with assert_raises_regex(ValueError, ".*stand_lon.*" ): with assert_raises_regex(ValueError, ".*stand_lon.*"):
xy_to_ll_proj(45, 50, map_proj=2, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=2, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000., dx=3000.,
@ -231,7 +224,6 @@ def make_test(xy_or_ll_out):
dx=30000., truelat1=30., truelat2=30., dx=30000., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=90., pole_lon=0.) stand_lon=-89., pole_lat=90., pole_lon=0.)
p_def = xy_to_ll_proj(45, 50, map_proj=2, ref_lat=17.933, p_def = xy_to_ll_proj(45, 50, map_proj=2, ref_lat=17.933,
ref_lon=-100.0735, known_x=0, known_y=0, ref_lon=-100.0735, known_x=0, known_y=0,
dx=30000., truelat1=30., dx=30000., truelat1=30.,
@ -239,10 +231,9 @@ def make_test(xy_or_ll_out):
nt.assert_allclose(to_np(p_all), to_np(p_def)) nt.assert_allclose(to_np(p_all), to_np(p_def))
# Mercator - truelat1 # Mercator - truelat1
with assert_raises_regex(ValueError, ".*truelat1.*" ): with assert_raises_regex(ValueError, ".*truelat1.*"):
xy_to_ll_proj(45, 50, map_proj=2, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=2, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=3000.) dx=3000.)
@ -252,7 +243,6 @@ def make_test(xy_or_ll_out):
dx=30000., truelat1=30., truelat2=30., dx=30000., truelat1=30., truelat2=30.,
stand_lon=-89., pole_lat=90., pole_lon=0.) stand_lon=-89., pole_lat=90., pole_lon=0.)
p_def = xy_to_ll_proj(45, 50, map_proj=3, ref_lat=19.1075, p_def = xy_to_ll_proj(45, 50, map_proj=3, ref_lat=19.1075,
ref_lon=-101.008, known_x=0, known_y=0, ref_lon=-101.008, known_x=0, known_y=0,
dx=30000., truelat1=30.) dx=30000., truelat1=30.)
@ -261,24 +251,24 @@ def make_test(xy_or_ll_out):
# Lat/lon - stand_lon, dy, pole_lat, pole_lon # Lat/lon - stand_lon, dy, pole_lat, pole_lon
with assert_raises_regex(ValueError, ".*stand_lon.*" ): with assert_raises_regex(ValueError, ".*stand_lon.*"):
xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
dx=.2698388) dx=.2698388)
with assert_raises_regex(ValueError, ".*dy.*" ): with assert_raises_regex(ValueError, ".*dy.*"):
xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
stand_lon=89.0, stand_lon=89.0,
dx=.2698388) dx=.2698388)
with assert_raises_regex(ValueError, ".*pole_lat.*" ): with assert_raises_regex(ValueError, ".*pole_lat.*"):
xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
stand_lon=89.0, stand_lon=89.0,
dx=.2698388, dy=.2698388) dx=.2698388, dy=.2698388)
with assert_raises_regex(ValueError, ".*pole_lon.*" ): with assert_raises_regex(ValueError, ".*pole_lon.*"):
xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0, xy_to_ll_proj(45, 50, map_proj=6, ref_lat=45.0,
ref_lon=-120., known_x=0, known_y=0, ref_lon=-120., known_x=0, known_y=0,
stand_lon=89.0, stand_lon=89.0,
@ -292,7 +282,6 @@ def make_test(xy_or_ll_out):
stand_lon=-89., pole_lat=62.0, stand_lon=-89., pole_lat=62.0,
pole_lon=180.) pole_lon=180.)
p_def = xy_to_ll_proj(64, 40, map_proj=6, ref_lat=17.6759, p_def = xy_to_ll_proj(64, 40, map_proj=6, ref_lat=17.6759,
ref_lon=-101.4286, known_x=0, known_y=0, ref_lon=-101.4286, known_x=0, known_y=0,
stand_lon=-89., stand_lon=-89.,
@ -311,4 +300,3 @@ if __name__ == "__main__":
setattr(WRFLatLonProjTest, 'test_{0}'.format(v), test_func) setattr(WRFLatLonProjTest, 'test_{0}'.format(v), test_func)
ut.main() ut.main()

1
test/test_units.py

@ -51,6 +51,5 @@ class TestUnits(ut.TestCase):
self.assertEqual(var.attrs["units"], units) self.assertEqual(var.attrs["units"], units)
if __name__ == "__main__": if __name__ == "__main__":
ut.main() ut.main()

2
test/utests.py

@ -35,7 +35,7 @@ def setUpModule():
os.environ["OMP_NUM_THREADS"] = "4" os.environ["OMP_NUM_THREADS"] = "4"
this_path = os.path.realpath(__file__) this_path = os.path.realpath(__file__)
ncl_script = os.path.join(os.path.dirname(this_path), ncl_script = os.path.join(os.path.dirname(this_path), "ncl",
"ncl_get_var.ncl") "ncl_get_var.ncl")
for dir, outfile in zip(DIRS, REF_NC_FILES): for dir, outfile in zip(DIRS, REF_NC_FILES):

Loading…
Cancel
Save