Example #1
0
 def execute(self, test_str, imagefilename, imagethreshold, ncfiles, rtol, atol):
     print test_str
     if imagethreshold is None:  # user didn't specify a value
  	    imagethreshold = checkimage.defaultThreshold
     # Silence annoying messages about how to set the NetCDF file type.  Anything will do.
     cdms2.setNetcdfShuffleFlag(0)
     cdms2.setNetcdfDeflateFlag(0)
     cdms2.setNetcdfDeflateLevelFlag(0)
     
     # nonstandard, suitable for testing:
     proc = subprocess.Popen([self.diagstr], shell=True)
     proc_status = proc.wait()
     if proc_status!=0: 
         proc = subprocess.Popen([self.diagstr], shell=True)
         proc_status = proc.wait()
         if proc_status!=0: 
             raise DiagError("diags run failed")
 
     if self.keep:
         print "save ", imagefilename, ncfiles.keys()
         print "output directory is = ", self.outpath
     else:    
         # Test of graphics (png) file match:
         # This just looks at combined plot, aka summary plot, which is a compound of three plots.
         
         imagefname = os.path.join( self.outpath, imagefilename )
         imagebaselinefname = os.path.join( self.baselinepath, imagefilename )
         #pdb.set_trace()
         print "OK THRESHOLD IS:",imagethreshold
         graphics_result = checkimage.check_result_image( imagefname, imagebaselinefname, imagethreshold )
         print "Graphics file", imagefname, "match difference:", graphics_result
         
         #initialize to successful graphics check
         GR_CLOSE = (graphics_result == 0)
         assert(GR_CLOSE), 'graphic images are not close'
         
         # Test of NetCDF data (nc) file match:
         NC_CLOSE = True
         for ncfilename, ncvars in ncfiles.items():
             for var in ncvars:
                 #print ncfilename, var
                 try:
                     #print ">>>>>>>>>>>>>", var, ncfilename
                     close = self.closeness( var, ncfilename, rtol, atol )
                     if not close:
                       print var, ' in ', os.path.join(self.outpath,ncfilename), ' is not close from the one in:',os.path.join(self.baselinepath,ncfilename)
                 except:
                     print 'NetCDF comparison failed for ', var, ' in file: ', os.path.join(self.outpath,ncfilename),"vs",os.path.join(self.baselinepath,ncfilename)
                     close = False
                 NC_CLOSE = NC_CLOSE and close
         assert(NC_CLOSE), 'NetCDF files are not close'
         
         #cleanup the temp files
         if GR_CLOSE and NC_CLOSE:
             shutil.rmtree(self.outpath)
Example #2
0
 def checkImage(self,fnm,src=None,threshold=checkimage.defaultThreshold,pngReady=False,pngPathSet=False):
     if src is None:
         src = os.path.join(self.basedir,os.path.basename(fnm))
     if not pngPathSet:
         fnm = os.path.join(self.pngsdir,fnm)
     print("Test file  :",fnm)
     print("Source file:",src)
     if not pngReady:
         self.x.png(fnm,width=self.x.width, height=self.x.height, units="pixels")
     ret = checkimage.check_result_image(fnm,src,threshold, update_baseline=self.update)
     self.assertEqual(ret,0)
     return ret
Example #3
0
 def check_image(self, compare_against):
     """
     Checks the current render window's output against the image specified in the argument,
     returns the result of checkimage.check_result_image
     """
     generate_png(self.win, self.test_file)
     pth = os.path.join(os.path.dirname(__file__), "../..")
     sys.path.append(pth)
     import checkimage
     print "fnm:", self.test_file
     print "src:", compare_against
     return checkimage.check_result_image(self.test_file, compare_against, checkimage.defaultThreshold)
Example #4
0
 def check_image(self, compare_against):
     """
     Checks the current render window's output against the image specified in the argument,
     returns the result of checkimage.check_result_image
     """
     generate_png(self.win, self.test_file)
     pth = os.path.join(os.path.dirname(__file__), "../..")
     sys.path.append(pth)
     import checkimage
     print "fnm:", self.test_file
     print "src:", compare_against
     return checkimage.check_result_image(self.test_file, compare_against,
                                          checkimage.defaultThreshold)
Example #5
0
 def checkImage(self,fnm,src=None,threshold=checkimage.defaultThreshold,pngReady=False,pngPathSet=False):
     if src is None:
         src = os.path.join(self.basedir,os.path.basename(fnm))
     if not pngPathSet:
         fnm = os.path.join(self.pngsdir,fnm)
     print("Test file  :",fnm)
     print("Source file:",src)
     if not pngReady:
         self.x.png(fnm,
                    width=self.x.width,
                    height=self.x.height,
                    units="pixels")
     ret = checkimage.check_result_image(fnm,src,threshold)
     self.assertEqual(ret,0)
     return ret
Example #6
0
    def test(self):
        self.do_test()

        if self.test_file is not None:
            generate_png(self.win, self.test_file)
            if len(sys.argv) >= 2:
                src=sys.argv[1]
                pth = os.path.join(os.path.dirname(__file__),"../..")
                sys.path.append(pth)
                import checkimage
                print "fnm:", self.test_file
                print "src:", src
                self.passed = checkimage.check_result_image(self.test_file, src, checkimage.defaultThreshold)

        print sys.argv[0], "passed" if self.passed == 0 else "failed"
        sys.exit(self.passed)
Example #7
0
    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 )

        ret = checkimage.check_result_image( test_image, self.image_name,\
                checkimage.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)
Example #8
0
    def test( self, interactive=False ):      
        import checkimage
        self.build()
#        test_image = os.path.join( self.test_dir, 'images', '.'.join( [ self.name, 'png' ] ) )
        test_image = '.'.join( [ self.name, 'test', 'png' ] )
        ref_image  = '.'.join( [ self.name, 'png' ] )
        self.canvas.png( test_image )
        print "Copying ref image %s to %s in %s " % ( self.image_name, ref_image, os.path.abspath('.') )
        shutil.copy( self.image_name, ref_image )
        ret = checkimage.check_result_image( ref_image, test_image, checkimage.defaultThreshold )
        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)
Example #9
0
    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)

        ret = checkimage.check_result_image( test_image, self.image_name,\
                checkimage.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)
