def check_image(self, compare_against): """ Checks the current render window's output against the image specified in the argument, returns the result of regression.check_result_image """ generate_png(self.win, self.test_file) pth = os.path.join(os.path.dirname(__file__), "../..") sys.path.append(pth) import vcs.testing.regression as regression return regression.check_result_image(self.test_file, compare_against)
def test( self, interactive=False ): self.build() # test_image = os.path.join( self.test_dir, 'images', '.'.join( [ self.name, 'png' ] ) ) test_image = '.'.join( [ self.name, 'test', 'png' ] ) self.canvas.png( test_image, width = 900, height = 600 ) ret = regression.check_result_image( test_image, self.image_name,\ regression.defaultThreshold+3. ) if interactive: print "Type <Enter> to continue and update ref image ( type 'n' to skip update )." sys.stdout.flush() line = sys.stdin.readline() if line[0] <> 'n': self.update_image() sys.exit(ret)
def plot_a_ratio(s,gm,ratio): ret = 0 x = regression.init() x.drawlogooff() x.open() x.geometry(400,800) y = regression.init() y.open() y.geometry(800,400) for X in [x,y]: X.plot(s,gm,ratio=ratio) if X.islandscape(): orient = "ldscp" else: orient = "port" fnm = "aspect_ratio_%s_%s.png" % (orient,ratio) X.png(fnm) src = os.path.join(pth0,fnm) ret += regression.check_result_image(fnm, src) return ret
def plot_a_ratio(s, gm, ratio): ret = 0 x = regression.init() x.drawlogooff() x.open() x.geometry(400, 800) y = regression.init() y.open() y.geometry(800, 400) for X in [x, y]: X.plot(s, gm, ratio=ratio) if X.islandscape(): orient = "ldscp" else: orient = "port" fnm = "aspect_ratio_%s_%s.png" % (orient, ratio) X.png(fnm) src = os.path.join(pth0, fnm) ret += regression.check_result_image(fnm, src) return ret
import os, sys, cdms2, vcs, vcs.testing.regression as regression src1 = sys.argv[1] src2 = sys.argv[2] x = regression.init() f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc")) s=f("clt",time=slice(0,1),latitude=(-7,5),squeeze=1) x.plot(s,bg=1) fnm = "test_vcs_issue_960_labels_1.png" x.png(fnm) ret = regression.check_result_image(fnm, src1) b=x.createboxfill() b.datawc_y1=-7 b.datawc_y2=5 x.plot(s,b,bg=1) fnm = "test_vcs_issue_960_labels_2.png" x.png(fnm) ret += regression.check_result_image(fnm, src2) sys.exit(ret)
import vcs, numpy, cdms2, MV2, os, sys, vcs.testing.regression as regression x = vcs.init() a=numpy.arange(100) a.shape=(10,10) x.plot(a,bg=1) fnm = "test_vcs_draw_logo_on.png" x.png(fnm) regression.check_result_image(fnm, sys.argv[1])
import vcs import sys import argparse import vcs.testing.regression as regression import os p =argparse.ArgumentParser() p.add_argument("-H","--fitToHeight",default=True,action="store_false") p.add_argument("-u","--units",default="percent") p.add_argument("-x","--xoffset",default=0,type=float) p.add_argument("-y","--yoffset",default=0,type=float) p.add_argument("-z","--zoom",default=1.,type=float) p.add_argument("-s","--source",default="./somefile.png") args = p.parse_args(sys.argv[1:]) print args bg=True x=vcs.init(bg=bg,geometry=(1200,800)) x.open() png = os.path.join(sys.prefix,"share","uvcdat","sample_data","BlueMarble.ppm") x.put_png_on_canvas(png,args.zoom,args.xoffset,args.yoffset,args.units,args.fitToHeight) fnm = "test_vcs_put_png_on_canvas_%s_%s_%s_%s_%s" % (args.zoom,args.xoffset,args.yoffset,args.units,args.fitToHeight) x.png(fnm) ret = regression.check_result_image(fnm+'.png',args.source,20.)
gm.scale = 4. x.plot(u, v, gm, bg=bg) elif gm_type in ["scatter", "xvsy"]: x.plot(s, s2, gm, bg=bg) else: x.plot(s, gm, bg=bg) fnm = "test_vcs_basic_%s" % gm_type.lower() if args.mask: fnm += "_masked" elif args.bigvalues: fnm += "_bigvalues" if args.projtype != "default": fnm += "_%s_proj" % args.projtype if args.zero: fnm += "_zero" if args.transparent: fnm += "_transparent" fnm += nm_xtra x.png(fnm) print "fnm:", fnm print "src:", src if args.show: raw_input("Press Enter") ret = regression.check_result_image(fnm + '.png', src, 20., cleanup=not args.keep) if args.show: raw_input("Press Enter") sys.exit(ret)
assert histo2.fillareastyles == histo.fillareastyles assert histo2.fillareacolors == histo.fillareacolors assert histo2.fillareaindices == histo.fillareaindices print "Inherited all values." histo2.levels = [10, 20, 10, 100, 110, 50, 20] histo3 = vcsaddons.createhistogram(source=histo2.name, x=x) print "Checking name-based inheritance" assert histo3.bins == histo2.bins assert histo3.line == histo2.line assert histo3.linewidth == histo2.linewidth assert histo3.linecolors == histo2.linecolors assert histo3.fillareastyles == histo2.fillareastyles assert histo3.fillareacolors == histo2.fillareacolors assert histo3.fillareaindices == histo2.fillareaindices print "Inherited all values." histo3.datawc_y1 = -1 histo3.datawc_y2 = 200000 histo3.datawc_x1 = 0 histo3.datawc_x2 = 100 histo3.bins = None histo3.plot(clt, template="default", bg=True) fnm = "test_vcs_addons_histogram_inherit.png" x.png(fnm) ret = regression.check_result_image(fnm, src) sys.exit(ret)
import os, sys, vcs.testing.regression as regression import vcs from vcsaddons import EzTemplate import cdms2, vcs, sys ## 12 plots 1 legend per row on the right ## Initialize VCS x = vcs.init() x.drawlogooff() bg = True M = EzTemplate.Multi(rows=4, columns=3) M.legend.direction = 'vertical' for i in range(12): t = M.get(legend='local') if i % 3 != 2: t.legend.priority = 0 # Turn off legend fnm = "test_12_plot_one_leg_per_row_right.png" M.preview(fnm, bg=bg) ret = regression.check_result_image(fnm, sys.argv[1]) if not bg: raw_input("Press Enter") sys.exit(ret)
#Now plots the amplitude underneath the data b = x.createboxfill() b.xticlabels1 = vcs.elements["list"]["Lon30"] b.yticlabels1 = vcs.elements["list"]["Lat20"] x.plot(A, b, bg=bg) u.setAxis(0, lats) u.setAxis(1, lons) v.setAxis(0, lats) v.setAxis(1, lons) x.plot(u, v, gm, bg=bg) ret = 0 if args.show: x.interact() else: fnm = "test_vcs_basic_vectors_%i" % args.angle if args.mask: fnm += "_masked" if args.scale != 1.: fnm += "_%.1g" % args.scale fnm += nm_xtra x.png(fnm) print "fnm:", fnm print "src:", src ret = regression.check_result_image(fnm + '.png', src, regression.defaultThreshold, cleanup=not args.keep) if args.show: raw_input("Press Enter") sys.exit(ret)
s = f("clt", slice(0, 12)) # read only 12 times steps to speed up things gm = vcs.creategraphicsmethod(gm_type, "default") if args.projtype != "default": p = vcs.createprojection() try: ptype = int(args.projtype) except: ptype = args.projtype p.type = ptype gm.projection = p x.plot(s, gm, bg=1) x.animate.create() prefix = "test_vcs_animate_%s_%s" % (gm_type.lower(), args.projtype.lower()) x.animate.save("%s.mp4" % prefix) pngs = x.animate.close(preserve_pngs=True) # so we can look at them again ret = 0 pdir = os.path.split(pngs[0])[0] p = pdir + os.sep + "anim_0.png" ret = regression.check_result_image(p, args.src, args.threshold) if ret == 0 and not args.keep: for f in pngs: if os.path.isfile(f): os.remove(f) os.removedirs(pdir) os.remove("%s.mp4" % prefix) sys.exit(ret)
gm.markercolor = [100, 0, 0, 50.] if gm_type=="vector": gm.scale = 4. x.plot(u,v,gm,bg=bg) elif gm_type in ["scatter","xvsy"]: x.plot(s,s2,gm,bg=bg) else: x.plot(s,gm,bg=bg) fnm = "test_vcs_basic_%s" % gm_type.lower() if args.mask: fnm+="_masked" elif args.bigvalues: fnm+="_bigvalues" if args.projtype!="default": fnm+="_%s_proj" % args.projtype if args.zero: fnm+="_zero" if args.transparent: fnm+="_transparent" fnm+=nm_xtra x.png(fnm) print "fnm:",fnm print "src:",src if args.show: raw_input("Press Enter") ret = regression.check_result_image(fnm+'.png',src,20., cleanup=not args.keep) if args.show: raw_input("Press Enter") sys.exit(ret)
import sys, cdms2, vcs, vcs.testing.regression as regression data = cdms2.open(vcs.sample_data+"/clt.nc") v = data['v'][...,::10,::10] u = data['u'][...,::10,::10] canvas = regression.init() gv = vcs.createvector() gv.scaletype = 'off' canvas.plot(u, v, gv) outFilename = 'test_vcs_vectors_scale_options_off.png' canvas.png(outFilename) ret = regression.check_result_image(outFilename, sys.argv[1]) canvas.clear() v = data['v'][...,::4,::4] u = data['u'][...,::4,::4] gv.scaletype = 'constant' gv.scale = 0.1 canvas.plot(u, v, gv) outFilename = 'test_vcs_vectors_scale_options_constant.png' canvas.png(outFilename) ret += regression.check_result_image(outFilename, sys.argv[2]) canvas.clear() v = data['v'] u = data['u'] gv.scale = 1.0 gv.scaletype = 'linear'
import os, sys, cdms2, vcs, vcs.testing.regression as regression x = regression.init() x.backgroundcolor = (255, 255, 255) x.open() x.backgroundcolor = (255, 255, 0) x.update() regression.check_result_image(x, "test_backgroundcolor_yellow.png")
# Initialize the canvas canvas = regression.init() # Plot the dataset canvas.plot(clt, bg=bg) # Mask values masked = cdms2.MV2.masked_greater(clt, 50.) gm = vcs.creategraphicsmethod(gm_type, "default") # Set the missing color and opacity gm.missing = [50., 50., 50., 50.] # Plot the masked values canvas.plot(masked, gm, bg=bg) # Write to png file fnm = "test_vcs_missing_opacity_%s" % args.gm.lower() canvas.png(fnm) # Test the output ret = regression.check_result_image(fnm + '.png', args.src, args.threshold, cleanup=not args.keep) if args.show: raw_input("Press Enter") sys.exit(ret)
nm_xtra += "_SH" else: nm_xtra += "_NH" if args.lon1 != args.lon2: xtra["longitude"] = (args.lon1, args.lon2) nm_xtra += "_%i_%i" % (args.lon1, args.lon2) if not args.contig: nm_xtra += "_non-contig" xtra["time"] = slice(0, 1) xtra["squeeze"] = 1 f = cdms2.open(os.path.join(vcs.sample_data, 'tas_ccsr-95a_1979.01-1979.12.nc')) s = f("tas", **xtra) f.close() x.plot(s, gm, bg=bg) fnm = "test_vcs_%s_%s" % (args.gm.lower(), args.fill_style.lower()) if args.projtype != "default": fnm += "_%s_proj" % args.projtype fnm += nm_xtra x.png(fnm) print "fnm:", fnm print "src:", src ret = regression.check_result_image(fnm + '.png', src, args.threshold, cleanup=not args.keep) if args.show: raw_input("Press Enter") sys.exit(ret)
x.setantialiasing(0) x.drawlogooff() x.setbgoutputdimensions(1200,1091,units="pixels") iso=x.createisoline() iso.label='y' levs = range(0,101,10) iso.level=levs # add dummy values to levs to get the correct number of cols cols=vcs.getcolors(levs+[56,]) print levs print cols iso.textcolors = cols iso.linecolors = cols x.plot(s,iso,bg=1) x.animate.create() print "Saving now" prefix= os.path.split(__file__)[1][:-3] x.animate.save("%s.mp4"%prefix) pngs = x.animate.close(preserve_pngs = True) # so we can look at them again src_pth = sys.argv[1] pth = os.path.join(src_pth,prefix) ret = 0 for p in pngs: print "Checking:",p ret += regression.check_result_image(p,os.path.join(pth,os.path.split(p)[1])) if ret == 0: os.removedirs(os.path.split(p)[0]) os.remove("%s.mp4" % prefix) sys.exit(ret)
import vcs, numpy, cdms2, MV2, os, sys, time, vcs.testing.regression as regression pth = os.path.join(os.path.dirname(__file__),"..") sys.path.append(pth) f = cdms2.open(os.path.join(vcs.sample_data,"clt.nc")) s = f("clt",slice(0,12)) # read only 12 times steps to speed up things x = regression.init() gm=x.createisofill() x.plot(s,gm,bg=1) x.animate.create() print "Saving now" prefix= os.path.split(__file__)[1][:-3] x.animate.save("%s.mp4"%prefix) pngs = x.animate.close(preserve_pngs = True) # so we can look at them again src_pth = sys.argv[1] pth = os.path.join(src_pth,prefix) ret = 0 for p in pngs: ret += regression.check_result_image(p,os.path.join(pth,os.path.split(p)[1]), regression.defaultThreshold) if ret == 0: os.removedirs(os.path.split(p)[0]) os.remove("%s.mp4" % prefix) sys.exit(ret)
x.setcolormap("rainbow") gm = vcs.createvector() gm.scale = args.scale nm_xtra = "" xtra = {} import cdms2 import os f = cdms2.open(os.path.join(vcs.sample_data, "clt.nc")) u = f("u") v = f("v") u = MV2.masked_greater(u, 35.0)[..., ::2, ::2] v = MV2.masked_greater(v, 888.0)[..., ::2, ::2] print u.max(), v.max(), u.min(), v.min() # x.plot(U) x.plot(u, v, gm, bg=bg) ret = 0 if args.show: pass # x.interact() else: fnm = "test_vcs_vectors_missing" if args.scale != 5.0: fnm += "_%.1g" % args.scale fnm += nm_xtra x.png(fnm) ret = regression.check_result_image(fnm + ".png", src, regression.defaultThreshold, cleanup=not args.keep) if args.show: raw_input("Press Enter") sys.exit(ret)
import sys, cdms2, vcs, vcs.testing.regression as regression data = cdms2.open(vcs.sample_data + "/clt.nc") v = data['v'][..., ::10, ::10] u = data['u'][..., ::10, ::10] canvas = regression.init() gv = vcs.createvector() gv.scaletype = 'off' canvas.plot(u, v, gv) outFilename = 'test_vcs_vectors_scale_options_off.png' canvas.png(outFilename) ret = regression.check_result_image(outFilename, sys.argv[1]) canvas.clear() v = data['v'][..., ::4, ::4] u = data['u'][..., ::4, ::4] gv.scaletype = 'constant' gv.scale = 0.1 canvas.plot(u, v, gv) outFilename = 'test_vcs_vectors_scale_options_constant.png' canvas.png(outFilename) ret += regression.check_result_image(outFilename, sys.argv[2]) canvas.clear() v = data['v'] u = data['u'] gv.scale = 1.0 gv.scaletype = 'linear'
x = regression.init() polar = vcsaddons.getpolar("annual_cycle") polar.markers = ["dot"] polar.markersizes = [3] polar.magnitude_tick_angle = numpy.pi / 8 import cdms2, cdutil f = cdms2.open(os.path.join(vcs.sample_data, "clt.nc")) clt = f("clt") cdutil.setAxisTimeBoundsMonthly(clt.getTime()) averaged_time = cdutil.averager(clt, axis="t") averaged_time = averaged_time.reshape( (1, averaged_time.shape[0], averaged_time.shape[1])) averaged_time_for_departures = numpy.repeat(averaged_time, len(clt), axis=0) clt_departures = clt - averaged_time_for_departures clt_departures.setAxisList(clt.getAxisList()) avg_departures = cdutil.averager(clt_departures, axis="xy") theta = range(1, len(clt) + 1) magnitude = avg_departures polar.plot(magnitude, theta, bg=True, x=x) fnm = "test_vcs_addons_polar_annual.png" x.png(fnm) ret = regression.check_result_image(fnm, src) sys.exit(ret)
import os, sys, cdms2, vcs, vcs.testing.regression as regression src1 = sys.argv[1] src2 = sys.argv[2] x = regression.init() f = cdms2.open(os.path.join(vcs.sample_data, "clt.nc")) s = f("clt", time=slice(0, 1), latitude=(-7, 5), squeeze=1) x.plot(s, bg=1) fnm = "test_vcs_issue_960_labels_1.png" x.png(fnm) ret = regression.check_result_image(fnm, src1) b = x.createboxfill() b.datawc_y1 = -7 b.datawc_y2 = 5 x.plot(s, b, bg=1) fnm = "test_vcs_issue_960_labels_2.png" x.png(fnm) ret += regression.check_result_image(fnm, src2) sys.exit(ret)