Skip to content

Commit 11fc132

Browse files
Merge pull request #1544 from UV-CDAT/preserve_display_plots
Preserve display plots on update, instead of trashing them all
2 parents 8923986 + 7340f8f commit 11fc132

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

Packages/vcs/vcs/Canvas.py

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,13 +2244,13 @@ def drawtextcombined(self, Tt_name=None, To_name=None, string=None,
22442244
# Set alias for the secondary drawtextcombined.
22452245
drawtext = drawtextcombined
22462246

2247-
_plot_keywords_ = ['variable', 'grid', 'xaxis', 'yaxis', 'xrev', 'yrev', 'continents', 'xarray', 'yarray',
2248-
'name', 'time', 'units', 'ymd', 'file_comment',
2249-
'xbounds', 'ybounds', 'xname', 'yname', 'xunits', 'yunits', 'xweights', 'yweights',
2250-
'comment1', 'comment2', 'comment3', 'comment4', 'hms', 'long_name', 'zaxis',
2251-
'zarray', 'zname', 'zunits', 'taxis', 'tarray', 'tname', 'tunits', 'waxis', 'warray',
2252-
'wname', 'wunits', 'bg', 'ratio', 'donotstoredisplay', 'render', 'continents_line']
2247+
_plot_keywords_ = ['variable', 'grid', 'xaxis', 'xarray', 'xrev', 'yaxis', 'yarray', 'yrev', 'continents',
2248+
'xbounds', 'ybounds', 'zaxis', 'zarray', 'taxis', 'tarray', 'waxis', 'warray', 'bg', 'ratio',
2249+
'donotstoredisplay', 'render', 'continents_line', "display_name"]
22532250

2251+
_deprecated_plot_keywords_ = ["time", "units", "file_comment", "xname", "yname", "zname", "tname", "wname",
2252+
"xunits", "yunits", "zunits", "tunits", "wunits", "comment1", "comment2", "comment3",
2253+
"comment4", "long_name"]
22542254
# def replot(self):
22552255
# """ Clears and plots with last used plot arguments
22562256
# """
@@ -2297,28 +2297,10 @@ def plot(self, *actual_args, **keyargs):
22972297
'3',3: y dim will be 3 times bigger than x dim (restricted to original tempalte.data area
22982298
Adding a 't' at the end of the ratio, makes the tickmarks and boxes move along.
22992299
2300-
Variable attribute keys:
2301-
comment1 = string #Comment plotted above file_comment
2302-
comment2 = string #Comment plotted above comment1
2303-
comment3 = string #Comment plotted above comment2
2304-
comment4 = string #Comment plotted above comment4
2305-
file_comment = string #Comment (defaults to file.comment)
2306-
hms = string (hh:mm:ss) #Hour, minute, second
2307-
long_name = string #Descriptive variable name
2308-
name = string #Variable name (defaults to var.id)
2309-
time = cdtime #instance (relative or absolute),
2310-
cdtime, reltime or abstime value
2311-
units = string #Variable units
2312-
ymd = string (yy/mm/dd) #Year, month, day
2313-
23142300
Dimension attribute keys (dimension length=n):
23152301
[x|y|z|t|w]array = NumPy array of length n # x or y Dimension values
23162302
[x|y|z|t|w]array = NumPy array of length n # x or y Dimension values
23172303
[x|y]bounds = NumPy array of shape (n,2) # x or y Dimension boundaries
2318-
[x|y|z|t|w]name = string # x or y Dimension name
2319-
[x|y|z|t|w]units = string # x or y Dimension units
2320-
[x|y]weights = NumPy array of length n # x or y Dimension weights (used to
2321-
calculate area-weighted mean)
23222304
23232305
CDMS object:
23242306
[x|y|z|t|w]axis = CDMS axis object # x or y Axis
@@ -2345,7 +2327,13 @@ def plot(self, *actual_args, **keyargs):
23452327
# Values 6 through 11 signify the line type
23462328
# defined by the files data_continent_other7
23472329
# through data_continent_other12.
2348-
2330+
continents_line = vcs.getline("default") # VCS line object to define continent appearance
2331+
donotstoredisplay = True|False # Whether the displayplot object generated by this plot are stored
2332+
render = True|False # Whether to actually render the plot or not (useful for doing a
2333+
# bunch of plots in a row)
2334+
display_name = "__display_123" # VCS Display plot name (used to prevent duplicate display plots)
2335+
ratio = 1.5|"autot"|"auto" # Ratio of height/width for the plot; autot and auto will choose a
2336+
# "good" ratio for you.
23492337
Graphics Output in Background Mode:
23502338
bg = 0|1 # if ==1, create images in the background
23512339
(Don't display the VCS Canvas)
@@ -3464,16 +3452,20 @@ def set_convert_labels(copy_mthd, test=0):
34643452
"unknown taylordiagram graphic method: %s" %
34653453
arglist[4])
34663454
t.plot(arglist[0], canvas=self, template=arglist[2], **keyargs)
3467-
nm, src = self.check_name_source(None, "default", "display")
3468-
dn = displayplot.Dp(nm)
3455+
3456+
dname = keyargs.get("display_name")
3457+
if dname is not None:
3458+
dn = vcs.elements["display"][dname]
3459+
else:
3460+
nm, src = self.check_name_source(None, "default", "display")
3461+
dn = displayplot.Dp(nm)
34693462
dn.continents = self.getcontinentstype()
34703463
dn.continents_line = self.getcontinentsline()
34713464
dn.template = arglist[2]
34723465
dn.g_type = arglist[3]
34733466
dn.g_name = arglist[4]
34743467
dn.array = arglist[:2]
34753468
dn.extradisplays = t.displays
3476-
# dn.array=arglist[0]
34773469
for p in slab_changed_attributes.keys():
34783470
tmp = slab_changed_attributes[p]
34793471
if tmp == (None, None):
@@ -3502,11 +3494,14 @@ def set_convert_labels(copy_mthd, test=0):
35023494
doratio == "0" or doratio[:4] == "auto"):
35033495
doratio = "1t"
35043496
for keyarg in keyargs.keys():
3505-
if keyarg not in self.__class__._plot_keywords_ + \
3506-
self.backend._plot_keywords:
3507-
warnings.warn(
3508-
'Unrecognized vcs plot keyword: %s, assuming backend (%s) keyword' %
3509-
(keyarg, self.backend.type))
3497+
if keyarg not in self.__class__._plot_keywords_ + self.backend._plot_keywords:
3498+
if keyarg in self.__class__._deprecated_plot_keywords_:
3499+
warnings.warn("Deprecation Warning: Keyword '%s' will be removed in the next version"
3500+
"of UV-CDAT." % keyarg)
3501+
else:
3502+
warnings.warn(
3503+
'Unrecognized vcs plot keyword: %s, assuming backend (%s) keyword' %
3504+
(keyarg, self.backend.type))
35103505