Example #10
0
    def test(self):
        self.do_test()

        if self.test_file is not None:
            generate_png(self.win, self.test_file)
            if len(sys.argv) >= 2:
                src = sys.argv[1]
                pth = os.path.join(os.path.dirname(__file__), "../..")
                sys.path.append(pth)
                import checkimage
                print "fnm:", self.test_file
                print "src:", src
                self.passed = checkimage.check_result_image(
                    self.test_file, src, checkimage.defaultThreshold)

        print sys.argv[0], "passed" if self.passed == 0 else "failed"
        sys.exit(self.passed)
Example #11
0
 def test(self, interactive=False):
     import checkimage
     self.build()
     #        test_image = os.path.join( self.test_dir, 'images', '.'.join( [ self.name, 'png' ] ) )
     test_image = '.'.join([self.name, 'test', 'png'])
     ref_image = '.'.join([self.name, 'png'])
     self.canvas.png(test_image)
     print "Copying ref image %s to %s in %s " % (
         self.image_name, ref_image, os.path.abspath('.'))
     shutil.copy(self.image_name, ref_image)
     ret = checkimage.check_result_image(ref_image, test_image,
                                         checkimage.defaultThreshold)
     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)
Example #12
0
    def execute(self, test_str, imagefilename, imagethreshold, ncfiles, rtol,
                atol):
        print test_str
        # Silence annoying messages about how to set the NetCDF file type.  Anything will do.
        cdms2.setNetcdfShuffleFlag(0)
        cdms2.setNetcdfDeflateFlag(0)
        cdms2.setNetcdfDeflateLevelFlag(0)

        # nonstandard, suitable for testing:
        proc = subprocess.Popen([self.diagstr], shell=True)
        proc_status = proc.wait()
        if proc_status != 0:
            raise DiagError("diags run failed")

        if self.keep:
            print "save ", imagefilename, ncfiles.keys()
            print "output directory is = ", self.outpath
        else:
            # Test of graphics (png) file match:
            # This just looks at combined plot, aka summary plot, which is a compound of three plots.

            imagefname = os.path.join(self.outpath, imagefilename)
            imagebaselinefname = os.path.join(self.baselinepath, imagefilename)
            graphics_result = checkimage.check_result_image(
                imagefname, imagebaselinefname, imagethreshold)
            print "Graphics file", imagefname, "match difference:", graphics_result

            # Test of NetCDF data (nc) file match:
            CLOSE = True
            for ncfilename, ncvars in ncfiles.items():
                for var in ncvars:
                    #print ncfilename, var
                    try:
                        close = self.closeness(var, ncfilename, rtol, atol)
                        if not close:
                            print var, ' in ', ncfilename, ' is not close.'
                    except:
                        print 'comparison failed for ', var, ' in file: ', ncfilename
                        close = False
                    CLOSE = CLOSE and close

            #cleanup the temp files
            shutil.rmtree(self.outpath)
            assert (CLOSE), 'data are not close'
Example #13
0
 def execute(self, test_str, imagefilename, imagethreshold, ncfiles, rtol, atol):
     print test_str
     # Silence annoying messages about how to set the NetCDF file type.  Anything will do.
     cdms2.setNetcdfShuffleFlag(0)
     cdms2.setNetcdfDeflateFlag(0)
     cdms2.setNetcdfDeflateLevelFlag(0)
     
     # nonstandard, suitable for testing:
     proc = subprocess.Popen([self.diagstr], shell=True)
     proc_status = proc.wait()
     if proc_status!=0: 
         raise DiagError("diags run failed")
 
     if self.keep:
         print "save ", imagefilename, ncfiles.keys()
         print "output directory is = ", self.outpath
     else:    
         # Test of graphics (png) file match:
         # This just looks at combined plot, aka summary plot, which is a compound of three plots.
         
         imagefname = os.path.join( self.outpath, imagefilename )
         imagebaselinefname = os.path.join( self.baselinepath, imagefilename )
         graphics_result = checkimage.check_result_image( imagefname, imagebaselinefname, imagethreshold )
         print "Graphics file", imagefname, "match difference:", graphics_result
         
         # Test of NetCDF data (nc) file match:
         CLOSE = True
         for ncfilename, ncvars in ncfiles.items():
             for var in ncvars:
                 #print ncfilename, var
                 try:
                     close = self.closeness( var, ncfilename, rtol, atol )
                     if not close:
                         print var, ' in ', ncfilename, ' is not close.'
                 except:
                     print 'comparison failed for ', var, ' in file: ', ncfilename
                     close = False
                 CLOSE = CLOSE and close
                 
         #cleanup the temp files
         shutil.rmtree(self.outpath)
         assert(CLOSE), 'data are not close'
Example #14
0
def plot_a_ratio(s,gm,ratio):
    ret = 0
    x=vcs.init()
    x.open()
    x.geometry(400,800)
    y=vcs.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)
        print "fnm:",fnm
        src = os.path.join(pth0,fnm)
        print "src:",src
        ret += checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
    return ret
Example #15
0
def plot_a_ratio(s, gm, ratio):
    ret = 0
    x = vcs.init()
    x.open()
    x.geometry(400, 800)
    y = vcs.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)
        print "fnm:", fnm
        src = os.path.join(pth0, fnm)
        print "src:", src
        ret += checkimage.check_result_image(fnm, src,
                                             checkimage.defaultThreshold)
    return ret
Example #16
0
    #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 = checkimage.check_result_image(fnm + '.png',
                                        src,
                                        checkimage.defaultThreshold,
                                        cleanup=not args.keep)
if args.show:
    raw_input("Press Enter")
