Skip to content

Commit

Permalink
Merge pull request #1291 from UV-CDAT/issue_1274_import_missing
Browse files Browse the repository at this point in the history
Issue 1274 import missing
  • Loading branch information
aashish24 committed May 12, 2015
2 parents 66bab1b + 77efa33 commit b70346c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Packages/vcs/Lib/Canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import os
import sys
import random
import genutil
from cdms2.grid import AbstractRectGrid
import shutil, inspect
import VCS_validation_functions
Expand Down Expand Up @@ -735,13 +734,16 @@ def _reconstruct_tv(self, arglist, keyargs):
_process_keyword(tv, 'name', 'name', keyargs, default=tv.id)
time = keyargs.get('time')
if time is not None:
ctime = time.tocomp()
ar.date = str(ctime)
if isinstance(time,(str,unicode)):
ctime = cdtime.s2c(str(time))
else:
ctime = time.tocomp()
tv.user_date = str(ctime)
_process_keyword(tv, 'units', 'units', keyargs)
_process_keyword(tv, 'date', 'ymd', keyargs)
# If date has still not been set, try to get it from the first
# time value if present
if not hasattr(tv, 'date') and not hasattr(tv, 'time'):
if not hasattr(tv, 'user_date') and not hasattr(tv, 'date') and not hasattr(tv, 'time'):
change_date_time(tv, 0)

# Draw continental outlines if specified.
Expand Down Expand Up @@ -885,8 +887,10 @@ def __init__(self, gui = 0, mode = 1, pause_time=0, call_from_gui=0, size=None,

is_canvas = len(vcs.return_display_names()[0])

## TODO get rid of all these gui_canvas_closed I think the code is not even here anymore
## I believe it was for the old editor style
if gui_canvas_closed == 1:
showerror( "Error Message to User", "There can only be one VCS Canvas GUI opened at any given time and the VCS Canvas GUI cannot operate with other VCS Canvases.")
raise RuntimeError("There can only be one VCS Canvas GUI opened at any given time and the VCS Canvas GUI cannot operate with other VCS Canvases.")
return

self.winfo_id = -99
Expand Down
7 changes: 7 additions & 0 deletions Packages/vcs/Lib/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,13 @@ def renderTemplate(self,tmpl,data,gm,taxis,zaxis):
returned["vtk_backend_%s_text_actor" % d.backend["vtk_backend_template_attribute"]] = t
self.canvas.display_names.remove(d.name)
del(vcs.elements["display"][d.name])
## Sometimes user passes "date" as an attribute to replace date
if hasattr(data,"user_date"):
taxis = cdms2.createAxis([cdtime.s2r(data.user_date,"days since 1900").value])
taxis.designateTime()
taxis.units="days since 1900"
if zaxis is not None and zaxis.isTime():
zaxis=taxis
if taxis is not None:
try:
tstr = str(cdtime.reltime(taxis[0],taxis.units).tocomp(taxis.getCalendar()))
Expand Down
1 change: 1 addition & 0 deletions Packages/vcs/Lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import colormap
import vcsaddons
import cdms2
import genutil

indent = 1
sort_keys = True
Expand Down
10 changes: 10 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ cdat_add_test(vcs_test_taylor_2_quads
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_boxfill_number_color_more_than_number_levels.py
)
cdat_add_test(test_vcs_user_passed_date
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_user_passed_date.py
"${BASELINE_DIR}/test_vcs_user_passed_date.png"
)
cdat_add_test(test_vcs_user_passed_date_as_string
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_user_passed_date_as_string.py
"${BASELINE_DIR}/test_vcs_user_passed_date_as_string.png"
)
cdat_add_test(test_vcs_auto_time_labels
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_auto_time_labels.py
Expand Down
17 changes: 17 additions & 0 deletions testing/vcs/test_vcs_user_passed_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import vcs,cdms2,os,sys,cdtime
src=sys.argv[1]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
f=cdms2.open(os.path.join(vcs.prefix,"sample_data","clt.nc"))
s=f("clt",squeeze=1)
x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
x.plot(s,bg=1,time=cdtime.comptime(2015))
fnm = os.path.split(__file__)[1][:-3]+".png"
x.png(fnm)
print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)
17 changes: 17 additions & 0 deletions testing/vcs/test_vcs_user_passed_date_as_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import vcs,cdms2,os,sys,cdtime
src=sys.argv[1]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
f=cdms2.open(os.path.join(vcs.prefix,"sample_data","clt.nc"))
s=f("clt",squeeze=1)
x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
x.plot(s,bg=1,time='2015-02-23')
fnm = os.path.split(__file__)[1][:-3]+".png"
x.png(fnm)
print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)

0 comments on commit b70346c

Please sign in to comment.