|
| 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