sys.exit(ret)
Example #17
0
import sys,os,cdms2,vcs
import vcs
src1=sys.argv[1]
src2=sys.argv[2]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
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)
print "fnm:",fnm
print "src:",src1
ret = checkimage.check_result_image(fnm,src1,checkimage.defaultThreshold)
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)
print "fnm:",fnm
print "src:",src2
ret += checkimage.check_result_image(fnm,src2,checkimage.defaultThreshold)
sys.exit(ret)
Example #18
0
def execute(test_str, plotset, obstype, varid, season, imagefilename,
            imagethreshold, ncfiles, rtol, atol):
    print test_str
    # Silence annoying messages about how to set the NetCDF file type.  Anything will do.
    cdms2.setNetcdfShuffleFlag(0)
    cdms2.setNetcdfDeflateFlag(0)
    cdms2.setNetcdfDeflateLevelFlag(0)

    #get commmand line args
    p = argparse.ArgumentParser(description="Basic gm testing code for vcs")
    p.add_argument("--datadir",
                   dest="datadir",
                   help="root directory for model and obs data")
    p.add_argument("--baseline",
                   dest="baseline",
                   help="directory with baseline files for comparing results")
    p.add_argument("--keep",
                   dest="keep",
                   help="Iff True, will keep computed png and nc files")
    args = p.parse_args(sys.argv[1:])
    datadir = args.datadir
    baselinepath = args.baseline
    keep = args.keep

    #setup paths to data
    modelpath = os.path.join(datadir, 'cam_output')
    obspath = os.path.join(datadir, 'obs_atmos')
    outpath = tempfile.mkdtemp() + "/"
    print "outpath=", outpath

    #setup string to be executed and run script
    #diagstr = "diags --outputdir '%s' --model path=%s,climos=no --obs path=%s,filter=\"f_contains('NCEP')\",climos=yes --package AMWG --set 3 --var T --seasons JJA" % (outpath, modelpath, obspath)
    diagstr_parts = [
        " --outputdir %s " % (outpath),
        " --model path=%s,climos=no " % (modelpath),
        " --obs path=%s,filter=\"f_contains('%s')\",climos=yes " %
        (obspath, obstype), " --package AMWG ",
        " --set %s " % (str(plotset)),
        " --var %s" % (varid),
        " --seasons %s" % (season)
    ]
    diagstr = "diags "
    for part in diagstr_parts:
        diagstr += part
    print 'executing '
    print diagstr

    # nonstandard, suitable for testing:
    proc = subprocess.Popen([diagstr], shell=True)
    proc_status = proc.wait()
    if proc_status != 0:
        raise DiagError("diags run failed")

    if keep:
        print "save ", imagefilename, ncfiles.keys()
        print "output directory is = ", outpath
    else:
        # Test of graphics (png) file match:
        # This just looks at combined plot, aka summary plot, which is a compound of three plots.

        imagefname = os.path.join(outpath, imagefilename)
        imagebaselinefname = os.path.join(baselinepath, imagefilename)
        graphics_result = checkimage.check_result_image(
            imagefname, imagebaselinefname, imagethreshold)
        print "Graphics file", imagefname, "match difference:", graphics_result

        # Test of NetCDF data (nc) file match:
        CLOSE = True
        for ncfilename, ncvars in ncfiles.items():
            for var in ncvars:
                #print ncfilename, var
                print baselinepath
                try:
                    close = closeness(var, ncfilename, outpath, baselinepath,
                                      rtol, atol)
                    if not close:
                        print var, ' in ', ncfilename, ' is not close.'
                except:
                    print 'comparison failed ', ncfilename, var
                    close = False
                CLOSE = CLOSE and close

        #cleanup the temp files
        shutil.rmtree(outpath)
        assert (CLOSE)  #, 'data are not close'
s_esmf_lin.id = "ESMF Linear"
s_esmf_con = s.regrid(grid_dest,regridTool="esmf",regridMethod="conservative")
s_esmf_lin.id = "ESMF Conservative"

x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

t=x.createtemplate()
t.blank()
t.data.priority=1
t.legend.priority=1
t.dataname.priority=1
t.dataname.y=t.dataname.y*.95
M=EzTemplate.Multi(template=t,x=x,rows=2,columns=2)
gm=x.createboxfill()
levels= vcs.mkscale(*vcs.minmax(s))
cols = vcs.getcolors(levels)
gm.boxfill_type = "custom"
gm.fillareacolors = cols
gm.levels = levels
x.plot(s,M.get(),gm,bg=1)
x.plot(s_regrid2,M.get(),gm,bg=1)
x.plot(s_esmf_lin,M.get(),gm,bg=1)
x.plot(s_esmf_con,M.get(),gm,bg=1)
x.png("esmf_issue_1125")

