Exemple #1
0
 def creategraphicsmethod(self, typeName, name, nameSource):
     """Creates a graphicsmethod 'name' with type 'typeName' as a copy of 'nameSource'"""
     typeName = str(typeName)
     name = str(name)
     if (nameSource is None):
         nameSource = 'default'
     else:
         nameSource = str(nameSource)
     vcs.creategraphicsmethod(typeName, nameSource, name)
     return self.getgraphicsmethod(typeName, name)
Exemple #2
0
 def creategraphicsmethod(self, typeName, name, nameSource):
     """Creates a graphicsmethod 'name' with type 'typeName' as a copy of 'nameSource'"""
     typeName = str(typeName)
     name = str(name)
     if (nameSource is None):
         nameSource = 'default'
     else:
         nameSource = str(nameSource)
     vcs.creategraphicsmethod(typeName, nameSource, name)
     return self.getgraphicsmethod(typeName, name)
    def projected(self, gm_type, projtype="default"):
        s = None

        if gm_type == "meshfill":
            f = cdms2.open(os.path.join(vcs.sample_data,
                                        "sampleCurveGrid4.nc"))
            s2 = f("sample")

            s = MV2.resize(s2, (4, 32, 48))
            s.id = 'sample'
            t = cdms2.createAxis(range(4))
            t.units = "months since 2015"
            t.id = "time"
            t.designateTime()
            s.setAxis(0, t)
            s.setAxis(1, s2.getAxis(0))
            s.setAxis(2, s2.getAxis(1))
            s.setGrid(s2.getGrid())
            for i in range(4):
                s[i] = s[i] * (1 + float(i) / 10.)
        else:
            s = self.clt("clt", slice(
                0, 12))  # read only 12 times steps to speed up things

        gm = vcs.creategraphicsmethod(gm_type, "default")
        if projtype != "default":
            p = vcs.createprojection()
            try:
                ptype = int(projtype)
            except:
                ptype = projtype
            p.type = ptype
            gm.projection = p

        self.x.clear()
        self.x.plot(s, gm, bg=self.bg)
        self.x.animate.create()

        prefix = "test_vcs_animate_%s_%s" % (gm_type.lower(), projtype.lower())
        self.x.animate.save("%s.mp4" % prefix)
        pngs = self.x.animate.close(
            preserve_pngs=True)  # so we can look at them again

        pdir = os.path.split(pngs[0])[0]
        p = os.path.join(pdir, "anim_0.png")
        src = os.path.join(
            self.basedir, "test_vcs_animate_projected_%s_%s.png" %
            (gm_type.lower(), projtype.lower()))
        self.checkImage(p, pngReady=True, src=src)
        for f in pngs:
            if os.path.isfile(f):
                os.remove(f)
        os.removedirs(pdir)
        os.remove("%s.mp4" % prefix)
Exemple #4
0
    def testVCSreset1only(self):
        for gtype in vcs.listelements():
            b0 = vcs.listelements(gtype)
            if gtype == 'colormap':
                b = vcs.createcolormap()
                xtra = vcs.createisofill()
                untouched = vcs.listelements("isofill")
            elif gtype == "template":
                b = vcs.createtemplate()
            elif gtype == "textcombined":
                b = vcs.createtextcombined()
            elif gtype == "textorientation":
                b = vcs.createtextorientation()
            elif gtype == "texttable":
                b = vcs.createtexttable()
            elif gtype == "fillarea":
                b = vcs.createfillarea()
            elif gtype == "projection":
                b = vcs.createprojection()
            elif gtype == "marker":
                b = vcs.createmarker()
            elif gtype == "line":
                b = vcs.createline()
            elif gtype in ["display", "font", "fontNumber", "list", "format"]:
                vcs.manageElements.reset()
                continue
            else:
                b = vcs.creategraphicsmethod(gtype)
            if gtype != "colormap":
                xtra = vcs.createcolormap()
                untouched = vcs.listelements("colormap")
            b1 = vcs.listelements(gtype)
            self.assertNotEqual(b0, b1)
            vcs.manageElements.reset(gtype)
            b2 = vcs.listelements(gtype)
            self.assertEqual(b0, b2)
            if gtype == "colormap":
                self.assertEqual(untouched, vcs.listelements("isofill"))
            else:
                self.assertEqual(untouched, vcs.listelements("colormap"))
            vcs.manageElements.reset()
            if gtype == "colormap":
                self.assertNotEqual(untouched, vcs.listelements("isofill"))
            else:
                self.assertNotEqual(untouched, vcs.listelements("colormap"))

        # case for 1d weirdness
        sc = vcs.createscatter()
        vcs.manageElements.reset()
