def test_setlineattributes(self): l = vcs.createline("vcs_test_set_line") l.color = 242 l.width = 5.6 l.type = "dash" self.assertEqual(l.color, [242]) self.assertEqual(l.width, [5.6]) self.assertEqual(l.type, ["dash"]) v = vcs.createvector() v.setLineAttributes("vcs_test_set_line") self.assertEqual(v.linecolor, 242) self.assertEqual(v.linewidth, 5.6) self.assertEqual(v.linetype, "dash") yx = vcs.create1d() yx.setLineAttributes(l) self.assertEqual(yx.linecolor, 242) self.assertEqual(yx.linewidth, 5.6) self.assertEqual(yx.linetype, "dash") iso = vcs.createisoline() # Note "solid" is a line name. iso.setLineAttributes([l, "solid", l]) self.assertEqual(iso.linecolors, [242, 1, 242]) self.assertEqual(iso.linewidths, [5.6, 1, 5.6]) self.assertEqual(iso.linetypes, ['dash', 'solid', 'dash'])
def plotminmax(outpath, mins, maxs, varname): canvas = vcs.init() gm = vcs.create1d() mn, mx = vcs.minmax(mins, maxs) gm.datawc_y1 = mn gm.datawc_y2 = mx template = vcs.createtemplate() template.scale(.95) template.move(.05, 'x') template.blank(["max", "mean"]) canvas.plot(mins, gm, template, id=varname) template = vcs.createtemplate() template.scale(.95) template.move(.05, 'x') template.blank(["min", "mean"]) canvas.plot(maxs, gm, template, id=varname) canvas.png(outpath) canvas.clear()
import sys, os import vcs import sys import cdms2 import vtk import os import MV2 bg = not False x = vcs.init() x.setcolormap("rainbow") gm = vcs.create1d() xtra = {} f = cdms2.open(os.path.join(vcs.prefix, 'sample_data', 'clt.nc')) s = f("clt", **xtra) s = s(latitude=(20, 20, "cob"), longitude=(112, 112, "cob"), squeeze=1) s2 = MV2.sin(s) s2 -= s2 s -= s x.plot(s, gm, bg=bg) x.png('test_vcs_basic_oned_zero.png')
end_date = cdtime.reltime(time_axis[-1], time_axis.units).tocomp() if mindate is None: mindate = start_date else: mindate = min(start_date, mindate) if maxdate is None: maxdate = end_date else: maxdate = max(maxdate, end_date) maxval = max(maxval, variable.max()) x = vcs.init() oned = vcs.create1d() oned.datawc_y1 = minval oned.datawc_y2 = maxval oned.datawc_x1 = mindate oned.datawc_x2 = maxdate scale = vcs.utils.mkscale(minval, maxval) labels = numpy.array(scale) labels = (10**labels) labels = numpy.round(labels, 0) labels = list(labels) labels[0] = 0 nice_labels = [] for i in range(len(labels)): val = int(labels[i])
import filecmp import vcs, numpy, os, sys src = sys.argv[1] if os.path.exists("test_vcs_dump_json.json"): os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createisofill("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createisoline("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createmeshfill("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.create1d("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createfillarea("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createvector("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createtext("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createline("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createmarker("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createtemplate("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createprojection("vcs_instance") b.script("test_vcs_dump_json", "a")
import vcs,os,filecmp import vcs,numpy,os,sys src=sys.argv[1] if os.path.exists("test_vcs_dump_json.json"): os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createisofill("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createisoline("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createmeshfill("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.create1d("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createfillarea("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createtext("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createline("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createmarker("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createtemplate("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createprojection("Charles.Doutriaux") b.script("test_vcs_dump_json","a") assert(filecmp.cmp("test_vcs_dump_json.json",src))
import filecmp import vcs,numpy,os,sys src = sys.argv[1] if os.path.exists("test_vcs_dump_json.json"): os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createisofill("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createisoline("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createmeshfill("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.create1d("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createfillarea("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createvector("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createtext("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createline("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createmarker("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createtemplate("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createprojection("vcs_instance") b.script("test_vcs_dump_json","a")
import sys,os import vcs import sys import cdms2 import vtk import os import MV2 bg = not False x=vcs.init() x.setcolormap("rainbow") gm = vcs.create1d() xtra = {} f=cdms2.open(os.path.join(vcs.prefix,'sample_data','clt.nc')) s=f("clt",**xtra) s=MV2.masked_greater(s,78.) s = s(latitude=(20,20,"cob"),longitude=(112,112,"cob"),squeeze=1) s2=MV2.sin(s) x.plot(s,gm,bg=bg) x.png('test_vcs_basic_oned_masked.png')
def spaghetti_plot(variables, template=None, min_y=None, max_y=None, left_label=None, right_label=None, tick_sides=None, line="default", marker="default", x_labels="*", y_labels="*", canvas=None): """ This file is ready to be imported by your scripts, and you can just call this function. Sample usage is below. variables: List of variables to plot template: The template to use as the base for the plot. min_y: If you want to adjust the y axis bounds, you can set a minimum value. Will be derived from data if not specified. max_y: If you want to adjust the y axis bounds, you can set a maximum value. Will be derived from data if not specified. left_label: Text to put on the left Y axis right_label: Text to put on the right Y axis tick_sides: A list of "left" or "right" values indicating which side of the chart you want the variable axes to be displayed. line: A line object or name of a line object used to describe the lines plotted. Set to None to hide. marker: A marker object or name of a marker object used to describe the markers plotted. Set to None to hide. x_labels: Dictionary for setting axis tick labels y_labels: Dictionary for setting axis tick labels """ if canvas is None: canvas = vcs.init() if isinstance(template, (str, unicode)): template = vcs.gettemplate(template) if template is None: # Use our custom default template for 1ds template = vcs.createtemplate() # Shrink the template a bit template.scale(.78, "x") template.move(.02, "x") template.yname.x = .01 template.data.y1 = .1 template.box1.y1 = .1 ticlen = template.xtic1.y2 - template.xtic1.y1 template.xtic1.y1 = template.data.y1 template.xtic1.y2 = template.xtic1.y1 + ticlen template.xtic2.priority = 0 template.xlabel1.y = template.xtic1.y2 - .01 template.legend.x1 = template.data.x2 + (1 - template.data.x2) / 3. template.legend.x2 = .95 template.legend.y1 = template.data.y1 template.legend.y2 = template.data.y2 template.yname.y = (template.data.y1 + template.data.y2) / 2. template.xname.y = template.xlabel1.y - .05 # The labels don't make any sense with multiple values; hide them. template.min.priority = 0 template.max.priority = 0 template.mean.priority = 0 template.dataname.priority = 0 templates = EzTemplate.oneD(len(variables), template=template) templates.x = canvas if tick_sides is None: tick_sides = ["left"] * len(variables) clean_ticks = [] for t in tick_sides: if t.lower() not in ('left', 'right'): raise ValueError( "tick_sides must be a list of 'left' or 'right' values; found '%s'." % t) clean_ticks.append(t.lower()) tick_sides = clean_ticks if len(tick_sides) < len(variables): tick_sides += tick_sides[-1:] * len(variables) # Store min/max per side for appropriate scaling min_vals = {"left": min_y, "right": min_y} if min_y is None: for i, var in enumerate(variables): v_min = min(var) min_y = min_vals[tick_sides[i]] if min_y is None or min_y > v_min: min_vals[tick_sides[i]] = v_min max_vals = {"left": max_y, "right": max_y} if max_y is None: for i, var in enumerate(variables): v_max = max(var) max_y = max_vals[tick_sides[i]] if max_y is None or max_y < v_max: max_vals[tick_sides[i]] = v_max if isinstance(line, (str, unicode)): line = vcs.getline(line) if isinstance(marker, (str, unicode)): marker = vcs.getmarker(marker) to_pad = [] if line is not None: widths = line.width to_pad.append(widths) styles = line.type to_pad.append(styles) colors = line.color to_pad.append(colors) if marker is not None: markers = marker.type to_pad.append(markers) marker_colors = marker.color to_pad.append(marker_colors) marker_sizes = marker.size to_pad.append(marker_sizes) for padded in to_pad: if len(padded) < len(variables): padded += padded[-1:] * (len(variables) - len(padded)) for n in range(len(variables)): gm = vcs.create1d() if line is not None: gm.line = styles[n] gm.linewidth = widths[n] gm.linecolor = colors[n] else: gm.linewidth = 0 if marker is not None: gm.marker = markers[n] gm.markersize = marker_sizes[n] gm.markercolor = marker_colors[n] else: gm.marker = None gm.datawc_y1 = min_vals[tick_sides[n]] gm.datawc_y2 = max_vals[tick_sides[n]] template = templates.get(n) gm.xticlabels1 = x_labels if tick_sides[n] == "left": if tick_sides.index("left") == n: template.ylabel1.priority = 1 if left_label is not None: template.yname.priority = 0 left_text = vcs.createtext( Tt_source=template.yname.texttable, To_source=template.yname.textorientation) left_text.x = template.yname.x left_text.y = template.yname.y left_text.string = [left_label] templates.x.plot(left_text) else: template.ylabel1.priority = 0 template.yname.priority = 0 template.ylabel2.priority = 0 gm.yticlabels1 = y_labels gm.yticlabels2 = "" else: template.ylabel1.priority = 0 if tick_sides.index("right") == n: template.ylabel2.priority = 1 if right_label is not None: right_text = vcs.createtext( Tt_source=template.yname.texttable, To_source=template.yname.textorientation) right_text.x = template.data.x2 + (template.data.x1 - template.yname.x) right_text.y = template.yname.y right_text.string = [right_label] templates.x.plot(right_text) else: template.ylabel2.priority = 0 gm.yticlabels1 = "" gm.yticlabels2 = y_labels if n != 0: template.xlabel1.priority = 0 template.xname.priority = 0 var = variables[n] templates.x.plot(var, gm, template) return templates.x
import vcs l = vcs.createline("vcs_test_set_line") l.color = 242 l.width = 5.6 l.type = "dash" v = vcs.createvector() v.setLineAttributes("vcs_test_set_line") assert (v.linecolor == 242) assert (v.linewidth == 5.6) assert (v.linetype == "dash") yx = vcs.create1d() yx.setLineAttributes(l) assert (yx.linecolor == 242) assert (yx.linewidth == 5.6) assert (yx.linetype == "dash") iso = vcs.createisoline() # Note "solid" is a line name. iso.setLineAttributes([l, "solid", l]) assert (iso.linecolors == [242, 1, 242]) assert (iso.linewidths == [5.6, 1, 5.6]) assert (iso.linetypes == ['dash', 'solid', 'dash'])
import vcs l = vcs.createline("vcs_test_set_line") l.color=242 l.width = 5.6 l.type = "dash" v=vcs.createvector() v.setLineAttributes("vcs_test_set_line") assert(v.linecolor == 242) assert(v.linewidth == 5.6) assert(v.linetype == "dash") yx = vcs.create1d() yx.setLineAttributes(l) assert(yx.linecolor == 242) assert(yx.linewidth == 5.6) assert(yx.linetype == "dash") iso = vcs.createisoline() # Note "solid" is a line name. iso.setLineAttributes([l, "solid", l]) assert(iso.linecolors == [242, 1, 242]) assert(iso.linewidths == [5.6, 1, 5.6]) assert(iso.linetypes == ['dash', 'solid', 'dash'])
def spaghetti_plot(variables, template=None, min_y=None, max_y=None, left_label=None, right_label=None, tick_sides=None, line="default", marker="default", x_labels="*", y_labels="*", canvas=None): """ This file is ready to be imported by your scripts, and you can just call this function. Sample usage is below. variables: List of variables to plot template: The template to use as the base for the plot. min_y: If you want to adjust the y axis bounds, you can set a minimum value. Will be derived from data if not specified. max_y: If you want to adjust the y axis bounds, you can set a maximum value. Will be derived from data if not specified. left_label: Text to put on the left Y axis right_label: Text to put on the right Y axis tick_sides: A list of "left" or "right" values indicating which side of the chart you want the variable axes to be displayed. line: A line object or name of a line object used to describe the lines plotted. Set to None to hide. marker: A marker object or name of a marker object used to describe the markers plotted. Set to None to hide. x_labels: Dictionary for setting axis tick labels y_labels: Dictionary for setting axis tick labels """ if canvas is None: canvas = vcs.init() if isinstance(template, (str, unicode)): template = vcs.gettemplate(template) if template is None: # Use our custom default template for 1ds template = vcs.createtemplate() # Shrink the template a bit template.scale(.78, "x") template.move(.02, "x") template.yname.x = .01 template.data.y1 = .1 template.box1.y1 = .1 ticlen = template.xtic1.y2 - template.xtic1.y1 template.xtic1.y1 = template.data.y1 template.xtic1.y2 = template.xtic1.y1 + ticlen template.xtic2.priority = 0 template.xlabel1.y = template.xtic1.y2 - .01 template.legend.x1 = template.data.x2 + (1 - template.data.x2) / 3. template.legend.x2 = .95 template.legend.y1 = template.data.y1 template.legend.y2 = template.data.y2 template.yname.y = (template.data.y1 + template.data.y2)/2. template.xname.y = template.xlabel1.y - .05 # The labels don't make any sense with multiple values; hide them. template.min.priority = 0 template.max.priority = 0 template.mean.priority = 0 template.dataname.priority = 0 templates = EzTemplate.oneD(len(variables), template=template) templates.x = canvas if tick_sides is None: tick_sides = ["left"] * len(variables) clean_ticks = [] for t in tick_sides: if t.lower() not in ('left', 'right'): raise ValueError("tick_sides must be a list of 'left' or 'right' values; found '%s'." % t) clean_ticks.append(t.lower()) tick_sides = clean_ticks if len(tick_sides) < len(variables): tick_sides += tick_sides[-1:] * len(variables) # Store min/max per side for appropriate scaling min_vals = {"left": min_y, "right": min_y} if min_y is None: for i, var in enumerate(variables): v_min = min(var) min_y = min_vals[tick_sides[i]] if min_y is None or min_y > v_min: min_vals[tick_sides[i]] = v_min max_vals = {"left": max_y, "right": max_y} if max_y is None: for i, var in enumerate(variables): v_max = max(var) max_y = max_vals[tick_sides[i]] if max_y is None or max_y < v_max: max_vals[tick_sides[i]] = v_max if isinstance(line, (str, unicode)): line = vcs.getline(line) if isinstance(marker, (str, unicode)): marker = vcs.getmarker(marker) to_pad = [] if line is not None: widths = line.width to_pad.append(widths) styles = line.type to_pad.append(styles) colors = line.color to_pad.append(colors) if marker is not None: markers = marker.type to_pad.append(markers) marker_colors = marker.color to_pad.append(marker_colors) marker_sizes = marker.size to_pad.append(marker_sizes) for padded in to_pad: if len(padded) < len(variables): padded += padded[-1:] * (len(variables) - len(padded)) for n in range(len(variables)): gm = vcs.create1d() if line is not None: gm.line = styles[n] gm.linewidth = widths[n] gm.linecolor = colors[n] else: gm.linewidth = 0 if marker is not None: gm.marker = markers[n] gm.markersize = marker_sizes[n] gm.markercolor = marker_colors[n] else: gm.marker = None gm.datawc_y1 = min_vals[tick_sides[n]] gm.datawc_y2 = max_vals[tick_sides[n]] template = templates.get(n) gm.xticlabels1 = x_labels if tick_sides[n] == "left": if tick_sides.index("left") == n: template.ylabel1.priority = 1 if left_label is not None: template.yname.priority = 0 left_text = vcs.createtext(Tt_source=template.yname.texttable, To_source=template.yname.textorientation) left_text.x = template.yname.x left_text.y = template.yname.y left_text.string = [left_label] templates.x.plot(left_text) else: template.ylabel1.priority = 0 template.yname.priority = 0 template.ylabel2.priority = 0 gm.yticlabels1 = y_labels gm.yticlabels2 = "" else: template.ylabel1.priority = 0 if tick_sides.index("right") == n: template.ylabel2.priority = 1 if right_label is not None: right_text = vcs.createtext(Tt_source=template.yname.texttable, To_source=template.yname.textorientation) right_text.x = template.data.x2 + (template.data.x1 - template.yname.x) right_text.y = template.yname.y right_text.string = [right_label] templates.x.plot(right_text) else: template.ylabel2.priority = 0 gm.yticlabels1 = "" gm.yticlabels2 = y_labels if n != 0: template.xlabel1.priority = 0 template.xname.priority = 0 var = variables[n] templates.x.plot(var, gm, template) return templates.x
def plot(self, array, template=None, bg=False, render=True, x=None): """Parallel Coordinates plot array must be of shape: (...,Dim1,Nlines) """ if not array.ndim > 1: raise Exception("Array must be at least 2D") nlines = array.shape[-1] length = array.shape[-2] # Pad attributes related to Y axis for att in ["datawc_y1", "datawc_y2", "yticlabels"]: # prepare local lists exec("%s = list(self.%s)" % (att, att)) exec("while len(%s) < length: %s+=[%s[-1]]" % (att, att, att)) data = array.asma() maxs = numpy.ma.max(data, axis=-1) mins = numpy.ma.min(data, axis=-1) if template is not None: t = vcs.createtemplate(source=template) else: t = vcs.createtemplate(source=self.template) for i in range(length): levels = vcs.mkscale(mins[i], maxs[i]) # Do we need to create our range if numpy.allclose(datawc_y1[i], 1.e20): # noqa datawc_y1[i] = levels[0] # noqa datawc_y2[i] = levels[-1] # noqa maxs[i] = datawc_y2[i] # noqa mins[i] = datawc_y1[i] # noqa # Do we have tics? if yticlabels[i] == "*": # noqa yticlabels[i] = vcs.mklabels(levels) # noqa if x is None: x = self.x self.drawYAxes(mins, maxs, yticlabels, t, x, bg) # noqa ax = array.getAxis(-2) deflbls = {} for i in range(length): deflbls[float(i) / (length - 1)] = str(ax[i]) if hasattr(ax, "units") and isinstance(ax.units, (list, tuple)): deflbls[float(i) / (length - 1)] += " (%s)" % ax.units[i] if self.xticlabels1 == "*": lbls1 = deflbls else: lbls1 = self.xticlabels1 if self.xmtics1 == "": lbls1m = deflbls else: lbls1m = self.xmtics1 if self.xticlabels2 == "*": lbls2 = deflbls else: lbls2 = self.xticlabels2 if self.xmtics2 == "": lbls2m = deflbls else: lbls2m = self.xmtics2 for l_tmp, lbls in enumerate([lbls1, lbls1m, lbls2, lbls2m]): ln = x.createline(source=t.xtic1.line) xs = [] ys = [] if l_tmp % 2 == 0: if l_tmp == 0: txt = x.createtext(To_source=t.xlabel1.textorientation, Tt_source=t.xlabel1.texttable) else: txt = x.createtext(To_source=t.xlabel2.textorientation, Tt_source=t.xlabel2.texttable) txs = [] tys = [] ts = [] for loc in lbls: xs.append([loc, loc]) if l_tmp == 0: ys.append([t.xtic1.y1, t.xtic1.y2]) txs.append(loc) tys.append(t.xlabel1.y) ts.append(lbls[loc]) ln.priority = t.xtic1.priority txt.priority = t.xlabel1.priority elif l_tmp == 1: ys.append([t.xmintic1.y1, t.xmintic1.y2]) ln.priority = t.xmintic1.priority elif l_tmp == 2: ys.append([t.xtic2.y1, t.xtic2.y2]) txs.append(loc) tys.append(t.xlabel2.y) ts.append(lbls[loc]) ln.priority = t.xtic2.priority txt.priority = t.xlabel2.priority elif l_tmp == 3: ys.append([t.xmintic2.y1, t.xmintic2.y2]) ln.priority = t.xmintic2.priority ln.x = xs ln.y = ys ln.viewport = [t.data.x1, t.data.x2, 0, 1] x.plot(ln, bg=bg, render=False) if l_tmp % 2 == 0: # text on txt.viewport = ln.viewport txt.x = txs txt.y = tys txt.string = ts x.plot(txt, bg=bg, render=False) # Normalizes deltas = maxs - mins data = (data - mins[:, numpy.newaxis]) / deltas[:, numpy.newaxis] # Pad attributes related to number of lines lineAtts = ["linetypes", "linewidths", "markertypes", "markersizes"] if self.markercolors is not None: lineAtts.append("markercolors") if self.linecolors is not None: lineAtts.append("linecolors") for att in lineAtts: # prepare local lists exec("%s = list(self.%s)" % (att, att)) exec("while len(%s) < nlines: %s+=[%s[-1]]" % (att, att, att)) if self.linecolors is None: linecolors = vcs.getcolors(list(range(nlines + 1))) if self.markercolors is None: markercolors = vcs.getcolors(list(range(nlines + 1))) # Mark fully missing models scratched = [] for i in range(nlines): if data[:, i].count() > 0: scratched.append(False) else: scratched.append(True) # Now draws the legend t.drawLinesAndMarkersLegend( x, linecolors, linetypes, linewidths, # noqa markercolors, markertypes, markersizes, # noqa [str(v) for v in array.getAxis(-1)], bg=bg, render=False, scratched=scratched) lst = ["max", "min", "mean"] t.blank(lst) t.drawAttributes(x, array, self, bg=bg) t.blank() t.data.priority = 1 for i in range(nlines): if data[:, i].count() > 0: ln_tmp = vcs.create1d() ln_tmp.colormap = self.colormap ln_tmp.linecolor = linecolors[i] ln_tmp.linewidth = linewidths[i] # noqa ln_tmp.linetype = linetypes[i] # noqa ln_tmp.marker = markertypes[i] # noqa ln_tmp.markercolor = markercolors[i] ln_tmp.markersize = markersizes[i] # noqa ln_tmp.datawc_y1 = 0. ln_tmp.datawc_y2 = 1. if i < nlines - 1: x.plot(data[:, i], t, ln_tmp, bg=bg, render=False) else: x.plot(data[:, i], t, ln_tmp, bg=bg, render=render)
def testAxisConvert(self): gm = vcs.create1d() gm.yaxisconvert = "log10" data = MV2.arange(10) data_pow = MV2.power(10, data) data_pow.id = "test" self.x.plot(data_pow, gm, bg=self.bg) self.checkImage("test_vcs_yaxisconvert_log10.png") self.x.clear() gm.flip = True gm.yaxisconvert = "linear" gm.xaxisconvert = "log10" self.x.plot(data_pow, gm, bg=self.bg) self.checkImage("test_vcs_xaxisconvert_log10_flip.png") self.x.clear() gm.flip = False gm.xaxisconvert = "linear" gm.yaxisconvert = "ln" data_exp = MV2.exp(data) data_exp.id = "test" self.x.plot(data_exp, gm, bg=self.bg) self.checkImage("test_vcs_yaxisconvert_ln.png") self.x.clear() gm.flip = False gm.xaxisconvert = "area_wt" gm.yaxisconvert = "linear" data2 = self.clt("clt", time=slice(0, 1), longitude=slice(23, 24), squeeze=1) self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_xaxisconvert_areawt.png") self.x.clear() gm.flip = True gm.yaxisconvert = "area_wt" gm.xaxisconvert = "linear" self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_yaxisconvert_areawt_flip.png") self.x.clear() gm.flip = False gm.xaxisconvert = "log10" gm.yaxisconvert = "ln" self.x.plot(data_pow, data_exp, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_log10_ln.png") self.x.clear() #gm.flip = True data2[:] = MV2.power(10, MV2.arange(1, data2.shape[0] + 1)) data2 = data2[:10] gm.xaxisconvert = "area_wt" gm.yaxisconvert = "log10" self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10.png") self.x.clear() gm.flip = True gm.yaxisconvert = "area_wt" gm.xaxisconvert = "log10" self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10_flip.png") self.x.clear() gm.flip = False gm.xaxisconvert = "area_wt" gm.yaxisconvert = "log10" data_axis = MV2.array(data2.getAxis(0)[:]) data_axis.id = "test" self.x.plot(data_axis, data2, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10_2arrays.png") with self.assertRaises(RuntimeError): self.x.clear() gm.flip = True self.x.plot(data_axis, data2, gm, bg=self.bg) self.x.clear() gm.flip = False gm.xaxisconvert = "area_wt" gm.yaxisconvert = "log10" gm.xticlabels1 = {-90: "90S", -80: "80S", -70: "70S", -60: "60S"} gm.xticlabels2 = {-85: "85S", -75: "75S", -65: "65S", -55: "55S"} mtics = {} def func(x): mtics[x] = "" map(func, range(-90, -40, 10)) gm.xmtics2 = mtics mtics = {} map(func, range(-85, -40, 10)) gm.xmtics1 = mtics gm.yticlabels1 = {100: "hun"} gm.yticlabels2 = {1000: "thou"} gm.ymtics1 = {10: "", 1000: ""} gm.ymtics2 = {10000: "", 1000: ""} gm.list() tmpl = vcs.createtemplate() for num in ["1", "2"]: for loc in ["x", "y"]: for attr in ["mintic", "tic"]: filled_attr = "{}{}{}".format(loc, attr, num) print("PRIO FOR ATT:", filled_attr) obj = getattr(tmpl, filled_attr) obj.priority = 1 obj.list() tmpl.xlabel1.priority = 1 tmpl.xlabel2.priority = 1 tmpl.ylabel1.priority = 1 tmpl.ylabel2.priority = 1 self.x.plot(data_axis, data2, gm, tmpl, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10_user_labels.png")
import filecmp import vcs, numpy, os, sys src = sys.argv[1] if os.path.exists("test_vcs_dump_json.json"): os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createisofill("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createisoline("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createmeshfill("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.create1d("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createfillarea("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createtext("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createline("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createmarker("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createtemplate("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createprojection("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") assert (filecmp.cmp("test_vcs_dump_json.json", src))