Skip to content

Commit

Permalink
BUG: datawc does not work on a time axis.
Browse files Browse the repository at this point in the history
This happened because datawc is converted to cdtime.reltime type.
  • Loading branch information
danlipsa committed Jun 3, 2016
1 parent 196dc30 commit f6b81f3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Packages/vcs/vcs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,13 +1666,25 @@ def creategraphicsmethod(gtype, gname='default', name=None):
return copy_mthd


# Returns the float value for datawc_...
# datawc_ can be a float or a cdtime.reltime
# TODO: Investigate why datawc is converted to a cdtime.reltime
def getDataWcValue(v):
if (type(v) is type(cdtime.reltime(0, 'months since 1900'))):
return v.value
else:
return v


def getworldcoordinates(gm, X, Y):
"""Given a graphics method and two axes
figures out correct world coordinates"""
# compute the spanning in x and y, and adjust for the viewport
wc = [0, 1, 0, 1]
try:
if gm.datawc_x1 > 9.E19:
datawc = [getDataWcValue(gm.datawc_x1), getDataWcValue(gm.datawc_x2),
getDataWcValue(gm.datawc_y1), getDataWcValue(gm.datawc_y2)]
if numpy.isclose(datawc[0], 1.e20):
try:
i = 0
try:
Expand All @@ -1684,8 +1696,8 @@ def getworldcoordinates(gm, X, Y):
except:
wc[0] = X[:].min()
else:
wc[0] = gm.datawc_x1
if gm.datawc_x2 > 9.E19:
wc[0] = datawc[0]
if numpy.isclose(datawc[1], 1.e20):
try:
i = -1
try:
Expand All @@ -1697,18 +1709,18 @@ def getworldcoordinates(gm, X, Y):
except:
wc[1] = X[:].max()
else:
wc[1] = gm.datawc_x2
wc[1] = datawc[1]
except:
return wc
if (((not isinstance(X, cdms2.axis.TransientAxis) and
isinstance(Y, cdms2.axis.TransientAxis)) or
not vcs.utils.monotonic(X[:])) and
numpy.allclose([gm.datawc_x1, gm.datawc_x2], 1.e20))\
numpy.allclose([datawc[0], datawc[1]], 1.e20))\
or (hasattr(gm, "projection") and
vcs.elements["projection"][gm.projection].type != "linear"):
wc[0] = X[:].min()
wc[1] = X[:].max()
if gm.datawc_y1 > 9.E19:
if numpy.isclose(datawc[2], 1.e20):
try:
i = 0
try:
Expand All @@ -1720,8 +1732,8 @@ def getworldcoordinates(gm, X, Y):
except:
wc[2] = Y[:].min()
else:
wc[2] = gm.datawc_y1
if gm.datawc_y2 > 9.E19:
wc[2] = datawc[2]
if numpy.isclose(datawc[3], 1.e20):
try:
i = -1
try:
Expand All @@ -1733,16 +1745,16 @@ def getworldcoordinates(gm, X, Y):
except:
wc[3] = Y[:].max()
else:
wc[3] = gm.datawc_y2
wc[3] = datawc[3]
if (((not isinstance(Y, cdms2.axis.TransientAxis) and
isinstance(X, cdms2.axis.TransientAxis)) or not vcs.utils.monotonic(Y[:])) and
numpy.allclose([gm.datawc_y1, gm.datawc_y2], 1.e20)) \
numpy.allclose([datawc[2], datawc[3]], 1.e20)) \
or (hasattr(gm, "projection") and
vcs.elements["projection"][
gm.projection].type.lower().split()[0]
not in ["linear", "polar"] and
numpy.allclose([gm.datawc_y1, gm.datawc_y2], 1.e20) and
numpy.allclose([gm.datawc_x1, gm.datawc_x2], 1.e20)):
numpy.allclose([datawc[2], datawc[3]], 1.e20) and
numpy.allclose([datawc[0], datawc[1]], 1.e20)):
wc[2] = Y[:].min()
wc[3] = Y[:].max()
if wc[3] == wc[2]:
Expand Down
5 changes: 5 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ if (CDAT_DOWNLOAD_SAMPLE_DATA)
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_boxfill_custom.py
"${BASELINE_DIR}/test_vcs_boxfill_custom.png"
)
cdat_add_test(test_vcs_boxfill_datawc_time
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_boxfill_datawc_time.py
"${BASELINE_DIR}/test_vcs_boxfill_datawc_time.png"
)
cdat_add_test(test_vcs_boxfill_custom_non_default_levels
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_boxfill_custom_non_default_levels.py
Expand Down
23 changes: 23 additions & 0 deletions testing/vcs/test_vcs_boxfill_datawc_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import cdms2, os, sys, vcs, cdtime, testing.regression as regression

# Test that we can restrict the plot using datawc along a time axis
dataFile = cdms2.open(os.path.join(vcs.sample_data, "clt.nc"))
clt = dataFile("clt")
clt = clt(latitude=(-90.0, 90.0), longitude=(0.), squeeze=1,
time=('1979-1-1 0:0:0.0', '1988-12-1 0:0:0.0'))

# Initialize canvas:
canvas = regression.init()

# Create and plot quick boxfill with default settings:
boxfill=canvas.createboxfill()

# Change the type
boxfill.boxfill_type = 'custom'
boxfill.datawc_y1 = 12

canvas.plot(clt, boxfill, bg=1)

# Load the image testing module:
# Create the test image and compare:
regression.run(canvas, "test_vcs_boxfill_datawc_time.png")

0 comments on commit f6b81f3

Please sign in to comment.