Пример #1
0
def plot_template():
    tmpl = json.loads(request.args["tmpl"])
    t = templ_from_json(tmpl)
    canvas = vcs.init(bg=True)
    g = vcs.createboxfill()
    g.xmtics1 = {.5 * i: "" for i in range(1,20,2)}
    g.xmtics2 = g.xmtics1
    g.ymtics1 = g.xmtics1
    g.ymtics2 = g.xmtics1
    ticlabels = {i: str(i) for i in range(10)}
    g.xticlabels1 = ticlabels
    g.yticlabels1 = ticlabels
    g.yticlabels2 = ticlabels
    g.xticlabels2 = ticlabels
    v = [[0] * 10] * 10
    v = cdms2.tvariable.TransientVariable(v)

    t.plot(canvas, v, g)
    if t.legend.priority:
        t.drawColorBar([(0,0,0,0)], [0, 1], x=canvas)
    _, tmp = tempfile.mkstemp(suffix=".png")
    # For certain templates the renWin can be None
    if(canvas.backend.renWin):
        # Only call render if renWin exists
        canvas.backend.renWin.Render()
        canvas.png(tmp)
    # create response from the tmp file, blank or otherwise
    resp = send_file(tmp)
    # Clean up file automatically after request
    wr = weakref.ref(resp, lambda x: os.remove(tmp))
    canvas.close()
    # clean up temporary boxfill and template we created
    del vcs.elements["boxfill"][g.name]
    del vcs.elements["template"][t.name]
    return resp
Пример #2
0
def plot_template():
    tmpl = json.loads(request.args["tmpl"])
    t = templ_from_json(tmpl)
    canvas = vcs.init(bg=True)
    g = vcs.createboxfill()
    g.xmtics1 = {.5 * i: "" for i in range(1,20,2)}
    g.xmtics2 = g.xmtics1
    g.ymtics1 = g.xmtics1
    g.ymtics2 = g.xmtics1
    ticlabels = {i: str(i) for i in range(10)}
    g.xticlabels1 = ticlabels
    g.yticlabels1 = ticlabels
    g.yticlabels2 = ticlabels
    g.xticlabels2 = ticlabels
    v = [[0] * 10] * 10
    v = cdms2.tvariable.TransientVariable(v)

    t.plot(canvas, v, g)
    if t.legend.priority:
        t.drawColorBar([(0,0,0,0)], [0, 1], x=canvas)

    canvas.backend.renWin.Render()

    del vcs.elements["template"][t.name]

    _, tmp = tempfile.mkstemp(suffix=".png")
    canvas.png(tmp)
    resp = send_file(tmp)
    # Clean up file automatically after request
    wr = weakref.ref(resp, lambda x: os.remove(tmp))
    canvas.close()
    return resp
Пример #3
0
def plot_template():
    tmpl = json.loads(request.args["tmpl"])
    t = templ_from_json(tmpl)
    canvas = vcs.init(bg=True)
    g = vcs.createboxfill()
    g.xmtics1 = {.5 * i: "" for i in range(1,20,2)}
    g.xmtics2 = g.xmtics1
    g.ymtics1 = g.xmtics1
    g.ymtics2 = g.xmtics1
    ticlabels = {i: str(i) for i in range(10)}
    g.xticlabels1 = ticlabels
    g.yticlabels1 = ticlabels
    g.yticlabels2 = ticlabels
    g.xticlabels2 = ticlabels
    v = [[0] * 10] * 10
    v = cdms2.tvariable.TransientVariable(v)

    t.plot(canvas, v, g)
    if t.legend.priority:
        t.drawColorBar([(0,0,0,0)], [0, 1], x=canvas)
    _, tmp = tempfile.mkstemp(suffix=".png")
    # For certain templates the renWin can be None
    if(canvas.backend.renWin):
        # Only call render if renWin exists
        canvas.backend.renWin.Render() 
        canvas.png(tmp)
    # create response from the tmp file, blank or otherwise
    resp = send_file(tmp) 
    # Clean up file automatically after request
    wr = weakref.ref(resp, lambda x: os.remove(tmp))
    canvas.close()
    # clean up temporary boxfill and template we created
    del vcs.elements["boxfill"][g.name] 
    del vcs.elements["template"][t.name]
    return resp
Пример #4
0
    def testExtend(self):

        box = vcs.createboxfill()

        box.ext_1 = True
        self.assertTrue(numpy.allclose(box.levels, [1e20] * 2))

        box.ext_2 = True
        self.assertTrue(numpy.allclose(box.levels, [1e20] * 2))

        box.levels = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        self.assertFalse(box.ext_1)
        self.assertFalse(box.ext_1)

        box.ext_1 = True
        self.assertTrue(box.levels[0] < -9e19)

        box.ext_2 = True
        self.assertTrue(box.levels[-1] > 9e19)

        box.ext_1 = False
        self.assertTrue(box.levels[0] > -9e19)

        box.ext_2 = False
        self.assertTrue(box.levels[-1] < 9e19)
Пример #5
0
def editors():
    editor = LegendEditorWidget()
    b = vcs.createboxfill()
    v = cdms2.open(vcs.sample_data + "/clt.nc")("clt")
    l = legend.VCSLegend(b, v)
    editor.setObject(l)

    return editor
Пример #6
0
def editors():
    box = vcs.createboxfill()
    tmpl = vcs.createtemplate()
    var = cdms2.open(vcs.sample_data + "/clt.nc")("clt")
    axis = VCSAxis(box, tmpl, "y1", var)

    edit_1 = AxisEditorWidget("x")
    edit_1.setAxisObject(axis)

    edit_2 = AxisEditorWidget("y")
    edit_2.setAxisObject(axis)

    return (edit_1, edit_2)
