Skip to content

Commit 9d6bed6

Browse files
committed
Tests for animation of projected plots
1 parent de8d649 commit 9d6bed6

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

testing/vcs/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,18 @@ cdat_add_test(vcs_test_taylor_2_quads
652652
ENDFOREACH(style)
653653
ENDFOREACH(gm)
654654

655+
FOREACH(gm isofill meshfill boxfill)
656+
FOREACH(proj polar robinson mercator mollweide lambert)
657+
cdat_add_test(vcs_test_animate_projected_${gm}_${proj}
658+
"${PYTHON_EXECUTABLE}"
659+
"${cdat_SOURCE_DIR}/testing/vcs/test_vcs_gms_animate_projected_plots.py"
660+
--gm_type=${gm}
661+
--projection_type=${proj}
662+
--source_dir=${BASELINE_DIR}
663+
)
664+
ENDFOREACH(proj)
665+
ENDFOREACH(gm)
666+
655667
FOREACH(flip None X XY Y)
656668
cdat_add_test(vcs_test_flip${flip}
657669
"${PYTHON_EXECUTABLE}"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Test animation of projected plots
2+
3+
import argparse
4+
import cdms2
5+
import MV2
6+
import os
7+
import sys
8+
import vcs
9+
10+
pth = os.path.join(os.path.dirname(__file__), "..")
11+
sys.path.append(pth)
12+
import checkimage # noqa
13+
14+
p = argparse.ArgumentParser(description="Testing animation of projected plots")
15+
p.add_argument("--gm_type", dest="gm", help="gm to test")
16+
p.add_argument("--projection_type", dest="projtype", default="default",
17+
help="use a specific projection type")
18+
p.add_argument("--source_dir", dest="src", help="baseline directory")
19+
p.add_argument("--keep", dest="keep", action="store_true", default=False,
20+
help="Save images, even if baseline matches.")
21+
p.add_argument("--threshold", dest="threshold", type=int,
22+
default=checkimage.defaultThreshold,
23+
help="Threshold value for image differnces")
24+
25+
args = p.parse_args(sys.argv[1:])
26+
27+
gm_type = args.gm
28+
29+
x = vcs.init()
30+
x.setantialiasing(0)
31+
x.drawlogooff()
32+
x.setbgoutputdimensions(1200, 1091, units="pixels")
33+
34+
s = None
35+
36+
if gm_type == "meshfill":
37+
f = cdms2.open(os.path.join(vcs.sample_data, "sampleCurveGrid4.nc"))
38+
s2 = f("sample")
39+
40+
s = MV2.resize(s2, (4, 32, 48))
41+
t = cdms2.createAxis(range(4))
42+
t.units = "months since 2015"
43+
t.id = "time"
44+
t.designateTime()
45+
s.setAxis(0, t)
46+
s.setAxis(1, s2.getAxis(0))
47+
s.setAxis(2, s2.getAxis(1))
48+
s.setGrid(s2.getGrid())
49+
for i in range(4):
50+
s[i] = s[i] * (1 + float(i)/10.)
51+
else:
52+
f = cdms2.open(os.path.join(vcs.sample_data, "clt.nc"))
53+
s = f("clt", slice(0, 12)) # read only 12 times steps to speed up things
54+
55+
gm = vcs.creategraphicsmethod(gm_type, "default")
56+
if args.projtype != "default":
57+
p = vcs.createprojection()
58+
try:
59+
ptype = int(args.projtype)
60+
except:
61+
ptype = args.projtype
62+
p.type = ptype
63+
gm.projection = p
64+
65+
x.plot(s, gm, bg=1)
66+
x.animate.create()
67+
68+
prefix = "test_vcs_animate_%s_%s" % (gm_type.lower(), args.projtype.lower())
69+
x.animate.save("%s.mp4" % prefix)
70+
pngs = x.animate.close(preserve_pngs=True) # so we can look at them again
71+
72+
baseline_pth = os.path.join(args.src, prefix)
73+
ret = 0
74+
for p in pngs:
75+
ret += checkimage.check_result_image(p, os.path.join(baseline_pth,
76+
os.path.split(p)[1]),
77+
args.threshold)
78+
if ret == 0 and not args.keep:
79+
os.removedirs(os.path.split(p)[0])
80+
os.remove("%s.mp4" % prefix)
81+
sys.exit(ret)

0 commit comments

Comments
 (0)