ret = checkimage.check_result_image("esmf_issue_1125.png",png,checkimage.defaultThreshold)
sys.exit(ret)
Example #20
0
    def test_portrait(self):
        try:
            import vcs
        except:
            raise RuntimeError(
                "Sorry your python is not build with VCS support cannot geenrate portrait plots")

        import json
        # CDAT MODULES
        import pcmdi_metrics
        import pcmdi_metrics.graphics.portraits
        import MV2
        import numpy
        from genutil import statistics
        import os
        import sys
        import glob

        # CREATES VCS OBJECT AS A PORTAIT PLOT AND LOADS PLOT SETTINGS FOR
        # EXAMPLE
        x = vcs.init()
        x.portrait()
        # Turn off antialiasing for test suite
        x.setantialiasing(0)

        # PARAMETERS STUFF
        P = pcmdi_metrics.graphics.portraits.Portrait()

        # Turn off verbosity
        P.verbose = False

        P.PLOT_SETTINGS.levels = [-1.e20, -.5, -.4, -.3, -.2, -.1,
                                  0., .1, .2, .3, .4, .5, 1.e20]

        P.PLOT_SETTINGS.x1 = .1
        P.PLOT_SETTINGS.x2 = .85
        P.PLOT_SETTINGS.y1 = .12
        P.PLOT_SETTINGS.y2 = .95

        P.PLOT_SETTINGS.xtic2y1 = P.PLOT_SETTINGS.y1
        P.PLOT_SETTINGS.xtic2y2 = P.PLOT_SETTINGS.y2
        P.PLOT_SETTINGS.ytic2x1 = P.PLOT_SETTINGS.x1
        P.PLOT_SETTINGS.ytic2x2 = P.PLOT_SETTINGS.x2

        # P.PLOT_SETTINGS.missing_color = 3
        # P.PLOT_SETTINGS.logo = None
        P.PLOT_SETTINGS.time_stamp = None
        P.PLOT_SETTINGS.draw_mesh = 'n'
        # P.PLOT_SETTINGS.tictable.font = 3

        x.scriptrun(
            os.path.join(
                pcmdi_metrics.__path__[0],
                "..",
                "..",
                "..",
                "..",
                "share",
                "graphics",
                'vcs',
                'portraits.scr'))
        P.PLOT_SETTINGS.colormap = 'bl_rd_12'
        # cols=vcs.getcolors(P.PLOT_SETTINGS.levels,range(16,40),split=1)
        cols = vcs.getcolors(P.PLOT_SETTINGS.levels, range(144, 156), split=1)
        P.PLOT_SETTINGS.fillareacolors = cols

        P.PLOT_SETTINGS.parametertable.expansion = 100

        # LIST OF VARIABLES TO BE USED IN PORTRAIT PLOT
        vars = [
            'pr',
            'rsut',
            'rsutcs',
            'rlutcs',
            'tas',
            'tos',
            'sos',
            'zos',
            'ua-850',
            'ua-200',
            'zg-500']
        vars = []

        # LOAD METRICS DICTIONARIES FROM JSON FILES FOR EACH VAR AND STORE AS A
        # SINGLE DICTIONARY
        var_cmip5_dics = {}
        mods = set()
        json_files = glob.glob(
            os.path.join(
                pcmdi_metrics.__path__[0],
                "..",
                "..",
                "..",
                "..",
                "share",
                "CMIP_metrics_results",
                "CMIP5",
                "amip",
                "*.json"))

        for fnm in json_files:
            f = open(fnm)
            d = json.load(f)
            var = os.path.basename(fnm).split("_")[0]
            vars.append(var)
            for m in d.keys():
                mods.add(m)
            if var in var_cmip5_dics:
                var_cmip5_dics[var].update(d)
            else:
                var_cmip5_dics[var] = d

        vars.sort()
        mods = sorted(list(mods))
        print "Models:",mods
        for bad in ["GridInfo", "References", "RegionalMasking",
                    "metrics_git_sha1", "uvcdat_version"]:
            if bad in mods:
                mods.remove(bad)
            else:
                print "Not removing column %s (not present)" % bad

        # ORGANIZE METRICS INTO A VARIABLES X MODELS MATRIX

        out1_rel = MV2.zeros(
            (len(vars),
             len(mods)),
            MV2.float32)  # DEFINE ARRAY

        vn = -1  # VARIABLE INDEX
        for var in vars:  # LOOP OVER VARIABLE
            vn = vn + 1

            vals = []
            for mod in mods:  # LOOP OVER MODEL
                try:
                    rms = var_cmip5_dics[var][mod]["defaultReference"][
                        "r1i1p1"]["global"]['rms_xyt_ann_GLB']
                    if P.verbose:
                        print var, ' ', mod, '  ', repr(rms), ' WITH global'
                except:
                    rms = 1.e20
                    if P.verbose:
                        print var, ' ', mod, '  ', repr(rms), ' missing'

                rms = float(rms)
                vals.append(rms)

            vars_ar = MV2.array(vals)
            # COMPUTE MEDIAN RESULT FOR PORTRAIT NORMALIZATION
            med_rms = statistics.median(vars_ar)[0]

            mn = -1  # MODEL INDEX
            for mod in mods:
                mn = mn + 1
                try:
                    out1_rel[vn, mn] = (float(var_cmip5_dics[var][mod]["defaultReference"][
                                        "r1i1p1"]["global"]['rms_xyt_ann_GLB']) - med_rms) / med_rms  # RELATIVE ERROR
                except:
                    out1_rel[vn, mn] = numpy.ma.masked

        # ADD SPACES FOR LABELS TO ALIGN AXIS LABELS WITH PLOT
        modsAxis = mods
        varsAxis = vars

        # LOOP THROUGH LISTS TO ADD SPACES
        for i in range(len(modsAxis)):
            modsAxis[i] = modsAxis[i] + '  '
        for i in range(len(varsAxis)):
            varsAxis[i] = varsAxis[i] + '  '

        yax = [s.encode('utf-8')
               for s in mods]  # CHANGE FROM UNICODE TO BYTE STRINGS
        xax = vars

        # GENERATE PLOT
        P.decorate(out1_rel, xax, yax)
        # P.plot(out1_rel,x=x,multiple=1.1,bg=0)  # FOR PLOTTING TRIANGLES WHEN
        # USING TWO OR MORE REFERENCE DATA SETS
        P.plot(out1_rel, bg=1, x=x)
        # x.backend.renWin.Render()

        # END OF PLOTTING

        # SAVE PLOT
        src = os.path.join(os.path.dirname(__file__), "testPortrait.png")
        print src
        fnm = os.path.join(os.getcwd(), "testPortrait.png")
        x.png(fnm)
        ret = checkimage.check_result_image(
            fnm,
            src,
            checkimage.defaultThreshold)
        if ret != 0:
            sys.exit(ret)
Example #21
0
 U = U(lon=(-105.0, -15.0),lev=(1000.0, 0.10000000100000001),lat=(7.0, 50.0),squeeze=1,)
 canvas = vcs.init()
 gm3D_Scalar = vcs.get3d_scalar('default')
 args = []
 args.append(U)
 gm3D_Scalar.VerticalScaling = 1.0
 gm3D_Scalar.IsosurfaceValue = 24.463887522462002
 gm3D_Scalar.ToggleVolumePlot =  vcs.on
 gm3D_Scalar.ScaleColormap = [-15.383988656109274, 10.447561660497996, 1]
 gm3D_Scalar.ScaleTransferFunction = [6.016036405845739, 12.382244144298838, 1]
 gm3D_Scalar.XSlider = -105.0
 gm3D_Scalar.ScaleOpacity = [0.0, 0.42135967065922453]
 gm3D_Scalar.Animation = 0.0
 gm3D_Scalar.ZSlider = 0.0, vcs.on
 gm3D_Scalar.YSlider = 7.0, vcs.on
 kwargs = { 'cdmsfile': f.id }
 args.append( gm3D_Scalar )
 canvas.plot( *args, **kwargs )
 plotApp = canvas.backend.plotApps[ gm3D_Scalar ]
 
 test_image = 'dv3d_basic_run_test.png'
 reference_image = 'dv3d_basic_run_test_ref.png'
 canvas.png( test_image )
 
 if image_check:
     import checkimage
     ret = checkimage.check_result_image( test_image, reference_image, checkimage.defaultThreshold )
     print " Image Test returned:  %d " % ret
     sys.exit(ret)
     
 canvas.interact()
