def testVCSMeshfillWrap(self): data = numpy.array([1]) lats = numpy.array([0.]) lons = numpy.array([0.]) blats = [-10, -10, 10, 10] blons = [-10, 10, 10, -10] mesh = numpy.zeros((1, 2, 4)) mesh[:, 0] = blats[:] mesh[:, 1] = blons[:] x = vcs.init() gm = vcs.createmeshfill() gm.datawc_x1 = -45 gm.datawc_x2 = 45 gm.datawc_y1 = -45 gm.datawc_y2 = 45 gm.mesh = True for wrap in [[22., 0.], [0., 22.], [22., 22.]]: gm.wrap = wrap self.x.plot(data, mesh, gm) fileName = "test_vcs_meshfill_wrap_{:.0f}_{:.0f}.png".format( wrap[0], wrap[1]) self.checkImage(fileName) self.x.clear()
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.createoneD("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 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.createmeshfill() p = vcs.createprojection() ptype = int('0') p.type = ptype gm.projection = p xtra = {} f = cdms2.open(os.path.join(vcs.prefix, 'sample_data', 'sampleCurveGrid4.nc')) s = f("sample", **xtra) gm.mesh = True s = MV2.masked_less(s, 1150.) x.plot(s, gm, bg=bg) x.png('test_vcs_basic_meshfill_masked_0_proj.png')
def plot(self, data=None, mesh=None, template=None, meshfill=None, x=None, bg=0, multiple=1.1): self.bg = bg # Create the vcs canvas if x is not None: self.x = x # Continents bug # x.setcontinentstype(0) # gets the thing to plot ! if data is None: data = self.get() # Do we use a predefined template ? if template is None: template = self.generateTemplate() else: if isinstance(template, vcs.template.P): tid = template.name elif isinstance(template, str): tid = template else: raise 'Error cannot understand what you mean by template=' + \ str(template) template = vcs.createtemplate(source=tid) # Do we use a predefined meshfill ? if meshfill is None: mtics = {} for i in range(100): mtics[i - .5] = '' meshfill = vcs.createmeshfill() meshfill.xticlabels1 = eval(data.getAxis(1).names) meshfill.yticlabels1 = eval(data.getAxis(0).names) meshfill.datawc_x1 = -.5 meshfill.datawc_x2 = data.shape[1] - .5 meshfill.datawc_y1 = -.5 meshfill.datawc_y2 = data.shape[0] - .5 meshfill.mesh = self.PLOT_SETTINGS.draw_mesh meshfill.missing = self.PLOT_SETTINGS.missing_color meshfill.xticlabels2 = mtics meshfill.yticlabels2 = mtics if self.PLOT_SETTINGS.colormap is None: self.set_colormap() elif self.x.getcolormapname() != self.PLOT_SETTINGS.colormap: self.x.setcolormap(self.PLOT_SETTINGS.colormap) if self.PLOT_SETTINGS.levels is None: min, max = vcs.minmax(data) if max != 0: max = max + .000001 levs = vcs.mkscale(min, max) else: levs = self.PLOT_SETTINGS.levels if len(levs) > 1: meshfill.levels = levs if self.PLOT_SETTINGS.fillareacolors is None: if self.PLOT_SETTINGS.colormap is None: # Default colormap only use range 16->40 cols = vcs.getcolors(levs, list(range(16, 40)), split=1) else: cols = vcs.getcolors(levs, split=1) meshfill.fillareacolors = cols else: meshfill.fillareacolors = self.PLOT_SETTINGS.fillareacolors # Now creates the mesh associated n = int(multiple) ntot = int((multiple - n) * 10 + .1) sh = list(data.shape) sh.append(2) Indx = MV2.indices((sh[0], sh[1])) Y = Indx[0] X = Indx[1] if ntot == 1: sh.append(4) M = MV2.zeros(sh) M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y + .5 M[:, :, 1, 3] = X - .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 4)) elif ntot == 2: sh.append(3) M = MV2.zeros(sh) M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 - (n - 1) M[:, :, 1, 1] = X - 0.5 + (n - 1) M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) elif ntot == 3: design = int((multiple - n) * 100 + .1) if design == 33: sh.append(3) M = MV2.zeros(sh) if n == 1: M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 elif n == 2: M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 elif n == 3: M[:, :, 0, 0] = Y + .5 M[:, :, 1, 0] = X + .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) elif design == 32: sh.append(5) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X d = .5 / MV2.sqrt(3.) if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X - .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X if n == 2: M[:, :, 0, 1] = Y - d M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - .5 M[:, :, 1, 3] = X + .5 M[:, :, 0, 4] = Y - d M[:, :, 1, 4] = X + .5 elif n == 3: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X + .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X M = MV2.reshape(M, (sh[0] * sh[1], 2, 5)) else: sh.append(5) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X d = 1. / 3. if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X - .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X if n == 2: M[:, :, 0, 1] = Y - d M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - .5 M[:, :, 1, 3] = X + .5 M[:, :, 0, 4] = Y - d M[:, :, 1, 4] = X + .5 elif n == 3: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X + .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X M = MV2.reshape(M, (sh[0] * sh[1], 2, 5)) elif ntot == 4: sh.append(3) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 elif n == 2: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 elif n == 3: M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 elif n == 4: M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) else: if isinstance(meshfill, vcs.meshfill.P): tid = mesh.id elif isinstance(meshfill, str): tid = mesh else: raise 'Error cannot understand what you mean by meshfill=' + \ str(meshfill) meshfill = vcs.createmeshfill(source=tid) if mesh is None: mesh = M raveled = MV2.ravel(data) self.x.plot(raveled, mesh, template, meshfill, bg=self.bg) # If required plot values if self.PLOT_SETTINGS.values.show: self.draw_values(raveled, mesh, meshfill, template) # Now prints the rest of the title, etc... # but only if n==1 if n == 1: axes_param = [] for a in data.getAxis(0).id.split('___'): axes_param.append(a) for a in data.getAxis(1).id.split('___'): axes_param.append(a) nparam = 0 for p in self.parameters_list: if p not in self.dummies and \ p not in self.auto_dummies and \ p not in axes_param: nparam += 1 if self.verbose: print('NPARAM:', nparam) if nparam > 0: for i in range(nparam): j = MV2.ceil(float(nparam) / (i + 1.)) if j <= i: break npc = i # number of lines npl = int(j) # number of coulmns if npc * npl < nparam: npl += 1 # computes space between each line dl = (.95 - template.data.y2) / npl dc = .9 / npc npci = 0 # counter for columns npli = 0 # counter for lines for p in self.parameters_list: if p not in self.dummies and \ p not in self.auto_dummies and \ p not in axes_param: txt = self.x.createtext( None, self.PLOT_SETTINGS.parametertable.name, None, self.PLOT_SETTINGS.parameterorientation.name) value = getattr(self, p) if (isinstance(value, (list, tuple)) and len(value) == 1): txt.string = p + ':' + \ str(self.makestring(p, value[0])) display = 1 elif isinstance(value, (str, int, float)): txt.string = p + ':' + \ str(self.makestring(p, value)) display = 1 else: display = 0 if display: # Now figures out where to put these... txt.x = [(npci) * dc + dc / 2. + .05] txt.y = [1. - (npli) * dl - dl / 2.] npci += 1 if npci >= npc: npci = 0 npli += 1 if p in list(self.altered.keys()): dic = self.altered[p] if dic['size'] is not None: txt.size = dic['size'] if dic['color'] is not None: txt.color = dic['color'] if dic['x'] is not None: txt.x = dic['x'] if dic['y'] is not None: txt.y = dic['y'] self.x.plot(txt, bg=self.bg, continents=0) if self.PLOT_SETTINGS.time_stamp is not None: sp = time.ctime().split() sp = sp[:3] + [sp[-1]] self.PLOT_SETTINGS.time_stamp.string = ''.join(sp) self.x.plot( self.PLOT_SETTINGS.time_stamp, bg=self.bg, continents=0) if self.PLOT_SETTINGS.logo is not None: self.PLOT_SETTINGS.logo.plot(self.x, bg=self.bg) return mesh, template, meshfill
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.createmeshfill() p = vcs.createprojection() ptype = int('-3') p.type = ptype gm.projection = p xtra = {} xtra["latitude"] = (-90.0,0.0) xtra["longitude"] = (-180.0,180.0) f=cdms2.open(os.path.join(vcs.prefix,'sample_data','sampleCurveGrid4.nc')) s=f("sample",**xtra) gm.mesh=True x.plot(s,gm,bg=bg)
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.createoneD("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")