Browse Source

Modified CI unit tests to remove the warnings. Added __eq__ operator for projection, Fixes #26 .

main
Bill Ladwig 8 years ago
parent
commit
7f518e6015
  1. 8
      doc/source/new.rst
  2. 70
      src/wrf/projection.py
  3. BIN
      test/ci_tests/ci_result_file.nc
  4. BIN
      test/ci_tests/ci_test_file.nc
  5. 8
      test/ci_tests/make_test_file.py

8
doc/source/new.rst

@ -4,6 +4,14 @@ What's New
Releases Releases
------------- -------------
v1.0.4
^^^^^^^^^^^^^^
- Release 1.0.4
- Fix warnings with continuous integration tests which was caused by fill
values being written as NaN to the NetCDF result file.
- Added the __eq__ operator to the WrfProj projection base class.
v1.0.3 v1.0.3
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

70
src/wrf/projection.py

@ -2,6 +2,7 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
import numpy as np import numpy as np
import math import math
from decimal import Decimal, Context, ROUND_HALF_UP
from .config import basemap_enabled, cartopy_enabled, pyngl_enabled from .config import basemap_enabled, cartopy_enabled, pyngl_enabled
from .constants import Constants, ProjectionTypes from .constants import Constants, ProjectionTypes
@ -176,6 +177,73 @@ class WrfProj(object):
if self.stand_lon is None: if self.stand_lon is None:
self.stand_lon = self._cen_lon self.stand_lon = self._cen_lon
@staticmethod
def _context_equal(x, y, ctx):
"""Return True if both objects are equal based on the provided context.
Args:
x (numeric): A numeric value.
y (numeric): A numeric value.
ctx (:class:`decimal.Context`): A decimal Context object.
Returns:
:obj:`bool`: True if the values are equal based on the provided
context, False otherwise.
"""
if x is not None:
if y is None:
return False
# Note: The float conversion is because these may come in as
# numpy.float32 or numpy.float64, which Decimal does not know
# how to handle.
if (Decimal(float(x)).normalize(ctx) !=
Decimal(float(y)).normalize(ctx)):
return False
else:
if y is not None:
return False
return True
def __eq__(self, other):
"""Return True if this projection object is the same as *other*.
Note: WRF can use either floats or doubles, so only going to
guarantee floating point precision equivalence, in case the different
types are ever compared (or a projection is hand constructed). For WRF
domains, 7-digit equivalence should be good enough.
"""
if self.map_proj is not None:
if self.map_proj != other.map_proj:
return False
else:
if other.map_proj is not None:
return False
# Only checking for floating point equal.
ctx = Context(prec=7, rounding=ROUND_HALF_UP)
return (WrfProj._context_equal(self.truelat1, other.truelat1, ctx) and
WrfProj._context_equal(self.truelat2, other.truelat2, ctx) and
WrfProj._context_equal(self.moad_cen_lat, other.moad_cen_lat,
ctx) and
WrfProj._context_equal(self.stand_lon, other.stand_lon,
ctx) and
WrfProj._context_equal(self.pole_lat, other.pole_lat, ctx) and
WrfProj._context_equal(self.pole_lon, other.pole_lon, ctx) and
WrfProj._context_equal(self.dx, other.dx, ctx) and
WrfProj._context_equal(self.dy, other.dy, ctx))
def _basemap(self, geobounds, **kwargs): def _basemap(self, geobounds, **kwargs):
@ -291,7 +359,7 @@ class WrfProj(object):
"""Return a :class:`matplotlib.mpl_toolkits.basemap.Basemap` object """Return a :class:`matplotlib.mpl_toolkits.basemap.Basemap` object
for the map projection. for the map projection.
Arguments: Args:
geobounds (:class:`wrf.GeoBounds`, optional): The geobounds to geobounds (:class:`wrf.GeoBounds`, optional): The geobounds to
get the extents. If set to None and using the *var* parameter, get the extents. If set to None and using the *var* parameter,

BIN
test/ci_tests/ci_result_file.nc

Binary file not shown.

BIN
test/ci_tests/ci_test_file.nc

Binary file not shown.

8
test/ci_tests/make_test_file.py

@ -7,7 +7,7 @@ import numpy as np
from netCDF4 import Dataset from netCDF4 import Dataset
from wrf import (getvar, interplevel, interpline, vertcross, vinterp, py2round, from wrf import (getvar, interplevel, interpline, vertcross, vinterp, py2round,
CoordPair, ll_to_xy, xy_to_ll) CoordPair, ll_to_xy, xy_to_ll, to_np)
VARS_TO_KEEP = ("XLAT", "XLONG", "XLAT_U", "XLAT_V", "XLONG_U", "XLONG_V", VARS_TO_KEEP = ("XLAT", "XLONG", "XLAT_U", "XLAT_V", "XLONG_U", "XLONG_V",
"U", "V", "W", "PH", "PHB", "T", "P", "PB", "Q2", "T2", "U", "V", "W", "PH", "PHB", "T", "P", "PB", "Q2", "T2",
@ -15,7 +15,7 @@ VARS_TO_KEEP = ("XLAT", "XLONG", "XLAT_U", "XLAT_V", "XLONG_U", "XLONG_V",
"QGRAUP", "QRAIN", "QSNOW", "MAPFAC_M", "MAPFAC_U", "QGRAUP", "QRAIN", "QSNOW", "MAPFAC_M", "MAPFAC_U",
"MAPFAC_V", "F", "HGT", "RAINC", "RAINSH", "RAINNC") "MAPFAC_V", "F", "HGT", "RAINC", "RAINSH", "RAINNC")
DIMS_TO_TRIM = ("west_east", "south_north", "bottom_top", "bottom_top_stag", DIMS_TO_TRIM = ("west_east", "south_north", #"bottom_top", "bottom_top_stag",
"west_east_stag", "south_north_stag") "west_east_stag", "south_north_stag")
WRF_DIAGS = ["avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz", WRF_DIAGS = ["avo", "eth", "cape_2d", "cape_3d", "ctt", "dbz", "mdbz",
@ -81,7 +81,9 @@ def add_to_ncfile(outfile, var, varname):
ncvar = outfile.createVariable(varname, var.dtype, var.dims, ncvar = outfile.createVariable(varname, var.dtype, var.dims,
zlib=True, fill_value=fill_value) zlib=True, fill_value=fill_value)
ncvar[:] = var[:]
var_vals = to_np(var)
ncvar[:] = var_vals[:]
def make_result_file(opts): def make_result_file(opts):

Loading…
Cancel
Save