Example #22
0
import cdms2
import vcs
x=vcs.init()
import sys,os
src = sys.argv[1]
pth = os.path.join(os.path.dirname(src),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(sys.prefix+"/sample_data/clt.nc")
s=f("clt",slice(0,15))
x.plot(s,bg=1)
x.animate.create(thread_it=0)
x.animate.save("test_vcs_anim_basic.mp4")

cmd = "ffmpeg -i test_vcs_anim_basic.mp4 test_anim_basic_out_%d.png"
import subprocess
import shlex
p=subprocess.Popen(shlex.split(cmd))
p.wait()

ret = 0 
## now check the generated images
for i in range(15):
 src_img = src % (i+1)
 ret+=checkimage.check_result_image("test_anim_basic_out_%i.png" % (i+1),src_img,0.05)
sys.exit(ret)
Example #23
0
# Initialize canvas:
canvas = vcs.init()
canvas.setbgoutputdimensions(1200,1091,units="pixels")
canvas.drawlogooff()

# Create and plot quick boxfill with default settings:
boxfill=canvas.createboxfill()

# Change the type
boxfill.boxfill_type = 'custom'
levels = range(20,81,10)
boxfill.levels=levels
boxfill.ext_1="y"
boxfill.ext_2="y"
boxfill.fillareacolors=vcs.getcolors(boxfill.levels)

canvas.plot(clt, boxfill, bg=1)

# Load the image testing module:
testingDir = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(testingDir)
import checkimage

# Create the test image and compare:
baseline = sys.argv[1]
testFile = "test_boxfill_custom_ext1_ext2.png"
canvas.png(testFile)
ret = checkimage.check_result_image(testFile, baseline,
                                    checkimage.defaultThreshold)
sys.exit(ret)
Example #24
0
     -6.74967902  -7.09622319  -5.93836983  -4.04592997  -2.65591499
        -1.68180032  -0.86935245  -0.40114047  -0.54273785  -1.36178957
           -2.67488251  -3.87524401  -4.84708491  -5.49186142  -5.28618944
              -4.30557389  -2.89804038  -1.53825408  -1.84771029  -2.74948361
                 -2.23517037  -1.73306118  -0.71200646   0.76416785   1.51511193
                    -0.04018418  -1.54564706  -1.88664877  -0.43751604   0.89988184
                        0.33437949  -1.70341844  -3.79880014  -4.03570169  -4.7740073
                           -5.04626101  -3.77609961  -3.18667176  -2.21038272  -1.3666902
                              -0.54267951  -0.16472441  -0.52871418  -0.83520848  -0.90315403
                                 -0.21747426   0.01922666   0.89621996   1.75691927   3.12657503
                                     4.55749531   6.04921304   7.20744489   7.65294958""".split()
data = numpy.array(data,dtype=numpy.float)
data = MV2.array(data)

data=MV2.masked_where(MV2.logical_and(data>-4,data<-2),data)

#yx.datawc_x1 = 0
#yx.datawc_x2 = 80
##yx.datawc_y1 =-12 
#yx.datawc_y2 = 12 


x.plot(data,yx,bg=1)
fnm = "test_vcs_1d_missing.png"
x.png(fnm)

print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)
import vcs_legacy
x=vcs_legacy.init()
import sys,os
src = sys.argv[1]
pth = os.path.join(os.path.dirname(src),"..")
sys.path.append(pth)
import checkimage

m=x.createmarker()
m.x=[.5]
m.y=[.5]
m.type=18
m.size = 24
m.color=242
x.plot(m,bg=1)
x.setbgoutputdimensions(1200,1091,units="pixels")
x.png("test_vcs_legacy_hurricane_marker")

ret = checkimage.check_result_image("test_vcs_legacy_hurricane_marker.png",src,0.05)
sys.exit(ret)
Example #26
0
import sys
import time
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",slice(0,12)) # read only 12 times steps to speed up things

x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

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:
  print "Checking:",p
  ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
if ret == 0:
    os.removedirs(os.path.split(p)[0])
    os.remove("%s.mp4" % prefix)
sys.exit(ret)
  vcs._colorMap = "blue_to_grn"
  x.setcolormap("blue_to_grey")
else:
  ## Still setting vcs and canvas to make sure it is not used
  vcs._colorMap = "blue_to_grn"
  x.setcolormap("blue_to_grey")
  gm.colormap = "blue_to_orange"

if args.gm != "meshfill":
  f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
  if args.gm == "vector":
    u = f("u")
    v = f("v")
  else:
    s=f("clt",slice(0,1))
else:
  f=cdms2.open(os.path.join(vcs.sample_data,'sampleCurveGrid4.nc'))
  s=f("sample")
if args.gm == "vector":
  x.plot(u,v,gm,bg=True)
else:
  x.plot(s,gm,bg=True)

fnm = "test_vcs_colormaps_source_%s_%s.png" % (args.gm,args.src)
x.png(fnm)
baselineImage = args.baseline
ret = checkimage.check_result_image(fnm, baselineImage,
                                    checkimage.defaultThreshold)

sys.exit(ret)
Example #28
0
import vcs_legacy
x = vcs_legacy.init()
import sys, os
src = sys.argv[1]
pth = os.path.join(os.path.dirname(src), "..")
sys.path.append(pth)
import checkimage

m = x.createmarker()
m.x = [.5]
m.y = [.5]
m.type = 18
m.size = 24
m.color = 242
x.plot(m, bg=1)
x.setbgoutputdimensions(1200, 1091, units="pixels")
x.png("test_vcs_legacy_hurricane_marker")

ret = checkimage.check_result_image("test_vcs_legacy_hurricane_marker.png",
                                    src, 0.05)
sys.exit(ret)
Example #29
0
    text.height = 12
    colors.append(100 + 12 * i)
    if i%2 == 0:
      texts.append(text.name)
    else:
      texts.append(text)
isoline.text = texts

# First test using isoline.text[...].color
canvas.plot(data, isoline, bg=1)

baselineImage = "%s%s"%baseline
testImage = os.path.abspath("test_isoline_labels.png")
canvas.png(testImage)

ret = checkimage.check_result_image(testImage, baselineImage,
                                    checkimage.defaultThreshold)

# Now set isoline.linecolors and test again.
canvas.clear()
isoline.linecolors = colors
canvas.plot(data, isoline, bg=1)

baselineImage = "%s%d%s"%(baseline[0], 2, baseline[1])
testImage = os.path.abspath("test_isoline_labels2.png")
canvas.png(testImage)

ret += checkimage.check_result_image(testImage, baselineImage,
                                     checkimage.defaultThreshold)

# Now set isoline.textcolors and test again.
canvas.clear()
import sys, os, cdms2, vcs
import vcs
src1 = sys.argv[1]
src2 = sys.argv[2]
pth = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(pth)
import checkimage
x = vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200, 1091, units="pixels")
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)
print "fnm:", fnm
print "src:", src1
ret = checkimage.check_result_image(fnm, src1, checkimage.defaultThreshold)
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)
print "fnm:", fnm
print "src:", src2
ret += checkimage.check_result_image(fnm, src2, checkimage.defaultThreshold)
sys.exit(ret)
Example #31
0
    text.height = 12
    colors.append(100 + 12 * i)
    if i % 2 == 0:
        texts.append(text.name)
    else:
        texts.append(text)
isoline.text = texts

# First test using isoline.text[...].color
canvas.plot(data, isoline, bg=1)

baselineImage = "%s%s" % baseline
testImage = os.path.abspath("test_isoline_labels.png")
canvas.png(testImage)

ret = checkimage.check_result_image(testImage, baselineImage,
                                    checkimage.defaultThreshold)

# Now set isoline.linecolors and test again.
canvas.clear()
isoline.linecolors = colors
canvas.plot(data, isoline, bg=1)

baselineImage = "%s%d%s" % (baseline[0], 2, baseline[1])
testImage = os.path.abspath("test_isoline_labels2.png")
canvas.png(testImage)

ret += checkimage.check_result_image(testImage, baselineImage,
                                     checkimage.defaultThreshold)

# Now set isoline.textcolors and test again.
canvas.clear()
Example #32
0
diagstr = "diags --outputdir '%s' --model path=%s,climos=no --obs path=%s,filter=\"f_contains('NCEP')\",climos=yes --varopts 850 --package AMWG --set 5 --var T --seasons ANN" % (pathout,path1,path2)
# nonstandard, suitable for testing:
#diagstr = "diags --outputdir '%s' --model path=%s,climos=yes --obs path=%s,filter=\"f_contains('NCEP')\",climos=yes --varopts 850 --package AMWG --set 5 --var T --seasons ANN" % (pathout,os.path.join(datadir,'cam_output_climo'),path2)
proc = subprocess.Popen([diagstr],shell=True)
proc_status = proc.wait()
if proc_status!=0: 
    raise DiagError("diags run failed")

# Test of graphics (png) file match:
# This just looks at combined plot, aka summary plot, which is a compound of three plots.
filename = 'set5_Global_ANN_T-combined.png'
fname = os.path.join( pathout, filename )
baselinefname = os.path.join( baselinepath, filename )
threshold = 1.0e6
graphics_result = checkimage.check_result_image( fname, baselinefname, threshold )
print "Graphics file",fname,"match difference:",graphics_result

# Test of NetCDF data (nc) file match:
rtol = 1.0e-3
atol = 1.0e-2   # suitable for temperatures
filename = 'T_ANN_at_850_mbar_(1)_None.nc'
varname = 'dv_T_lp_ANN_ft0_None_None'
close1 = closeness( varname, filename, pathout, baselinepath, rtol, atol )
filename = 'T_ANN_at_850_mbar_(2)_None.nc'
varname = 'dv_T_lp_ANN_ft1_None_None'
close2 = closeness( varname, filename, pathout, baselinepath, rtol, atol )
filename = 'T_ANN_at_850_mbar_(1)-(2)_None,_None.nc'
varname = 'dv_T_lp_ANN_ft0_None_None_dv_T_lp_ANN_ft1_None_None'
close12 = closeness( varname, filename, pathout, baselinepath, rtol, atol )
close = close1 and close2 and close12
-0.14836133615864944 -0.17956528904564023 -0.21109198032585794
-0.23846429237248942 -0.2598536549218765 -0.27795672866320387
-0.2939939095159731 -0.30541031366330024 -0.307643559333884
-0.30078421139811795 -0.2841339526883441 -0.26485737397202497
-0.24287299694779327 -0.22379014890999907 -0.20121548204699846
-0.1746486732156772 -0.14585019344118372 -0.12070675757803526
-0.0997891159111037 -0.08229393660994214 -0.06779720501287469
-0.057213385470859794 -0.04875768191096844 -0.0402377347189964
-0.030169328367807245 -0.017560662894847895 -0.006968922654137132
0.0009773980274431048 0.007054306637034288 0.010472286514133042
0.010702384151997032 0.009231553701801242 0.007544033101056543
0.004639797857203645 -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999.
""".split()
data = numpy.array(data,dtype=numpy.float)
data = MV2.masked_less(data,-900)
#yx.datawc_x1 = 0
#yx.datawc_x2 = 80
##yx.datawc_y1 =-12 
#yx.datawc_y2 = 12 


x.plot(data,yx,bg=1)
fnm = "test_vcs_1D_datawc_missing.png"
x.png(fnm)
print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,0.05)
sys.exit(ret)
Example #34
0
    def test_portrait(self):
        try:
            import vcs
        except:
            raise RuntimeError(
                "Sorry your python is not build with VCS support cannot geenrate portrait plots")

        import json
        # CDAT MODULES
        import pcmdi_metrics
        import pcmdi_metrics.graphics.portraits
        import MV2
        import numpy
        from genutil import statistics
        import os
        import sys
        import glob

        print
        print
        print
        print
        print "---------------------------------------------------"
        print "RUNNING: Portrait test"
        print "---------------------------------------------------"
        print
        print
        print
        print
        # CREATES VCS OBJECT AS A PORTAIT PLOT AND LOADS PLOT SETTINGS FOR
        # EXAMPLE
        x = vcs.init()
        x.portrait()
        # Turn off antialiasing for test suite
        x.setantialiasing(0)

        # PARAMETERS STUFF
        P = pcmdi_metrics.graphics.portraits.Portrait()

        # Turn off verbosity
        P.verbose = False

        P.PLOT_SETTINGS.levels = [-1.e20, -.5, -.4, -.3, -.2, -.1,
                                  0., .1, .2, .3, .4, .5, 1.e20]

        P.PLOT_SETTINGS.x1 = .1
        P.PLOT_SETTINGS.x2 = .85
        P.PLOT_SETTINGS.y1 = .12
        P.PLOT_SETTINGS.y2 = .95

        P.PLOT_SETTINGS.xtic2y1 = P.PLOT_SETTINGS.y1
        P.PLOT_SETTINGS.xtic2y2 = P.PLOT_SETTINGS.y2
        P.PLOT_SETTINGS.ytic2x1 = P.PLOT_SETTINGS.x1
        P.PLOT_SETTINGS.ytic2x2 = P.PLOT_SETTINGS.x2

        # P.PLOT_SETTINGS.missing_color = 3
        # P.PLOT_SETTINGS.logo = None
        P.PLOT_SETTINGS.time_stamp = None
        P.PLOT_SETTINGS.draw_mesh = 'n'
        # P.PLOT_SETTINGS.tictable.font = 3

        x.scriptrun(
            os.path.join(
                sys.prefix,
                "share",
                "pmp",
                "graphics",
                'vcs',
                'portraits.scr'))
        P.PLOT_SETTINGS.colormap = 'bl_rd_12'
        # cols=vcs.getcolors(P.PLOT_SETTINGS.levels,range(16,40),split=1)
        cols = vcs.getcolors(P.PLOT_SETTINGS.levels, range(144, 156), split=1)
        P.PLOT_SETTINGS.fillareacolors = cols

        P.PLOT_SETTINGS.parametertable.expansion = 100

        # LIST OF VARIABLES TO BE USED IN PORTRAIT PLOT
        vars = [
            'pr',
            'rsut',
            'rsutcs',
            'rlutcs',
            'tas',
            'tos',
            'sos',
            'zos',
            'ua-850',
            'ua-200',
            'zg-500']
        vars = []

        # LOAD METRICS DICTIONARIES FROM JSON FILES FOR EACH VAR AND STORE AS A
        # SINGLE DICTIONARY
        var_cmip5_dics = {}
        mods = set()
        json_files = glob.glob(
            os.path.join(
                os.path.dirname(__file__),
                "json",
                "*.json"))

        for fnm in json_files:
            f = open(fnm)
            d = json.load(f)
            var = os.path.basename(fnm).split("_")[0]
            vars.append(var)
            for m in d.keys():
                mods.add(m)
            if var in var_cmip5_dics:
                var_cmip5_dics[var].update(d)
            else:
                var_cmip5_dics[var] = d

        vars.sort()
        mods = sorted(list(mods))
        print "Models:", mods
        for bad in ["GridInfo", "References", "RegionalMasking",
                    "metrics_git_sha1", "uvcdat_version"]:
            if bad in mods:
                mods.remove(bad)
            else:
                print "Not removing column %s (not present)" % bad

        # ORGANIZE METRICS INTO A VARIABLES X MODELS MATRIX

        out1_rel = MV2.zeros(
            (len(vars),
             len(mods)),
            MV2.float32)  # DEFINE ARRAY

        vn = -1  # VARIABLE INDEX
        for var in vars:  # LOOP OVER VARIABLE
            vn = vn + 1

            vals = []
            for mod in mods:  # LOOP OVER MODEL
                try:
                    rms = var_cmip5_dics[var][mod]["defaultReference"][
                        "r1i1p1"]["global"]['rms_xyt_ann_GLB']
                    if P.verbose:
                        print var, ' ', mod, '  ', repr(rms), ' WITH global'
                except:
                    rms = 1.e20
                    if P.verbose:
                        print var, ' ', mod, '  ', repr(rms), ' missing'

                rms = float(rms)
                vals.append(rms)

            vars_ar = MV2.array(vals)
            # COMPUTE MEDIAN RESULT FOR PORTRAIT NORMALIZATION
            med_rms = statistics.median(vars_ar)[0]

            mn = -1  # MODEL INDEX
            for mod in mods:
                mn = mn + 1
                try:
                    out1_rel[vn, mn] = (float(var_cmip5_dics[var][mod]["defaultReference"][
                                        "r1i1p1"]["global"]['rms_xyt_ann_GLB']) - med_rms) / med_rms  # RELATIVE ERROR
                except:
                    out1_rel[vn, mn] = numpy.ma.masked

        # ADD SPACES FOR LABELS TO ALIGN AXIS LABELS WITH PLOT
        modsAxis = mods
        varsAxis = vars

        # LOOP THROUGH LISTS TO ADD SPACES
        for i in range(len(modsAxis)):
            modsAxis[i] = modsAxis[i] + '  '
        for i in range(len(varsAxis)):
            varsAxis[i] = varsAxis[i] + '  '

        yax = [s.encode('utf-8')
               for s in mods]  # CHANGE FROM UNICODE TO BYTE STRINGS
        xax = vars

        # GENERATE PLOT
        P.decorate(out1_rel, xax, yax)
        # P.plot(out1_rel,x=x,multiple=1.1,bg=0)  # FOR PLOTTING TRIANGLES WHEN
        # USING TWO OR MORE REFERENCE DATA SETS
        P.plot(out1_rel, bg=1, x=x)
        # x.backend.renWin.Render()

        # END OF PLOTTING

        # SAVE PLOT
        src = os.path.join(os.path.dirname(__file__), "testPortrait.png")
        print src
        fnm = os.path.join(os.getcwd(), "testPortrait.png")
        x.png(fnm)
        ret = checkimage.check_result_image(
            fnm,
            src,
            checkimage.defaultThreshold)
        if ret != 0:
            sys.exit(ret)