Пример #7
0
def editors():
    box = vcs.createboxfill()
    tmpl = vcs.createtemplate()
    var = cdms2.open(vcs.sample_data + "/clt.nc")("clt")
    axis = vcsaxis.VCSAxis(box, tmpl, "y1", var)

    edit_1 = AxisEditor.AxisEditorWidget("x")
    edit_1.setAxisObject(axis)

    edit_2 = AxisEditor.AxisEditorWidget("y")
    edit_2.setAxisObject(axis)

    return (edit_1, edit_2)
Пример #8
0
 def setUp(self):
     f = cdms2.open(os.path.join(cdat_info.get_sampledata_path(), "clt.nc"))
     s = f("clt", slice(0, 1))
     self.x = vcs.init(bg=True, geometry=(800, 600))
     b = vcs.createboxfill()
     t = vcs.createtemplate()
     to = vcs.createtextorientation()
     to.angle = 90
     t.xlabel1.textorientation = to
     b.xticlabels1 = {45: "45N"}
     b.datawc_x1 = -180
     b.datawc_x2 = 180.
     self.b = b
     self.t = t
     self.x.plot(s, b, t)
     self.x.png("testClick")
     self.s = s
Пример #9
0
 def testColorcells(self):
     b = vcs.createboxfill()
     x = vcs.init()
     b.colormap = "rainbow"
     x.setcolormap("rainbow")
     self.assertEqual(x.colormap, "rainbow")
     self.assertEqual(x.getcolormapname(), "rainbow")
     self.assertEqual(x.getcolormap().name, "default")
     self.assertEqual(x.getcolorcell(16), [55., 6., 98., 100.])
     self.assertEqual(vcs.getcolorcell(16, x), [55., 6., 98., 100.])
     self.assertEqual(vcs.getcolorcell(16, b), [55, 6., 98., 100.])
     vcs.setcolorcell("rainbow", 16, 100, 100, 100)
     self.assertEqual(x.getcolorcell(16), [100., 100., 100., 100.])
     x.setcolorcell(16, 0, 100, 0)
     self.assertEqual(x.getcolorcell(16), [0., 100., 0., 100.])
     vcs.setcolorcell(b, 16, 100, 100, 100)
     self.assertEqual(x.getcolorcell(16), [100., 100., 100., 100.])
Пример #10
0
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))
Пример #11
0
clt = clt_file("clt")

template = vcs.createtemplate()
template.blank()
template.data.priority = 1
template.box1.priority = 1
template.xtic1.priority = 1
template.ytic1.priority = 1
template.xtic2.priority = 1
template.ytic2.priority = 1

template.xlabel1.priority = 1
template.xlabel1.y = .2
template.ylabel1.priority = 1
template.ylabel1.x = .03

template.title.priority = 1

graphics_method = vcs.createboxfill()
graphics_method.yticlabels1 = {lat: " " if lat % 45 != 0 else  str(lat) for lat in range(-90, 90, 10)}
graphics_method.xticlabels1 = {lon: " " if lon % 90 != 0 else  str(lon) for lon in range(-180, 180, 10)}

multi = EzTemplate.Multi(template=template.name, columns=2, rows=5, top_margin=.05, bottom_margin=.1, left_margin = .1, right_margin = .1, vertical_spacing=.05)

for row in range(5):
	for col in range(2):
		tmpl_instance = multi.get(row=row, column=col)
		canvas.plot(clt, tmpl_instance, graphics_method, bg=1, ratio="autot")

canvas.png("multi.png")
Пример #12
0
 def save(self, name=None):
     if name is None:
         self.editedGM.emit(self.gm)
     else:
         gm = vcs.createboxfill(name, self.gm)
         self.createdGM.emit(gm)
Пример #13
0
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")
Пример #14
0
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))
Пример #15
0
 def save(self, name=None):
     if name is None:
         self.editedGM.emit(self.gm)
     else:
         gm = vcs.createboxfill(name, self.gm)
         self.createdGM.emit(gm)
Пример #16
0
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.createboxfill()

p = vcs.createprojection()
ptype = 'aeqd'
p.type = ptype
gm.projection = p

xtra = {}
gm.datawc_y1 = 0.0
gm.datawc_y2 = 90.0

xtra["latitude"] = (90.0, 0.0)

f = cdms2.open(os.path.join(vcs.prefix, 'sample_data', 'clt.nc'))
s = f("clt", **xtra)
x.plot(s, gm, bg=bg)

x.png('test_vcs_basic_boxfill_aeqd_proj_gmflip_NH_via_gm.png')
Пример #17
0
import vcs, numpy, cdms2, MV2, os, sys

src = sys.argv[1]
pth0 = os.path.dirname(__file__)
pth = os.path.join(pth0, "..")
sys.path.append(pth)
import checkimage

f = cdms2.open(os.path.join(pth0, "celine.nc"))
s = f("data")
x = vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.scriptrun(os.path.join(pth0, "celine.json"))
i = x.getisofill("celine")
b = vcs.createboxfill()
b.levels = i.levels
b.fillareacolors = i.fillareacolors
b.boxfill_type = "custom"
x.plot(s, b, bg=1)
fnm = "test_celine_iso_2.png"
x.png(fnm)

print "fnm:", fnm
print "src:", src
ret = checkimage.check_result_image(fnm, src, checkimage.defaultThreshold)
sys.exit(ret)
Пример #18
0
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")