Exemple #5
0
 def setGraphicsMethod(self, gm):
     if (isinstance(gm, list)):
         self._plot.graphics_method = vcs.getgraphicsmethod(gm[0], gm[1])
         return
     for t in vcs.listelements():
         if len(vcs.listelements(t)):
             o = vcs.elements[t].values()[0]
             if hasattr(o, "g_name"):
                 if o.g_name == gm["g_name"]:
                     break
     else:
         return False
     my_gm = vcs.creategraphicsmethod(t)
     for k in gm:
         if k == "name":
             continue
         if gm[k] == 100000000000000000000:
             gm[k] = 1e20
         if gm[k] == -100000000000000000000:
             gm[k] = -1e20
         if isinstance(gm[k], list):
             conv = []
             for v in gm[k]:
                 if v == 100000000000000000000:
                     conv.append(1e20)
                 elif v == -100000000000000000000:
                     conv.append(-1e20)
                 else:
                     conv.append(v)
             gm[k] = conv
         if hasattr(my_gm, k):
             try:
                 setattr(my_gm, k, gm[k])
             except:
                 print "Could not set attribute %s on graphics method of type %s" % (
                     k, t)
     if "ext_1" in gm:
         my_gm.ext_1 = gm["ext_1"]
     if "ext_2" in gm:
         my_gm.ext_2 = gm["ext_2"]
     self._plot.graphics_method = my_gm
Exemple #6
0
    def setGraphicsMethod(self, gm):
        if (isinstance(gm, list)):
            self._plot.graphics_method = vcs.getgraphicsmethod(gm[0], gm[1])
            return
        for t in vcs.listelements():
            if len(vcs.listelements(t)):
                o = list(vcs.elements[t].values())[0]
                if hasattr(o, "g_name"):
                    if o.g_name == gm["g_name"]:
                        break
        else:
            return False

        my_gm = vcs.creategraphicsmethod(t)
        updateGraphicsMethodProps(gm, my_gm)

        if "ext_1" in gm:
            my_gm.ext_1 = gm["ext_1"]
        if "ext_2" in gm:
            my_gm.ext_2 = gm["ext_2"]
        self._plot.graphics_method = my_gm