35113506
if arglist[0] is not None or 'variable' in keyargs:
35123507
arglist[0] = self._reconstruct_tv(arglist, keyargs)
@@ -3725,9 +3720,13 @@ def set_convert_labels(copy_mthd, test=0):
37253720
else:
37263721
returned_kargs = self.backend.plot(*arglist, **keyargs)
37273722
if not keyargs.get("donotstoredisplay", False):
3728-
nm, src = self.check_name_source(
3729-
None, "default", "display")
3730-
dn = displayplot.Dp(nm, parent=self)
3723+
dname = keyargs.get("display_name")
3724+
if dname is not None:
3725+
dn = vcs.elements['display'][dname]
3726+
else:
3727+
nm, src = self.check_name_source(
3728+
None, "default", "display")
3729+
dn = displayplot.Dp(nm, parent=self)
37313730
dn.template = arglist[2]
37323731
dn.g_type = arglist[3]
37333732
dn.g_name = arglist[4]
@@ -3872,13 +3871,20 @@ def clear(self, *args, **kargs):
38723871
a.plot(array,'default','isofill','quick')
38733872
a.clear()
38743873
3874+
Internally, update() calls clear() to assist in removing plots. The preserve_display argument is used to
3875+
make sure that the display plots that are associated with the current canvas are not eliminated, and
3876+
are still able to be used to regenerate the plots.
38753877
"""
38763878
if self.animate.created():
38773879
self.animate.close()
38783880
if self.configurator is not None:
38793881
self.configurator.stop_animating()
38803882
self.animate_info = []
38813883
self.animate.update_animate_display_list()
3884+
3885+
preserve_display = kargs.get("preserve_display", False)
3886+
if "preserve_display" in kargs:
3887+
del kargs["preserve_display"]
38823888
self.backend.clear(*args, **kargs)
38833889
for nm in self.display_names:
38843890
# Lets look at elements created by dispaly production
@@ -3893,7 +3899,8 @@ def clear(self, *args, **kargs):
38933899
for k in new_elts[e]:
38943900
if k in vcs.elements[e].keys():
38953901
del(vcs.elements[e][k])
3896-
del(vcs.elements["display"][nm])
3902+
if not preserve_display:
3903+
del(vcs.elements["display"][nm])
38973904
self.display_names = []
38983905
return
38993906

Packages/vcs/vcs/VTKPlots.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,21 @@ def configureEvent(self, obj, ev):
299299
parg.append(d.g_type)
300300
parg.append(d.g_name)
301301
plots_args.append(parg)
302-
kwarg = {}
302+
key = {"display_name": dnm}
303303
if d.ratio is not None:
304-
kwarg["ratio"] = d.ratio
304+
key["ratio"] = d.ratio
305+
key["continents"] = d.continents
306+
key["continents_line"] = d.continents_line
307+
key_args.append(key)
305308

306-
kwarg["continents"] = d.continents
307-
kwarg["continents_line"] = d.continents_line
308-
309-
key_args.append(kwarg)
310-
311-
# Have to pull out the UI layer so it doesn't get borked by the clear
309+
# Have to pull out the UI layer so it doesn't get borked by the z
312310
self.hideGUI()
313311

314312
if self.canvas.configurator is not None:
315313
restart_anim = self.canvas.configurator.animation_timer is not None
316314
else:
317315
restart_anim = False
318-
self.canvas.clear(render=False)
316+
self.canvas.clear(render=False, preserve_display=True)
319317

320318
for i, pargs in enumerate(plots_args):
321319
self.canvas.plot(*pargs, render=False, **key_args[i])

0 commit comments

Comments
 (0)