-
Notifications
You must be signed in to change notification settings - Fork 37
/
test_pmp_portraits.py
112 lines (93 loc) · 3.66 KB
/
test_pmp_portraits.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
#!/usr/bin/env python
from __future__ import print_function
import basepmpgraphics
import os
import pcmdi_metrics.graphics.portraits
import MV2
import numpy
import genutil
import vcs
import sys
import pkg_resources
one = pkg_resources.Requirement.parse("pcmdi_metrics")
try:
egg_pth = pkg_resources.resource_filename(one, "share/pmp")
except Exception:
# python 2 seems to fail when ran in home directory of source?
egg_pth = os.path.join(os.getcwd(), "share", "pmp")
class TestPortraits(basepmpgraphics.TestGraphics):
def __init__(self,*args,**kargs):
kargs["geometry"] = {"width":814,"height":606}
super(TestPortraits,self).__init__(*args,**kargs)
def test_portrait(self):
print()
print()
print()
print()
print("---------------------------------------------------")
print("RUNNING: Portrait test")
print("---------------------------------------------------")
print()
print()
print()
print()
# CREATES VCS OBJECT AS A PORTAIT PLOT AND LOADS PLOT SETTINGS FOR
# EXAMPLE
self.x.portrait()
# PARAMETERS STUFF
P = pcmdi_metrics.graphics.portraits.Portrait()
# Turn off verbosity
P.verbose = False
P.PLOT_SETTINGS.levels = [-1.e20, -.5, -.4, -.3, -.2, -.1,
0., .1, .2, .3, .4, .5, 1.e20]
P.PLOT_SETTINGS.x1 = .1
P.PLOT_SETTINGS.x2 = .85
P.PLOT_SETTINGS.y1 = .12
P.PLOT_SETTINGS.y2 = .95
P.PLOT_SETTINGS.xtic2.y1 = P.PLOT_SETTINGS.y1
P.PLOT_SETTINGS.xtic2.y2 = P.PLOT_SETTINGS.y2
P.PLOT_SETTINGS.ytic2.x1 = P.PLOT_SETTINGS.x1
P.PLOT_SETTINGS.ytic2.x2 = P.PLOT_SETTINGS.x2
# P.PLOT_SETTINGS.missing_color = 3
P.PLOT_SETTINGS.logo = os.path.join(egg_pth, "graphics", "png", "PCMDILogo-old_348x300px_72dpi.png")
P.PLOT_SETTINGS.logo.y = .95
P.PLOT_SETTINGS.logo.x = .93
P.PLOT_SETTINGS.logo.width = 85
P.PLOT_SETTINGS.time_stamp = None
P.PLOT_SETTINGS.draw_mesh = 'n'
# P.PLOT_SETTINGS.tictable.font = 3
self.x.scriptrun(
os.path.join(
egg_pth,
"graphics",
'vcs',
'portraits.scr'))
P.PLOT_SETTINGS.colormap = 'bl_rd_12'
# cols=vcs.getcolors(P.PLOT_SETTINGS.levels,range(16,40),split=1)
cols = vcs.getcolors(P.PLOT_SETTINGS.levels, list(range(144, 156)), split=1)
P.PLOT_SETTINGS.fillareacolors = cols
P.PLOT_SETTINGS.parametertable.expansion = 100
J = self.loadJSON()
mods = sorted(J.getAxis("model")[:])
variables = sorted(J.getAxis("variable")[:])
print("MODELS:",len(mods),mods)
print("VARS:",len(variables),variables)
# Get what we need
out1_rel = J(statistic=["rms_xyt"],season=["ann"],region="global")(squeeze=1)
out1_rel, med = genutil.grower(out1_rel,genutil.statistics.median(out1_rel,axis=1)[0])
out1_rel[:] = (out1_rel.asma() - med.asma())/ med.asma()
# ADD SPACES FOR LABELS TO ALIGN AXIS LABELS WITH PLOT
modsAxis = mods
variablesAxis = variables
# LOOP THROUGH LISTS TO ADD SPACES
for i in range(len(modsAxis)):
modsAxis[i] = modsAxis[i] + ' '
for i in range(len(variablesAxis)):
variablesAxis[i] = variablesAxis[i] + ' '
yax = [str(s) for s in mods]
# GENERATE PLOT
P.decorate(out1_rel, variables, yax)
# USING TWO OR MORE REFERENCE DATA SETS
P.plot(out1_rel, x=self.x)
fnm = os.path.join(os.getcwd(), "testPortrait.png")
self.checkImage(fnm)