import vcs
import cdms2
import os,sys
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s=f("clt")
x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
iso=x.createisoline()
t=x.createtext()
t.color=243
t.height=25
to=x.createtextorientation()
to.height = 55
tt=x.createtexttable()
tt.color=245
iso.textcolors=[None,None,None,242,244]
iso.text=[t,tt,to]
iso.label="y"
x.plot(s,iso,bg=1)
x.png("test_vcs_isoline_labels_multi_label_input_types.png")

src=sys.argv[1]

ret = checkimage.check_result_image('test_vcs_isoline_labels_multi_label_input_types.png',src,checkimage.defaultThreshold)
sys.exit(ret)
Example #36
0
dataonly = vcs.createtemplate()
dataonly.blank()
dataonly.data.priority = 1

multitemplate = EzTemplate.Multi(template=dataonly, rows=4, columns=3)

line_styles = ['long-dash', 'dot', 'dash', 'dash-dot', 'solid']

for i in range(12):
    cont_index = i % 6 + 1
    cont_line = vcs.createline()
    cont_line.width = i % 3 + 1
    cont_line.type = line_styles[i % 5]
    cont_line.color = i + 200
    template = multitemplate.get(i)
    canvas.plot(clt, template, boxfill, continents=cont_index, continents_line=cont_line, bg=1)