Exemple #7
0
 def isSlowingDown(self, gmtype):
     n = 100
     print("Testing slow down for:", gmtype)
     maxpct = 100.
     fastest = 100000.
     avg = 0.
     times = []
     for i in range(n):
         start = time.time()
         gm = vcs.creategraphicsmethod(gmtype)
         gm.datawc_x1 = 0.
         gm.datawc_x2 = 2.
         gm.datawc_y1 = 0.
         gm.datawc_y2 = 2.
         self.x.plot(gm, *self.gmtypes[gmtype])
         end = time.time()
         elapsed = end - start
         if elapsed < fastest:
             fastest = elapsed
         pct = (elapsed / fastest * 100.)
         times.append(elapsed)
         if i > 5 and pct > maxpct:  # skip the first 5 times to make sure system gets in groovy mode
             maxpct = pct
         avg += elapsed
         self.x.clear()
         self.x.removeobject(gm)
         print(elapsed)
     a, b = numpy.polyfit(numpy.arange(n - 5),
                          numpy.array(times[5:]) / fastest, 1)
     print("\tMax percentage", maxpct)
     print("\tFastest time:", fastest)
     print("\tAvg time:", avg / n)
     print("\tFit coeff:", a, b)
     if a > 25.E-2:
         return True
     return False
    def gmPatternHatch(self,
                       gm_type="isofill",
                       fill_style="pattern",
                       projtype="default",
                       lat1=-90,
                       lat2=90,
                       lon1=-180,
                       lon2=180,
                       contig=True):

        self.x.setcolormap("classic")

        gm = vcs.creategraphicsmethod(gm_type, "default")
        if projtype != "default":
            p = vcs.createprojection()
            try:
                ptype = int(projtype)
            except:
                ptype = projtype
            p.type = ptype
            gm.projection = p

        if contig:
            gm.levels = [220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320]
        else:
            gm.levels = [[230, 235], [240, 245], [250, 255], [260, 265],
                         [270, 275], [280, 285], [290, 295], [300, 305],
                         [310, 315], [320, 325]]
        gm.fillareastyle = fill_style
        gm.fillareacolors = [242, 244, 237, 248, 250, 252, 44, 243, 139, 247]
        if fill_style == "hatch":
            gm.fillareaindices = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
            gm.fillareaopacity = [50, 75, 20, 100, 25, 30, 40, 80, 60, 100]
        else:
            gm.fillareaindices = [1, 3, 5, 7, 9, 11, 18, 15, 17, 19]
            gm.fillareaopacity = [50, 75, 20, 0, 25, 30, 100, 0, 60, 0]

        if gm_type == "boxfill":
            gm.boxfill_type = "custom"

        if gm_type == "meshfill":
            gm.mesh = True

        nm_xtra = ""
        xtra = {}
        if lat1 != lat2:
            gm.datawc_y1 = lat1
            gm.datawc_y2 = lat2
            xtra["latitude"] = (lat1, lat2)
            if lat1 < 0:
                nm_xtra += "_SH"
            else:
                nm_xtra += "_NH"
        if lon1 != lon2:
            xtra["longitude"] = (lon1, lon2)
            nm_xtra += "_%i_%i" % (lon1, lon2)
        if not 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()
        self.x.clear()
        self.x.plot(s, gm, bg=self.bg)
        fnm = "test_vcs_%s_%s" % (gm_type.lower(), fill_style.lower())
        if projtype != "default":
            fnm += "_%s_proj" % projtype
        fnm += nm_xtra
        self.checkImage(fnm + ".png")
p.add_argument("--non-contiguous", dest="contig", default=True, action="store_false", help="use non contiguous levels")

args = p.parse_args(sys.argv[1:])

gm_type = args.gm
src = args.src

bg = not args.show

x = vcs.init()
x.setantialiasing(0)
x.setcolormap("classic")

if bg:
    x.setbgoutputdimensions(1200, 1091, units="pixels")
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

if args.contig:
    gm.levels = [220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320]
else:
    gm.levels = [[230, 235], [240, 245], [250, 255], [260, 265], [270, 275],
                 [280, 285], [290, 295], [300, 305], [310, 315], [320, 325]]
gm.fillareastyle = args.fill_style
Exemple #10
0
               help="use non contiguous levels")

args = p.parse_args(sys.argv[1:])

gm_type = args.gm
src = args.src

bg = not args.show

x = vcs.init()
x.setantialiasing(0)
x.setcolormap("classic")

if bg:
    x.setbgoutputdimensions(1200, 1091, units="pixels")
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

if args.contig:
    gm.levels = [220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320]
else:
    gm.levels = [[230, 235], [240, 245], [250, 255], [260, 265], [270, 275],
                 [280, 285], [290, 295], [300, 305], [310, 315], [320, 325]]
gm.fillareastyle = args.fill_style