Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: datawc does not work on a time axis. #2007

Merged
merged 1 commit into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danlipsa why months since 1900, we should use the gm.datawc_units and gm.datawc_calendar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doutriaux1 This is a way to get the type, so the actual value does not matter. I got this from Canvas.py:3051. Is there a better way to get the type returned by cdtime.reltime?

Copy link
Contributor

@doutriaux1 doutriaux1 Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about component time?

a=cdtime.reltime(45,"months since 1945")
b=cdtime.comptime(2000)
gm = x.createboxfill()
gm.datawc_x1 = b
type(gm.datawc_x1) is type(a)
False

Is it ok to return v if it's a component time?

Copy link
Contributor Author

@danlipsa danlipsa Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doutriaux1 What is comptime? I did not try it, so probably not. It does not work with rel time either - I did try that. Its not clear from the documentation that datawc_ accepts objects beyond float values. I added an issue for this and we can fix it and add tests.
#2009
The question is: should we do this for 2.6 or leave it for later? Note this PR solves the user's issue. @aashish24 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. A comptime is a componentTime. Basically a date. Whereas reltime is a relative time, i.e a delta since some reference date. You should take a look at: http://uvcdat.llnl.gov/documentation/cdms/cdms_3.html

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")