-
Notifications
You must be signed in to change notification settings - Fork 68
/
test_vcs_basic_gms.py
149 lines (138 loc) · 4.44 KB
/
test_vcs_basic_gms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sys,os
import argparse
p = argparse.ArgumentParser(description="Basic gm testing code for vcs")
p.add_argument("--source", dest="src", help="source image file")
p.add_argument("--gm_type", dest="gm", help="gm to test")
p.add_argument("--show", dest="show", action="store_true",help="show plots on screen (no bg)")
p.add_argument("--projection-type", dest="projtype", default="default", help="use a specific projection type")
p.add_argument("--lat1", dest="lat1", default=0, type=float, help="First latitude")
p.add_argument("--lat2", dest="lat2", default=0, type=float, help="Last latitude")
p.add_argument("--lon1", dest="lon1", default=0, type=float, help="First Longitude")
p.add_argument("--lon2", dest="lon2", default=0, type=float, help="Last Longitude")
p.add_argument("--range_via_gm", dest="rg", action="store_true", help="Set the range via graphic method ")
p.add_argument("--gm_flips_lat_range", dest="flip", action="store_true", help="Set the range via graphic method to flip of data")
p.add_argument("--zero", dest="zero", action="store_true", help="Set the data to zero everywhere")
p.add_argument("--keep", dest="keep", action="store_true",help="Save image, even if baseline matches.")
p.add_argument("--transparent", dest="transparent", action="store_true",help="Add transparency to colors")
dataMods = p.add_mutually_exclusive_group()
dataMods.add_argument("--mask", dest="mask", action="store_true",help="mask out part of data")
dataMods.add_argument("--bigvalues", dest="bigvalues", action="store_true",help="replace some of the data with 1e40")
args = p.parse_args(sys.argv[1:])
gm_type= args.gm
src = args.src
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
import vcs
import sys
import cdms2
import vtk
import os
import MV2
bg = not args.show
x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
if bg:
x.setbgoutputdimensions(1200,1091,units="pixels")
x.setcolormap("rainbow")
exec("gm=vcs.create%s()" % gm_type)
if args.projtype != "default":
p = vcs.createprojection()
try:
ptype = int(args.projtype)
except:
ptype = args.projtype
p.type = ptype
gm.projection = p
nm_xtra=""
xtra = {}
if args.lat1!=args.lat2:
if args.rg:
if args.flip:
gm.datawc_y1=args.lat2
gm.datawc_y2=args.lat1
nm_xtra+="_gmflip"
else:
gm.datawc_y1=args.lat1
gm.datawc_y2=args.lat2
xtra["latitude"] = (args.lat1,args.lat2)
if args.lat1<0:
nm_xtra+="_SH"
else:
nm_xtra+="_NH"
if args.lon1!=args.lon2:
if args.rg:
gm.datawc_x1=args.lon1
gm.datawc_x2=args.lon2
xtra["longitude"] = (args.lon1,args.lon2)
nm_xtra+="_%i_%i" % (args.lon1,args.lon2)
if args.rg:
nm_xtra+="_via_gm"
if gm_type=="meshfill":
f=cdms2.open(os.path.join(vcs.sample_data,'sampleCurveGrid4.nc'))
else:
f=cdms2.open(os.path.join(vcs.sample_data,'clt.nc'))
if gm_type=="vector":
u=f("u",**xtra)
v=f("v",**xtra)
if args.mask:
u=MV2.masked_greater(u,58.)
if args.zero:
u-=u
v-=v
elif gm_type=="meshfill":
s=f("sample",**xtra)
if args.mask:
s=MV2.masked_less(s,1150.)
elif args.bigvalues:
s[s < 1150] = 1e40
if args.zero:
s-=s
else:
s=f("clt",**xtra)
if args.mask:
s=MV2.masked_greater(s,78.)
elif args.bigvalues:
s[s > 78] = 1e40
if gm_type in ["1d","yxvsx","xyvsy","xvsy","scatter"]:
s = s(latitude=(20,20,"cob"),longitude=(112,112,"cob"),squeeze=1)
s2=MV2.sin(s)
if args.zero:
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 args.transparent:
cmap = x.createcolormap()
for i in range(256): # tweaks all colors
cmap.setcolorcell(i,100.,0,0,i/2.55)
x.setcolormap(cmap)
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"
if args.transparent:
fnm+="_transparent"
fnm+=nm_xtra
x.png(fnm)
print "fnm:",fnm
print "src:",src
if args.show:
raw_input("Press Enter")
ret = checkimage.check_result_image(fnm+'.png',src,20., cleanup=not args.keep)
if args.show:
raw_input("Press Enter")
sys.exit(ret)