# Load the image testing module:
testingDir = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(testingDir)
import checkimage

# Create the test image and compare:
baseline = sys.argv[1]
testFile = "test_continents.png"
canvas.png(testFile)
ret = checkimage.check_result_image(testFile, baseline,
                                    25)
sys.exit(ret)
-0.058062458673116 -0.08764922509099882 -0.11697036914487152
-0.14836133615864944 -0.17956528904564023 -0.21109198032585794
-0.23846429237248942 -0.2598536549218765 -0.27795672866320387
-0.2939939095159731 -0.30541031366330024 -0.307643559333884
-0.30078421139811795 -0.2841339526883441 -0.26485737397202497
-0.24287299694779327 -0.22379014890999907 -0.20121548204699846
-0.1746486732156772 -0.14585019344118372 -0.12070675757803526
-0.0997891159111037 -0.08229393660994214 -0.06779720501287469
-0.057213385470859794 -0.04875768191096844 -0.0402377347189964
-0.030169328367807245 -0.017560662894847895 -0.006968922654137132
0.0009773980274431048 0.007054306637034288 0.010472286514133042
0.010702384151997032 0.009231553701801242 0.007544033101056543
0.004639797857203645 -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999.
""".split()
data = numpy.array(data, dtype=numpy.float)
data = MV2.masked_less(data, -900)
#yx.datawc_x1 = 0
#yx.datawc_x2 = 80
##yx.datawc_y1 =-12
#yx.datawc_y2 = 12

x.plot(data, yx, bg=1)
fnm = "test_vcs_1D_datawc_missing.png"
x.png(fnm)
print "fnm:", fnm
print "src:", src
ret = checkimage.check_result_image(fnm, src, 0.05)
sys.exit(ret)
Example #38
0
sys.path.append(pth)
import checkimage

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 = vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200, 1091, units="pixels")

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:
    print "Checking:", p
    ret += checkimage.check_result_image(
        p, os.path.join(pth,
                        os.path.split(p)[1]), checkimage.defaultThreshold)
if ret == 0:
    os.removedirs(os.path.split(p)[0])
    os.remove("%s.mp4" % prefix)
sys.exit(ret)
import vcs
import cdms2
import os,sys
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
f=cdms2.open(os.path.join(sys.prefix,"sample_data","clt.nc"))
s=f("clt")
x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
iso=x.createisoline()
t=x.createtext()
t.color=243
t.height=25
to=x.createtextorientation()
to.height = 55
tt=x.createtexttable()
tt.color=245
iso.textcolors=[None,None,None,242,244]
iso.text=[t,tt,to]
iso.label="y"
x.plot(s,iso,bg=1)
x.png("test_vcs_isoline_labels_multi_label_input_types.png")

src=sys.argv[1]

ret = checkimage.check_result_image('test_vcs_isoline_labels_multi_label_input_types.png',src,checkimage.defaultThreshold)
sys.exit(ret)
Example #40
0
x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

m = x.createmarker()
M=7
m.worldcoordinate=[0,M,0,M]
m.type = wmo
m.color=[242,]
m.size=[10.,]
xs = []
ys=[]
for Y in range(7):
  for X in range(15):
    ys.append([M-M*(Y+1)/8.,])
    xs.append([M*(X+1)/16.,])
m.x = xs
m.y = ys
m.list()
x.plot(m,bg=1)
fnm = "wmo_markers.png"
x.png(fnm)


print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)

Example #41
0
diagstr = "diags --outputdir '%s' --model path=%s,climos=no --obs path=%s,filter=\"f_contains('NCEP')\",climos=yes --varopts 850 --package AMWG --set 5 --var T --seasons ANN" % (
    pathout, path1, path2)
# nonstandard, suitable for testing:
#diagstr = "diags --outputdir '%s' --model path=%s,climos=yes --obs path=%s,filter=\"f_contains('NCEP')\",climos=yes --varopts 850 --package AMWG --set 5 --var T --seasons ANN" % (pathout,os.path.join(datadir,'cam_output_climo'),path2)
proc = subprocess.Popen([diagstr], shell=True)
proc_status = proc.wait()
if proc_status != 0:
    raise DiagError("diags run failed")

# Test of graphics (png) file match:
# This just looks at combined plot, aka summary plot, which is a compound of three plots.
filename = 'set5_Global_ANN_T-combined.png'
fname = os.path.join(pathout, filename)
baselinefname = os.path.join(baselinepath, filename)
threshold = 1.0e6
graphics_result = checkimage.check_result_image(fname, baselinefname,
                                                threshold)
print "Graphics file", fname, "match difference:", graphics_result

# Test of NetCDF data (nc) file match:
rtol = 1.0e-3
atol = 1.0e-2  # suitable for temperatures
filename = 'T_ANN_at_850_mbar_(1)_None.nc'
varname = 'dv_T_lp_ANN_ft0_None_None'
close1 = closeness(varname, filename, pathout, baselinepath, rtol, atol)
filename = 'T_ANN_at_850_mbar_(2)_None.nc'
varname = 'dv_T_lp_ANN_ft1_None_None'
close2 = closeness(varname, filename, pathout, baselinepath, rtol, atol)
filename = 'T_ANN_at_850_mbar_(1)-(2)_None,_None.nc'
varname = 'dv_T_lp_ANN_ft0_None_None_dv_T_lp_ANN_ft1_None_None'
close12 = closeness(varname, filename, pathout, baselinepath, rtol, atol)
close = close1 and close2 and close12
Example #42
0
           s2-=s2
    if args.zero:
       s-=s

if args.bigvalues:
    gm.levels = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1.e36]

if gm_type=="vector":
    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"
fnm+=nm_xtra
x.png(fnm)
print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm+'.png',src,checkimage.defaultThreshold, cleanup=not args.keep)
if args.show:
    raw_input("Press Enter")
sys.exit(ret)
isoline = canvas.createisoline()
isoline.label = "y"
texts = []
colors = []
levels = []
for i in range(7):
    levels.append(i*10)
    text = canvas.createtext()
    text.color = 255 - 20 * i
    text.height = 12
    colors.append(10 + 10 * i)
    if i % 2 == 0:
        texts.append(text.name)
    else:
        texts.append(text)
isoline.levels = levels
isoline.text = texts
isoline.linecolors = colors

isoline.linewidths = (1, 2, 3, 4, 1)
isoline.line = ('dot', 'dash', 'solid', 'dash-dot', 'long-dash', 'dot', 'dash')

# Next plot the isolines with labels
canvas.plot(data, isoline, bg=1)

testImage = os.path.abspath("test_isoline_width_stipple.png")
canvas.png(testImage)

ret = checkimage.check_result_image(testImage, baselineImage, 30)
sys.exit(ret)